Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AWS4 compatibility fixes #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
13 changes: 8 additions & 5 deletions httpie_aws_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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):
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down