Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanJField committed Feb 8, 2024
1 parent 1ae2b5a commit e99b9c7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 19 deletions.
25 changes: 20 additions & 5 deletions data_management/object_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@
import hmac
import time

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
bucket = settings.BUCKETS['default']
expiry_time = int(time.time() + int(bucket['duration']))
path = bucket['bucket_name'] + '/' + 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)
sig = hmac.new(bucket['secret_key'].encode('utf-8'), hmac_body.encode('utf-8'), sha1).hexdigest()
url = '%s%s?temp_url_sig=%s&temp_url_expires=%d' % (bucket['url'], path, sig, expiry_time)
if filename:
url = '%s&filename=%s' % (url, filename)
return url

def create_legacy_url(path, method, filename=None):
bucket = settings.BUCKETS['default']
expiry_time = int(time.time() + int(bucket['duration']))
path = bucket['bucket_name'] + '/' + 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(bucket['secret_key'].encode('utf-8'), hmac_body.encode('utf-8'), sha1).hexdigest()
url = '%s%s?temp_url_sig=%s&temp_url_expires=%d' % (bucket['url'], path, sig, expiry_time)
if filename:
url = '%s&filename=%s' % (url, filename)
return url
15 changes: 4 additions & 11 deletions data_management/settings.py
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
2 changes: 2 additions & 0 deletions drams/base_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

REMOTE = False

ALLOWED_HOSTS = ['127.0.0.1', 'localhost']

# The URL of the central public registry
Expand Down
8 changes: 7 additions & 1 deletion drams/local-settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
ALLOWED_HOSTS.extend(
filter(None, os.environ.get("FAIR_ALLOWED_HOSTS", "").split(","))
)
DOMAIN_URL = "http://127.0.0.1:8000/"
DOMAIN_URL = "http://127.0.0.1:8000/"

DEBUG = True
CONFIG_LOCATION = "example_config.ini"
SOCIAL_AUTH_GITHUB_KEY = 'a1b2c3d4'
SOCIAL_AUTH_GITHUB_SECRET = 'e5f6g7h8i9'
AUTH_METHOD = "GitHub"
12 changes: 11 additions & 1 deletion drams/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

ALLOWED_HOSTS = ['data.fairdatapipeline.org', '127.0.0.1', 'localhost']

REMOTE = True

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
Expand All @@ -26,5 +28,13 @@
}
}

CONFIG_LOCATION = os.path.join(os.path.expanduser('~'), 'config.ini')
BUCKETS = {
'default': {
'url' : '#',
'bucket_name:': '#',
'access_key': '#',
'secret_key': '#',
'duration': '600'
}
}
CACHE_DURATION = 300
13 changes: 12 additions & 1 deletion drams/test-remote-settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
ALLOWED_HOSTS.extend(
filter(None, os.environ.get("FAIR_ALLOWED_HOSTS", "").split(","))
)
CONFIG_LOCATION = "example_config.ini"

BUCKETS = {
'default': {
'url' : 'http://127.0.0.1:4566/',
'bucket_name:': 'fair',
'access_key': 'AccessKey',
'secret_key': 'SecretKey',
'duration': '60'
}
}

REMOTE = True
DOMAIN_URL = 'http://127.0.0.1:8001/'
DEBUG = True

0 comments on commit e99b9c7

Please sign in to comment.