From 26367cd76d046cf006a53d116bd789a7c860513e Mon Sep 17 00:00:00 2001 From: Jordan Guymon Date: Mon, 20 Nov 2017 10:21:17 -0800 Subject: [PATCH] Use the session profile to write when running aws configure --- .changes/next-release/bugfix-Configure-3035.json | 5 +++++ awscli/customizations/configure/configure.py | 8 ++++---- tests/unit/customizations/configure/__init__.py | 6 +++--- tests/unit/customizations/configure/test_configure.py | 10 +++++----- 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 .changes/next-release/bugfix-Configure-3035.json diff --git a/.changes/next-release/bugfix-Configure-3035.json b/.changes/next-release/bugfix-Configure-3035.json new file mode 100644 index 000000000000..e39cb4b8c062 --- /dev/null +++ b/.changes/next-release/bugfix-Configure-3035.json @@ -0,0 +1,5 @@ +{ + "category": "Configure", + "description": "Fix a bug where the configure command would write to the incorrect profile, fixes `#2970 `__.", + "type": "bugfix" +} diff --git a/awscli/customizations/configure/configure.py b/awscli/customizations/configure/configure.py index 9b7b1ab7c681..1f23021676e4 100644 --- a/awscli/customizations/configure/configure.py +++ b/awscli/customizations/configure/configure.py @@ -112,10 +112,10 @@ def _run_main(self, parsed_args, parsed_globals): config_filename = os.path.expanduser( self._session.get_config_variable('config_file')) if new_values: - self._write_out_creds_file_values(new_values, - parsed_globals.profile) - if parsed_globals.profile is not None: - section = profile_to_section(parsed_globals.profile) + profile = self._session.profile + self._write_out_creds_file_values(new_values, profile) + if profile is not None: + section = profile_to_section(profile) new_values['__section__'] = section self._config_writer.update_config(new_values, config_filename) diff --git a/tests/unit/customizations/configure/__init__.py b/tests/unit/customizations/configure/__init__.py index 2e738d2d9ed4..2b4eb901b1b8 100644 --- a/tests/unit/customizations/configure/__init__.py +++ b/tests/unit/customizations/configure/__init__.py @@ -17,7 +17,7 @@ class FakeSession(object): def __init__(self, all_variables, profile_does_not_exist=False, config_file_vars=None, environment_vars=None, - credentials=None): + credentials=None, profile=None): self.variables = all_variables self.profile_does_not_exist = profile_does_not_exist self.config = {} @@ -28,7 +28,7 @@ def __init__(self, all_variables, profile_does_not_exist=False, environment_vars = {} self.environment_vars = environment_vars self._credentials = credentials - self.profile = None + self.profile = profile def get_credentials(self): return self._credentials @@ -62,4 +62,4 @@ def emit_first_non_none_response(self, *args, **kwargs): def _build_profile_map(self): if self.full_config is None: return None - return self.full_config['profiles'] \ No newline at end of file + return self.full_config['profiles'] diff --git a/tests/unit/customizations/configure/test_configure.py b/tests/unit/customizations/configure/test_configure.py index 6dc2319c9611..cb244e2c93fe 100644 --- a/tests/unit/customizations/configure/test_configure.py +++ b/tests/unit/customizations/configure/test_configure.py @@ -95,9 +95,9 @@ def test_some_values_changed(self): {'output': 'NEW OUTPUT FORMAT'}, 'myconfigfile') def test_section_name_can_be_changed_for_profiles(self): - # If the user specifies "--profile myname" we need to write - # this out to the [profile myname] section. - self.global_args.profile = 'myname' + # If the user specifies a profile we need to write this out to + # the [profile myname] section. + self.session.profile = 'myname' self.configure(args=[], parsed_globals=self.global_args) # Note the __section__ key name. self.assert_credentials_file_updated_with( @@ -115,11 +115,11 @@ def test_session_says_profile_does_not_exist(self): # We should handle this case, and write out a new profile section # in the config file. session = FakeSession({'config_file': 'myconfigfile'}, - profile_does_not_exist=True) + profile_does_not_exist=True, + profile='profile-does-not-exist') self.configure = configure.ConfigureCommand(session, prompter=self.precanned, config_writer=self.writer) - self.global_args.profile = 'profile-does-not-exist' self.configure(args=[], parsed_globals=self.global_args) self.assert_credentials_file_updated_with( {'aws_access_key_id': 'new_value',