Skip to content

Commit

Permalink
Testing version updates
Browse files Browse the repository at this point in the history
  • Loading branch information
k-burt-uch committed Oct 21, 2023
1 parent 9570fd3 commit b74f0c3
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 223 deletions.
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*.DS_Store
*.vscode

.idea
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -117,9 +117,9 @@ output_manifest.csv

.dccache
.idea
# Files generated during pytest
input.csv
test_combined_discovery_metadata.tsv
test_combined_discovery_metadata_exact_match.tsv
tmp_output_file.csv
tmp_output_file_info.csv
# pytest output
/input.csv
/test_combined_discovery_metadata.tsv
/test_combined_discovery_metadata_exact_match.tsv
/tmp_output_file.csv
/tmp_output_file_info.csv
81 changes: 67 additions & 14 deletions gen3/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ def create_record(
urls_metadata=None,
version=None,
authz=None,
description=None,
content_created_date=None,
content_updated_date=None,
):
"""
Expand All @@ -413,24 +416,42 @@ def create_record(
urls_metadata (dict): metadata attached to each url
baseid (str): optional baseid to group with previous entries versions
version (str): entry version string
description (str): optional description of the object
content_created_date (datetime): optional creation date and time of the content being indexed
content_updated_date (datetime): optional update date and time of the content being indexed
Returns:
Document: json representation of an entry in indexd
"""
rec = self.client.create(
hashes,
size,
did,
urls,
file_name,
metadata,
baseid,
acl,
urls_metadata,
version,
authz,
if urls is None:
urls = []
json = {
"urls": urls,
"form": "object",
"hashes": hashes,
"size": size,
"file_name": file_name,
"metadata": metadata,
"urls_metadata": urls_metadata,
"baseid": baseid,
"acl": acl,
"authz": authz,
"version": version,
"description": description,
"content_created_date": content_created_date,
"content_updated_date": content_updated_date,
}
if did:
json["did"] = did
resp = self.client._post(
"index/",
headers={"content-type": "application/json"},
data=client.json_dumps(json),
auth=self.client.auth,
)
return rec.to_json()
raise_for_status_and_print_error(resp)

return resp.json()

@backoff.on_exception(backoff.expo, Exception, **DEFAULT_BACKOFF_SETTINGS)
async def async_create_record(
Expand All @@ -447,6 +468,9 @@ async def async_create_record(
version=None,
authz=None,
_ssl=None,
description=None,
content_created_date=None,
content_updated_date=None,
):
"""
Asynchronous function to create a record in indexd.
Expand All @@ -464,6 +488,9 @@ async def async_create_record(
urls_metadata (dict): metadata attached to each url
baseid (str): optional baseid to group with previous entries versions
version (str): entry version string
description (str): optional description of the object
content_created_date (datetime): optional creation date and time of the content being indexed
content_updated_date (datetime): optional update date and time of the content being indexed
Returns:
Document: json representation of an entry in indexd
Expand Down Expand Up @@ -494,7 +521,12 @@ async def async_create_record(
json["version"] = version
if authz:
json["authz"] = authz

if description:
json["description"] = description
if content_created_date:
json["content_created_date"] = content_created_date
if content_updated_date:
json["content_updated_date"] = content_updated_date
# aiohttp only allows basic auth with their built in auth, so we
# need to manually add JWT auth header
headers = {"Authorization": self.client.auth._get_auth_value()}
Expand Down Expand Up @@ -550,6 +582,9 @@ def create_new_version(
urls_metadata=None,
version=None,
authz=None,
description=None,
content_created_date=None,
content_updated_date=None,
):
"""
Expand All @@ -573,6 +608,9 @@ def create_new_version(
urls_metadata (dict): metadata attached to each url
version (str): entry version string
authz (str): RBAC string
description (str): optional description of the object
content_created_date (datetime): optional creation date and time of the content being indexed
content_updated_date (datetime): optional update date and time of the content being indexed
body: json/dictionary format
- Metadata object that needs to be added to the store.
Expand All @@ -594,6 +632,9 @@ def create_new_version(
"acl": acl,
"authz": authz,
"version": version,
"description": description,
"content_created_date": content_created_date,
"content_updated_date": content_updated_date,
}
if did:
json["did"] = did
Expand Down Expand Up @@ -684,6 +725,9 @@ def update_record(
acl=None,
authz=None,
urls_metadata=None,
description=None,
content_created_date=None,
content_updated_date=None,
):
"""
Expand All @@ -705,6 +749,9 @@ def update_record(
"acl": acl,
"authz": authz,
"urls_metadata": urls_metadata,
"description": description,
"content_created_date": content_created_date,
"content_updated_date": content_updated_date,
}
rec = self.client.get(guid)
for k, v in updatable_attrs.items():
Expand All @@ -725,6 +772,9 @@ async def async_update_record(
authz=None,
urls_metadata=None,
_ssl=None,
description=None,
content_created_date=None,
content_updated_date=None,
**kwargs,
):
"""
Expand All @@ -746,6 +796,9 @@ async def async_update_record(
"acl": acl,
"authz": authz,
"urls_metadata": urls_metadata,
"description": description,
"content_created_date": content_created_date,
"content_updated_date": content_updated_date,
}
record = await self.async_get_record(guid)
revision = record.get("rev")
Expand Down
Loading

0 comments on commit b74f0c3

Please sign in to comment.