Exemple #1
0
 def test_config(self):
     os.environ['FOO_CONFIG_FILE'] = path('aws_config')
     session = botocore.session.get_session(self.env_vars)
     session.get_config()
     self.assertEqual(len(session.available_profiles), 2)
     self.assertIn('default', session.available_profiles)
     self.assertIn('personal', session.available_profiles)
Exemple #2
0
 def test_config(self):
     self.environ["FOO_CONFIG_FILE"] = path("aws_config")
     session = botocore.session.get_session(self.env_vars)
     session.get_config()
     self.assertEqual(len(session.available_profiles), 2)
     self.assertIn("default", session.available_profiles)
     self.assertIn("personal", session.available_profiles)
Exemple #3
0
 def test_config(self):
     self.environ['FOO_CONFIG_FILE'] = path('aws_config')
     session = botocore.session.get_session(self.env_vars)
     session.get_config()
     self.assertEqual(len(session.available_profiles), 2)
     self.assertIn('default', session.available_profiles)
     self.assertIn('personal', session.available_profiles)
Exemple #4
0
 def test_config(self):
     config_path = os.path.join(os.path.dirname(__file__),
                                'aws_config')
     os.environ['FOO_CONFIG_FILE'] = config_path
     session = botocore.session.get_session(self.env_vars)
     session.get_config()
     assert len(session.available_profiles) == 2
     assert 'default' in session.available_profiles
     assert 'personal' in session.available_profiles
Exemple #5
0
 def test_profile_cached_returns_same_values(self):
     self.environ["FOO_CONFIG_FILE"] = path("aws_bad_profile")
     self.environ["FOO_DEFAULT_PROFILE"] = "personal1"
     session = botocore.session.get_session(self.env_vars)
     # First time is built from scratch.
     config = session.get_config()
     # Second time is cached.
     cached_config = session.get_config()
     # Both versions should be identical.
     self.assertEqual(config, cached_config)
Exemple #6
0
 def test_profile_cached_returns_same_values(self):
     self.environ['FOO_CONFIG_FILE'] = path('aws_bad_profile')
     self.environ['FOO_DEFAULT_PROFILE'] = 'personal1'
     session = botocore.session.get_session(self.env_vars)
     # First time is built from scratch.
     config = session.get_config()
     # Second time is cached.
     cached_config = session.get_config()
     # Both versions should be identical.
     self.assertEqual(config, cached_config)
Exemple #7
0
 def test_default_profile_specified_raises_exception(self):
     # If you explicity set the default profile and you don't
     # have that in your config file, an exception is raised.
     config_path = os.path.join(os.path.dirname(__file__), 'cfg',
                                'boto_config_empty')
     self.environ['FOO_CONFIG_FILE'] = config_path
     self.environ['FOO_PROFILE'] = 'default'
     session = botocore.session.get_session(self.env_vars)
     # In this case, even though we specified default, because
     # the boto_config_empty config file does not have a default
     # profile, we should be raising an exception.
     with self.assertRaises(botocore.exceptions.ProfileNotFound):
         session.get_config()
Exemple #8
0
 def test_default_profile_specified_raises_exception(self):
     # If you explicity set the default profile and you don't
     # have that in your config file, an exception is raised.
     config_path = os.path.join(os.path.dirname(__file__), 'cfg',
                                'boto_config_empty')
     self.environ['FOO_CONFIG_FILE'] = config_path
     self.environ['FOO_PROFILE'] = 'default'
     session = botocore.session.get_session(self.env_vars)
     # In this case, even though we specified default, because
     # the boto_config_empty config file does not have a default
     # profile, we should be raising an exception.
     with self.assertRaises(botocore.exceptions.ProfileNotFound):
         session.get_config()
Exemple #9
0
 def test_profile_does_not_exist_with_default_profile(self):
     session = botocore.session.get_session(self.env_vars)
     config = session.get_config()
     # We should have loaded this properly, and we'll check
     # that foo_access_key which is defined in the config
     # file should be present in the loaded config dict.
     self.assertIn('foo_access_key', config)
Exemple #10
0
 def test_profile_does_not_exist_with_default_profile(self):
     session = botocore.session.get_session(self.env_vars)
     config = session.get_config()
     # We should have loaded this properly, and we'll check
     # that foo_access_key which is defined in the config
     # file should be present in the loaded config dict.
     self.assertIn('foo_access_key', config)
