Class: Uc3DmpProvenance::Finder
- Inherits:
-
Object
- Object
- Uc3DmpProvenance::Finder
- Defined in:
- lib/uc3-dmp-provenance/finder.rb
Overview
Helper for fetching Provenance JSON records
Class Method Summary collapse
-
.from_lambda_cotext(identity:, client: nil, logger: nil) ⇒ Object
Get the Provenance item for the Lambda :event.
-
.from_pk(p_key:, logger: nil) ⇒ Object
Fetch the Provenance by it’s PK.
Class Method Details
.from_lambda_cotext(identity:, client: nil, logger: nil) ⇒ Object
Get the Provenance item for the Lambda :event
Expecting the :claims hash from the requestContext portion of the :event. It should look something like this:
{
"sub": "abcdefghijklmnopqrstuvwxyz",
"token_use": "access",
"scope": "https://auth.dmphub-dev.cdlib.org/dev.write",
"auth_time": "1675895546",
"iss": "https://cognito-idp.us-west-2.amazonaws.com/us-west-A_123456",
"exp": "Wed Feb 08 22:42:26 UTC 2023",
"iat": "Wed Feb 08 22:32:26 UTC 2023",
"version": "2",
"jti": "5d3be8a7-c595-1111-yyyy-xxxxxxxxxx",
"client_id": "abcdefghijklmnopqrstuvwxyz"
}
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/uc3-dmp-provenance/finder.rb', line 30 def from_lambda_cotext(identity:, client: nil, logger: nil) return nil unless identity.is_a?(Hash) && !identity['iss'].nil? && !identity['client_id'].nil? client = client.nil? ? Uc3DmpDynamo::Client.new : client client_name = _cognito_client_id_to_name(claim: identity, logger:) resp = client.get_item( key: { PK: Helper.append_pk_prefix(provenance: client_name), SK: Helper::SK_PROVENANCE_PREFIX }, logger: ) resp.nil? || resp.empty? ? nil : resp end |
.from_pk(p_key:, logger: nil) ⇒ Object
Fetch the Provenance by it’s PK.
Expecting either the name (e.g. ‘dmptool` or the qualified PK (e.g. `PROVENANCE#dmptool`)
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/uc3-dmp-provenance/finder.rb', line 46 def from_pk(p_key:, logger: nil) return nil if p_key.nil? p_key = Helper.append_pk_prefix(provenance: p_key) resp = client.get_item( key: { PK: Helper.append_pk_prefix(provenance: p_key), SK: Helper::SK_PROVENANCE_PREFIX }, logger: ) resp.nil? || resp.empty? ? nil : resp end |