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-1828_APIS3ObjectLink #278

Merged
merged 5 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
## Added
- New script to add nypl_login flag to Links objects
- Added nypl_login flag to nypl mapping
- New APIUtils method to generate a presigned url for S3 actions
## Fixed

## 2023-09-05 version -- v0.12.3
Expand Down
30 changes: 29 additions & 1 deletion api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
from model import Collection, Edition
import re
from model.postgres.collection import COLLECTION_EDITIONS
from logger import createLog
from botocore.exceptions import ClientError


logger = createLog(__name__)

class APIUtils():
QUERY_TERMS = [
'keyword', 'title', 'author', 'subject', 'identifier', 'authority: identifier', 'viaf', 'lcnaf',
'date', 'startYear', 'endYear', 'language', 'format', 'govDoc', 'showAll'
'date', 'startYear', 'endYear', 'language', 'format', 'govDoc', 'showAll', 'key'
]

FORMAT_CROSSWALK = {
Expand Down Expand Up @@ -508,3 +513,26 @@ def validatePassword(password, hash, salt):
hashedPassword = scrypt(password, salt=salt, n=2**14, r=8, p=1)

return hashedPassword == hash

@staticmethod
def generate_presigned_url(s3_client, client_method, method_parameters, expires_in):
"""
Generate a presigned Amazon S3 URL that can be used to perform an action.

:param s3_client: A Boto3 Amazon S3 client.
:param client_method: The name of the client method that the URL performs.
:param method_parameters: The parameters of the specified client method.
:param expires_in: The number of seconds the presigned URL is valid for.
:return: The presigned URL.
"""
try:
url = s3_client.generate_presigned_url(
ClientMethod=client_method, Params=method_parameters, ExpiresIn=expires_in
)
logger.info("Got presigned URL: %s", url)
except ClientError:
logger.exception(
"Couldn't get a presigned URL for client method '%s'.", client_method
)
raise
return url
2 changes: 1 addition & 1 deletion scripts/nyplLoginFlags.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def main():

for link in dbManager.session.query(Link) \
.filter(or_(Link.media_type == 'application/html+edd', Link.media_type == 'application/x.html+edd')).all():
if link.flags['edd'] == True:
if link.flags and 'edd' in link.flags and link.flags['edd'] == True:
#The link.flags doesn't update if the dict method isn't called on it
newLinkFlag = dict(link.flags)
newLinkFlag['nypl_login'] = True
Expand Down
2 changes: 1 addition & 1 deletion swagger.v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@
}
}
}
},
},
mitri-slory marked this conversation as resolved.
Show resolved Hide resolved
"/link/{id}": {
"get": {
"tags": ["digital-research-books"],
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_api_work_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from api.utils import APIUtils


class TestSearchBlueprint:
class TestWorkBlueprint:
@pytest.fixture
def mockUtils(self, mocker):
return mocker.patch.multiple(
Expand Down
Loading