From 85d3fbd98d63d8db79b9acf74be863506ff0d90e Mon Sep 17 00:00:00 2001 From: Garrett Holmstrom Date: Fri, 31 May 2013 16:36:50 -0700 Subject: [PATCH] Move AWS_ACCESS_KEY fetching to a saner function --- requestbuilder/auth.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/requestbuilder/auth.py b/requestbuilder/auth.py index dd2814c..82218eb 100644 --- a/requestbuilder/auth.py +++ b/requestbuilder/auth.py @@ -85,6 +85,11 @@ class HmacKeyAuth(BaseAuth): # If the current user/region was explicitly set (e.g. with --region), # use that first self.configure_from_configfile(only_if_explicit=True) + # Try the environment next + if 'AWS_ACCESS_KEY' in os.environ and not self.args.get('key_id'): + self.args['key_id'] = os.getenv('AWS_ACCESS_KEY') + if 'AWS_SECRET_KEY' in os.environ and not self.args.get('secret_key'): + self.args['secret_key'] = os.getenv('AWS_SECRET_KEY') # See if an AWS credential file was given in the environment self.configure_from_aws_credential_file() # Try the requestbuilder config file next @@ -96,10 +101,6 @@ class HmacKeyAuth(BaseAuth): raise AuthError('missing secret key; please supply one with -S') def configure_from_aws_credential_file(self): - if 'AWS_ACCESS_KEY' in os.environ and not self.args.get('key_id'): - self.args['key_id'] = os.getenv('AWS_ACCESS_KEY') - if 'AWS_SECRET_KEY' in os.environ and not self.args.get('secret_key'): - self.args['secret_key'] = os.getenv('AWS_SECRET_KEY') if 'AWS_CREDENTIAL_FILE' in os.environ: path = os.getenv('AWS_CREDENTIAL_FILE') path = os.path.expandvars(path)