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

Add AWS Token option to allow using AWS roles #2

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ So you may skip them in command line invocation in case you have aws config.
[--temp-dir TEMP_DIR]
[--s3-access-key-id S3_ACCESS_KEY_ID]
[--s3-secret-access-key S3_SECRET_ACCESS_KEY]
[--s3-access-token S3_ACCESS_TOKEN]
[--s3-endpoint S3_ENDPOINT]
[--s3-region S3_REGION]
[--s3-public-read]
Expand All @@ -56,6 +57,7 @@ So you may skip them in command line invocation in case you have aws config.
* `--temp-dir` - /(optional)/directory used to store temporary artifacts (default is .mkrepo)
* `--s3-access-key-id` - /(optional)/ specify S3 access key ID
* `--s3-secret-access-key` - /(optional)/ specify S3 secret key
* `--s3-access-token` - /(optional)/ specify role token
* `--s3-endpoint` - /(optional)/ specify S3 server URI
* `--s3-region` - /(optional)/ specify S3 region (default is us-east-1)
* `--s3-public-read` - /(optional)/ set read-only permission on files uploaded
Expand Down
18 changes: 11 additions & 7 deletions mkrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ def update_repo(path, args):
else:
bucket, prefix = path, '.'

stor = storage.S3Storage(args.s3_endpoint,
bucket,
prefix,
args.s3_access_key_id,
args.s3_secret_access_key,
args.s3_region,
args.s3_public_read)
stor = storage.S3Storage(endpoint=args.s3_endpoint,
bucket=bucket,
prefix=prefix,
aws_access_key_id=args.s3_access_key_id,
aws_secret_access_key=args.s3_secret_access_key,
aws_access_token=args.s3_access_token,
aws_region=args.s3_region,
aws_public_read=args.s3_public_read)

else:
stor = storage.FilesystemStorage(path)
Expand Down Expand Up @@ -74,6 +75,9 @@ def main():
parser.add_argument(
'--s3-secret-access-key', help='secret key for connecting to S3')

parser.add_argument(
'--s3-access-token', help='token for connecting to S3')

parser.add_argument(
'--s3-endpoint',
help='region endpoint for connecting to S3 (default: s3.amazonaws.com)')
Expand Down
3 changes: 3 additions & 0 deletions storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def __init__(self,
prefix="",
aws_access_key_id=None,
aws_secret_access_key=None,
aws_access_token=None,
aws_region=None,
aws_public_read=False):
self.bucket = bucket
Expand All @@ -137,12 +138,14 @@ def __init__(self,
self.client = boto3.client('s3', endpoint_url=endpoint,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_access_token,
region_name=aws_region)
self.resource = boto3.resource(
's3',
endpoint_url=endpoint,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_session_token=aws_access_token,
region_name=aws_region)

def read_file(self, key):
Expand Down