Пример #1
0
 def test_configure_from_multiple_sources(self):
     # Here the profile is from an env var, the
     # region is from the config file, and the credentials
     # are from an iam-role.
     env_vars = {'profile': 'myprofilename'}
     config_file_vars = {'region': 'us-west-2'}
     credentials = mock.Mock()
     credentials.access_key = 'access_key'
     credentials.secret_key = 'secret_key'
     credentials.method = 'iam-role'
     session = FakeSession(
         all_variables={'config_file': '/config/location'},
         environment_vars=env_vars,
         config_file_vars=config_file_vars,
         credentials=credentials)
     session.session_var_map = {
         'region': ('region', 'AWS_REGION'),
         'profile': ('profile', 'AWS_DEFAULT_PROFILE')
     }
     stream = StringIO()
     self.configure_list = configure.ConfigureListCommand(session, stream)
     self.configure_list(args=[], parsed_globals=None)
     rendered = stream.getvalue()
     # The profile came from an env var.
     self.assertRegexpMatches(
         rendered, 'profile\s+myprofilename\s+env\s+AWS_DEFAULT_PROFILE')
     # The region came from the config file.
     self.assertRegexpMatches(
         rendered, 'region\s+us-west-2\s+config-file\s+/config/location')
     # The credentials came from an IAM role.  Note how we're
     # also checking that the access_key/secret_key are masked
     # with '*' chars except for the last 4 chars.
     self.assertRegexpMatches(rendered, r'access_key\s+\*+_key\s+iam-role')
     self.assertRegexpMatches(rendered, r'secret_key\s+\*+_key\s+iam-role')
Пример #2
0
 def test_configure_from_env(self):
     env_vars = {'profile': 'myprofilename'}
     session = FakeSession(
         all_variables={'config_file': '/config/location'},
         environment_vars=env_vars)
     session.session_var_map = {'profile': (None, "PROFILE_ENV_VAR")}
     stream = StringIO()
     self.configure_list = configure.ConfigureListCommand(session, stream)
     self.configure_list(args=[], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertRegexpMatches(
         rendered, 'profile\s+myprofilename\s+env\s+PROFILE_ENV_VAR')
Пример #3
0
 def test_configure_from_config_file(self):
     config_file_vars = {'region': 'us-west-2'}
     session = FakeSession(
         all_variables={'config_file': '/config/location'},
         config_file_vars=config_file_vars)
     session.session_var_map = {'region': ('region', "AWS_REGION")}
     stream = StringIO()
     self.configure_list = configure.ConfigureListCommand(session, stream)
     self.configure_list(args=[], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertRegexpMatches(
         rendered, 'region\s+us-west-2\s+config-file\s+/config/location')
Пример #4
0
 def test_configure_list_command_nothing_set(self):
     # Test the case where the user only wants to change a single_value.
     session = FakeSession(
         all_variables={'config_file': '/config/location'})
     stream = StringIO()
     self.configure_list = configure.ConfigureListCommand(session, stream)
     self.configure_list(args=[], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertRegexpMatches(rendered, 'profile\s+<not set>')
     self.assertRegexpMatches(rendered, 'access_key\s+<not set>')
     self.assertRegexpMatches(rendered, 'secret_key\s+<not set>')
     self.assertRegexpMatches(rendered, 'region\s+<not set>')