Exemple #11
0
 def test_default_values_are_used_in_configs(self):
     env_vars = {'config_file': (
         None, 'FOO_CONFIG_FILE', path('aws_config'))}
     session = botocore.session.get_session(env_vars)
     config = session.get_config()
     self.assertEqual(config['aws_access_key_id'], 'foo')
     self.assertEqual(config['aws_secret_access_key'], 'bar')
Exemple #12
0
 def test_default_values_are_used_in_configs(self):
     env_vars = {'config_file': (
         None, 'FOO_CONFIG_FILE', path('aws_config'))}
     session = botocore.session.get_session(env_vars)
     config = session.get_config()
     self.assertEqual(config['aws_access_key_id'], 'foo')
     self.assertEqual(config['aws_secret_access_key'], 'bar')
Exemple #13
0
 def test_nested_hierarchy_parsing(self):
     self.environ["FOO_CONFIG_FILE"] = path("aws_config_nested")
     session = botocore.session.get_session(self.env_vars)
     config = session.get_config()
     self.assertEqual(config["aws_access_key_id"], "foo")
     self.assertEqual(config["region"], "us-west-2")
     self.assertEqual(config["s3"]["signature_version"], "s3v4")
     self.assertEqual(config["cloudwatch"]["signature_version"], "v4")
Exemple #14
0
 def test_nested_hierarchy_parsing(self):
     self.environ['FOO_CONFIG_FILE'] = path('aws_config_nested')
     session = botocore.session.get_session(self.env_vars)
     config = session.get_config()
     self.assertEqual(config['aws_access_key_id'], 'foo')
     self.assertEqual(config['region'], 'us-west-2')
     self.assertEqual(config['s3']['signature_version'], 's3v4')
     self.assertEqual(config['cloudwatch']['signature_version'], 'v4')
Exemple #15
0
 def test_bad_profile(self):
     self.environ["FOO_CONFIG_FILE"] = path("aws_bad_profile")
     self.environ["FOO_DEFAULT_PROFILE"] = "personal1"
     session = botocore.session.get_session(self.env_vars)
     config = session.get_config()
     profiles = session.available_profiles
     self.assertEqual(len(profiles), 3)
     self.assertIn("my profile", profiles)
     self.assertIn("personal1", profiles)
     self.assertIn("default", profiles)
     self.assertEqual(config, {"aws_access_key_id": "access_personal1", "aws_secret_access_key": "key_personal1"})
Exemple #16
0
 def test_env_vars_trump_defaults(self):
     env_vars = {"config_file": (None, "FOO_CONFIG_FILE", path("aws_config"))}
     self.environ["FOO_CONFIG_FILE"] = path("aws_config_other")
     # aws_config has access/secret keys of foo/bar, while
     # aws_config_other has access/secret key of other_foo/other_bar,
     # which is what should be used by the session since env vars
     # trump the default value.
     session = botocore.session.get_session(env_vars)
     config = session.get_config()
     self.assertEqual(config["aws_access_key_id"], "other_foo")
     self.assertEqual(config["aws_secret_access_key"], "other_bar")
Exemple #17
0
 def test_env_vars_trump_defaults(self):
     env_vars = {'config_file': (
         None, 'FOO_CONFIG_FILE', path('aws_config'))}
     self.environ['FOO_CONFIG_FILE'] = path('aws_config_other')
     # aws_config has access/secret keys of foo/bar, while
     # aws_config_other has access/secret key of other_foo/other_bar,
     # which is what should be used by the session since env vars
     # trump the default value.
     session = botocore.session.get_session(env_vars)
     config = session.get_config()
     self.assertEqual(config['aws_access_key_id'], 'other_foo')
     self.assertEqual(config['aws_secret_access_key'], 'other_bar')
Exemple #18
0
 def test_bad_profile(self):
     os.environ['FOO_CONFIG_FILE'] = path('aws_bad_profile')
     os.environ['FOO_DEFAULT_PROFILE'] = 'personal1'
     session = botocore.session.get_session(self.env_vars)
     config = session.get_config()
     profiles = session.available_profiles
     self.assertEqual(len(profiles), 3)
     self.assertIn('my profile', profiles)
     self.assertIn('personal1', profiles)
     self.assertIn('default', profiles)
     self.assertEqual(config, {'aws_access_key_id': 'access_personal1',
                               'aws_secret_access_key': 'key_personal1'})
