diff --git a/.changes/next-release/enhancement-ecr-62148.json b/.changes/next-release/enhancement-ecr-62148.json new file mode 100644 index 000000000000..6661cbbdd9cd --- /dev/null +++ b/.changes/next-release/enhancement-ecr-62148.json @@ -0,0 +1,5 @@ +{ + "category": "``ecr``", + "type": "enhancement", + "description": "Add ``--include-email/--no-include-email`` to the ``get-login`` command." +} diff --git a/awscli/customizations/ecr.py b/awscli/customizations/ecr.py index 721e3ba01b48..d5f42a2a7738 100644 --- a/awscli/customizations/ecr.py +++ b/awscli/customizations/ecr.py @@ -38,7 +38,31 @@ class ECRLogin(BasicCommand): 'Amazon ECR registries that you want to log in to.', 'required': False, 'nargs': '+' - } + }, + { + 'name': 'include-email', + 'action': 'store_true', + 'group_name': 'include-email', + 'dest': 'include_email', + 'default': True, + 'required': False, + 'help_text': ( + "Specify if the '-e' flag should be included in the " + "'docker login' command. The '-e' option has been deprecated " + "and is removed in docker version 17.06 and later. You must " + "specify --no-include-email If you're using docker version " + "17.06 or later. The default behavior is to include the " + "'-e' flag."), + }, + { + 'name': 'no-include-email', + 'help_text': 'Include email arg', + 'action': 'store_false', + 'default': True, + 'group_name': 'include-email', + 'dest': 'include_email', + 'required': False, + }, ] def _run_main(self, parsed_args, parsed_globals): @@ -52,6 +76,10 @@ def _run_main(self, parsed_args, parsed_globals): for auth in result['authorizationData']: auth_token = b64decode(auth['authorizationToken']).decode() username, password = auth_token.split(':') - sys.stdout.write('docker login -u %s -p %s -e none %s\n' - % (username, password, auth['proxyEndpoint'])) + command = ['docker', 'login', '-u', username, '-p', password] + if parsed_args.include_email: + command.extend(['-e', 'none']) + command.append(auth['proxyEndpoint']) + sys.stdout.write(' '.join(command)) + sys.stdout.write('\n') return 0 diff --git a/tests/functional/ecr/test_get_login.py b/tests/functional/ecr/test_get_login.py index 65bee886eb1b..95efb0b589ce 100644 --- a/tests/functional/ecr/test_get_login.py +++ b/tests/functional/ecr/test_get_login.py @@ -15,7 +15,8 @@ class TestGetLoginCommand(BaseAWSCommandParamsTest): - def test_prints_get_login_command(self): + def setUp(self): + super(TestGetLoginCommand, self).setUp() self.parsed_responses = [ { 'authorizationData': [ @@ -27,12 +28,22 @@ def test_prints_get_login_command(self): ] }, ] - stdout, _, rc = self.run_cmd("ecr get-login") + + def test_prints_get_login_command(self): + stdout = self.run_cmd("ecr get-login")[0] self.assertIn( 'docker login -u foo -p bar -e none 1235.ecr.us-east-1.io', stdout) self.assertEquals(1, len(self.operations_called)) self.assertNotIn('registryIds', self.operations_called[0][1]) + def test_prints_login_command_with_no_email(self): + stdout = self.run_cmd("ecr get-login --no-include-email")[0] + self.assertNotIn('-e none', stdout) + + def test_prints_login_with_email_flag(self): + stdout = self.run_cmd("ecr get-login --include-email")[0] + self.assertIn('-e none', stdout) + def test_prints_multiple_get_login_commands(self): self.parsed_responses = [ { @@ -50,7 +61,7 @@ def test_prints_multiple_get_login_commands(self): ] }, ] - stdout, _, rc = self.run_cmd("ecr get-login --registry-ids 1234 5678") + stdout = self.run_cmd("ecr get-login --registry-ids 1234 5678")[0] self.assertIn( 'docker login -u foo -p bar -e none 1235.ecr.us-east-1.io\n', stdout)