api-key-factory 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import click
4
+
5
+ from api_key_factory.factory.key import Key
6
+
7
+
8
+ @click.group()
9
+ @click.version_option("1.0.0", prog_name="api_key_factory")
10
+ def cli() -> None:
11
+ """A simple CLI tool to generate API keys and their corresponding
12
+ SHA-256 hashes.
13
+ """
14
+ pass
15
+
16
+
17
+ @cli.command()
18
+ @click.option(
19
+ "-n",
20
+ "--num",
21
+ "num",
22
+ type=click.IntRange(min=1),
23
+ default=1,
24
+ help="Number of API keys to generate",
25
+ )
26
+ def generate(
27
+ num: int,
28
+ ) -> None:
29
+ """Command to generate API keys and their corresponding SHA-256 hashes.
30
+
31
+ Args:
32
+ num (int): Number of API keys to generate. Default 1.
33
+
34
+ Raises:
35
+ click.ClickException: Error when writing output file
36
+ """
37
+ for _ in range(num):
38
+ key = Key()
39
+ click.echo(f"{key.get_value()} {key.get_hash()}")
40
+
41
+
42
+ if __name__ == "__main__":
43
+ cli() # pragma: no cover
File without changes
@@ -0,0 +1,50 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import hashlib
4
+ import uuid
5
+
6
+ from pydantic import BaseModel
7
+
8
+
9
+ class Key(BaseModel):
10
+ """Utility class for creating keys."""
11
+
12
+ prefix: str
13
+ rand_uuid: str
14
+
15
+ def __init__(self, prefix: str = ""):
16
+ """Constructor.
17
+
18
+ Args:
19
+ prefix (str): Prefix of the token. Default empty.
20
+ """
21
+ rand_uuid = uuid.uuid4()
22
+
23
+ super().__init__(prefix=prefix, rand_uuid=str(rand_uuid))
24
+
25
+ def get_value(self) -> str:
26
+ """Get the token as a string.
27
+
28
+ Returns:
29
+ str: The token string.
30
+ """
31
+ if len(self.prefix) > 0:
32
+ value = self.prefix + "-" + self.rand_uuid
33
+ else:
34
+ value = self.rand_uuid
35
+
36
+ return value
37
+
38
+ def get_hash(self) -> str:
39
+ """Get the token as a hashed SHA-256 string.
40
+
41
+ Returns:
42
+ str: The hashed token string.
43
+ """
44
+ value = self.get_value()
45
+
46
+ hash_object = hashlib.sha256()
47
+ value_encoded = value.encode("utf-8")
48
+ hash_object.update(value_encoded)
49
+
50
+ return hash_object.hexdigest()
@@ -0,0 +1,119 @@
1
+ Metadata-Version: 2.3
2
+ Name: api-key-factory
3
+ Version: 1.0.0
4
+ Summary: A simple CLI tool to generate API Key
5
+ Project-URL: Homepage, https://gitlab.com/op_so/projects/api-key-factory
6
+ Project-URL: Documentation, https://op_so.gitlab.io/projects/api-key-factory
7
+ Author-email: FX Soubirou <soubirou@yahoo.fr>
8
+ License: MIT
9
+ License-File: LICENSE
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.10
14
+ Requires-Dist: click>=8.1.7
15
+ Requires-Dist: pydantic>=2.6.3
16
+ Description-Content-Type: text/markdown
17
+
18
+ # `api-key-factory`
19
+
20
+ [![Software License](https://img.shields.io/badge/license-MIT-informational.svg?style=for-the-badge)](LICENSE)
21
+ [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release&style=for-the-badge)](https://github.com/semantic-release/semantic-release)
22
+ [![Pipeline Status](https://gitlab.com/op_so/projects/api-key-factory/badges/main/pipeline.svg)](https://gitlab.com/op_so/projects/api-key-factory/pipelines)
23
+
24
+ [![Built with Material for MkDocs](https://img.shields.io/badge/Material_for_MkDocs-526CFE?style=for-the-badge&logo=MaterialForMkDocs&logoColor=white)](https://op_so.gitlab.io/projects/api-key-factory/) Source code documentation
25
+
26
+ A CLI tool to generate API keys and their corresponding [SHA-256](https://en.wikipedia.org/wiki/SHA-2) hashes. The secret part of the key is an [UUID (Universally Unique Identifier) version 4 (random)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_(random)).
27
+
28
+ Example of generated a API key:
29
+
30
+ ```bash
31
+ mykey-8590efb6-0a68-4390-8537-99a54928c669
32
+ ```
33
+
34
+ ```bash
35
+ Usage: api-key-factory [OPTIONS] COMMAND [ARGS]...
36
+
37
+ A simple CLI tool to generate API keys and their corresponding SHA-256
38
+ hashes.
39
+
40
+ Options:
41
+ --version Show the version and exit.
42
+ --help Show this message and exit.
43
+
44
+ Commands:
45
+ generate Command to generate API keys and their corresponding SHA-256...
46
+ ```
47
+
48
+ ## `generate`
49
+
50
+ Get all files with `yaml/yml` extension from the input directory and generate the
51
+ markdown files in the output directory.
52
+
53
+ ```bash
54
+ Usage: api-key-factory generate [OPTIONS]
55
+
56
+ Command to generate API keys and their corresponding SHA-256 hashes.
57
+
58
+ Raises: click.ClickException: Error when writing output file
59
+
60
+ Options:
61
+ -n, --num INTEGER RANGE Number of API keys to generate [x>=1]
62
+ --help Show this message and exit.
63
+ ```
64
+
65
+ Example:
66
+
67
+ ```bash
68
+ $ api-key-factory generate
69
+ e4feb87a-ff10-4cce-bbe2-3b9dcbeb019c 1e6d309d41b3a1b7a4855aba3382bdafcb7476db97416a7ecd9fcabe4292c5ca
70
+ ```
71
+
72
+ ## Installation
73
+
74
+ ### With `Python` environment
75
+
76
+ To use:
77
+
78
+ - Minimal Python version: 3.10
79
+
80
+ Installation with Python `pip`:
81
+
82
+ ```bash
83
+ python3 -m pip install api-key-factory
84
+ api-key-factory --help
85
+ ```
86
+
87
+ ## Develpement
88
+
89
+ ### With [Rye](https://rye.astral.sh/)
90
+
91
+ To use:
92
+
93
+ - Minimal Python version: 3.10
94
+
95
+ Installation documentation: [https://rye.astral.sh/guide/installation/](https://rye.astral.sh/guide/installation/)
96
+
97
+ ```bash
98
+ # Set environment
99
+ rye sync
100
+ # Lint
101
+ rye run lint
102
+ # Tests
103
+ rye run test
104
+ # Run
105
+ rye run api-key-factory --help
106
+ ```
107
+
108
+ ## Authors
109
+
110
+ <!-- vale off -->
111
+ - **FX Soubirou** - *Initial work* - [GitLab repositories](https://gitlab.com/op_so)
112
+ <!-- vale on -->
113
+
114
+ ## License
115
+
116
+ <!-- vale off -->
117
+ This program is free software: you can redistribute it and/or modify it under the terms of the MIT License (MIT).
118
+ See the [LICENSE](https://opensource.org/licenses/MIT) for details.
119
+ <!-- vale on -->
@@ -0,0 +1,9 @@
1
+ api_key_factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ api_key_factory/api_key_factory.py,sha256=ND7tLAkohaOdciN0D_Fp_AWHD7oH5B-THb5ngfHp50Q,878
3
+ api_key_factory/factory/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ api_key_factory/factory/key.py,sha256=VhYB6xnJ0SImyi1Fx-gJoLBdx6jKy94Hj0UojvchmDY,1096
5
+ api_key_factory-1.0.0.dist-info/METADATA,sha256=ZOvaSZwebczOY0kJV0YXq_hvIjtWUgPhYI0SrJvnUyY,3525
6
+ api_key_factory-1.0.0.dist-info/WHEEL,sha256=1yFddiXMmvYK7QYTqtRNtX66WJ0Mz8PYEiEUoOUUxRY,87
7
+ api_key_factory-1.0.0.dist-info/entry_points.txt,sha256=PP2deter2inrdochHMX1lhnf1qXh7vlmOkEx6dd4p4g,72
8
+ api_key_factory-1.0.0.dist-info/licenses/LICENSE,sha256=6j37YDpY2ikwX8yV80eUpAGPDShonchJW9nyFpqAGKM,1095
9
+ api_key_factory-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.25.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ api-key-factory = api_key_factory.api_key_factory:cli
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2024 FX Soubirou soubirou@yahoo.fr
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.