Skip to content
Permalink
Browse files
AIRAVATA-3458 Support get_data_product_metadata when user isn't owner
  • Loading branch information
machristie committed May 6, 2021
1 parent 76f44b1 commit f1cbe976a0c898179b26557395dcd46b21b831d4
Showing 2 changed files with 44 additions and 4 deletions.
@@ -402,7 +402,44 @@ def get_data_product_metadata(request, data_product=None, data_product_uri=None)
if data_product is None:
data_product = _get_data_product(request, data_product_uri)
storage_resource_id, path = _get_replica_resource_id_and_filepath(data_product)
return get_file_metadata(request, path, storage_resource_id)
if _is_remote_api():
resp = _call_remote_api(
request,
"/data-products/",
params={'product-uri': data_product.productUri})
data = resp.json()
file = {
"name": os.path.basename(path),
# FIXME: since this isn't the true relative path, going to leave out for now
# "path": path,
"resource_path": path,
"created_time": convert_iso8601_to_datetime(data['creationTime'], microseconds=False),
"size": data['filesize']
}
mime_type = None
if 'mime-type' in data_product.productMetadata:
mime_type = data_product.productMetadata['mime-type']
file['data-product-uri'] = data_product_uri
file['mime_type'] = mime_type
# TODO: remove this, there's no need for hidden files
file['hidden'] = False
return file
backend = get_user_storage_provider(request,
owner_username=data_product.ownerName,
storage_resource_id=storage_resource_id)
if backend.is_file(path):
_, files = backend.get_metadata(path)
file = files[0]
mime_type = None
if 'mime-type' in data_product.productMetadata:
mime_type = data_product.productMetadata['mime-type']
file['data-product-uri'] = data_product_uri
file['mime_type'] = mime_type
# TODO: remove this, there's no need for hidden files
file['hidden'] = False
return file
else:
raise ObjectDoesNotExist("File does not exist at that path.")


def get_file(request, path, storage_resource_id=None):
@@ -793,7 +830,7 @@ def _get_replica_resource_id_and_filepath(data_product):
return (replica_location.storageResourceId,
unquote(urlparse(replica_location.filePath).path))
else:
return None
return None, None


def _is_remote_api():
@@ -1,6 +1,9 @@
import datetime


def convert_iso8601_to_datetime(iso8601string):
def convert_iso8601_to_datetime(iso8601string, microseconds=True):
"""Convert ISO8601 datetime string to a datetime instance."""
return datetime.datetime.strptime(iso8601string, "%Y-%m-%dT%H:%M:%S.%fZ")
if microseconds:
return datetime.datetime.strptime(iso8601string, "%Y-%m-%dT%H:%M:%S.%fZ")
else:
return datetime.datetime.strptime(iso8601string, "%Y-%m-%dT%H:%M:%SZ")

0 comments on commit f1cbe97

Please sign in to comment.