apikey.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
  6. <meta name="generator" content="pdoc3 0.11.6">
  7. <title>source.apikey API documentation</title>
  8. <meta name="description" content="">
  9. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/sanitize.min.css" integrity="sha512-y1dtMcuvtTMJc1yPgEqF0ZjQbhnc/bFhyvIyVNb9Zk5mIGtqVaAB1Ttl28su8AvFMOY0EwRbAe+HCLqj6W7/KA==" crossorigin>
  10. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/13.0.0/typography.min.css" integrity="sha512-Y1DYSb995BAfxobCkKepB1BqJJTPrOp3zPL74AWFugHHmmdcvO+C48WLrUOlhGMc0QG7AE3f7gmvvcrmX2fDoA==" crossorigin>
  11. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css" crossorigin>
  12. <style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:1.5em;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:2em 0 .50em 0}h3{font-size:1.4em;margin:1.6em 0 .7em 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .2s ease-in-out}a:visited{color:#503}a:hover{color:#b62}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900;font-weight:bold}pre code{font-size:.8em;line-height:1.4em;padding:1em;display:block}code{background:#f3f3f3;font-family:"DejaVu Sans Mono",monospace;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source > summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible;min-width:max-content}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em 1em;margin:1em 0}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
  13. <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul ul{padding-left:1em}.toc > ul > li{margin-top:.5em}}</style>
  14. <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
  15. <script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js" integrity="sha512-D9gUyxqja7hBtkWpPWGt9wfbfaMGVt9gnyCvYa+jojwwPHLCzUm5i8rpk7vD7wNee9bA35eYIjobYPaQuKS1MQ==" crossorigin></script>
  16. <script>window.addEventListener('DOMContentLoaded', () => {
  17. hljs.configure({languages: ['bash', 'css', 'diff', 'graphql', 'ini', 'javascript', 'json', 'plaintext', 'python', 'python-repl', 'rust', 'shell', 'sql', 'typescript', 'xml', 'yaml']});
  18. hljs.highlightAll();
  19. /* Collapse source docstrings */
  20. setTimeout(() => {
  21. [...document.querySelectorAll('.hljs.language-python > .hljs-string')]
  22. .filter(el => el.innerHTML.length > 200 && ['"""', "'''"].includes(el.innerHTML.substring(0, 3)))
  23. .forEach(el => {
  24. let d = document.createElement('details');
  25. d.classList.add('hljs-string');
  26. d.innerHTML = '<summary>"""</summary>' + el.innerHTML.substring(3);
  27. el.replaceWith(d);
  28. });
  29. }, 100);
  30. })</script>
  31. </head>
  32. <body>
  33. <main>
  34. <article id="content">
  35. <header>
  36. <h1 class="title">Module <code>source.apikey</code></h1>
  37. </header>
  38. <section id="section-intro">
  39. </section>
  40. <section>
  41. </section>
  42. <section>
  43. </section>
  44. <section>
  45. </section>
  46. <section>
  47. <h2 class="section-title" id="header-classes">Classes</h2>
  48. <dl>
  49. <dt id="source.apikey.apikey"><code class="flex name class">
  50. <span>class <span class="ident">apikey</span></span>
  51. <span>(</span><span>content: str)</span>
  52. </code></dt>
  53. <dd>
  54. <details class="source">
  55. <summary>
  56. <span>Expand source code</span>
  57. </summary>
  58. <pre><code class="python">class apikey:
  59. &#34;&#34;&#34;
  60. This class represents API key, and it is also creating new apikeys from
  61. device random numbers generator.
  62. Methods
  63. ------
  64. get_raw_size() : int
  65. Return size of bytes which was loaded from device random number
  66. generator.
  67. get_size() : int
  68. Return lenght of the API key as string.
  69. get_prefix() : str
  70. Return prefix of the API keys.
  71. create() : apikey
  72. Create new random API key.
  73. export() : str
  74. Export API key as string.
  75. &#34;&#34;&#34;
  76. def __init__(self, content: str) -&gt; None:
  77. &#34;&#34;&#34;
  78. It recreate API key object from key, which was previously exported
  79. to string.
  80. Raises
  81. ------
  82. ValueError
  83. When API key lenght is not correct.
  84. Parameters
  85. ---------
  86. content : str
  87. Preiviously exported API key string.
  88. &#34;&#34;&#34;
  89. if len(content) != self.get_size():
  90. raise ValueError(&#34;API key lenght is not correct.&#34;)
  91. self.__content = content
  92. def get_raw_size(self: object | None = None) -&gt; int:
  93. &#34;&#34;&#34;
  94. It return lenght of the random bytes in the API key.
  95. Returns
  96. -------
  97. int
  98. Lenght of the random bytes in the API key.
  99. &#34;&#34;&#34;
  100. return 128
  101. def get_size(self: object | None = None) -&gt; int:
  102. &#34;&#34;&#34;
  103. It return lenght of the API key string, with prefix and random bytes
  104. converted to the hex string.
  105. Returns
  106. -------
  107. int
  108. Lenght of the API key string.
  109. &#34;&#34;&#34;
  110. return len(apikey.get_prefix()) + apikey.get_raw_size() * 2
  111. def get_prefix(self: object | None = None) -&gt; str:
  112. &#34;&#34;&#34;
  113. It return API key prefix.
  114. Returns
  115. -------
  116. str
  117. Prefix for the API key.
  118. &#34;&#34;&#34;
  119. return &#34;cxtk_&#34;
  120. def create() -&gt; object:
  121. &#34;&#34;&#34;
  122. It create new API key from random number generator device.
  123. Returns
  124. -------
  125. apikey
  126. New random API key.
  127. &#34;&#34;&#34;
  128. raw = os.urandom(apikey.get_raw_size())
  129. key = apikey.get_prefix() + raw.hex()
  130. return apikey(key)
  131. def export(self) -&gt; str:
  132. &#34;&#34;&#34;
  133. It export API key as string.
  134. Returns
  135. -------
  136. str
  137. API key string content.
  138. &#34;&#34;&#34;
  139. return self.__content
  140. def __repr__(self) -&gt; str:
  141. &#34;&#34;&#34;
  142. It return readable API key description (first 32 letters).
  143. Returns
  144. -------
  145. str
  146. Readable API key description.
  147. &#34;&#34;&#34;
  148. return &#34;API key: \&#34;&#34; + self.__content[0:32] + &#34;...\&#34;&#34;
  149. def __str__(self) -&gt; str:
  150. &#34;&#34;&#34;
  151. It return API key string content.
  152. Returns
  153. -------
  154. str
  155. API key as string.
  156. &#34;&#34;&#34;
  157. return self.__content
  158. def __eq__(self, other) -&gt; bool:
  159. &#34;&#34;&#34;
  160. It check that API keys are same.
  161. Returns
  162. -------
  163. bool
  164. True when API keys are same.
  165. &#34;&#34;&#34;
  166. return self.__content == other.__content
  167. def __ne__(self, other) -&gt; bool:
  168. &#34;&#34;&#34;
  169. It check that API keys are not same.
  170. Returns
  171. -------
  172. bool
  173. True when API keys are not same.
  174. &#34;&#34;&#34;
  175. return self.__content != other.__content</code></pre>
  176. </details>
  177. <div class="desc"><p>This class represents API key, and it is also creating new apikeys from
  178. device random numbers generator.</p>
  179. <h2 id="methods">Methods</h2>
  180. <p>get_raw_size() : int
  181. Return size of bytes which was loaded from device random number
  182. generator.</p>
  183. <p>get_size() : int
  184. Return lenght of the API key as string.</p>
  185. <p>get_prefix() : str
  186. Return prefix of the API keys.</p>
  187. <p>create() : apikey
  188. Create new random API key.</p>
  189. <p>export() : str
  190. Export API key as string.</p>
  191. <p>It recreate API key object from key, which was previously exported
  192. to string.</p>
  193. <h2 id="raises">Raises</h2>
  194. <dl>
  195. <dt><code>ValueError</code></dt>
  196. <dd>When API key lenght is not correct.</dd>
  197. </dl>
  198. <h2 id="parameters">Parameters</h2>
  199. <dl>
  200. <dt><strong><code>content</code></strong> :&ensp;<code>str</code></dt>
  201. <dd>Preiviously exported API key string.</dd>
  202. </dl></div>
  203. <h3>Methods</h3>
  204. <dl>
  205. <dt id="source.apikey.apikey.create"><code class="name flex">
  206. <span>def <span class="ident">create</span></span>(<span>) ‑> object</span>
  207. </code></dt>
  208. <dd>
  209. <details class="source">
  210. <summary>
  211. <span>Expand source code</span>
  212. </summary>
  213. <pre><code class="python">def create() -&gt; object:
  214. &#34;&#34;&#34;
  215. It create new API key from random number generator device.
  216. Returns
  217. -------
  218. apikey
  219. New random API key.
  220. &#34;&#34;&#34;
  221. raw = os.urandom(apikey.get_raw_size())
  222. key = apikey.get_prefix() + raw.hex()
  223. return apikey(key)</code></pre>
  224. </details>
  225. <div class="desc"><p>It create new API key from random number generator device.</p>
  226. <h2 id="returns">Returns</h2>
  227. <dl>
  228. <dt><code><a title="source.apikey.apikey" href="#source.apikey.apikey">apikey</a></code></dt>
  229. <dd>New random API key.</dd>
  230. </dl></div>
  231. </dd>
  232. <dt id="source.apikey.apikey.export"><code class="name flex">
  233. <span>def <span class="ident">export</span></span>(<span>self) ‑> str</span>
  234. </code></dt>
  235. <dd>
  236. <details class="source">
  237. <summary>
  238. <span>Expand source code</span>
  239. </summary>
  240. <pre><code class="python">def export(self) -&gt; str:
  241. &#34;&#34;&#34;
  242. It export API key as string.
  243. Returns
  244. -------
  245. str
  246. API key string content.
  247. &#34;&#34;&#34;
  248. return self.__content</code></pre>
  249. </details>
  250. <div class="desc"><p>It export API key as string.</p>
  251. <h2 id="returns">Returns</h2>
  252. <dl>
  253. <dt><code>str</code></dt>
  254. <dd>API key string content.</dd>
  255. </dl></div>
  256. </dd>
  257. <dt id="source.apikey.apikey.get_prefix"><code class="name flex">
  258. <span>def <span class="ident">get_prefix</span></span>(<span>self: object | None = None) ‑> str</span>
  259. </code></dt>
  260. <dd>
  261. <details class="source">
  262. <summary>
  263. <span>Expand source code</span>
  264. </summary>
  265. <pre><code class="python">def get_prefix(self: object | None = None) -&gt; str:
  266. &#34;&#34;&#34;
  267. It return API key prefix.
  268. Returns
  269. -------
  270. str
  271. Prefix for the API key.
  272. &#34;&#34;&#34;
  273. return &#34;cxtk_&#34;</code></pre>
  274. </details>
  275. <div class="desc"><p>It return API key prefix.</p>
  276. <h2 id="returns">Returns</h2>
  277. <dl>
  278. <dt><code>str</code></dt>
  279. <dd>Prefix for the API key.</dd>
  280. </dl></div>
  281. </dd>
  282. <dt id="source.apikey.apikey.get_raw_size"><code class="name flex">
  283. <span>def <span class="ident">get_raw_size</span></span>(<span>self: object | None = None) ‑> int</span>
  284. </code></dt>
  285. <dd>
  286. <details class="source">
  287. <summary>
  288. <span>Expand source code</span>
  289. </summary>
  290. <pre><code class="python">def get_raw_size(self: object | None = None) -&gt; int:
  291. &#34;&#34;&#34;
  292. It return lenght of the random bytes in the API key.
  293. Returns
  294. -------
  295. int
  296. Lenght of the random bytes in the API key.
  297. &#34;&#34;&#34;
  298. return 128</code></pre>
  299. </details>
  300. <div class="desc"><p>It return lenght of the random bytes in the API key.</p>
  301. <h2 id="returns">Returns</h2>
  302. <dl>
  303. <dt><code>int</code></dt>
  304. <dd>Lenght of the random bytes in the API key.</dd>
  305. </dl></div>
  306. </dd>
  307. <dt id="source.apikey.apikey.get_size"><code class="name flex">
  308. <span>def <span class="ident">get_size</span></span>(<span>self: object | None = None) ‑> int</span>
  309. </code></dt>
  310. <dd>
  311. <details class="source">
  312. <summary>
  313. <span>Expand source code</span>
  314. </summary>
  315. <pre><code class="python">def get_size(self: object | None = None) -&gt; int:
  316. &#34;&#34;&#34;
  317. It return lenght of the API key string, with prefix and random bytes
  318. converted to the hex string.
  319. Returns
  320. -------
  321. int
  322. Lenght of the API key string.
  323. &#34;&#34;&#34;
  324. return len(apikey.get_prefix()) + apikey.get_raw_size() * 2</code></pre>
  325. </details>
  326. <div class="desc"><p>It return lenght of the API key string, with prefix and random bytes
  327. converted to the hex string.</p>
  328. <h2 id="returns">Returns</h2>
  329. <dl>
  330. <dt><code>int</code></dt>
  331. <dd>Lenght of the API key string.</dd>
  332. </dl></div>
  333. </dd>
  334. </dl>
  335. </dd>
  336. </dl>
  337. </section>
  338. </article>
  339. <nav id="sidebar">
  340. <div class="toc">
  341. <ul></ul>
  342. </div>
  343. <ul id="index">
  344. <li><h3>Super-module</h3>
  345. <ul>
  346. <li><code><a title="source" href="index.html">source</a></code></li>
  347. </ul>
  348. </li>
  349. <li><h3><a href="#header-classes">Classes</a></h3>
  350. <ul>
  351. <li>
  352. <h4><code><a title="source.apikey.apikey" href="#source.apikey.apikey">apikey</a></code></h4>
  353. <ul class="">
  354. <li><code><a title="source.apikey.apikey.create" href="#source.apikey.apikey.create">create</a></code></li>
  355. <li><code><a title="source.apikey.apikey.export" href="#source.apikey.apikey.export">export</a></code></li>
  356. <li><code><a title="source.apikey.apikey.get_prefix" href="#source.apikey.apikey.get_prefix">get_prefix</a></code></li>
  357. <li><code><a title="source.apikey.apikey.get_raw_size" href="#source.apikey.apikey.get_raw_size">get_raw_size</a></code></li>
  358. <li><code><a title="source.apikey.apikey.get_size" href="#source.apikey.apikey.get_size">get_size</a></code></li>
  359. </ul>
  360. </li>
  361. </ul>
  362. </li>
  363. </ul>
  364. </nav>
  365. </main>
  366. <footer id="footer">
  367. <p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.11.6</a>.</p>
  368. </footer>
  369. </body>
  370. </html>