Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions S3/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
# In python 3, unicode -> str, and str -> bytes
unicode = str

PY32 = (sys.version_info >= (3, 2))


def is_bool_true(value):
"""Check to see if a string is true, yes, on, or 1
Expand Down Expand Up @@ -268,7 +270,7 @@ def __init__(self, configfile = None, access_key=None, secret_key=None, access_t
try:
self.read_config_file(configfile)
except IOError:
if 'AWS_CREDENTIAL_FILE' in os.environ or 'AWS_PROFILE' in os.environ:
if 'AWS_SHARED_CREDENTIALS_FILE' in os.environ or 'AWS_CREDENTIAL_FILE' in os.environ or 'AWS_PROFILE' in os.environ:
self.aws_credential_file()

# override these if passed on the command-line
Expand Down Expand Up @@ -440,7 +442,8 @@ def role_refresh(self):
def aws_credential_file(self):
try:
aws_credential_file = os.path.expanduser('~/.aws/credentials')
credential_file_from_env = os.environ.get('AWS_CREDENTIAL_FILE')
credential_file_from_env = os.environ.get('AWS_SHARED_CREDENTIALS_FILE') \
or os.environ.get('AWS_CREDENTIAL_FILE')
if credential_file_from_env and \
os.path.isfile(credential_file_from_env):
aws_credential_file = base_unicodise(credential_file_from_env)
Expand All @@ -455,17 +458,23 @@ def aws_credential_file(self):
config_string = fp.read()
try:
try:
# readfp is replaced by read_file in python3,
# but so far readfp it is still available.
config.readfp(io.StringIO(config_string))
buf = io.StringIO(config_string)
if PY32:
config.read_file(buf)
else:
config.readfp(buf)
except MissingSectionHeaderError:
# if header is missing, this could be deprecated
# credentials file format as described here:
# https://blog.csanchez.org/2011/05/
# then do the hacky-hack and add default header
# to be able to read the file with PyConfigParser()
config_string = u'[default]\n' + config_string
config.readfp(io.StringIO(config_string))
buf = io.StringIO(config_string)
if PY32:
config.read_file(buf)
else:
config.readfp(buf)
except ParsingError as exc:
raise ValueError(
"Error reading aws_credential_file "
Expand Down
Loading