Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/awscli/customizations/ecr_public.py
1566 views
1
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
from awscli.customizations.commands import BasicCommand
14
from awscli.customizations.utils import create_client_from_parsed_globals
15
16
from base64 import b64decode
17
import sys
18
19
20
def register_ecr_public_commands(cli):
21
cli.register('building-command-table.ecr-public', _inject_commands)
22
23
24
def _inject_commands(command_table, session, **kwargs):
25
command_table['get-login-password'] = ECRPublicGetLoginPassword(session)
26
27
28
class ECRPublicGetLoginPassword(BasicCommand):
29
"""Get a password to be used with container clients such as Docker"""
30
NAME = 'get-login-password'
31
32
DESCRIPTION = BasicCommand.FROM_FILE(
33
'ecr-public/get-login-password_description.rst')
34
35
def _run_main(self, parsed_args, parsed_globals):
36
ecr_public_client = create_client_from_parsed_globals(
37
self._session,
38
'ecr-public',
39
parsed_globals)
40
result = ecr_public_client.get_authorization_token()
41
auth = result['authorizationData']
42
auth_token = b64decode(auth['authorizationToken']).decode()
43
_, password = auth_token.split(':')
44
sys.stdout.write(password)
45
sys.stdout.write('\n')
46
return 0
47
48