Example #1
0
 def test_configure_from_config_file(self):
     # this is not a known configuration so this is ignored.
     config_file_vars = {
         'foo': 'bar',
         CDP_ACCESS_KEY_ID_KEY_NAME: 'key_id',
         CDP_PRIVATE_KEY_KEY_NAME: 'mysecretkey'
     }
     context = FakeContext(
         all_variables={'config_file': '/config/location'},
         config_file_vars=config_file_vars)
     context.context_var_map = {'region': ('region', "CDP_REGION")}
     context.full_config = {
         'profiles': {
             'default': {
                 'region': 'CDP_REGION'
             }
         }
     }
     stream = six.StringIO()
     self.configure_list = ConfigureListCommand(stream)
     self.configure_list(context, args=[], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertRegexpMatches(rendered,
                              'profile\\s+<not set>\\s+None\\s+None')
     self.assertRegexpMatches(
         rendered, 'cdp_access_key_id\\s+\\*+y_id\\s+config-file')
     self.assertRegexpMatches(rendered,
                              'cdp_private_key\\s+\\*+tkey\\s+config-file')
Example #2
0
 def test_dotted_get(self):
     context = FakeContext({})
     context.full_config = {'preview': {'foo': 'true'}}
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context, args=['preview.foo'], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'true')
Example #3
0
 def test_get_nested_attribute_from_default_does_not_exist(self):
     context = FakeContext({})
     context.full_config = {'profiles': {}}
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context,
                args=['default.s3.signature_version'],
                parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), '')
Example #4
0
 def test_get_from_profile(self):
     context = FakeContext({})
     context.full_config = \
         {'profiles': {'testing': {'cdp_access_key_id': 'access_key'}}}
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context,
                args=['profile.testing.cdp_access_key_id'],
                parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'access_key')
Example #5
0
 def test_dotted_not_in_full_config_get(self):
     context = FakeContext({})
     context.full_config = {
         'profiles': {
             'dev': {
                 'someconf': {
                     'foobar': 'true'
                 }
             }
         }
     }
     stream = six.StringIO()
     context.variables['profile'] = 'dev'
     config_get = ConfigureGetCommand(stream)
     config_get(context, args=['someconf.foobar'], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'true')
Example #6
0
 def test_get_nested_attribute(self):
     context = FakeContext({})
     context.full_config = {
         'profiles': {
             'testing': {
                 's3': {
                     'signature_version': 's3v4'
                 }
             }
         }
     }
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context,
                args=['profile.testing.s3.signature_version'],
                parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 's3v4')
Example #7
0
 def test_configure_list_command_nothing_set(self):
     # Test the case where the user only wants to change a single_value.
     context = FakeContext(
         all_variables={'config_file': '/config/location'})
     context.full_config = {
         'profiles': {
             'default': {
                 'region': 'CDP_REGION'
             }
         }
     }
     stream = six.StringIO()
     self.configure_list = ConfigureListCommand(stream)
     self.configure_list(context, args=[], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertRegexpMatches(rendered, 'profile\\s+<not set>')
     self.assertRegexpMatches(rendered, 'cdp_access_key_id\\s+<not set>')
     self.assertRegexpMatches(rendered, 'cdp_private_key\\s+<not set>')
Example #8
0
 def test_dotted_get_with_profile(self):
     context = FakeContext({})
     context.full_config = {
         'profiles': {
             'thu-dev': {
                 'thu': {
                     'instance_profile': 'my_ip'
                 }
             }
         }
     }
     context.config = {'thu': {'instance_profile': 'my_ip'}}
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context,
                args=['thu-dev.thu.instance_profile'],
                parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'my_ip')
Example #9
0
 def test_configure_from_env(self):
     env_vars = {'profile': 'myprofilename'}
     context = FakeContext(
         all_variables={'config_file': '/config/location'},
         environment_vars=env_vars)
     context.context_var_map = {'profile': (None, "PROFILE_ENV_VAR")}
     context.full_config = {
         'profiles': {
             'default': {
                 'region': 'CDP_REGION'
             }
         }
     }
     stream = six.StringIO()
     self.configure_list = ConfigureListCommand(stream)
     self.configure_list(context, args=[], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertRegexpMatches(
         rendered, 'profile\\s+myprofilename\\s+env\\s+PROFILE_ENV_VAR')
Example #10
0
 def test_predefined_section_with_profile(self):
     # Test that we retrieve the predefined section config var even if it's
     # under a profile.
     context = FakeContext({})
     context.full_config = {
         'profiles': {
             'thu-dev': {
                 'thu': {
                     'instance_profile': 'my_ip'
                 }
             },
             'preview': {
                 'foo': 'true'
             }
         }
     }
     stream = six.StringIO()
     config_get = ConfigureGetCommand(stream)
     config_get(context, args=['preview.foo'], parsed_globals=None)
     rendered = stream.getvalue()
     self.assertEqual(rendered.strip(), 'true')
Example #11
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'}
     credentials = mock.Mock()
     credentials.access_key_id = 'access_key'
     credentials.private_key = 'private_key'
     credentials.method = 'foobar'
     context = FakeContext(
         all_variables={'config_file': '/config/location'},
         environment_vars=env_vars,
         config_file_vars={},
         credentials=credentials)
     context.context_var_map = {
         'region': ('region', 'CDP_REGION'),
         'profile': ('profile', 'CDP_DEFAULT_PROFILE')
     }
     context.full_config = {
         'profiles': {
             'default': {
                 'region': 'CDP_REGION'
             }
         }
     }
     stream = six.StringIO()
     self.configure_list = ConfigureListCommand(stream)
     self.configure_list(context, args=[], parsed_globals=None)
     rendered = stream.getvalue()
     # The profile came from an env var.
     self.assertRegexpMatches(
         rendered, 'profile\\s+myprofilename\\s+env\\s+CDP_DEFAULT_PROFILE')
     # The credentials came from 'foobar'.  Note how we're
     # also checking that the access_key/private_key are masked
     # with '*' chars except for the last 4 chars.
     self.assertRegexpMatches(rendered,
                              r'cdp_access_key_id\s+\*+_key\s+foobar')
     self.assertRegexpMatches(rendered,
                              r'cdp_private_key\s+\*+_key\s+foobar')