Exemple #19
0
 def test_env_vars_trump_defaults(self):
     env_vars = {'config_file': (
         None, 'FOO_CONFIG_FILE', path('aws_config'))}
     os.environ['FOO_CONFIG_FILE'] = path('aws_config_other')
     # aws_config has access/secret keys of foo/bar, while
     # aws_config_other has access/secret key of other_foo/other_bar,
     # which is what should be used by the session since env vars
     # trump the default value.
     session = botocore.session.get_session(env_vars)
     config = session.get_config()
     self.assertEqual(config['aws_access_key_id'], 'other_foo')
     self.assertEqual(config['aws_secret_access_key'], 'other_bar')
Exemple #20
0
 def test_bad_profile(self):
     self.environ['FOO_CONFIG_FILE'] = path('aws_bad_profile')
     self.environ['FOO_DEFAULT_PROFILE'] = 'personal1'
     session = botocore.session.get_session(self.env_vars)
     config = session.get_config()
     profiles = session.available_profiles
     self.assertEqual(len(profiles), 3)
     self.assertIn('my profile', profiles)
     self.assertIn('personal1', profiles)
     self.assertIn('default', profiles)
     self.assertEqual(config, {'aws_access_key_id': 'access_personal1',
                               'aws_secret_access_key': 'key_personal1'})
Exemple #21
0
 def test_profile_does_not_exist_raises_exception(self):
     # Given we have no profile:
     self.environ['FOO_PROFILE'] = 'profile_that_does_not_exist'
     session = botocore.session.get_session(self.env_vars)
     with self.assertRaises(botocore.exceptions.ProfileNotFound):
         session.get_config()
Exemple #22
0
 def test_nested_bad_config(self):
     self.environ['FOO_CONFIG_FILE'] = path('aws_config_nested_bad')
     session = botocore.session.get_session(self.env_vars)
     with self.assertRaises(botocore.exceptions.ConfigParseError):
         cfg = session.get_config()
Exemple #23
0
 def test_config_not_found(self):
     self.environ['FOO_CONFIG_FILE'] = path('aws_config_notfound')
     session = botocore.session.get_session(self.env_vars)
     self.assertEqual(session.get_config(), {})
Exemple #24
0
 def test_config_parse_error(self):
     config_path = os.path.join(os.path.dirname(__file__), "aws_config_bad")
     os.environ["AWS_CONFIG_FILE"] = config_path
     session = botocore.session.get_session()
     with self.assertRaises(botocore.exceptions.ConfigParseError):
         config = session.get_config()
Exemple #25
0
 def test_nested_bad_config(self):
     self.environ["FOO_CONFIG_FILE"] = path("aws_config_nested_bad")
     session = botocore.session.get_session(self.env_vars)
     with self.assertRaises(botocore.exceptions.ConfigParseError):
         cfg = session.get_config()
Exemple #26
0
 def test_config_not_found(self):
     config_path = os.path.join(os.path.dirname(__file__), "aws_config_notfound")
     os.environ["AWS_CONFIG_FILE"] = config_path
     session = botocore.session.get_session()
     with self.assertRaises(botocore.exceptions.ConfigNotFound):
         config = session.get_config()
Exemple #27
0
 def test_config_not_found(self):
     self.environ["FOO_CONFIG_FILE"] = path("aws_config_notfound")
     session = botocore.session.get_session(self.env_vars)
     self.assertEqual(session.get_config(), {})
Exemple #28
0
 def test_profile_does_not_exist_raises_exception(self):
     # Given we have no profile:
     self.environ['FOO_PROFILE'] = 'profile_that_does_not_exist'
     session = botocore.session.get_session(self.env_vars)
     with self.assertRaises(botocore.exceptions.ProfileNotFound):
         session.get_config()
Exemple #29
0
 def test_config_not_found(self):
     os.environ['FOO_CONFIG_FILE'] = path('aws_config_notfound')
     session = botocore.session.get_session(self.env_vars)
     self.assertEqual(session.get_config(), {})
Exemple #30
0
 def test_default_values_are_used_in_configs(self):
     env_vars = {"config_file": (None, "FOO_CONFIG_FILE", path("aws_config"))}
     session = botocore.session.get_session(env_vars)
     config = session.get_config()
     self.assertEqual(config["aws_access_key_id"], "foo")
     self.assertEqual(config["aws_secret_access_key"], "bar")