-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
157 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: pypi-publish | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- '**/*.py' | ||
workflow_dispatch: | ||
inputs: | ||
dry_run: | ||
type: choice | ||
description: Dry run mode | ||
required: true | ||
options: | ||
- "true" | ||
- "false" | ||
|
||
jobs: | ||
pypi-publisher: | ||
runs-on: thevickypedia-lite | ||
steps: | ||
- name: Set dry-run | ||
run: | | ||
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | ||
echo "::notice title=DryRun::Setting dry run to ${{ inputs.dry_run }} for '${{ github.event_name }}' event" | ||
echo "dry_run=${{ inputs.dry_run }}" >> $GITHUB_ENV | ||
elif [[ "${{ github.event_name }}" == "push" ]]; then | ||
echo "::notice title=DryRun::Setting dry run to true for '${{ github.event_name }}' event" | ||
echo "dry_run=true" >> $GITHUB_ENV | ||
else | ||
echo "::notice title=DryRun::Setting dry run to false for '${{ github.event_name }}' event" | ||
echo "dry_run=false" >> $GITHUB_ENV | ||
fi | ||
- uses: thevickypedia/pypi-publisher@v3 | ||
with: | ||
token: ${{ secrets.PYPI_TOKEN }} | ||
dry-run: ${{ env.dry_run }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
[project] | ||
name = "VaultAPI" | ||
dynamic = ["version", "dependencies"] | ||
description = "API to create and retrieve secrets from an encrypted vault." | ||
readme = "README.md" | ||
authors = [{ name = "Vignesh Rao", email = "[email protected]" }] | ||
license = { file = "LICENSE" } | ||
classifiers = [ | ||
"License :: OSI Approved :: MIT License", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Development Status :: 2 - Pre-Alpha", | ||
"Operating System :: MacOS :: MacOS X", | ||
"Operating System :: Microsoft :: Windows", | ||
"Operating System :: POSIX :: Linux" | ||
] | ||
keywords = ["vaultapi", "vault", "fastapi"] | ||
requires-python = ">=3.10" | ||
|
||
[tool.setuptools] | ||
packages = ["vaultapi"] | ||
|
||
[tool.setuptools.dynamic] | ||
version = {attr = "vaultapi.version"} | ||
dependencies = { file = ["requirements.txt"] } | ||
|
||
[project.optional-dependencies] | ||
dev = ["sphinx==5.1.1", "pre-commit", "recommonmark", "gitverse"] | ||
|
||
[project.scripts] | ||
# sends all the args to commandline function, where the arbitary commands as processed accordingly | ||
vaultapi = "vaultapi:commandline" | ||
|
||
[build-system] | ||
requires = ["setuptools", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/thevickypedia/VaultAPI" | ||
Docs = "https://thevickypedia.github.io/VaultAPI" | ||
Source = "https://github.com/thevickypedia/VaultAPI" | ||
"Bug Tracker" = "https://github.com/thevickypedia/VaultAPI/issues" | ||
"Release Notes" = "https://github.com/thevickypedia/VaultAPI/blob/main/release_notes.rst" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,72 @@ | ||
import sys | ||
|
||
import click | ||
from cryptography.fernet import Fernet | ||
|
||
from vaultapi.main import start # noqa: F401 | ||
|
||
version = "0.0.0" | ||
|
||
|
||
@click.command() | ||
@click.argument("run", required=False) | ||
@click.argument("start", required=False) | ||
@click.argument("keygen", required=False) | ||
@click.option("--version", "-V", is_flag=True, help="Prints the version.") | ||
@click.option("--help", "-H", is_flag=True, help="Prints the help section.") | ||
@click.option( | ||
"--env", | ||
"-E", | ||
type=click.Path(exists=True), | ||
help="Environment configuration filepath.", | ||
) | ||
def commandline(*args, **kwargs) -> None: | ||
"""Starter function to invoke vaultapi via CLI commands. | ||
**Flags** | ||
- ``--version | -V``: Prints the version. | ||
- ``--help | -H``: Prints the help section. | ||
- ``--env | -E``: Environment configuration filepath. | ||
**Commands** | ||
``encryptor | decryptor``: Initiates the API server. | ||
""" | ||
assert sys.argv[0].lower().endswith("vaultapi"), "Invalid commandline trigger!!" | ||
options = { | ||
"--version | -V": "Prints the version.", | ||
"--help | -H": "Prints the help section.", | ||
"--env | -E": "Environment configuration filepath.", | ||
"start | run": "Initiates the API server.", | ||
} | ||
# weird way to increase spacing to keep all values monotonic | ||
_longest_key = len(max(options.keys())) | ||
_pretext = "\n\t* " | ||
choices = _pretext + _pretext.join( | ||
f"{k} {'·' * (_longest_key - len(k) + 8)}→ {v}".expandtabs() | ||
for k, v in options.items() | ||
) | ||
if kwargs.get("version"): | ||
click.echo(f"vaultapi {version}") | ||
sys.exit(0) | ||
if kwargs.get("help"): | ||
click.echo( | ||
f"\nUsage: vaultapi [arbitrary-command]\nOptions (and corresponding behavior):{choices}" | ||
) | ||
sys.exit(0) | ||
trigger = kwargs.get("start") or kwargs.get("run") or kwargs.get("keygen") or "" | ||
if trigger and trigger.lower() in ("start", "run"): | ||
# Click doesn't support assigning defaults like traditional dictionaries, so kwargs.get("max", 100) won't work | ||
start(env_file=kwargs.get("env")) | ||
sys.exit(0) | ||
elif trigger.lower() == "keygen": | ||
key = Fernet.generate_key() | ||
click.secho( | ||
f"\nStore this as 'secret' or pass it as kwargs\n\n{key.decode()}\n" | ||
) | ||
sys.exit(0) | ||
else: | ||
click.secho(f"\n{kwargs}\nNo command provided", fg="red") | ||
click.echo( | ||
f"Usage: vaultapi [arbitrary-command]\nOptions (and corresponding behavior):{choices}" | ||
) | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters