Skip to content

Commit

Permalink
Merge pull request #2972 from joguSD/profile
Browse files Browse the repository at this point in the history
 Use the session profile to write when running aws configure
  • Loading branch information
joguSD authored Nov 28, 2017
2 parents aaa201d + 26367cd commit 82b5324
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-Configure-3035.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"category": "Configure",
"description": "Fix a bug where the configure command would write to the incorrect profile, fixes `#2970 <https://github.com/aws/aws-cli/issues/2970>`__.",
"type": "bugfix"
}
8 changes: 4 additions & 4 deletions awscli/customizations/configure/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/customizations/configure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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
Expand Down Expand Up @@ -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']
return self.full_config['profiles']
10 changes: 5 additions & 5 deletions tests/unit/customizations/configure/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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',
Expand Down

0 comments on commit 82b5324

Please sign in to comment.