Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the session profile to write when running aws configure #2972

Merged
merged 1 commit into from
Nov 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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