Commit 3a05b44b authored by Sutton's avatar Sutton
Browse files

Making comments conform to python doc standard

parent 30fde309
......@@ -17,36 +17,37 @@ from configparser import SafeConfigParser
import requests
from osdu_api.model.http_method import HttpMethod
'''
Base client that is meant to be extended by service specific clients
'''
class BaseClient:
"""
Base client that is meant to be extended by service specific clients
"""
'''
Base client gets initialized with configuration values and a bearer token
based on provider-specific logic
'''
def __init__(self):
"""
Base client gets initialized with configuration values and a bearer token
based on provider-specific logic
"""
self._parse_config()
self.unauth_retries = 0
if self.use_service_principal == 'True' or self.use_service_principal == 'true':
self._refresh_service_principal_token()
'''
Example config file:
[environment]
data_partition_id=opendes
storage_url=https://[STORAGE_ENDPOINT]/api/storage/v2
search_url=https://[SEARCH_ENDPOINT]/api/search/v2
data_workflow_url=https://[WORKFLOW_ENDPOINT]/api/data-workflow/v1
file_dms_url=https://[FILE_DMS_ENDPOINT]/api/filedms/v2
dataset_registry_url=https://[DATASET_REGISTRY_URL]/api/dataset-registry/v1
[provider]
name=aws
entitlements_module_name=entitlements_client
'''
def _parse_config(self):
"""
Example config file:
[environment]
data_partition_id=opendes
storage_url=https://[STORAGE_ENDPOINT]/api/storage/v2
search_url=https://[SEARCH_ENDPOINT]/api/search/v2
data_workflow_url=https://[WORKFLOW_ENDPOINT]/api/data-workflow/v1
file_dms_url=https://[FILE_DMS_ENDPOINT]/api/filedms/v2
dataset_registry_url=https://[DATASET_REGISTRY_URL]/api/dataset-registry/v1
[provider]
name=aws
entitlements_module_name=entitlements_client
"""
config_parser = SafeConfigParser(os.environ)
config_file_name = 'osdu_api.ini'
found_names = config_parser.read(config_file_name)
......@@ -66,20 +67,19 @@ class BaseClient:
self.provider = config_parser.get('provider', 'name')
self.service_principal_module_name = config_parser.get('provider', 'service_principal_module_name')
'''
The path to the logic to get a valid bearer token is dynamically injected based on
what provider and entitlements module name is provided in the configuration yaml
'''
def _refresh_service_principal_token(self):
"""
The path to the logic to get a valid bearer token is dynamically injected based on
what provider and entitlements module name is provided in the configuration yaml
"""
entitlements_client = importlib.import_module('osdu_api.provider.%s.%s' % (self.provider, self.service_principal_module_name))
self.service_principal_token = entitlements_client.get_service_principal_token()
'''
Makes a request using python's built in requests library. Takes additional headers if
necessary
'''
def make_request(self, method: HttpMethod, url: str, data = '', add_headers = {}, params = {}, bearer_token = None):
"""
Makes a request using python's built in requests library. Takes additional headers if
necessary
"""
if bearer_token is not None and 'Bearer ' not in bearer_token:
bearer_token = 'Bearer ' + bearer_token
......
......@@ -19,10 +19,11 @@ from osdu_api.model.data_workflow.start_workflow import StartWorkflow
from osdu_api.model.data_workflow.update_status_request import UpdateStatusRequest
from osdu_api.model.http_method import HttpMethod
'''
Holds the logic for interfacing with Data Workflow's api
'''
class DataWorkflowClient(BaseClient):
"""
Holds the logic for interfacing with Data Workflow's api
"""
def start_workflow(self, start_workflow: StartWorkflow, bearer_token=None):
return self.make_request(method=HttpMethod.POST, url='{}{}'.format(self.data_workflow_url, '/startWorkflow'),
data=start_workflow.to_JSON(), bearer_token=bearer_token)
......
......@@ -19,11 +19,12 @@ from osdu_api.model.data_workflow.workflow_schedule import WorkflowSchedule
from osdu_api.model.data_workflow.get_workflow_schedules_request import GetWorkflowSchedulesRequest
from osdu_api.model.http_method import HttpMethod
'''
Holds the logic for interfacing with Data Workflow's scheduling api
'''
class DataWorkflowSchedulingClient(BaseClient):
"""
Holds the logic for interfacing with Data Workflow's scheduling api
"""
def create_workflow_schedule(self, workflow_schedule: WorkflowSchedule, bearer_token=None):
return self.make_request(method=HttpMethod.POST, url='{}{}'.format(self.data_workflow_url, '/scheduling'),
data=workflow_schedule.to_JSON(), bearer_token=bearer_token)
......
......@@ -17,11 +17,12 @@ from osdu_api.clients.base_client import BaseClient
from osdu_api.model.dataset.get_dataset_registry_request import GetDatasetRegistryRequest
from osdu_api.model.http_method import HttpMethod
'''
Holds the logic for interfacing with Data Registry Service's DMS api
'''
class DatasetDmsClient(BaseClient):
"""
Holds the logic for interfacing with Data Registry Service's DMS api
"""
def get_storage_instructions(self, resource_type_id: str, bearer_token=None):
params = {'resourceType': resource_type_id}
return self.make_request(method=HttpMethod.GET, url='{}{}'.format(self.dataset_url, '/getStorageInstructions'),
......
......@@ -18,10 +18,11 @@ from osdu_api.model.dataset.create_dataset_registries_request import CreateDatas
from osdu_api.model.dataset.get_dataset_registry_request import GetDatasetRegistryRequest
from osdu_api.model.http_method import HttpMethod
'''
Holds the logic for interfacing with Data Registry Service's api
'''
class DatasetRegistryClient(BaseClient):
"""
Holds the logic for interfacing with Data Registry Service's api
"""
def register_dataset(self, dataset_registries: CreateDatasetRegistriesRequest, bearer_token=None):
return self.make_request(method=HttpMethod.PUT, url='{}{}'.format(self.dataset_url, '/registerDataset'),
......
......@@ -18,10 +18,10 @@ from osdu_api.model.http_method import HttpMethod
from osdu_api.model.entitlements.group import Group
from osdu_api.model.entitlements.group_member import GroupMember
'''
Holds the logic for interfacing with Entitlement's api
'''
class EntitlementsClient(BaseClient):
"""
Holds the logic for interfacing with Entitlement's api
"""
def get_groups_for_user(self, bearer_token=None):
return self.make_request(method=HttpMethod.GET, url='{}{}'.format(self.entitlements_url, '/groups'), bearer_token=bearer_token)
......
......@@ -19,10 +19,11 @@ from osdu_api.model.legal.update_legal_tag import UpdateLegalTag
from osdu_api.model.legal.legal_tag_names import LegalTagNames
from osdu_api.model.http_method import HttpMethod
'''
Holds the logic for interfacing with Legal's api
'''
class LegalClient(BaseClient):
"""
Holds the logic for interfacing with Legal's api
"""
def get_legal_tag(self, legal_tag_name: str, bearer_token=None):
return self.make_request(method=HttpMethod.GET, url='{}{}/{}'.format(self.legal_url, '/legaltags', legal_tag_name), bearer_token=bearer_token)
......
......@@ -18,14 +18,12 @@ from osdu_api.model.http_method import HttpMethod
from osdu_api.model.search.query_response import QueryResponse
from osdu_api.model.search.query_request import QueryRequest
'''
Holds the logic for interfacing with Search's query api
'''
class SearchClient(BaseClient):
"""
Holds the logic for interfacing with Search's query api
"""
'''
Used to hit search's api endpoint "queryRecords"
'''
def query_records(self, query_request: QueryRequest, bearer_token = None):
return self.make_request(method=HttpMethod.POST, url='{}{}'.format(self.search_url, '/query'),
data=query_request.to_JSON(), bearer_token=bearer_token)
......
......@@ -18,28 +18,29 @@ from osdu_api.model.storage.record import Record
from osdu_api.model.storage.query_records_request import QueryRecordsRequest
from osdu_api.model.http_method import HttpMethod
'''
Holds the logic for interfacing with Storage's record api
'''
class RecordClient(BaseClient):
'''
Calls storage's api endpoint createOrUpdateRecords taking a list of record objects and constructing
the body of the request
Returns the response object for the call
class RecordClient(BaseClient):
"""
Holds the logic for interfacing with Storage's record api
"""
Example of code to new up a record:
acl = Acl(['data.test1@opendes.testing.com'], ['data.test1@opendes.testing.com'])
legal = Legal(['opendes-storage-1579034803194'], ['US'], LegalCompliance.compliant)
ancestry = RecordAncestry([])
id = 'opendes:welldb:123456'
kind = 'opendes:welldb:wellbore:1.0.0'
meta = [{}]
version = 0
data = {'id': 'test'}
record = Record(id, version, kind, acl, legal, data, ancestry, meta)
'''
def create_update_records(self, records: List[Record], bearer_token = None):
"""
Calls storage's api endpoint createOrUpdateRecords taking a list of record objects and constructing
the body of the request
Returns the response object for the call
Example of code to new up a record:
acl = Acl(['data.test1@opendes.testing.com'], ['data.test1@opendes.testing.com'])
legal = Legal(['opendes-storage-1579034803194'], ['US'], LegalCompliance.compliant)
ancestry = RecordAncestry([])
id = 'opendes:welldb:123456'
kind = 'opendes:welldb:wellbore:1.0.0'
meta = [{}]
version = 0
data = {'id': 'test'}
record = Record(id, version, kind, acl, legal, data, ancestry, meta)
"""
records_data = '['
for record in records:
records_data = '{}{}{}'.format(records_data, record.to_JSON(), ',')
......@@ -47,29 +48,28 @@ class RecordClient(BaseClient):
records_data = '{}{}'.format(records_data, ']')
return self.make_request(method=HttpMethod.PUT, url='{}{}'.format(self.storage_url, '/records'), data=records_data, bearer_token=bearer_token)
'''
Calls storage's api endpoint getLatestRecordVersion taking the required attributes
Returns the content for the response object
'''
def get_latest_record(self, recordId: str, attributes: List[str] = [], bearer_token = None):
"""
Calls storage's api endpoint getLatestRecordVersion taking the required attributes
Returns the content for the response object
"""
request_params = {'attribute': attributes}
return self.make_request(method=HttpMethod.GET, params=request_params, url=('{}{}/{}'.format(self.storage_url, '/records', recordId)), bearer_token=bearer_token)
'''
Calls storage's api endpoint getSpecificRecordVersion taking the required attributes
Returns the content for the response object
'''
def get_specific_record(self, recordId: str, version: str, attributes: List[str] = [], bearer_token = None):
"""
Calls storage's api endpoint getSpecificRecordVersion taking the required attributes
Returns the content for the response object
"""
request_params = {'attribute': attributes}
return self.make_request(method=HttpMethod.GET, params=request_params, url=('{}{}/{}/{}'.format(self.storage_url, '/records', recordId, version)), bearer_token=bearer_token)
'''
Calls storage's api endpoint getRecordVersions taking the one required parameter record id
Returns the content for the response object for the call containing the list of versions.
Find the versions in the response.content attribute
'''
def get_record_versions(self, recordId: str, bearer_token = None):
"""
Calls storage's api endpoint getRecordVersions taking the one required parameter record id
Returns the content for the response object for the call containing the list of versions.
Find the versions in the response.content attribute
"""
return self.make_request(method=HttpMethod.GET, url=('{}{}/{}'.format(self.storage_url, '/records/versions', recordId)), bearer_token=bearer_token)
def delete_record(self, recordId: str, bearer_token = None):
......
......@@ -18,10 +18,10 @@ from osdu_api.model.http_method import HttpMethod
from osdu_api.model.storage.schema.schema import Schema
from osdu_api.model.storage.schema.schema_attribute import SchemaAttribute
'''
Holds the logic for interfacing with Storage's R2 schema api
'''
class SchemaClient(BaseClient):
"""
Holds the logic for interfacing with Storage's R2 schema api
"""
def create_schema(self, schema: Schema, bearer_token=None):
return self.make_request(method=HttpMethod.POST, url='{}{}'.format(self.storage_url, '/schemas'),
......
......@@ -51,7 +51,7 @@ record = Record(kind, acl, legal, data)
query_request = QueryRequest(kind, "data.ResourceName = \"trajectories - 1000.json\"")
create_record_resp = record_client.create_update_records([record])
create_record_resp = record_client.create_update_records([record], bearer_token="eyJraWQiOiJrWmpnYTR5ZXJyWVwvdVByT29wSXBTNnVFWmZLRGVoTUt3d3VIRjAxZUlmOD0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI5MDE3NDdmOS1jMzRkLTQ5MjktYTczYi0zMzY5ZmU2NDNmYTYiLCJldmVudF9pZCI6ImNjYjg1MzY2LTNlZDMtNGMxZC04NDk2LTNjZjhmYzFjNTIyOSIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoib3BlbmlkIGVtYWlsIiwiYXV0aF90aW1lIjoxNjA5NzczODQ1LCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV8yOE8wMXlFN00iLCJleHAiOjE2MTEyNDU5NTEsImlhdCI6MTYxMTE1OTU1MSwidmVyc2lvbiI6MiwianRpIjoiODFkYjBlN2ItNTkxNy00ODZmLWIwMGUtZWYzNThmODM1ZGM3IiwiY2xpZW50X2lkIjoiNWxrcjZ2OGRrOHU2dnN1ZGVlZGluYW10OGEiLCJ1c2VybmFtZSI6ImphY29icm91Z2VhdUB0ZXN0aW5nLmNvbSJ9.Z_8lvjj3jCmXx2w0fG2IXK3Wsd1GVSufgWdOhEyXMqzOXIqWZNMrAOtXwng6oX5z0n2c3fXQEUC5QAjAXvrDx_elpqd9Gnpiauzu9t5sVthKYw6OOWzR3Ny_iR-V5zG-eXCXTnrvZJsibcEI7ouH5RyRe_zcUhfaDbixb1uKWUGbD2hUCyEr30FawkKOB5E-_PXQQdK0pJn_eAwj-Z_-8IFOETBI6xsYG9-QjQoyVcK1KYqHfMzP0moANP1T3PZSsXnpTZqDlPif8jD2hVpKCDF-rXa8eI45WE5XWBMh5gUUcgT5AiEXKMFll19-RSg0jnu3a3PZ1YnxkyFaaumCFg")
print(create_record_resp.status_code)
print(create_record_resp.content)
......@@ -63,6 +63,6 @@ if create_record_resp.status_code != 201:
# give the system 10 seconds to index the record
time.sleep(10)
search_record_resp = search_client.query_records(query_request)
search_record_resp = search_client.query_records(query_request, bearer_token="eyJraWQiOiJrWmpnYTR5ZXJyWVwvdVByT29wSXBTNnVFWmZLRGVoTUt3d3VIRjAxZUlmOD0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiI5MDE3NDdmOS1jMzRkLTQ5MjktYTczYi0zMzY5ZmU2NDNmYTYiLCJldmVudF9pZCI6ImNjYjg1MzY2LTNlZDMtNGMxZC04NDk2LTNjZjhmYzFjNTIyOSIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoib3BlbmlkIGVtYWlsIiwiYXV0aF90aW1lIjoxNjA5NzczODQ1LCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV8yOE8wMXlFN00iLCJleHAiOjE2MTEyNDU5NTEsImlhdCI6MTYxMTE1OTU1MSwidmVyc2lvbiI6MiwianRpIjoiODFkYjBlN2ItNTkxNy00ODZmLWIwMGUtZWYzNThmODM1ZGM3IiwiY2xpZW50X2lkIjoiNWxrcjZ2OGRrOHU2dnN1ZGVlZGluYW10OGEiLCJ1c2VybmFtZSI6ImphY29icm91Z2VhdUB0ZXN0aW5nLmNvbSJ9.Z_8lvjj3jCmXx2w0fG2IXK3Wsd1GVSufgWdOhEyXMqzOXIqWZNMrAOtXwng6oX5z0n2c3fXQEUC5QAjAXvrDx_elpqd9Gnpiauzu9t5sVthKYw6OOWzR3Ny_iR-V5zG-eXCXTnrvZJsibcEI7ouH5RyRe_zcUhfaDbixb1uKWUGbD2hUCyEr30FawkKOB5E-_PXQQdK0pJn_eAwj-Z_-8IFOETBI6xsYG9-QjQoyVcK1KYqHfMzP0moANP1T3PZSsXnpTZqDlPif8jD2hVpKCDF-rXa8eI45WE5XWBMh5gUUcgT5AiEXKMFll19-RSg0jnu3a3PZ1YnxkyFaaumCFg")
print(search_record_resp.results)
\ No newline at end of file
......@@ -20,7 +20,7 @@ data_workflow_url=%(BASE_URL)s/api/data-workflow/v1
file_dms_url=%(BASE_URL)s/api/filedms/v2
dataset_url=%(BASE_URL)s/api/dataset-registry/v1
entitlements_url=%(BASE_URL)s/api/entitlements/v1
use_service_principal=True
use_service_principal=False
[provider]
name=aws
......@@ -30,4 +30,4 @@ aws_oauth_custom_scope_ssm_path=/osdu/%(ENVIRONMENT)s/oauth-custom-scope
client_id_ssm_path=/osdu/%(ENVIRONMENT)s/client-credentials-client-id
client_secret_name=/osdu/%(ENVIRONMENT)s/client_credentials_secret
client_secret_dict_key=client_credentials_client_secret
region_name=%(AWS_REGION)s
\ No newline at end of file
region_name=%(AWS_REGION)s
......@@ -13,10 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
'''
Acl model mirroring what's found in core common
'''
class Acl:
"""
Acl model mirroring what's found in core common
"""
def __init__(self, viewers: list, owners: list):
self.viewers = viewers
self.owners = owners
......@@ -13,10 +13,10 @@
# limitations under the License.
from osdu_api.model.base import Base
'''
Request body to data workflow's start workflow endpoint. Input parameters is a dynamic object
but the API expects "datasetRegistryIds"
'''
class GetWorkflowSchedulesRequest(Base):
"""
Request body to data workflow's start workflow endpoint. Input parameters is a dynamic object
but the API expects "datasetRegistryIds"
"""
def __init__(self, schedule_names: list):
self.scheduleNames = schedule_names
......@@ -13,11 +13,12 @@
# limitations under the License.
from osdu_api.model.base import Base
'''
Request body to data workflow's start workflow endpoint. Input parameters is a dynamic object
but the API expects "datasetRegistryIds"
'''
class StartWorkflow(Base):
"""
Request body to data workflow's start workflow endpoint. Input parameters is a dynamic object
but the API expects "datasetRegistryIds"
"""
def __init__(self, dag_name: str, input_parameters: object):
self.dagName = dag_name
self.inputParameters = input_parameters
......@@ -13,10 +13,12 @@
# limitations under the License.
from osdu_api.model.base import Base
'''
Request body to data workflow's create schedule workflow input endpoint. Input parameters is a dynamic map object to the dag
'''
class WorkflowSchedule(Base):
"""
Request body to data workflow's create schedule workflow input endpoint. Input parameters is a dynamic map object to the dag
"""
def __init__(self, name: str, description: str, cron_schedule: str, dag_name: str, input_parameters: object):
self.name = name
self.description = description
......
......@@ -15,10 +15,12 @@ from typing import List
from osdu_api.model.storage.record import Record
from osdu_api.model.base import Base
'''
Request body to data workflow's start workflow endpoint. Input parameters is a dynamic object
but the API expects "datasetRegistryIds"
'''
class CreateDatasetRegistriesRequest(Base):
"""
Request body to data workflow's start workflow endpoint. Input parameters is a dynamic object
but the API expects "datasetRegistryIds"
"""
def __init__(self, dataset_registries: List[Record]):
self.datasetRegistries = dataset_registries
......@@ -13,10 +13,11 @@
# limitations under the License.
from osdu_api.model.base import Base
'''
Represents the attributes needed for OSDU to create a group
'''
class Group(Base):
"""
Represents the attributes needed for OSDU to create a group
"""
def __init__(self, name: str, description: str):
self.name = name
self.description = description
\ No newline at end of file
......@@ -13,10 +13,11 @@
# limitations under the License.
from osdu_api.model.base import Base
'''
Represents the attributes needed for OSDU to create a group member
'''
class GroupMember(Base):
"""
Represents the attributes needed for OSDU to create a group member
"""
def __init__(self, email: str, role: str):
self.email = email
self.role = role
\ No newline at end of file
......@@ -15,10 +15,11 @@
from osdu_api.model.legal_compliance import LegalCompliance
'''
Legal model mirroring what's found in core common
'''
class Legal:
"""
Legal model mirroring what's found in core common
"""
def __init__(self, legaltags: list, other_relevant_data_countries: list, status: LegalCompliance):
self.legaltags = legaltags
self.other_relevant_data_countries = other_relevant_data_countries
......
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