Commit d0139b44 authored by Niall McDaid's avatar Niall McDaid
Browse files

Move base url to config file

parent c83121a2
{
"base_url": "https://osdu-ship.msft-osdu-test.org",
"data_partition_id": "opendes",
"acl_domain": "contoso.com",
"legal":
{
"legal": {
"legaltags": ["opendes-public-usa-dataset-7643990"],
"otherRelevantDataCountries": ["US"],
"status": "compliant"
"status": "compliant"
},
"data": {
"default": {
"viewers": [ "data.default.viewers@opendes.contoso.com" ],
"owners": [ "data.default.owners@opendes.contoso.com" ]
"viewers": ["data.default.viewers@opendes.contoso.com"],
"owners": ["data.default.owners@opendes.contoso.com"]
}
}
}
}
\ No newline at end of file
......@@ -10,15 +10,13 @@ from lasloader.well_service import WellLogService
logger = get_logger(__name__)
def download_las(url: str,
token: str,
def download_las(token: str,
config_path: str,
welllog_id: str,
outfile: str,
curves: List[str] = None):
"""
Retrieve welllog data from an OSDU instance and save to a LAS format file
:param str url: The base URL of the OSDU instance
:param str token: a valid bearer token that is used to authenticate against the OSDU instance
:param str config_path: Path to the las metadata file
:param str welllog_id: The well bore id of the record to retrieve
......@@ -26,7 +24,7 @@ def download_las(url: str,
:param List[str] curves: The curves to retrieve, use None to get all curves
"""
config = Configuration(LocalFileLoader(), config_path)
client = OsduClient(url, token, config.data_partition_id)
client = OsduClient(config.base_url, token, config.data_partition_id)
service = WellLogService(client)
......
......@@ -14,21 +14,19 @@ logger = get_logger(__name__)
def wellbore(
input_path: str,
url: str,
token: str,
config_path: str,
no_recognize: bool = False):
"""
Ingest a LAS file (single) or directory of LAS files (bulk) into OSDU
:param str input_path: Path and filename of a LAS file OR path to directory containing LAS and config files.
:param str url: The base URL of the OSDU instance to which to upload the file.
:param str token: A valid bearer token that is used to authenticate the ingest request.
:param str config_path: Path to the LAS metadata file.
:param bool no_recognize: If true don't attempt to recognize the curves, otherwise recognize the curves
"""
config = Configuration(LocalFileLoader(), config_path)
las_parser = LasParser(LocalFileLoader())
client = OsduClient(url, token, config.data_partition_id)
client = OsduClient(config.base_url, token, config.data_partition_id)
service = WellBoreService(client, WellLogService(client))
failed_ingests = []
......@@ -59,19 +57,17 @@ def wellbore(
def welllog_data(
welllog_id: str,
input_path: str,
url: str,
token: str,
config_path: str):
"""
Write data from a LAS file to an existing Well Log.
:param str welllog_id: ID of well log to be updated.
:param str input_path: Path and filename of a LAS file containing data to be written to existing well log.
:param str url: The base URL of the OSDU instance to which to find the existing Well Log.
:param str token: A valid bearer token that is used to authenticate the update request.
:param str config_path: Path to the LAS metadata file.
"""
config = Configuration(LocalFileLoader(), config_path)
client = OsduClient(url, token, config.data_partition_id)
client = OsduClient(config.base_url, token, config.data_partition_id)
service = WellLogService(client)
service.ingest_welllog_data(input_path, welllog_id)
......
......@@ -9,39 +9,35 @@ from lasloader.file_loader import LocalFileLoader
logger = get_logger(__name__)
def wellbore(url: str,
token: str,
def wellbore(token: str,
config_path: str,
wellbore_id: str):
"""
Retrieve and print wellbore record from an OSDU instance
:param str url: The base URL of the OSDU instance
:param str token: a valid bearer token that is used to authenticate against the OSDU instance
:param str config_path: Path to the las metadata file
:param str wellbore_id: The well bore id of the record to retrieve
"""
config = Configuration(LocalFileLoader(), config_path)
client = OsduClient(url, token, config.data_partition_id)
client = OsduClient(config.base_url, token, config.data_partition_id)
logger.warning(f"Getting wellbore ID {wellbore_id}")
wellbore = client.get_wellbore_record(wellbore_id)
print(json.dumps(wellbore.get_raw_data(), indent=4, sort_keys=True))
def welllog(url: str,
token: str,
def welllog(token: str,
config_path: str,
welllog_id: str,
curves: bool = False):
"""
Retrieve and print welllog record from an OSDU instance
:param str url: The base URL of the OSDU instance
:param str token: a valid bearer token that is used to authenticate against the OSDU instance
:param str config_path: Path to the las metadata file
:param str wellbore_id: The well bore id of the record to retrieve
"""
config = Configuration(LocalFileLoader(), config_path)
client = OsduClient(url, token, config.data_partition_id)
client = OsduClient(config.base_url, token, config.data_partition_id)
logger.warning(f"Getting welllog ID {welllog_id}")
welllog = client.get_welllog_record(welllog_id)
......@@ -52,21 +48,19 @@ def welllog(url: str,
print(json.dumps(welllog.get_raw_data(), indent=4, sort_keys=True))
def welllog_data(url: str,
token: str,
def welllog_data(token: str,
config_path: str,
welllog_id: str,
curves: List[str] = None):
"""
Retrieve and print welllog data from an OSDU instance
:param str url: The base URL of the OSDU instance
:param str token: a valid bearer token that is used to authenticate against the OSDU instance
:param str config_path: Path to the las metadata file
:param str welllog_id: The welllog id of the record to retrieve
:param List[str] curves: The curves to retrieve, use None to get all curves
"""
config = Configuration(LocalFileLoader(), config_path)
client = OsduClient(url, token, config.data_partition_id)
client = OsduClient(config.base_url, token, config.data_partition_id)
logger.warning(f"Getting data for welllog ID {welllog_id}")
if curves:
......
......@@ -9,20 +9,18 @@ from lasloader.well_service import WellBoreService, WellLogService
logger = get_logger(__name__)
def wellbore_search(url: str,
token: str,
def wellbore_search(token: str,
config_path: str,
wellbore_name: str):
"""
Retrieve and print the ids of wellbores that match the specified name
:param str url: The base URL of the OSDU instance
:param str token: a valid bearer token that is used to authenticate against the OSDU instance
:param str config_path: Path to the las metadata file
:param str wellbore_name: The well bore name to search for
"""
config = Configuration(LocalFileLoader(), config_path)
client = OsduClient(url, token, config.data_partition_id)
client = OsduClient(config.base_url, token, config.data_partition_id)
service = WellBoreService(client, WellLogService(client))
data = service.search_for_wellbore(wellbore_name)
......
......@@ -8,11 +8,10 @@ from lasloader.well_service import WellLogService
logger = get_logger(__name__)
def welllog(welllog_id: str, url: str, token: str, config_path: str, curve_families: bool = True):
def welllog(welllog_id: str, token: str, config_path: str, curve_families: bool = True):
"""
Update an existing well log record.
:param str welllog_id: ID of the well log to be updated.
:param str url: The base URL of the OSDU instance to which the well log was ingested.
:param str token: A valid bearer token that is used to authenticate the update request.
:param str config_path: Path to the LAS metadata file.
:param str curve_families: If true, recognize and update the curve families, otherwise don't.
......@@ -20,7 +19,7 @@ def welllog(welllog_id: str, url: str, token: str, config_path: str, curve_famil
# This command currently only containes functionality to update the curve families of a well log.
# It is set up in such a way that it should be possible to extend to include other update operations in future if needed.
config = Configuration(LocalFileLoader(), config_path)
client = OsduClient(url, token, config.data_partition_id)
client = OsduClient(config.base_url, token, config.data_partition_id)
service = WellLogService(client)
if curve_families:
......
......@@ -17,6 +17,15 @@ class Configuration:
json_parser = JsonLoader(file_loader)
self._config = json_parser.load(path)
@property
def base_url(self) -> str:
"""
Gets the base url.
return: the base url for API calls
rtype: str
"""
return self._config.get("base_url")
@property
def data_partition_id(self) -> str:
"""
......
......@@ -83,7 +83,7 @@ class LasCommandLoader(CLICommandsLoader):
# 'ingest'
with ArgumentsContext(self, 'ingest') as arg_context:
self._register_input_path_argument(arg_context)
self._register_url_and_token_arguments(arg_context)
self._register_token_argument(arg_context)
with ArgumentsContext(self, 'ingest wellbore') as arg_context:
arg_context.argument('no_recognize', options_list=('--norecognize'), action='store_true',
......@@ -94,7 +94,7 @@ class LasCommandLoader(CLICommandsLoader):
# 'list'
with ArgumentsContext(self, 'list') as arg_context:
self._register_url_and_token_arguments(arg_context)
self._register_token_argument(arg_context)
with ArgumentsContext(self, 'list wellbore') as arg_context:
self._register_wellbore_id_flag(arg_context)
......@@ -110,7 +110,7 @@ class LasCommandLoader(CLICommandsLoader):
# 'update'
with ArgumentsContext(self, 'update') as arg_context:
self._register_url_and_token_arguments(arg_context)
self._register_token_argument(arg_context)
with ArgumentsContext(self, 'update welllog') as arg_context:
self._register_welllog_id_argument(arg_context)
......@@ -119,7 +119,7 @@ class LasCommandLoader(CLICommandsLoader):
# 'Search'
with ArgumentsContext(self, 'search') as arg_context:
self._register_url_and_token_arguments(arg_context)
self._register_token_argument(arg_context)
with ArgumentsContext(self, 'search wellbore') as arg_context:
arg_context.argument('wellbore_name', type=str, options_list=('--name'),
......@@ -127,7 +127,7 @@ class LasCommandLoader(CLICommandsLoader):
# 'download'
with ArgumentsContext(self, 'download') as arg_context:
self._register_url_and_token_arguments(arg_context)
self._register_token_argument(arg_context)
self._register_welllog_id_argument(arg_context)
self._register_curves_argument(arg_context)
arg_context.argument('outfile', type=str, options_list=('--out'),
......@@ -151,9 +151,7 @@ class LasCommandLoader(CLICommandsLoader):
arg_context.argument('welllog_id', type=str, options_list=('--welllog_id'),
help='The welllog id of the record.')
def _register_url_and_token_arguments(self, arg_context):
arg_context.argument('url', type=str, options_list=('-u', '--url'),
help='The base url of the OSDU instance.')
def _register_token_argument(self, arg_context):
arg_context.argument('token', type=str, options_list=('-t', '--token'),
help='A valid bearer token used to authenticate with the OSDU instance.')
......
{
"base_url": "https://osdu-ship.msft-osdu-test.org",
"data_partition_id": "opendes",
"acl_domain": "contoso.com",
"legal": {
"legaltags": [
"opendes-public-usa-dataset-7643990"
],
"otherRelevantDataCountries": [
"US"
],
"status": "compliant"
},
"data": {
"default": {
"viewers": [
"data.default.viewers@opendes.contoso.com"
],
"owners": [
"data.default.owners@opendes.contoso.com"
]
}
}
}
\ No newline at end of file
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