diff --git a/httpie_aws_auth.py b/httpie_aws_auth.py index 3de63ac..de94aa7 100644 --- a/httpie_aws_auth.py +++ b/httpie_aws_auth.py @@ -7,8 +7,7 @@ from httpie.status import ExitStatus from httpie.plugins import AuthPlugin -from httpie.compat import bytes -from awsauth import S3Auth +from requests_aws4auth import AWS4Auth __version__ = '0.0.3' @@ -21,7 +20,7 @@ SECRET = 'AWS_SECRET_ACCESS_KEY' -class BytesHeadersFriendlyS3Auth(S3Auth): +class BytesHeadersFriendlyS3Auth(AWS4Auth): def __call__(self, r): for k, v in r.headers.items(): if isinstance(v, bytes): @@ -35,7 +34,7 @@ def __call__(self, r): class AWSAuthPlugin(AuthPlugin): name = 'AWS auth' auth_type = 'aws' - description = '' + description = 'Obtains AWS credentials from AWS_* environment variables or from `--auth KEY_ID:KEY`' auth_require = False prompt_password = True @@ -45,6 +44,10 @@ def get_auth(self, username=None, password=None): # the behaviour would be confusing to the user. access_key = os.environ.get(KEY) if username is None else username secret = os.environ.get(SECRET) if password is None else password + session_token = os.environ.get('AWS_SESSION_TOKEN', default=None) + default_region = os.environ.get('AWS_DEFAULT_REGION', default="us-east-1") + region = os.environ.get('AWS_REGION', default=default_region) + service = "s3" if not access_key or not secret: missing = [] if not access_key: @@ -57,4 +60,4 @@ def get_auth(self, username=None, password=None): ) sys.exit(ExitStatus.PLUGIN_ERROR) - return BytesHeadersFriendlyS3Auth(access_key, secret) + return BytesHeadersFriendlyS3Auth(access_key, secret, region, service, session_token=session_token) diff --git a/setup.py b/setup.py index 28b8b3d..0a5ae68 100644 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ }, install_requires=[ 'httpie>=0.9.7', - 'requests-aws>=0.1.8' + 'requests-aws4auth>=1.0.0' ], classifiers=[ 'Development Status :: 5 - Production/Stable',