Skip to content

Commit

Permalink
PR review resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
BinamB committed Jun 24, 2024
1 parent e749870 commit 71ec4e7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion fence/blueprints/data/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def upload_data_file():

blank_index = BlankIndex(
file_name=params["file_name"],
authz=params.get("authz"),
authz=authz,
uploader=uploader,
guid=guid,
)
Expand Down
7 changes: 4 additions & 3 deletions fence/blueprints/data/indexd.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ def __init__(
self.authz = authz

self.guid = guid
self.guid = self.index_document["did"]
self.guid = self.index_document[
"did"
] # .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

@cached_property
def index_document(self):
Expand All @@ -278,11 +280,10 @@ def index_document(self):
indexd_response = requests.get(index_url)
if indexd_response.status_code == 200:
document = indexd_response.json()
self.guid = document["did"]
self.logger.info(f"Record with {self.guid} id found in Indexd.")
return document
else:
raise NotFound("No indexed document found with id {}".format(self.guid))
raise NotFound(f"No indexed document found with id {self.guid}")

return self._create_blank_record()

Expand Down
4 changes: 2 additions & 2 deletions openapis/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ paths:
"file_upload" on "/data_file" resource. When "authz" is *not* provided, this
endpoint will check for that permission for your user.
Accepts a "did" field in the request body. If "did" is provided, it checks indexd for an existing record. If not found, a new blank record will be created.
Accepts a "guid" field in the request body. If "guid" is provided, it checks indexd for an existing record. If not found, a new blank record will be created.
security:
- OAuth2:
- user
Expand Down Expand Up @@ -671,7 +671,7 @@ paths:
the GUID for this new record and an uploadId for multipart upload presigned url.
Accepts a "did" field in the request body. If "did" is provided, it checks indexd for an existing record. If not found, a new blank record will be created.
Accepts a "guid" field in the request body. If "guid" is provided, it checks indexd for an existing record. If not found, a new blank record will be created.
security:
- OAuth2:
- user
Expand Down
21 changes: 20 additions & 1 deletion tests/data/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,10 @@ def json(self):
def test_initialize_multipart_upload_with_guid_in_request(
app, client, auth_client, encoded_creds_jwt, user_client, indexd_200_response
):
"""
Test /data/multipart/init with guid parameter in request data
"""

class MockResponse(object):
def __init__(self, data, status_code=200):
self.data = data
Expand All @@ -1754,7 +1758,21 @@ def json(self):
did = str(uuid.uuid4())
if indexd_200_response:
data_requests.get.return_value = MockResponse(
INDEXD_RECORD_WITH_PUBLIC_AUTHZ_AND_ACL_POPULATED
{
"did": did,
"baseid": "",
"rev": "",
"size": 10,
"file_name": "file1",
"urls": ["s3://bucket1/key"],
"hashes": {},
"metadata": {},
"authz": ["/open"],
"acl": ["*"],
"form": "",
"created_date": "",
"updated_date": "",
}
)
data_requests.get.return_value.status_code = 200
else:
Expand All @@ -1776,6 +1794,7 @@ def json(self):
if indexd_200_response:
assert response.status_code == 201, response
assert "guid" in response.json
assert did == response.json.get("guid")
assert "uploadId" in response.json
else:
assert response.status_code == 404, response
Expand Down

0 comments on commit 71ec4e7

Please sign in to comment.