Skip to content

Commit 31530b8

Browse files
authored
Merge branch 'master' into feat/s3-delete-files
2 parents 2bf992a + 4d98387 commit 31530b8

File tree

5 files changed

+281
-68
lines changed

5 files changed

+281
-68
lines changed

fence/blueprints/data/blueprint.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def upload_data_file():
134134
authz = params.get("authz")
135135
uploader = None
136136

137+
guid = params.get("guid")
138+
137139
if authz:
138140
# if requesting an authz field, using new authorization method which doesn't
139141
# rely on uploader field, so clear it out
@@ -165,7 +167,10 @@ def upload_data_file():
165167
)
166168

167169
blank_index = BlankIndex(
168-
file_name=params["file_name"], authz=params.get("authz"), uploader=uploader
170+
file_name=params["file_name"],
171+
authz=authz,
172+
uploader=uploader,
173+
guid=guid,
169174
)
170175
default_expires_in = flask.current_app.config.get("MAX_PRESIGNED_URL_TTL", 3600)
171176

@@ -199,16 +204,16 @@ def upload_data_file():
199204
def init_multipart_upload():
200205
"""
201206
Initialize a multipart upload request
202-
203-
NOTE This endpoint does not currently accept a `bucket` parameter like
204-
`POST /upload` and `GET /upload/<GUID>` do.
205207
"""
206208
params = flask.request.get_json()
207209
if not params:
208210
raise UserError("wrong Content-Type; expected application/json")
209211
if "file_name" not in params:
210212
raise UserError("missing required argument `file_name`")
211-
blank_index = BlankIndex(file_name=params["file_name"])
213+
214+
guid = params.get("guid")
215+
216+
blank_index = BlankIndex(file_name=params["file_name"], guid=guid)
212217

213218
default_expires_in = flask.current_app.config.get("MAX_PRESIGNED_URL_TTL", 3600)
214219
expires_in = get_valid_expiration(

fence/blueprints/data/indexd.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,12 @@ class BlankIndex(object):
258258
"""
259259

260260
def __init__(
261-
self, uploader=None, file_name=None, logger_=None, guid=None, authz=None
261+
self,
262+
uploader=None,
263+
file_name=None,
264+
logger_=None,
265+
guid=None,
266+
authz=None,
262267
):
263268
self.logger = logger_ or logger
264269
self.indexd = (
@@ -279,8 +284,9 @@ def __init__(
279284
self.file_name = file_name
280285
self.authz = authz
281286

282-
# if a guid is not provided, this will create a blank record for you
283-
self.guid = guid or self.index_document["did"]
287+
self.guid = guid
288+
# .index_document is a cached property with code below, it creates/retrieves the actual record and this line updates the stored GUID to the returned record
289+
self.guid = self.index_document["did"]
284290

285291
@cached_property
286292
def index_document(self):
@@ -292,6 +298,20 @@ def index_document(self):
292298
response from indexd (the contents of the record), containing ``guid``
293299
and ``url``
294300
"""
301+
302+
if self.guid:
303+
index_url = self.indexd.rstrip("/") + "/index/" + self.guid
304+
indexd_response = requests.get(index_url)
305+
if indexd_response.status_code == 200:
306+
document = indexd_response.json()
307+
self.logger.info(f"Record with {self.guid} id found in Indexd.")
308+
return document
309+
else:
310+
raise NotFound(f"No indexed document found with id {self.guid}")
311+
312+
return self._create_blank_record()
313+
314+
def _create_blank_record(self):
295315
index_url = self.indexd.rstrip("/") + "/index/blank/"
296316
params = {"uploader": self.uploader, "file_name": self.file_name}
297317

openapis/swagger.yaml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ paths:
577577
Previous authorization check requires a more general, global upload permission:
578578
"file_upload" on "/data_file" resource. When "authz" is *not* provided, this
579579
endpoint will check for that permission for your user.
580+
581+
Accepts a "guid" field in the request body. If "guid" is provided, it checks indexd for an existing record. If not found, it raises a 404.
580582
security:
581583
- OAuth2:
582584
- user
@@ -602,6 +604,8 @@ paths:
602604
url:
603605
type: string
604606
description: the presigned URL usable for data upload
607+
404:
608+
description: Record with <guid> not found.
605609
'/data/upload/{file_id}':
606610
get:
607611
tags:
@@ -678,7 +682,10 @@ paths:
678682
flow, Fence needs to provide a list of endpoints for supporting multipart upload presigned url
679683
This is the first step on the API side for the multipart upload presigned url. This endpoint
680684
causes fence to make a request to indexd to create a new, blank index record, and returns
681-
the GUID for this new record and an uploadId for multipart upload presigned url
685+
the GUID for this new record and an uploadId for multipart upload presigned url.
686+
687+
688+
Accepts a "guid" field in the request body. If "guid" is provided, it checks indexd for an existing record. If not found, it raises a 404.
682689
security:
683690
- OAuth2:
684691
- user
@@ -704,6 +711,8 @@ paths:
704711
uploadId:
705712
type: string
706713
description: the uploadId for multipart upload presigned URL usable for data upload
714+
404:
715+
description: Record with <guid> not found.
707716

708717
'/multipart/upload':
709718
post:
@@ -1698,6 +1707,10 @@ components:
16981707
description: >-
16991708
the requested bucket to upload to.
17001709
If not provided, defaults to the configured DATA_UPLOAD_BUCKET.
1710+
guid:
1711+
type: string
1712+
required: false
1713+
description: GUID to be assigned to the object
17011714
expires_in:
17021715
type: integer
17031716
description: optional integer specifying the presigned URL lifetime
@@ -1708,6 +1721,7 @@ components:
17081721
description: requested authorization resources to be set on the
17091722
resulting indexed record. You must have proper authorization to set this
17101723
example:
1724+
guid: "123456abcd"
17111725
file_name: "my_file.bam"
17121726
bucket: "bucket1"
17131727
expires_in: 1200
@@ -1720,6 +1734,10 @@ components:
17201734
type: string
17211735
required: true
17221736
description: the file name to use for this upload
1737+
guid:
1738+
type: string
1739+
required: false
1740+
description: GUID to be assigned to the object
17231741
expires_in:
17241742
type: integer
17251743
description: optional integer specifying the presigned URL lifetime

0 commit comments

Comments
 (0)