Skip to content

Add cli tool #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added VERSION
Empty file.
54 changes: 54 additions & 0 deletions dotenv_to_ssm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

from pathlib import Path
import textwrap

import boto3
import click
import dotenv

client = boto3.client("ssm")


@click.command()
@click.argument("dotenv_file", type=click.Path(exists=True))
@click.argument("prefix", type=click.Path())
@click.option(
"--overwrite",
"Overwrite",
default=False,
help="Overwrite an existing parameter.",
)
@click.option(
"--type",
"Type",
default="SecureString",
type=click.Choice(["String", "StringList", "SecureString"], case_sensitive=False),
help="The type of parameter that you want to add to the system.",
)
def load(dotenv_file: click.Path, prefix: click.Path, **kwargs):
config = dotenv.dotenv_values(dotenv_file)

print(prefix)

for k, v in config.items():
path = Path(prefix) / k.lower()
try:
client.put_parameter(
Name=str(path),
Description="Created by the dotenv-to-ssm script.",
Value=v,
Tags=[
{"Key": "author", "Value": "string"},
],
**kwargs,
)
print(f"Created {path}")
except Exception as e:
error_text = textwrap.indent(str(e), prefix="\t")
print(f"Failed to create {path}: \n{error_text}")
print(kwargs)


if __name__ == "__main__":
load()
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
39 changes: 39 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
[metadata]
name = pydantic-ssm-settings
version = attr: src.VERSION
description = A Pydantic configuration provider for AWS SSM Parameter Store.
long_description = file: README.md
keywords = Pydantic, AWS, SSM, Parameter, Store
license = MIT
classifiers =
Intended Audience :: Developers
Intended Audience :: Information Technology
Intended Audience :: Science/Research
Programming Language :: Python :: 3.8
License :: OSI Approved :: MIT License
url = https://github.com/developmentseed/pydantic-ssm-settings
author = Anthony Lukach
author_email = [email protected]

[options]
zip_safe = False
include_package_data = True
packages = find:

[options.packages.find]

exclude = tests

install_requires =
pydantic

[options.entry_points]
console_scripts =
dotenv-to-ssm = dotenv_to_ssm:load [cli]

[options.extras_require]
cli =
boto3
click
python-dotenv

[tool:pytest]
testpaths = tests
addopts = -p no:hypothesispytest
Expand Down
29 changes: 0 additions & 29 deletions setup.py

This file was deleted.

1 change: 1 addition & 0 deletions pydantic_ssm_settings/__init__.py → src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .settings import AwsSsmSourceConfig

__all__ = ('AwsSsmSourceConfig',)
VERSION = '0.0.1'
File renamed without changes.
File renamed without changes.
File renamed without changes.