Get ECR logins

parent ff4dfdcb
......@@ -6,6 +6,7 @@ from akinaka_update.commands import update as update_commands
from akinaka_cleanup.commands import cleanup as cleanup_commands
from akinaka_rds.commands import copy as copy_commands
from akinaka_reporting.commands import reporting as reporting_commands
from akinaka_container.commands import container as container_commands
@click.group()
def cli():
......@@ -15,5 +16,6 @@ cli.add_command(update_commands)
cli.add_command(cleanup_commands)
cli.add_command(copy_commands)
cli.add_command(reporting_commands)
cli.add_command(container_commands)
cli()
import click
# This is the Click() group that's imported into the CLI at the top level
@click.group()
@click.option("--region", required=True, help="Region your resources are located in. N.B. Currently, only us-east-1 supports estimates")
@click.option("--role-arn", required=True, help="Role ARN which contains necessary assume permissions")
@click.pass_context
def container(ctx, region, role_arn):
ctx.obj = {'region': region, 'role_arn': role_arn}
pass
@container.command(name="get-ecr-login")
@click.pass_context
@click.option("--registry", required=True, help="Registry you want to retrieve a docker login auth for")
def bill_estimates(ctx, registry):
region = ctx.obj.get('region')
role_arn = ctx.obj.get('role_arn')
from .ecr import ecr_login
ecr_login.ECRLogin(region, role_arn).get_login(registry)
import boto3
from akinaka_client.aws_client import AWS_Client
from akinaka_libs import helpers
import base64
import logging
helpers.set_logger()
aws_client = AWS_Client()
class ECRLogin():
def __init__(self, region, assume_role_arn):
self.region = region
self.assume_role_arn = assume_role_arn
def get_login(self, registry):
ecr_client = aws_client.create_client('ecr', self.region, self.assume_role_arn)
token = ecr_client.get_authorization_token(registryIds=[registry])['authorizationData'][0]['authorizationToken']
decoded_token = base64.standard_b64decode(token).decode('utf-8')
username = decoded_token.split(":")[0]
password = decoded_token.split(":")[1]
login_string = "docker login -u {username} -p {password} https://{registry}.dkr.ecr.{region}.amazonaws.com".format(
username=username,
password=password,
registry=registry,
region=self.region
)
print(login_string)
......@@ -6,7 +6,7 @@ with open("README.md", "r") as fh:
setuptools.setup(
name="akinaka",
python_requires='>=3.3.0',
version="0.2.13",
version="0.2.14",
author="Afraz",
author_email="afraz@olindata.com",
description="OlinData's aws cli Extras",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment