api-key-factory 1.0.0__tar.gz
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.
- api_key_factory-1.0.0/.gitignore +18 -0
- api_key_factory-1.0.0/.gitlab-ci.yml +35 -0
- api_key_factory-1.0.0/.markdownlint.yaml +9 -0
- api_key_factory-1.0.0/.pre-commit-config.yaml +23 -0
- api_key_factory-1.0.0/.python-version +1 -0
- api_key_factory-1.0.0/.releaserc +26 -0
- api_key_factory-1.0.0/.vale.ini +8 -0
- api_key_factory-1.0.0/.yamllint +13 -0
- api_key_factory-1.0.0/LICENSE +21 -0
- api_key_factory-1.0.0/PKG-INFO +119 -0
- api_key_factory-1.0.0/README.md +102 -0
- api_key_factory-1.0.0/Taskfile.project.yml +52 -0
- api_key_factory-1.0.0/Taskfile.yml +187 -0
- api_key_factory-1.0.0/docs/api_key_factory.md +2 -0
- api_key_factory-1.0.0/docs/cli.md +7 -0
- api_key_factory-1.0.0/docs/factory/key.md +2 -0
- api_key_factory-1.0.0/docs/index.md +5 -0
- api_key_factory-1.0.0/lychee.toml +2 -0
- api_key_factory-1.0.0/mkdocs.yml +19 -0
- api_key_factory-1.0.0/pyproject.toml +74 -0
- api_key_factory-1.0.0/requirements-dev.lock +139 -0
- api_key_factory-1.0.0/requirements.lock +23 -0
- api_key_factory-1.0.0/src/api_key_factory/__init__.py +0 -0
- api_key_factory-1.0.0/src/api_key_factory/api_key_factory.py +43 -0
- api_key_factory-1.0.0/src/api_key_factory/factory/__init__.py +0 -0
- api_key_factory-1.0.0/src/api_key_factory/factory/key.py +50 -0
- api_key_factory-1.0.0/tests/factory/test_key.py +48 -0
- api_key_factory-1.0.0/tests/test_api_key_factory.py +19 -0
- api_key_factory-1.0.0/tests/test_generate.py +46 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
include:
|
|
3
|
+
- remote: 'https://gitlab.com/op_so/projects/gitlab-ci-templates/-/raw/main/templates/lint.gitlab-ci.yml'
|
|
4
|
+
- remote: 'https://gitlab.com/op_so/projects/gitlab-ci-templates/-/raw/main/templates/lint.python-rye.gitlab-ci.yml'
|
|
5
|
+
- remote: 'https://gitlab.com/op_so/projects/gitlab-ci-templates/-/raw/main/templates/gitlab-release.gitlab-ci.yml'
|
|
6
|
+
- remote: 'https://gitlab.com/op_so/projects/gitlab-ci-templates/-/raw/main/templates/python.rye-publish.gitlab-ci.yml'
|
|
7
|
+
|
|
8
|
+
variables:
|
|
9
|
+
IMAGE_PYTHON: jfxs/rye
|
|
10
|
+
LINT_VALE: "false"
|
|
11
|
+
LINT_MARKDOWN_GLOB: '"**/*.md" "#docs"'
|
|
12
|
+
|
|
13
|
+
stages:
|
|
14
|
+
- lint
|
|
15
|
+
- tests
|
|
16
|
+
- gitlab-release
|
|
17
|
+
- pypi-release
|
|
18
|
+
- pages-release
|
|
19
|
+
|
|
20
|
+
tests:pytest:
|
|
21
|
+
image: $IMAGE_PYTHON
|
|
22
|
+
stage: tests
|
|
23
|
+
before_script:
|
|
24
|
+
- rye --version
|
|
25
|
+
- rye sync
|
|
26
|
+
- rye run pytest --version
|
|
27
|
+
- mkdir -p reports/cov
|
|
28
|
+
script:
|
|
29
|
+
- rye run test
|
|
30
|
+
|
|
31
|
+
gitlab-release:
|
|
32
|
+
retry: 1
|
|
33
|
+
before_script:
|
|
34
|
+
- npx semantic-release --dry-run --no-ci
|
|
35
|
+
- if [ -s .VERSION ]; then task 00:project-set-version VERSION=$(cat .VERSION); fi
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
repos:
|
|
3
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
4
|
+
rev: v4.5.0
|
|
5
|
+
hooks:
|
|
6
|
+
- id: trailing-whitespace
|
|
7
|
+
- id: end-of-file-fixer
|
|
8
|
+
- id: check-yaml
|
|
9
|
+
- id: check-added-large-files
|
|
10
|
+
# Hooks added from sample-config
|
|
11
|
+
- id: check-executables-have-shebangs
|
|
12
|
+
- id: check-json
|
|
13
|
+
- id: check-merge-conflict
|
|
14
|
+
- id: check-shebang-scripts-are-executable
|
|
15
|
+
- id: check-symlinks
|
|
16
|
+
- id: check-toml
|
|
17
|
+
- id: check-xml
|
|
18
|
+
- id: detect-private-key
|
|
19
|
+
- id: end-of-file-fixer
|
|
20
|
+
- id: fix-byte-order-marker
|
|
21
|
+
- id: mixed-line-ending
|
|
22
|
+
- id: trailing-whitespace
|
|
23
|
+
args: [--markdown-linebreak-ext=md]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12.5
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"branches": [
|
|
3
|
+
"main",
|
|
4
|
+
"master"
|
|
5
|
+
],
|
|
6
|
+
"plugins": [
|
|
7
|
+
"@semantic-release/commit-analyzer",
|
|
8
|
+
"@semantic-release/release-notes-generator",
|
|
9
|
+
[
|
|
10
|
+
"@semantic-release/exec",
|
|
11
|
+
{
|
|
12
|
+
"verifyReleaseCmd": "echo ${nextRelease.version} > .VERSION"
|
|
13
|
+
}
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
"@semantic-release/gitlab",
|
|
17
|
+
{
|
|
18
|
+
"assets": [
|
|
19
|
+
{
|
|
20
|
+
"path": "src/"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
]
|
|
26
|
+
}
|
|
@@ -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.
|
|
@@ -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
|
+
[](LICENSE)
|
|
21
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
22
|
+
[](https://gitlab.com/op_so/projects/api-key-factory/pipelines)
|
|
23
|
+
|
|
24
|
+
[](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,102 @@
|
|
|
1
|
+
# `api-key-factory`
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://github.com/semantic-release/semantic-release)
|
|
5
|
+
[](https://gitlab.com/op_so/projects/api-key-factory/pipelines)
|
|
6
|
+
|
|
7
|
+
[](https://op_so.gitlab.io/projects/api-key-factory/) Source code documentation
|
|
8
|
+
|
|
9
|
+
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)).
|
|
10
|
+
|
|
11
|
+
Example of generated a API key:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
mykey-8590efb6-0a68-4390-8537-99a54928c669
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
Usage: api-key-factory [OPTIONS] COMMAND [ARGS]...
|
|
19
|
+
|
|
20
|
+
A simple CLI tool to generate API keys and their corresponding SHA-256
|
|
21
|
+
hashes.
|
|
22
|
+
|
|
23
|
+
Options:
|
|
24
|
+
--version Show the version and exit.
|
|
25
|
+
--help Show this message and exit.
|
|
26
|
+
|
|
27
|
+
Commands:
|
|
28
|
+
generate Command to generate API keys and their corresponding SHA-256...
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## `generate`
|
|
32
|
+
|
|
33
|
+
Get all files with `yaml/yml` extension from the input directory and generate the
|
|
34
|
+
markdown files in the output directory.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
Usage: api-key-factory generate [OPTIONS]
|
|
38
|
+
|
|
39
|
+
Command to generate API keys and their corresponding SHA-256 hashes.
|
|
40
|
+
|
|
41
|
+
Raises: click.ClickException: Error when writing output file
|
|
42
|
+
|
|
43
|
+
Options:
|
|
44
|
+
-n, --num INTEGER RANGE Number of API keys to generate [x>=1]
|
|
45
|
+
--help Show this message and exit.
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Example:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
$ api-key-factory generate
|
|
52
|
+
e4feb87a-ff10-4cce-bbe2-3b9dcbeb019c 1e6d309d41b3a1b7a4855aba3382bdafcb7476db97416a7ecd9fcabe4292c5ca
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Installation
|
|
56
|
+
|
|
57
|
+
### With `Python` environment
|
|
58
|
+
|
|
59
|
+
To use:
|
|
60
|
+
|
|
61
|
+
- Minimal Python version: 3.10
|
|
62
|
+
|
|
63
|
+
Installation with Python `pip`:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
python3 -m pip install api-key-factory
|
|
67
|
+
api-key-factory --help
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Develpement
|
|
71
|
+
|
|
72
|
+
### With [Rye](https://rye.astral.sh/)
|
|
73
|
+
|
|
74
|
+
To use:
|
|
75
|
+
|
|
76
|
+
- Minimal Python version: 3.10
|
|
77
|
+
|
|
78
|
+
Installation documentation: [https://rye.astral.sh/guide/installation/](https://rye.astral.sh/guide/installation/)
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Set environment
|
|
82
|
+
rye sync
|
|
83
|
+
# Lint
|
|
84
|
+
rye run lint
|
|
85
|
+
# Tests
|
|
86
|
+
rye run test
|
|
87
|
+
# Run
|
|
88
|
+
rye run api-key-factory --help
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Authors
|
|
92
|
+
|
|
93
|
+
<!-- vale off -->
|
|
94
|
+
- **FX Soubirou** - *Initial work* - [GitLab repositories](https://gitlab.com/op_so)
|
|
95
|
+
<!-- vale on -->
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
<!-- vale off -->
|
|
100
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the MIT License (MIT).
|
|
101
|
+
See the [LICENSE](https://opensource.org/licenses/MIT) for details.
|
|
102
|
+
<!-- vale on -->
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
# https://taskfile.dev
|
|
3
|
+
#
|
|
4
|
+
# Taskfile.project.yml for your main project tasks. Must be commited.
|
|
5
|
+
# If you always want the last version of the task templates, add the following line in your .gitignore file
|
|
6
|
+
# /Taskfile.d/
|
|
7
|
+
#
|
|
8
|
+
version: '3'
|
|
9
|
+
|
|
10
|
+
vars:
|
|
11
|
+
# TO MODIFY: Task templates to download separated by comma
|
|
12
|
+
# Example: TASK_TEMPLATES: go,lint,yarn
|
|
13
|
+
TASK_TEMPLATES: git,lint
|
|
14
|
+
|
|
15
|
+
tasks:
|
|
16
|
+
|
|
17
|
+
00-get-list-templates:
|
|
18
|
+
# Get the list of templates to download
|
|
19
|
+
# Do not remove
|
|
20
|
+
cmds:
|
|
21
|
+
- echo "{{.TASK_TEMPLATES}}"
|
|
22
|
+
silent: true
|
|
23
|
+
|
|
24
|
+
project-set-version:
|
|
25
|
+
desc: "[PROJECT] Set version in different files. Arguments: VERSION|V=x.y.z"
|
|
26
|
+
vars:
|
|
27
|
+
PY_FILE_VERSION: src/api_key_factory/api_key_factory.py
|
|
28
|
+
MD_FILE_VERSION: docs/index.md
|
|
29
|
+
VERSION: '{{default .V .VERSION}}'
|
|
30
|
+
cmds:
|
|
31
|
+
- echo "Version {{.VERSION}}"
|
|
32
|
+
- sed -i.bu "s/0\.0\.0/{{.VERSION}}/g" pyproject.toml
|
|
33
|
+
- defer: rm -f pyproject.toml.bu
|
|
34
|
+
- sed -i.bu "s/0\.0\.0/{{.VERSION}}/g" {{.PY_FILE_VERSION}}
|
|
35
|
+
- defer: rm -f {{.PY_FILE_VERSION}}.bu
|
|
36
|
+
- sed -i.bu "s/0\.0\.0/{{.VERSION}}/g" {{.MD_FILE_VERSION}}
|
|
37
|
+
- defer: rm -f {{.MD_FILE_VERSION}}.bu
|
|
38
|
+
preconditions:
|
|
39
|
+
- sh: test -n "{{.VERSION}}"
|
|
40
|
+
msg: "VERSION|V argument is required"
|
|
41
|
+
silent: true
|
|
42
|
+
|
|
43
|
+
30-pre-commit:
|
|
44
|
+
desc: "[PROJECT] Pre-commit checks."
|
|
45
|
+
cmds:
|
|
46
|
+
- date > {{.FILE_TASK_START}}
|
|
47
|
+
- defer: rm -f {{.FILE_TASK_START}}
|
|
48
|
+
- task lint:pre-commit
|
|
49
|
+
- task lint:all MEX='"#docs" "#styles" "#Taskfile.d" "#.venv" "#.cache"'
|
|
50
|
+
- echo "run also -> rye run lint & rye fmt"
|
|
51
|
+
- echo "" && echo "Checks Start $(cat {{.FILE_TASK_START}}) - End $(date)"
|
|
52
|
+
silent: true
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
---
|
|
2
|
+
# https://taskfile.dev
|
|
3
|
+
#
|
|
4
|
+
# Do not edit this file, instead use Taskfile.project.yml.
|
|
5
|
+
#
|
|
6
|
+
version: '3'
|
|
7
|
+
|
|
8
|
+
vars:
|
|
9
|
+
DIR_TASKFILES: Taskfile.d
|
|
10
|
+
FILE_TASK_START: "task-start-{{.TASK}}.txt"
|
|
11
|
+
FILE_TASK_START1: "task-start-{{.TASK}}1.txt"
|
|
12
|
+
TT_GIT_REPO: https://gitlab.com/op_so/task/task-templates/-/raw
|
|
13
|
+
|
|
14
|
+
includes:
|
|
15
|
+
00:
|
|
16
|
+
taskfile: Taskfile.project.yml
|
|
17
|
+
optional: true
|
|
18
|
+
# BEGIN-INCLUDES-TEMPLATES
|
|
19
|
+
git:
|
|
20
|
+
taskfile: Taskfile.d/git.yml
|
|
21
|
+
optional: true
|
|
22
|
+
lint:
|
|
23
|
+
taskfile: Taskfile.d/lint.yml
|
|
24
|
+
optional: true
|
|
25
|
+
# END-INCLUDES-TEMPLATES
|
|
26
|
+
|
|
27
|
+
tasks:
|
|
28
|
+
|
|
29
|
+
install-templates:
|
|
30
|
+
desc: "[CORE] Download/update tasks templates. Arguments: [PROXY|P=http://proxy:8080] [PROXY_CREDENTIALS|PC=username:password] (*)"
|
|
31
|
+
summary: |
|
|
32
|
+
[CORE] Download/update tasks templates.
|
|
33
|
+
Usage: task install-templates [PROXY|P=http://proxy_url:proxy_port] [PROXY_CREDENTIALS|PC=username:password]
|
|
34
|
+
|
|
35
|
+
Arguments:
|
|
36
|
+
PROXY | P Proxy URL (optional)
|
|
37
|
+
PROXY_CREDENTIALS | PC Proxy credentials username:password (optional)
|
|
38
|
+
|
|
39
|
+
Requirements:
|
|
40
|
+
- wget or curl
|
|
41
|
+
vars:
|
|
42
|
+
PROXY: '{{default .P .PROXY}}'
|
|
43
|
+
D_PROXY: '{{default .TASK_PROXY .PROXY}}'
|
|
44
|
+
PROXY_CREDENTIALS: '{{default .PC .PROXY_CREDENTIALS}}'
|
|
45
|
+
TASK_TEMPLATES:
|
|
46
|
+
sh: task 00:00-get-list-templates
|
|
47
|
+
FILE: '{{default .F .FILE}}'
|
|
48
|
+
D_FILE: '{{default "Taskfile.yml" .FILE}}'
|
|
49
|
+
BEGIN: " # BEGIN-INCLUDES-TEMPLATES"
|
|
50
|
+
PATTERN_BEGIN: "^{{.BEGIN}}"
|
|
51
|
+
END: "# END-INCLUDES-TEMPLATES"
|
|
52
|
+
cmds:
|
|
53
|
+
- date > {{.FILE_TASK_START}}
|
|
54
|
+
- defer: rm -f {{.FILE_TASK_START}}
|
|
55
|
+
- mkdir -p "{{.DIR_TASKFILES}}"
|
|
56
|
+
- if [ -z "{{.TASK_TEMPLATES}}" ]; then echo "Error TASK_TEMPLATES variable is empty in Taskfile.project.yml file" && exit 1; else echo "Download templates -> {{.TASK_TEMPLATES}}"; fi
|
|
57
|
+
- |
|
|
58
|
+
line_include_template_begin=$(grep -Fn '{{.BEGIN}}' "{{.D_FILE}}" | head -n 1 | cut -d ':' -f 1)
|
|
59
|
+
line_delete_begin=$(expr $line_include_template_begin + 1)
|
|
60
|
+
line_include_template_end=$(grep -Fn '{{.END}}' "{{.D_FILE}}" | head -n 1 | cut -d ':' -f 1)
|
|
61
|
+
line_delete_end=$(expr $line_include_template_end - 1)
|
|
62
|
+
if [ $line_delete_end -ge $line_delete_begin ]; then
|
|
63
|
+
sed -i'.bu' "${line_delete_begin},${line_delete_end}d" "{{.D_FILE}}"
|
|
64
|
+
fi
|
|
65
|
+
- defer: rm -f "{{.D_FILE}}".bu
|
|
66
|
+
- |
|
|
67
|
+
includes="{{.BEGIN}}"
|
|
68
|
+
for t in $(echo "{{.TASK_TEMPLATES}}" | tr "," " "); do
|
|
69
|
+
if echo "$t" | grep -q "\[" 2>/dev/null; then
|
|
70
|
+
task=$(echo "$t" | cut -d '[' -f 1)
|
|
71
|
+
else
|
|
72
|
+
task="$t"
|
|
73
|
+
fi
|
|
74
|
+
includes="$includes\\n ${task}:\\n taskfile: {{.DIR_TASKFILES}}/${task}.yml\\n optional: true"
|
|
75
|
+
done
|
|
76
|
+
sed -i'.bu' "s={{.PATTERN_BEGIN}}=${includes}=g" "{{.D_FILE}}"
|
|
77
|
+
- |
|
|
78
|
+
templates_list=$(task 00:00-get-list-templates)
|
|
79
|
+
for t in $(echo "{{.TASK_TEMPLATES}}" | tr "," " "); do
|
|
80
|
+
if echo "$t" | grep -q "\[" 2>/dev/null; then
|
|
81
|
+
task=$(echo "$t" | cut -d '[' -f 1)
|
|
82
|
+
v=$(echo "$t" | sed -e 's/.*\[\(.*\)\]/\1/')
|
|
83
|
+
version="v${v}"
|
|
84
|
+
else
|
|
85
|
+
task="$t"
|
|
86
|
+
version="main"
|
|
87
|
+
fi
|
|
88
|
+
echo "Download template: $task version: $version"
|
|
89
|
+
task download-template TEMPLATE=${task}.yml VERSION=$version PROXY={{.D_PROXY}} PROXY_CREDENTIALS={{.PROXY_CREDENTIALS}}
|
|
90
|
+
done
|
|
91
|
+
- echo "Install templates Start $(cat {{.FILE_TASK_START}}) - End $(date)"
|
|
92
|
+
silent: true
|
|
93
|
+
|
|
94
|
+
usage:
|
|
95
|
+
desc: "[CORE] Show the usage of a task. Arguments: TSK|T=task-name [FILE|F=Taskfile.dist.yml] (*)"
|
|
96
|
+
summary: |
|
|
97
|
+
[CORE] Show the usage of a task.
|
|
98
|
+
Usage: task [-t Taskfile.dist.yml] usage TSK|T=<task-name> [FILE|F=Taskfile.dist.yml]
|
|
99
|
+
|
|
100
|
+
Arguments:
|
|
101
|
+
TSK | T Name of the task (required)
|
|
102
|
+
FILE | F Taskfile path (optional, by default Taskfile.yml)
|
|
103
|
+
vars:
|
|
104
|
+
TSK: '{{default .T .TSK}}'
|
|
105
|
+
FILE: '{{default .F .FILE}}'
|
|
106
|
+
D_FILE: '{{default "Taskfile.yml" .FILE}}'
|
|
107
|
+
cmds:
|
|
108
|
+
- |
|
|
109
|
+
if [ ! -f "{{.D_FILE}}" ]; then
|
|
110
|
+
echo "{{.D_FILE}} does not exist!"
|
|
111
|
+
exit 1
|
|
112
|
+
fi
|
|
113
|
+
- task -t "{{.D_FILE}}" --summary "{{.TSK}}" | sed '/^dependencies:$/,$d' | sed '/^commands:$/,$d'
|
|
114
|
+
preconditions:
|
|
115
|
+
- sh: test -n "{{.TSK}}" || test -n "{{.T}}"
|
|
116
|
+
msg: "TSK|T argument is required"
|
|
117
|
+
silent: true
|
|
118
|
+
|
|
119
|
+
default:
|
|
120
|
+
desc: "[CORE] List of available tasks. Arguments: [FILE|F=Taskfile.project.yml] (*)"
|
|
121
|
+
summary: |
|
|
122
|
+
[CORE] Show the list of available tasks.
|
|
123
|
+
Usage: task [FILE|F=Taskfile.project.yml]
|
|
124
|
+
|
|
125
|
+
Arguments:
|
|
126
|
+
FILE | F Taskfile project path (optional, by default Taskfile.project.yml)
|
|
127
|
+
vars:
|
|
128
|
+
FILE: '{{default .F .FILE}}'
|
|
129
|
+
D_FILE: '{{default "Taskfile.project.yml" .FILE}}'
|
|
130
|
+
cmds:
|
|
131
|
+
- |
|
|
132
|
+
if [ -d "{{.DIR_TASKFILES}}" ]; then
|
|
133
|
+
for template in {{.DIR_TASKFILES}}/*.yml
|
|
134
|
+
do
|
|
135
|
+
template_name=$(basename "$template")
|
|
136
|
+
printf "\033[0;33m[ %s: ]\033[0m " "${template_name%.yml}" && task --list -t "$template" || true
|
|
137
|
+
echo ""
|
|
138
|
+
done
|
|
139
|
+
fi
|
|
140
|
+
- |
|
|
141
|
+
if [ ! -z "{{.D_FILE}}" ]; then
|
|
142
|
+
printf "\033[0;33m[ %s: ]\033[0m " "00" && task --list -t "{{.D_FILE}}" || true
|
|
143
|
+
fi
|
|
144
|
+
- echo ""
|
|
145
|
+
- echo " <task install-templates [PROXY|P=http://proxy:8080]> to install or update templates (Variable TASK_TEMPLATES in Taskfile.project.yml file)."
|
|
146
|
+
- echo " (*) <task usage TSK=task-name> will show the usage of the task."
|
|
147
|
+
silent: true
|
|
148
|
+
|
|
149
|
+
download-template:
|
|
150
|
+
cmds:
|
|
151
|
+
- |
|
|
152
|
+
if [ -x "$(command -v curl)" ]; then
|
|
153
|
+
if [ -z "{{.PROXY}}" ]; then
|
|
154
|
+
curl --progress-bar -o "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}"
|
|
155
|
+
else
|
|
156
|
+
if [ -z "{{.PROXY_CREDENTIALS}}" ]; then
|
|
157
|
+
echo "Proxy: {{.PROXY}}"
|
|
158
|
+
curl -x "{{.PROXY}}" --progress-bar -o "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}"
|
|
159
|
+
else
|
|
160
|
+
echo "Proxy with auth: {{.PROXY}}"
|
|
161
|
+
curl -U "{{.PROXY_CREDENTIALS}}" -x "{{.PROXY}}" --progress-bar -o "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}" --proxy-anyauth
|
|
162
|
+
fi
|
|
163
|
+
fi
|
|
164
|
+
else
|
|
165
|
+
if [ -z "{{.PROXY}}" ]; then
|
|
166
|
+
wget -cq -O "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}"
|
|
167
|
+
else
|
|
168
|
+
if [ -z "{{.PROXY_CREDENTIALS}}" ]; then
|
|
169
|
+
proxy={{.PROXY}}
|
|
170
|
+
echo "Proxy: $proxy"
|
|
171
|
+
else
|
|
172
|
+
proto=$(echo {{.PROXY}} | sed -e's,^\(.*://\).*,\1,g')
|
|
173
|
+
url=$(echo {{.PROXY}} | sed -e's,^.*://\(.*\),\1,g')
|
|
174
|
+
proxy="${proto}{{.PROXY_CREDENTIALS}}@${url}"
|
|
175
|
+
echo "Proxy: ${proto}****:****@${url}"
|
|
176
|
+
fi
|
|
177
|
+
export use_proxy=on && export http_proxy=$proxy && export https_proxy=$proxy && wget -cq -O "{{.DIR_TASKFILES}}/{{.TEMPLATE}}" "{{.TT_GIT_REPO}}/{{.VERSION}}/{{.DIR_TASKFILES}}/{{.TEMPLATE}}"
|
|
178
|
+
fi
|
|
179
|
+
fi
|
|
180
|
+
preconditions:
|
|
181
|
+
- sh: test -n "{{.TEMPLATE}}"
|
|
182
|
+
msg: "TEMPLATE argument is required"
|
|
183
|
+
- sh: test -n "{{.VERSION}}"
|
|
184
|
+
msg: "VERSION argument is required"
|
|
185
|
+
- sh: command -v curl || command -v wget
|
|
186
|
+
msg: "curl or wget are not installed"
|
|
187
|
+
silent: true
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
---
|
|
2
|
+
site_name: "api-key-factory source documentation"
|
|
3
|
+
|
|
4
|
+
theme:
|
|
5
|
+
name: "material"
|
|
6
|
+
|
|
7
|
+
plugins:
|
|
8
|
+
- search
|
|
9
|
+
- mkdocstrings
|
|
10
|
+
|
|
11
|
+
markdown_extensions:
|
|
12
|
+
- mkdocs-click
|
|
13
|
+
|
|
14
|
+
nav:
|
|
15
|
+
- 'index.md'
|
|
16
|
+
- 'cli.md'
|
|
17
|
+
- 'api_key_factory.md'
|
|
18
|
+
- 'factory':
|
|
19
|
+
- 'factory/key.md'
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "api-key-factory"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "A simple CLI tool to generate API Key"
|
|
5
|
+
authors = [
|
|
6
|
+
{ name = "FX Soubirou", email = "soubirou@yahoo.fr" }
|
|
7
|
+
]
|
|
8
|
+
license = { text = "MIT" }
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"click>=8.1.7",
|
|
17
|
+
"pydantic>=2.6.3"
|
|
18
|
+
]
|
|
19
|
+
requires-python = ">= 3.10"
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://gitlab.com/op_so/projects/api-key-factory"
|
|
23
|
+
Documentation = "https://op_so.gitlab.io/projects/api-key-factory"
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
api-key-factory = "api_key_factory.api_key_factory:cli"
|
|
27
|
+
|
|
28
|
+
[build-system]
|
|
29
|
+
requires = ["hatchling"]
|
|
30
|
+
build-backend = "hatchling.build"
|
|
31
|
+
|
|
32
|
+
[tool.rye]
|
|
33
|
+
managed = true
|
|
34
|
+
dev-dependencies = [
|
|
35
|
+
"black>=23.7.0",
|
|
36
|
+
"flake8>=6.1.0",
|
|
37
|
+
"flake8-pyproject>=1.2.3",
|
|
38
|
+
"isort>=5.13.2",
|
|
39
|
+
"mypy>=1.5.1",
|
|
40
|
+
"pytest>=7.4.0",
|
|
41
|
+
"pytest-cov>=4.1.0",
|
|
42
|
+
"mkdocs-material>=9.5.10",
|
|
43
|
+
"mkdocstrings[python]>=0.24.0",
|
|
44
|
+
"mkdocs-click>=0.8.1"
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
[tool.rye.scripts]
|
|
48
|
+
lint = { chain = ["lint:isort", "lint:black", "lint:mypy", "lint:flake8" ] }
|
|
49
|
+
"lint:isort" = "isort src/ tests/"
|
|
50
|
+
"lint:black" = "black src/ tests/"
|
|
51
|
+
"lint:mypy" = "mypy --strict src/ tests/"
|
|
52
|
+
"lint:flake8" = "flake8 src/ tests/"
|
|
53
|
+
"test" = "pytest --cov=src/ --cov-report html:reports/cov --cov-report term"
|
|
54
|
+
"doc-serve" = "mkdocs serve"
|
|
55
|
+
|
|
56
|
+
[tool.hatch.metadata]
|
|
57
|
+
allow-direct-references = true
|
|
58
|
+
|
|
59
|
+
[tool.hatch.build.targets.wheel]
|
|
60
|
+
packages = ["src/api_key_factory"]
|
|
61
|
+
|
|
62
|
+
[tool.black]
|
|
63
|
+
target-version = ['py312']
|
|
64
|
+
|
|
65
|
+
[tool.mypy]
|
|
66
|
+
mypy_path = "src"
|
|
67
|
+
strict = true
|
|
68
|
+
|
|
69
|
+
[tool.ruff]
|
|
70
|
+
target-version = "py312"
|
|
71
|
+
|
|
72
|
+
[tool.flake8]
|
|
73
|
+
max-line-length = 88
|
|
74
|
+
extend-ignore = ['E203']
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# generated by rye
|
|
2
|
+
# use `rye lock` or `rye sync` to update this lockfile
|
|
3
|
+
#
|
|
4
|
+
# last locked with the following flags:
|
|
5
|
+
# pre: false
|
|
6
|
+
# features: []
|
|
7
|
+
# all-features: false
|
|
8
|
+
# with-sources: false
|
|
9
|
+
# generate-hashes: false
|
|
10
|
+
# universal: false
|
|
11
|
+
|
|
12
|
+
-e file:.
|
|
13
|
+
annotated-types==0.7.0
|
|
14
|
+
# via pydantic
|
|
15
|
+
babel==2.16.0
|
|
16
|
+
# via mkdocs-material
|
|
17
|
+
black==24.8.0
|
|
18
|
+
certifi==2024.7.4
|
|
19
|
+
# via requests
|
|
20
|
+
charset-normalizer==3.3.2
|
|
21
|
+
# via requests
|
|
22
|
+
click==8.1.7
|
|
23
|
+
# via api-key-factory
|
|
24
|
+
# via black
|
|
25
|
+
# via mkdocs
|
|
26
|
+
# via mkdocs-click
|
|
27
|
+
# via mkdocstrings
|
|
28
|
+
colorama==0.4.6
|
|
29
|
+
# via griffe
|
|
30
|
+
# via mkdocs-material
|
|
31
|
+
coverage==7.6.1
|
|
32
|
+
# via pytest-cov
|
|
33
|
+
flake8==7.1.1
|
|
34
|
+
# via flake8-pyproject
|
|
35
|
+
flake8-pyproject==1.2.3
|
|
36
|
+
ghp-import==2.1.0
|
|
37
|
+
# via mkdocs
|
|
38
|
+
griffe==1.2.0
|
|
39
|
+
# via mkdocstrings-python
|
|
40
|
+
idna==3.8
|
|
41
|
+
# via requests
|
|
42
|
+
iniconfig==2.0.0
|
|
43
|
+
# via pytest
|
|
44
|
+
isort==5.13.2
|
|
45
|
+
jinja2==3.1.4
|
|
46
|
+
# via mkdocs
|
|
47
|
+
# via mkdocs-material
|
|
48
|
+
# via mkdocstrings
|
|
49
|
+
markdown==3.7
|
|
50
|
+
# via mkdocs
|
|
51
|
+
# via mkdocs-autorefs
|
|
52
|
+
# via mkdocs-click
|
|
53
|
+
# via mkdocs-material
|
|
54
|
+
# via mkdocstrings
|
|
55
|
+
# via pymdown-extensions
|
|
56
|
+
markupsafe==2.1.5
|
|
57
|
+
# via jinja2
|
|
58
|
+
# via mkdocs
|
|
59
|
+
# via mkdocs-autorefs
|
|
60
|
+
# via mkdocstrings
|
|
61
|
+
mccabe==0.7.0
|
|
62
|
+
# via flake8
|
|
63
|
+
mergedeep==1.3.4
|
|
64
|
+
# via mkdocs
|
|
65
|
+
# via mkdocs-get-deps
|
|
66
|
+
mkdocs==1.6.0
|
|
67
|
+
# via mkdocs-autorefs
|
|
68
|
+
# via mkdocs-material
|
|
69
|
+
# via mkdocstrings
|
|
70
|
+
mkdocs-autorefs==1.1.0
|
|
71
|
+
# via mkdocstrings
|
|
72
|
+
mkdocs-click==0.8.1
|
|
73
|
+
mkdocs-get-deps==0.2.0
|
|
74
|
+
# via mkdocs
|
|
75
|
+
mkdocs-material==9.5.33
|
|
76
|
+
mkdocs-material-extensions==1.3.1
|
|
77
|
+
# via mkdocs-material
|
|
78
|
+
mkdocstrings==0.25.2
|
|
79
|
+
# via mkdocstrings-python
|
|
80
|
+
mkdocstrings-python==1.10.8
|
|
81
|
+
# via mkdocstrings
|
|
82
|
+
mypy==1.11.2
|
|
83
|
+
mypy-extensions==1.0.0
|
|
84
|
+
# via black
|
|
85
|
+
# via mypy
|
|
86
|
+
packaging==24.1
|
|
87
|
+
# via black
|
|
88
|
+
# via mkdocs
|
|
89
|
+
# via pytest
|
|
90
|
+
paginate==0.5.7
|
|
91
|
+
# via mkdocs-material
|
|
92
|
+
pathspec==0.12.1
|
|
93
|
+
# via black
|
|
94
|
+
# via mkdocs
|
|
95
|
+
platformdirs==4.2.2
|
|
96
|
+
# via black
|
|
97
|
+
# via mkdocs-get-deps
|
|
98
|
+
# via mkdocstrings
|
|
99
|
+
pluggy==1.5.0
|
|
100
|
+
# via pytest
|
|
101
|
+
pycodestyle==2.12.1
|
|
102
|
+
# via flake8
|
|
103
|
+
pydantic==2.8.2
|
|
104
|
+
# via api-key-factory
|
|
105
|
+
pydantic-core==2.20.1
|
|
106
|
+
# via pydantic
|
|
107
|
+
pyflakes==3.2.0
|
|
108
|
+
# via flake8
|
|
109
|
+
pygments==2.18.0
|
|
110
|
+
# via mkdocs-material
|
|
111
|
+
pymdown-extensions==10.9
|
|
112
|
+
# via mkdocs-material
|
|
113
|
+
# via mkdocstrings
|
|
114
|
+
pytest==8.3.2
|
|
115
|
+
# via pytest-cov
|
|
116
|
+
pytest-cov==5.0.0
|
|
117
|
+
python-dateutil==2.9.0.post0
|
|
118
|
+
# via ghp-import
|
|
119
|
+
pyyaml==6.0.2
|
|
120
|
+
# via mkdocs
|
|
121
|
+
# via mkdocs-get-deps
|
|
122
|
+
# via pymdown-extensions
|
|
123
|
+
# via pyyaml-env-tag
|
|
124
|
+
pyyaml-env-tag==0.1
|
|
125
|
+
# via mkdocs
|
|
126
|
+
regex==2024.7.24
|
|
127
|
+
# via mkdocs-material
|
|
128
|
+
requests==2.32.3
|
|
129
|
+
# via mkdocs-material
|
|
130
|
+
six==1.16.0
|
|
131
|
+
# via python-dateutil
|
|
132
|
+
typing-extensions==4.12.2
|
|
133
|
+
# via mypy
|
|
134
|
+
# via pydantic
|
|
135
|
+
# via pydantic-core
|
|
136
|
+
urllib3==2.2.2
|
|
137
|
+
# via requests
|
|
138
|
+
watchdog==4.0.2
|
|
139
|
+
# via mkdocs
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# generated by rye
|
|
2
|
+
# use `rye lock` or `rye sync` to update this lockfile
|
|
3
|
+
#
|
|
4
|
+
# last locked with the following flags:
|
|
5
|
+
# pre: false
|
|
6
|
+
# features: []
|
|
7
|
+
# all-features: false
|
|
8
|
+
# with-sources: false
|
|
9
|
+
# generate-hashes: false
|
|
10
|
+
# universal: false
|
|
11
|
+
|
|
12
|
+
-e file:.
|
|
13
|
+
annotated-types==0.7.0
|
|
14
|
+
# via pydantic
|
|
15
|
+
click==8.1.7
|
|
16
|
+
# via api-key-factory
|
|
17
|
+
pydantic==2.8.2
|
|
18
|
+
# via api-key-factory
|
|
19
|
+
pydantic-core==2.20.1
|
|
20
|
+
# via pydantic
|
|
21
|
+
typing-extensions==4.12.2
|
|
22
|
+
# via pydantic
|
|
23
|
+
# via pydantic-core
|
|
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,48 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from api_key_factory.factory.key import Key
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestKey:
|
|
7
|
+
def test_default_constructor(self) -> None:
|
|
8
|
+
k = Key()
|
|
9
|
+
assert k.prefix == ""
|
|
10
|
+
assert len(k.rand_uuid) == 36
|
|
11
|
+
assert k.rand_uuid.count("-") == 4
|
|
12
|
+
|
|
13
|
+
def test_constructor_with_prefix(self) -> None:
|
|
14
|
+
k = Key("test")
|
|
15
|
+
assert k.prefix == "test"
|
|
16
|
+
assert len(k.rand_uuid) == 36
|
|
17
|
+
assert k.rand_uuid.count("-") == 4
|
|
18
|
+
|
|
19
|
+
def test_get_value_without_prefix(self) -> None:
|
|
20
|
+
k = Key()
|
|
21
|
+
v = k.get_value()
|
|
22
|
+
assert len(v) == 36
|
|
23
|
+
assert v.count("-") == 4
|
|
24
|
+
|
|
25
|
+
def test_get_value_with_prefix(self) -> None:
|
|
26
|
+
k = Key("test")
|
|
27
|
+
v = k.get_value()
|
|
28
|
+
assert len(v) == 41
|
|
29
|
+
assert v.count("-") == 5
|
|
30
|
+
assert v[:5] == "test-"
|
|
31
|
+
|
|
32
|
+
def test_get_hash_without_prefix(self) -> None:
|
|
33
|
+
k = Key()
|
|
34
|
+
h = k.get_hash()
|
|
35
|
+
assert len(h) == 64
|
|
36
|
+
assert h.count("-") == 0
|
|
37
|
+
|
|
38
|
+
def test_get_hash_without_prefix_defined_token(self) -> None:
|
|
39
|
+
k = Key()
|
|
40
|
+
k.rand_uuid = "6ad23e18-5ece-48ee-805d-e3ce973bd3de"
|
|
41
|
+
h = k.get_hash()
|
|
42
|
+
assert h == "d280d93d30b74ceca3cfd65e95c84affac408686f4d32b33723e6ac1e6378e10"
|
|
43
|
+
|
|
44
|
+
def test_get_hash_with_prefix_defined_token(self) -> None:
|
|
45
|
+
k = Key("test")
|
|
46
|
+
k.rand_uuid = "6ad23e18-5ece-48ee-805d-e3ce973bd3de"
|
|
47
|
+
h = k.get_hash()
|
|
48
|
+
assert h == "89a239eddc4a3ad4e7ddca8e359b9859f15a1d844fad87a3a9e2b23b6df7b9fe"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from click.testing import CliRunner
|
|
4
|
+
|
|
5
|
+
from api_key_factory import api_key_factory
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Test_api_key_factory:
|
|
9
|
+
def test_api_key_factory_help(self) -> None:
|
|
10
|
+
runner = CliRunner()
|
|
11
|
+
result = runner.invoke(api_key_factory.cli, ["--help"])
|
|
12
|
+
assert result.exit_code == 0
|
|
13
|
+
assert "[OPTIONS]" in result.stdout
|
|
14
|
+
|
|
15
|
+
def test_api_key_factory_version(self) -> None:
|
|
16
|
+
runner = CliRunner()
|
|
17
|
+
result = runner.invoke(api_key_factory.cli, ["--version"])
|
|
18
|
+
assert result.exit_code == 0
|
|
19
|
+
assert "version" in result.stdout
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
from click.testing import CliRunner
|
|
4
|
+
|
|
5
|
+
from api_key_factory import api_key_factory
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Test_generate:
|
|
9
|
+
def test_generate_help(self) -> None:
|
|
10
|
+
runner = CliRunner()
|
|
11
|
+
result = runner.invoke(api_key_factory.cli, ["generate", "--help"])
|
|
12
|
+
assert result.exit_code == 0
|
|
13
|
+
assert "generate [OPTIONS]" in result.stdout
|
|
14
|
+
|
|
15
|
+
def test_generate_without_option(self) -> None:
|
|
16
|
+
runner = CliRunner()
|
|
17
|
+
result = runner.invoke(api_key_factory.cli, ["generate"])
|
|
18
|
+
assert result.exit_code == 0
|
|
19
|
+
out = result.stdout
|
|
20
|
+
lines = out.splitlines()
|
|
21
|
+
assert len(lines) == 1
|
|
22
|
+
key_hash = lines[0].split()
|
|
23
|
+
assert len(key_hash[0]) == 36
|
|
24
|
+
assert len(key_hash[1]) == 64
|
|
25
|
+
|
|
26
|
+
def test_generate_with_n_option(self) -> None:
|
|
27
|
+
runner = CliRunner()
|
|
28
|
+
result = runner.invoke(api_key_factory.cli, ["generate", "-n", "3"])
|
|
29
|
+
assert result.exit_code == 0
|
|
30
|
+
out = result.stdout
|
|
31
|
+
lines = out.splitlines()
|
|
32
|
+
assert len(lines) == 3
|
|
33
|
+
key_hash = lines[0].split()
|
|
34
|
+
assert len(key_hash[0]) == 36
|
|
35
|
+
assert len(key_hash[1]) == 64
|
|
36
|
+
|
|
37
|
+
def test_generate_with_num_option(self) -> None:
|
|
38
|
+
runner = CliRunner()
|
|
39
|
+
result = runner.invoke(api_key_factory.cli, ["generate", "--num", "3"])
|
|
40
|
+
assert result.exit_code == 0
|
|
41
|
+
out = result.stdout
|
|
42
|
+
lines = out.splitlines()
|
|
43
|
+
assert len(lines) == 3
|
|
44
|
+
key_hash = lines[0].split()
|
|
45
|
+
assert len(key_hash[0]) == 36
|
|
46
|
+
assert len(key_hash[1]) == 64
|