diff --git a/data_management/object_storage.py b/data_management/object_storage.py index fc4f477..22e46fe 100644 --- a/data_management/object_storage.py +++ b/data_management/object_storage.py @@ -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 \ No newline at end of file diff --git a/data_management/settings.py b/data_management/settings.py index 8996a86..59da345 100644 --- a/data_management/settings.py +++ b/data_management/settings.py @@ -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 \ No newline at end of file + REMOTE_REGISTRY = False diff --git a/drams/base_settings.py b/drams/base_settings.py index 9965d46..835680a 100644 --- a/drams/base_settings.py +++ b/drams/base_settings.py @@ -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 diff --git a/drams/local-settings.py b/drams/local-settings.py index c839ad2..cc7f19b 100644 --- a/drams/local-settings.py +++ b/drams/local-settings.py @@ -7,4 +7,10 @@ ALLOWED_HOSTS.extend( filter(None, os.environ.get("FAIR_ALLOWED_HOSTS", "").split(",")) ) -DOMAIN_URL = "http://127.0.0.1:8000/" \ No newline at end of file +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" \ No newline at end of file diff --git a/drams/settings.py b/drams/settings.py index 1ecd539..c37df6a 100644 --- a/drams/settings.py +++ b/drams/settings.py @@ -5,6 +5,8 @@ ALLOWED_HOSTS = ['data.fairdatapipeline.org', '127.0.0.1', 'localhost'] +REMOTE = True + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', @@ -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 \ No newline at end of file diff --git a/drams/test-remote-settings.py b/drams/test-remote-settings.py index aae9983..21c9ab7 100644 --- a/drams/test-remote-settings.py +++ b/drams/test-remote-settings.py @@ -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 \ No newline at end of file