Skip to content
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ build:

test:
$(PYTHON) setup.py test

clean:
rm -rf dist/*
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ GitHub <https://github.com/Amsterdam/objectstore>`_ or file an issue at its

.. code-block:: bash

$ pip install --upgrade setuptools
$ pip install --upgrade setuptools wheel
$ python setup.py install develop

The `setuptools` pakage must be upgraded (as shown above) because the version
Expand Down
29 changes: 26 additions & 3 deletions objectstore/objectstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@

"""

import hmac
import logging
import os
# import pprint
from hashlib import sha1
from time import time

from swiftclient.client import Connection

LOG = logging.getLogger('objectstore')


logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
logging.getLogger("swiftclient").setLevel(logging.WARNING)
Expand All @@ -66,7 +67,7 @@ def make_config_from_env():

def get_connection(store_settings: dict = {}) -> Connection:
"""
get an objectsctore connection
get an objectstore connection
"""
store = store_settings

Expand Down Expand Up @@ -140,6 +141,28 @@ def put_object(
content_type=content_type)


def create_temp_url(connection, container: str, file_name: str, temp_url_key, expiry_minutes=0, expiry_hours=0,
expiry_days=0):
"""
Returns an url for users to temporarily access an object without further authentication
"""
# Create signature body
method = 'GET'
duration_in_seconds = ((((expiry_days * 24) + expiry_hours) * 60) + expiry_minutes) * 60
expires = int(time() + duration_in_seconds)
path = os.path.join(f'/{container}', file_name)
hmac_body = f'{method}\n{expires}\n{path}'.encode('utf-8')

# Create signature
key = bytes(temp_url_key, 'UTF-8')
sig = hmac.new(key, hmac_body, sha1).hexdigest()

# Create url
tenant_id = connection.os_options['tenant_id']
url = f'https://{tenant_id}.objectstore.eu{path}?temp_url_sig={sig}&temp_url_expires={expires}'
return url


def delete_object(connection, container: str, object_meta_data: dict) -> None:
"""
Delete single object from objectstore
Expand Down