本文整理匯總了Python中botocore.exceptions.ConfigNotFound方法的典型用法代碼示例。如果您正苦於以下問題:Python exceptions.ConfigNotFound方法的具體用法?Python exceptions.ConfigNotFound怎麽用?Python exceptions.ConfigNotFound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類botocore.exceptions
的用法示例。
在下文中一共展示了exceptions.ConfigNotFound方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load
# 需要導入模塊: from botocore import exceptions [as 別名]
# 或者: from botocore.exceptions import ConfigNotFound [as 別名]
def load(self):
"""
If there is are credentials in the configuration associated with
the session, use those.
"""
try:
full_config = self._config_parser(self._config_filename)
except ConfigNotFound:
return None
if self._profile_name in full_config['profiles']:
profile_config = full_config['profiles'][self._profile_name]
if self.ACCESS_KEY in profile_config:
logger.info("Credentials found in config file: %s",
self._config_filename)
access_key, secret_key = self._extract_creds_from_mapping(
profile_config, self.ACCESS_KEY, self.SECRET_KEY)
token = self._get_session_token(profile_config)
return Credentials(access_key, secret_key, token,
method=self.METHOD)
else:
return None
示例2: initialized
# 需要導入模塊: from botocore import exceptions [as 別名]
# 或者: from botocore.exceptions import ConfigNotFound [as 別名]
def initialized(session, **kwargs):
session.session_var_map["keyring"] = ("keyring", None, False, cast_bool)
try:
if session.get_config_variable("keyring") != False:
if session.profile is not None:
profile = session.profile
else:
profile = "default"
key, secret = persistence.get_credentials(profile)
session.set_credentials(key, secret)
except (ConfigNotFound, ProfileNotFound):
pass
示例3: parse_key_val_file
# 需要導入模塊: from botocore import exceptions [as 別名]
# 或者: from botocore.exceptions import ConfigNotFound [as 別名]
def parse_key_val_file(filename, _open=open):
try:
with _open(filename) as f:
contents = f.read()
return parse_key_val_file_contents(contents)
except OSError:
raise ConfigNotFound(path=filename)
示例4: get_scoped_config
# 需要導入模塊: from botocore import exceptions [as 別名]
# 或者: from botocore.exceptions import ConfigNotFound [as 別名]
def get_scoped_config(self):
"""
Returns the config values from the config file scoped to the current
profile.
The configuration data is loaded **only** from the config file.
It does not resolve variables based on different locations
(e.g. first from the session instance, then from environment
variables, then from the config file). If you want this lookup
behavior, use the ``get_config_variable`` method instead.
Note that this configuration is specific to a single profile (the
``profile`` session variable).
If the ``profile`` session variable is set and the profile does
not exist in the config file, a ``ProfileNotFound`` exception
will be raised.
:raises: ConfigNotFound, ConfigParseError, ProfileNotFound
:rtype: dict
"""
profile_name = self.get_config_variable('profile')
profile_map = self._build_profile_map()
# If a profile is not explicitly set return the default
# profile config or an empty config dict if we don't have
# a default profile.
if profile_name is None:
return profile_map.get('default', {})
elif profile_name not in profile_map:
# Otherwise if they specified a profile, it has to
# exist (even if it's the default profile) otherwise
# we complain.
raise ProfileNotFound(profile=profile_name)
else:
return profile_map[profile_name]
示例5: full_config
# 需要導入模塊: from botocore import exceptions [as 別名]
# 或者: from botocore.exceptions import ConfigNotFound [as 別名]
def full_config(self):
"""Return the parsed config file.
The ``get_config`` method returns the config associated with the
specified profile. This property returns the contents of the
**entire** config file.
:rtype: dict
"""
if self._config is None:
try:
config_file = self.get_config_variable('config_file')
self._config = botocore.configloader.load_config(config_file)
except ConfigNotFound:
self._config = {'profiles': {}}
try:
# Now we need to inject the profiles from the
# credentials file. We don't actually need the values
# in the creds file, only the profile names so that we
# can validate the user is not referring to a nonexistent
# profile.
cred_file = self.get_config_variable('credentials_file')
cred_profiles = botocore.configloader.raw_config_parse(
cred_file)
for profile in cred_profiles:
cred_vars = cred_profiles[profile]
if profile not in self._config['profiles']:
self._config['profiles'][profile] = cred_vars
else:
self._config['profiles'][profile].update(cred_vars)
except ConfigNotFound:
pass
return self._config