Skip to content

Commit

Permalink
Merge pull request #217 from FAIRDataPipeline/update/object-storage
Browse files Browse the repository at this point in the history
Update/object storage
  • Loading branch information
RyanJField authored Feb 9, 2024
2 parents 1ae2b5a + 42b3bf9 commit 8c99664
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 2,110 deletions.
10 changes: 2 additions & 8 deletions .github/workflows/fair-data-registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@ jobs:
else
brew install graphviz
fi
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Run Tests
run: |
poetry install
source $VENV
python -m pip install -r local-requirements.txt
DJANGO_SETTINGS_MODULE=drams.test-settings coverage run --omit=drams,scripts,tools manage.py test
- name: Generate XML
run: poetry run coverage xml
run: coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
40 changes: 24 additions & 16 deletions data_management/object_storage.py
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
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
1 change: 1 addition & 0 deletions local-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ setuptools>54.2
whitenoise==5.2.0
coverage
rocrate==0.7.0
boto3>=1.24
Loading

0 comments on commit 8c99664

Please sign in to comment.