Skip to content

Instantly share code, notes, and snippets.

@kayibal
Last active October 17, 2019 15:36
Show Gist options
  • Save kayibal/f7f5961247860ac0ff466473292a4364 to your computer and use it in GitHub Desktop.
Save kayibal/f7f5961247860ac0ff466473292a4364 to your computer and use it in GitHub Desktop.
DR PyPi URL builder
#!/Users/kayibal/miniconda3/bin/python
import boto3
import click
from urllib.parse import urlparse, urlunparse
def pypi_url(env):
ssm = boto3.client("ssm")
url = ssm.get_parameter(Name=f"/CodeBuild/PyPi/{env}/url", WithDecryption=True)[
"Parameter"
]["Value"]
un = ssm.get_parameter(Name=f"/CodeBuild/PyPi/{env}/un", WithDecryption=True)[
"Parameter"
]["Value"]
pw = ssm.get_parameter(Name=f"/CodeBuild/PyPi/{env}/pw", WithDecryption=True)[
"Parameter"
]["Value"]
parts = urlparse(url)
pypi_url = urlunparse(
[
parts.scheme,
f"{un}:{pw}@" + parts.netloc,
parts.path,
parts.params,
parts.query,
parts.fragment,
]
)
return pypi_url
@click.command()
@click.option('--env', default="Dev")
def cli(env):
print(pypi_url(env))
if __name__ == '__main__':
cli()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment