-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #217 from FAIRDataPipeline/update/object-storage
Update/object storage
- Loading branch information
Showing
11 changed files
with
64 additions
and
2,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
from hashlib import sha1 | ||
import hmac | ||
import time | ||
import boto3 | ||
|
||
from . import settings | ||
from django.conf import settings | ||
|
||
def create_url(path, method, filename=None): | ||
expiry_time = int(time.time() + int(settings.CONFIG.get('storage', 'duration'))) | ||
path = settings.CONFIG.get('storage', 'bucket') + '/' + path | ||
if method == 'GET': | ||
hmac_body = '%s\n%s\n%s' % ('GET', expiry_time, path) | ||
elif method == 'PUT': | ||
hmac_body = '%s\n%s\n%s' % ('PUT', expiry_time, path) | ||
sig = hmac.new(settings.CONFIG.get('storage', 'key').encode('utf-8'), hmac_body.encode('utf-8'), sha1).hexdigest() | ||
url = '%s%s?temp_url_sig=%s&temp_url_expires=%d' % (settings.CONFIG.get('storage', 'url'), path, sig, expiry_time) | ||
if filename: | ||
url = '%s&filename=%s' % (url, filename) | ||
return url | ||
def create_url(name, method, filename = None): | ||
bucket = settings.BUCKETS['default'] | ||
session = boto3.session.Session() | ||
s3_client = session.client( | ||
service_name= 's3', | ||
aws_access_key_id= bucket['access_key'], | ||
aws_secret_access_key= bucket['secret_key'], | ||
endpoint_url= bucket['url'], | ||
) | ||
if method == "GET": | ||
response = s3_client.generate_presigned_url('get_object', | ||
Params={'Bucket': bucket['bucket_name'], | ||
'Key': name, | ||
'ResponseContentDisposition': f'attachment; filename = {filename}',}, | ||
ExpiresIn=bucket['duration']) | ||
else: | ||
response = s3_client.generate_presigned_url('put_object', | ||
Params={'Bucket': bucket['bucket_name'], | ||
'Key': name}, | ||
ExpiresIn=bucket['duration']) | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,6 @@ | ||
from django.conf import settings | ||
|
||
import configparser | ||
import os | ||
import sys | ||
|
||
from django.conf import settings as conf_settings | ||
|
||
CONFIG = configparser.ConfigParser() | ||
if os.path.exists(conf_settings.CONFIG_LOCATION): | ||
CONFIG.read(conf_settings.CONFIG_LOCATION) | ||
REMOTE_REGISTRY = True | ||
if settings.AUTHORISED_USER_FILE: | ||
REMOTE_REGISTRY = settings.REMOTE | ||
else: | ||
REMOTE_REGISTRY = False | ||
REMOTE_REGISTRY = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ setuptools>54.2 | |
whitenoise==5.2.0 | ||
coverage | ||
rocrate==0.7.0 | ||
boto3>=1.24 |
Oops, something went wrong.