Commit c19f9076 authored by Spencer Sutton's avatar Spencer Sutton
Browse files

Added a create record and search for it example

parent b99b8158
'''
Basic example on creating a record and searching on it to get it back
'''
import os
import time
from osdu_api.storage.record_client import RecordClient
from osdu_api.search.search_client import SearchClient
# temporarily set environment variables in windows
os.environ['AWS_ACCESS_KEY_ID'] = 'AKIA5LUTQ6H7DFYQ3D7R'
os.environ['AWS_SECRET_ACCESS_KEY'] = '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'
os.environ['AWS_COGNITO_CLIENT_ID'] = '1k0965m7ojer8kls0vl62tdlal'
os.environ['AWS_COGNITO_AUTH_PARAMS_USER'] = 'spencer.sutton1@parivedasolutions.com'
os.environ['AWS_COGNITO_AUTH_PARAMS_PASSWORD'] = 'Osdu@123'
record_client = RecordClient()
search_client = SearchClient()
records = [
{
"data": {
"ResourceID": "srn:file/ascii:043253514614681856:",
"Data.GroupTypeProperties.PreLoadFilePath": "s3://osdu-test-data-918358651390/volve/horizons/Balder_Fm+ST0202R08_PS_PSDM_FULL_PP+STAT+TIME.dat",
"Data.GroupTypeProperties.FileSource": "",
"ResourceTypeID": "srn:type:file/ascii:",
"ResourceSecurityClassification": "srn:reference-data/ResourceSecurityClassification:RESTRICTED:",
"Data.GroupTypeProperties.EncodingFormatTypeID": "srn:reference-data/EncodingFormatType:Landmark:",
"AssociativeID": "f-1"
},
"kind": "opendes:osdu:file:0.2.0",
"namespace": "opendes:osdu",
"legal": {
"legaltags": [
"opendes-public-usa-dataset-5"
],
"otherRelevantDataCountries": [
"US"
],
"status": "compliant"
},
"id": "opendes:doc:59f9718a05e349c6b5ba38adb87a0317",
"acl": {
"viewers": [
"data.default.viewers@opendes.amazon.com"
],
"owners": [
"data.default.owners@opendes.amazon.com"
]
},
"type": "file",
"version": 0
}
]
query = {
"kind": "opendes:osdu:file:0.2.0",
"query": "data.Data.GroupTypeProperties.PreLoadFilePath: \"*Balder_Fm+ST0202R08_PS_PSDM_FULL_PP+STAT+TIME.dat\"",
"limit": 1000,
"aggregateBy": "kind"
}
create_record_resp = record_client.create_update_records_from_dict(records)
if create_record_resp.status_code != 201:
print("Record failed to create")
exit
# give the system 10 seconds to index the record
time.sleep(10)
search_record_resp = search_client.query_records_from_dict(query)
print(search_record_resp.results)
\ No newline at end of file
storage_url: https://1s8vxxyjl3.execute-api.us-east-1.amazonaws.com/api/storage/v2/records
search_url: https://1s8vxxyjl3.execute-api.us-east-1.amazonaws.com/api/search/v2/query
workflow_url: http://localhost:8090/updateStatusFunction
data_partition_id: opendes
# dynamically injects what provider-specific logic to use
provider: aws
entitlements_module_name: entitlements_client
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment