Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/tests/unit/customizations/configure/__init__.py
1569 views
1
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License"). You
4
# may not use this file except in compliance with the License. A copy of
5
# the License is located at
6
#
7
# http://aws.amazon.com/apache2.0/
8
#
9
# or in the "license" file accompanying this file. This file is
10
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
11
# ANY KIND, either express or implied. See the License for the specific
12
# language governing permissions and limitations under the License.
13
from botocore.exceptions import ProfileNotFound
14
15
16
class FakeSession(object):
17
18
def __init__(self, all_variables, profile_does_not_exist=False,
19
config_file_vars=None, environment_vars=None,
20
credentials=None, profile=None):
21
self.variables = all_variables
22
self.profile_does_not_exist = profile_does_not_exist
23
self.config = {}
24
if config_file_vars is None:
25
config_file_vars = {}
26
self.config_file_vars = config_file_vars
27
if environment_vars is None:
28
environment_vars = {}
29
self.environment_vars = environment_vars
30
self._credentials = credentials
31
self.profile = profile
32
33
def get_credentials(self):
34
return self._credentials
35
36
def get_scoped_config(self):
37
if self.profile_does_not_exist:
38
raise ProfileNotFound(profile='foo')
39
return self.config
40
41
def get_config_variable(self, name, methods=None):
42
if name == 'credentials_file':
43
# The credentials_file var doesn't require a
44
# profile to exist.
45
return '~/fake_credentials_filename'
46
if self.profile_does_not_exist and not name == 'config_file':
47
raise ProfileNotFound(profile='foo')
48
if methods is not None:
49
if 'env' in methods:
50
return self.environment_vars.get(name)
51
elif 'config' in methods:
52
return self.config_file_vars.get(name)
53
else:
54
return self.variables.get(name)
55
56
def emit(self, event_name, **kwargs):
57
pass
58
59
def emit_first_non_none_response(self, *args, **kwargs):
60
pass
61
62
def _build_profile_map(self):
63
if self.full_config is None:
64
return None
65
return self.full_config['profiles']
66
67