Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFR-1877: rewrite URLs as fulfillment URLs #286

Merged
merged 10 commits into from
Feb 1, 2024

Conversation

Apophenia
Copy link
Contributor

Description

This pull request rewrites the URLs of links for objects that are not EDD links and also nypl_login required. This should cover items within the scope of Limited Access.

Other options (like rewriting the links in the database and referring to a third, new column of S3 urls) were considered, but none of them seemed like they would work without heavily rewriting some of the code related to FRBRized output.

As it stands, almost all of the work is done at the "Format..." level for each hierarchy where links are part of the JSON formatted output. While this makes the change fairly superficial and it must be implemented in many places, it is hopefully transparent enough that this link overwriting can be easily found and modified and/or removed later if needed.

Motivation and Context

The link URLs in the database represent private s3 URLs. If the s3 URLs are sent as part of the JSON, there won't be any way for users (or the front end) to retrieve the contents of the URLs. The fulfill endpoint already contains the logic needed to generate a fulfill URL that points to the private item bucket via a time-gated URL that requires user authentication; however, the private URLs to s3 must be rewritten with these fulfillment URLs before the API output is returned.

@Apophenia Apophenia marked this pull request as ready for review February 1, 2024 14:31
Comment on lines +246 to +252
if formattedEdition.get("instances"):
for instance in formattedEdition['instances']:
for item in instance['items']:
# Map over item links and patch with pre-signed URL where necessary
item['links']= list(map(APIUtils.replacePrivateLinkUrl, item['links'], repeat(request)))

return formattedEdition
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good way to catch item links which the presigned url should replace.

Copy link
Contributor

@mitri-slory mitri-slory left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks great to me. I believe it's ready to be merged.

@Apophenia Apophenia merged commit 42c2155 into main Feb 1, 2024
2 checks passed
@Apophenia Apophenia deleted the SFR-1877_RewriteURLsAsFulfillmentURLs branch February 1, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants