Commit f6ebb167 authored by Christophe Lallement's avatar Christophe Lallement
Browse files

Merge branch 'update_example_code' into 'master'

Update example code

See merge request !16
parents 1fa94feb c1628ee1
Pipeline #89535 failed with stage
in 23 seconds
......@@ -13,25 +13,13 @@ Python 3.7
### pip install
```bash
pip install osdu-data-ecosystem-storage
pip install osdu-data-ecosystem-storage -extra-index-url https://community.opengroup.org/api/v4/projects/465/packages/pypi/simple
```
## Getting Started
Please follow the [installation procedure](#installation--usage) and then loog the the [example application](.§example.py)
## Documentation for API Endpoints
[storageGroupsAdministrationApi](odes_storage/docs/storageGroupsAdministrationApi.md
[storageGroupsAdministrationApi](odes_storage/docs/storageMembersAdministrationApi.md)
## Documentation For Models
[Documentation](../odes_storage/docs/)
## Documentation For Authorization
## Getting Started
TODO
Please follow the [installation procedure](#installation--usage) and look at [example application](./example.py)
## Contributing
......
import asyncio
from pprint import pprint
from odes_storage import AsyncApis as StorageApi, AuthApiClient as StorageClient
from odes_storage import AsyncApis as StorageApi, ApiClient, AuthApiClient
from odes_storage.models import CreateUpdateRecordsResponse, Legal, Record, StorageAcl
HOSTNAME = "https://os-storage-dot-opendes.appspot.com/api/storage"
TOKEN = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImY5ZDk3YjRjYWU5MGJjZDc2YWViMjAwMjZmNmI3NzBjYWMyMjE3ODMiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiI0ODk1NzIxMDc2OTUtb2FjajI0ZnRlNWExN3JtM2VsZ2lsaGJuNDljaWVnaG8uYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiI0ODk1NzIxMDc2OTUtb2FjajI0ZnRlNWExN3JtM2VsZ2lsaGJuNDljaWVnaG8uYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDM0MzY5NjA1NjQ3Njk2ODQzMzUiLCJoZCI6Im9wZW5kZXMucDRkLmNsb3VkLnNsYi1kcy5jb20iLCJlbWFpbCI6ImNsYWxsZW1lbnRAb3BlbmRlcy5wNGQuY2xvdWQuc2xiLWRzLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJhdF9oYXNoIjoiV1RBb1lVLTI5YTU3QmpOaV9IajNndyIsImlhdCI6MTU4NzU0MDI3NCwiZXhwIjoxNTg3NTQzODc0fQ.l3OljSD9N5FhNRbj8E8Gd3dyDj8Qi40r6W4e473tfTvGHzuE6QLpm5Yhp-l43HHHcOt_Gnbm-hEq6l9XXyx4yGAhna8Wp9vgz2HRlQDcXAB1WeYkBhzJ2PCu8QrT_cqahPzH8pqN8mNuTpEzJTVKZQJIm0Crs9DVz2XyIvCaUxX9lEqHKIzCVeRYjdoBKundRw4WKVXtrLd4ZX56fP9s06aUmHdrdN8BFmSn1JS2I8XNtPHarv_kKiItWbZIjWkjvM_OOCwx38oZUztTBq9W-uMh-nIT59PGj7e_RxtGUiEBlvkZroKvHg1wF1WcPOBQ5-EvW1oU19fjWkhyfbuQFQ"
DATA_PARTITION_ID = "opendes"
HOSTNAME = "http://127.0.0.1:8080"
TOKEN = "Bearer eyJ*******"
DATA_PARTITION = "my_data_partition"
ACL_DOMAIN = "acl_domain"
def make_storage_api_with_middleware():
async def client_middleware(request, call_next):
request.headers["Authorization"] = TOKEN
response = await call_next(request)
return response
api_client = ApiClient(host=HOSTNAME)
api_client.add_middleware(middleware=client_middleware)
return StorageApi(api_client)
def make_storage_api_with_auth_token():
return StorageApi(AuthApiClient(host=HOSTNAME, token=TOKEN))
async def main():
if 1:
storage_api = make_storage_api_with_middleware()
else:
storage_api = make_storage_api_with_auth_token()
record = Record(
kind="opendes:osdu:wellbore:2.0.0",
kind="osdu:wks:work-product-component--WellLog:1.1.0",
acl=StorageAcl(
viewers=["data.default.viewers@opendes.p4d.cloud.slb-ds.com"],
owners=["data.default.owners@opendes.p4d.cloud.slb-ds.com"],
viewers=[f"data.default.viewers@{DATA_PARTITION}.{ACL_DOMAIN}"],
owners=[f"data.default.owners@{DATA_PARTITION}.{ACL_DOMAIN}"],
),
legal=Legal(
legaltags=["opendes-public-usa-dataset-1"],
otherRelevantDataCountries=["US"],
legaltags=[f"{DATA_PARTITION}-default-legal"],
otherRelevantDataCountries=["FR"],
),
data={"msg": "hello world, from Data Ecosystem"},
data={"ReferenceCurveID": "MD", "Curves": [{"CurveID": "MD"}, {"CurveID": "GR"}]},
)
client = StorageApi(StorageClient(host=HOSTNAME, token=TOKEN))
created_record_response = await client.records_api.create_or_update_records(
data_partition_id=DATA_PARTITION_ID, skipdupes=False, record=[record],
created_record_response = await storage_api.records_api.create_or_update_records(
data_partition_id=DATA_PARTITION, skipdupes=False, record=[record],
)
assert isinstance(created_record_response, CreateUpdateRecordsResponse)
assert created_record_response.record_ids[0]
computed_record = await client.records_api.get_record(
data_partition_id=DATA_PARTITION_ID, id=created_record_response.record_ids[0],
pprint(created_record_response.__dict__)
computed_record = await storage_api.records_api.get_record(
data_partition_id=DATA_PARTITION, id=created_record_response.record_ids[0],
)
assert isinstance(computed_record, Record)
......@@ -41,7 +66,10 @@ async def main():
assert record.legal == computed_record.legal
assert record.data == computed_record.data
pprint(computed_record)
pprint(computed_record.__dict__)
await storage_api.client.close()
if __name__ == "__main__":
......
......@@ -9,7 +9,7 @@ with open("README.md", "r") as fh:
long_description = fh.read()
NAME = "osdu-data-ecosystem-storage"
VERSION = "1.3.0"
VERSION = "1.3.1"
# To install the library, run the following
#
# python setup.py install
......
Markdown is supported
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