Commit b8fc45be authored by Ritika Kaushal's avatar Ritika Kaushal
Browse files

Changes for csp specific base url prefix

parent 75154da6
Pipeline #108206 canceled with stages
{
"base_url": "https://osdu-ship.msft-osdu-test.org",
"csp_base_url_prefix": "no",
"csp_prefix_wellbore_service": "osdu-wellbore",
"csp_prefix_search_service": "osdu-search",
"data_partition_id": "opendes",
"wellbore_service_path_prefix": "",
"search_service_path_prefix": "",
"data_partition_id": "opendes",
"legal": {
"legaltags": ["opendes-public-usa-dataset-7643990"],
"otherRelevantDataCountries": ["US"],
......
......@@ -3,12 +3,14 @@ import httpx
from pandas import DataFrame
from importlib import import_module
from . import TARGET_MODULE_NAME
from unittest.mock import Mock
# Test target module import
Record = import_module(f"{TARGET_MODULE_NAME}.service.record_mapper").Record
osdu_client = import_module(f"{TARGET_MODULE_NAME}.wrapper.osdu_client")
DataLoaderWebResponseError = osdu_client.DataLoaderWebResponseError
OsduClient = osdu_client.OsduClient
Configuration = import_module(f"{TARGET_MODULE_NAME}.common.configuration").Configuration
class TestOsduClient:
......@@ -16,6 +18,14 @@ class TestOsduClient:
_expected_ids_str = [{"id": "321"}, {"id": "432"}, {"id": "543"}]
_access_token = "token"
_data_partition_id = "AnId"
_serviceName="wellbore"
mockConfig = Mock(spec=Configuration)
mockConfig.data_partition_id= "AnId"
mockConfig.wellbore_service_path_prefix=None
mockConfig.search_service_path_prefix=None
mockConfig.base_url = "http://test.bp.com"
def match_and_mock_post(self, request: any):
if request.method != "POST":
......@@ -74,7 +84,9 @@ class TestOsduClient:
respx_mock.post(f"{base_url}/api/os-wellbore-ddms/ddms/v3/wellbores").mock(side_effect=self.match_and_mock_post)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
# client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
response = client.create_wellbore(record)
......@@ -91,7 +103,8 @@ class TestOsduClient:
mock_response = httpx.Response(400)
respx_mock.post(f"{base_url}/api/os-wellbore-ddms/ddms/v3/wellbores").mock(return_value=mock_response)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
with pytest.raises(DataLoaderWebResponseError) as ex:
......@@ -109,8 +122,8 @@ class TestOsduClient:
respx_mock.post(f"{base_url}/api/os-wellbore-ddms/ddms/v3/welllogs").mock(side_effect=self.match_and_mock_post)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
response = client.post_welllog(record)
......@@ -126,8 +139,8 @@ class TestOsduClient:
mock_response = httpx.Response(500)
respx_mock.post(f"{base_url}/api/os-wellbore-ddms/ddms/v3/welllogs").mock(return_value=mock_response)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
with pytest.raises(DataLoaderWebResponseError) as ex:
client.post_welllog(record)
......@@ -148,8 +161,8 @@ class TestOsduClient:
mock_response = httpx.Response(500)
respx_mock.post(url).mock(return_value=mock_response)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
with pytest.raises(DataLoaderWebResponseError) as ex:
client.add_welllog_data(dataframe, welllog_id)
......@@ -169,7 +182,8 @@ class TestOsduClient:
respx_mock.post(url).mock(side_effect=self.match_and_mock_post_with_content_header)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
result = client.add_welllog_data(dataframe, welllog_id)
......@@ -186,7 +200,8 @@ class TestOsduClient:
respx_mock.get(url).mock(side_effect=self.match_and_mock_get)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
client.get_wellbore_record(wellbore_id)
......@@ -201,7 +216,8 @@ class TestOsduClient:
mock_response = httpx.Response(500)
respx_mock.get(url).mock(return_value=mock_response)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
with pytest.raises(DataLoaderWebResponseError) as ex:
......@@ -220,7 +236,8 @@ class TestOsduClient:
respx_mock.get(url).mock(side_effect=self.match_and_mock_get)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
client.get_welllog_record(welllogs_id)
......@@ -235,7 +252,8 @@ class TestOsduClient:
mock_response = httpx.Response(500)
respx_mock.get(url).mock(return_value=mock_response)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
with pytest.raises(DataLoaderWebResponseError) as ex:
......@@ -257,7 +275,8 @@ class TestOsduClient:
respx_mock.get(url).mock(side_effect=self.match_and_mock_get_return_bytes)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
result = client.get_welllog_data(welllog_id)
......@@ -276,7 +295,8 @@ class TestOsduClient:
respx_mock.get(url).mock(side_effect=self.match_and_mock_get_return_bytes)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
result = client.get_welllog_data(welllog_id, ["curve1", "curve2"])
......@@ -291,7 +311,8 @@ class TestOsduClient:
respx_mock.post(url).mock(side_effect=self.match_and_mock_post)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
result = client.post_log_recognition("mnemonic", "unit")
......@@ -306,9 +327,20 @@ class TestOsduClient:
respx_mock.post(url).mock(side_effect=self.match_and_mock_post)
client = OsduClient(base_url, self._access_token, self._data_partition_id)
#client = OsduClient(base_url, self._access_token, self._data_partition_id)
client = OsduClient(self.mockConfig, self._access_token)
# Act
result = client.search_for_wellbore("Wellbore Name")
assert result == ["321", "432", "543"]
def test_get_base_url(self, _serviceName):
# Assemble
base_url = "http://test.bp.com"
client = OsduClient(self.mockConfig, self._access_token)
# Act
result = client.get(self,_serviceName)
assert result.equals(base_url)
\ No newline at end of file
......@@ -30,7 +30,7 @@ def wellbore(
config = Configuration(LocalFileLoader(), config_path)
las_parser = LasParser(LocalFileLoader())
client = OsduClient(config.base_url, token, config.data_partition_id,config.csp_base_url_prefix,config.csp_prefix_wellbore_service,config.csp_prefix_search_service)
client = OsduClient(config, token)
service = WellBoreService(client, WellLogService(client))
failed_ingests = []
......
......@@ -73,28 +73,19 @@ class Configuration:
return self._config.get("las_file_mapping")
@property
def csp_base_url_prefix(self) -> str:
def wellbore_service_path_prefix(self) -> str:
"""
Gets the csp_base url prefix.
return: the csp base url prefix
Gets the wellbore_service_path_prefix.
return: the prefix for wellbore service
rtype: str
"""
return self._config.get("csp_base_url_prefix")
return self._config.get("wellbore_service_path_prefix")
@property
def csp_prefix_wellbore_service(self) -> str:
def search_service_path_prefix(self) -> str:
"""
Gets the csp_prefix_wellbore_service.
return: the csp prefix for wellbore search
Gets the search_service_path_prefix.
return: the prefix for search service
rtype: str
"""
return self._config.get("csp_prefix_wellbore_service")
@property
def csp_prefix_search_service(self) -> str:
"""
Gets the csp_prefix_ search service.
return: the csp prefix for search service
rtype: str
"""
return self._config.get("csp_prefix_search_service")
return self._config.get("search_service_path_prefix")
......@@ -4,6 +4,7 @@ import io
from knack.log import get_logger
from ..service.record_mapper import Record, WellLogRecord
from pandas import DataFrame, read_parquet
from ..common.configuration import Configuration
logger = get_logger(__name__)
......@@ -26,20 +27,21 @@ class DataLoaderWebResponseError(Exception):
class OsduClient:
def __init__(self, base_url: str, access_token: str, data_partition_id: str, csp_base_url_prefix: str, csp_prefix_wellbore_service: str, csp_prefix_search_service: str) -> None:
def __init__(self, config: Configuration, access_token: str) -> None:
"""
Create a new instance of a OsduClient
:param str base_url: The base URL of the OSDU instance.
:param str config: The configuration object having all properties.
:param str access_token: The access token required to access the OSDU instance.
:param str data_partition_id: The data partition ID
"""
self._access_token = access_token
self._base_url = base_url
self._data_partition_id = data_partition_id
self._csp_base_url_prefix = csp_base_url_prefix
self._csp_prefix_wellbore_service = csp_prefix_wellbore_service
self._csp_prefix_search_service = csp_prefix_search_service
self._base_url = config.base_url
self._data_partition_id = config.data_partition_id
self._wellbore_service_path_prefix = config.wellbore_service_path_prefix
self._search_service_path_prefix = config.search_service_path_prefix
self._wellbore_service="wellbore"
self._search_service="search"
def _create_headers(self) -> Dict[str, str]:
"""
......@@ -61,7 +63,7 @@ class OsduClient:
:return: the id of the new well bore
:rtype: str
"""
return self._post_data_with_id_response(f'{self._get_base_url("wellbore")}/api/os-wellbore-ddms/ddms/v3/wellbores', record)
return self._post_data_with_id_response(f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/wellbores', record)
def post_welllog(self, record: Union[Record, WellLogRecord]) -> List[any]:
"""
......@@ -73,7 +75,7 @@ class OsduClient:
:return: The ID of the created/updated well log
:rtype: List[any]
"""
return self._post_data_with_id_response(f'{self._get_base_url("wellbore")}/api/os-wellbore-ddms/ddms/v3/welllogs', record)
return self._post_data_with_id_response(f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/welllogs', record)
def get_wellbore_record(self, wellbore_id: str) -> Record:
"""
......@@ -84,8 +86,7 @@ class OsduClient:
:rtype: Record
"""
get_record_url = f'{self._get_base_url("wellbore")}/api/os-wellbore-ddms/ddms/v3/wellbores/{wellbore_id}'
#get_record_url = f"{self._base_url}/api/os-wellbore-ddms/ddms/v3/wellbores/{wellbore_id}"
get_record_url = f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/wellbores/{wellbore_id}'
return Record(self._send_request_json_response("GET", get_record_url, None, None))
......@@ -97,8 +98,7 @@ class OsduClient:
:return: the welllog record
:rtype: WellLogRecord
"""
get_record_url = f'{self._get_base_url("wellbore")}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}'
#get_record_url = f"{self._base_url}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}"
get_record_url = f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}'
return WellLogRecord(self._send_request_json_response("GET", get_record_url, None, None))
def add_welllog_data(self, data: DataFrame, welllog_id: str) -> None:
......@@ -109,8 +109,7 @@ class OsduClient:
:param str welllog_id: The id of the new well log
"""
url = f'{self._get_base_url("wellbore")}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}/data'
#url = f"{self._base_url}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}/data"
url = f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}/data'
# Adding content-type to standard headers
headers = self._create_headers()
......@@ -132,8 +131,7 @@ class OsduClient:
curves_query = f"&curves={','.join(curves)}"
get_welllog_data_url = f'{self._get_base_url("wellbore")}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}/data?describe=false{curves_query}'
#get_welllog_data_url = f"{self._base_url}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}/data?describe=false{curves_query}"
get_welllog_data_url = f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/ddms/v3/welllogs/{welllog_id}/data?describe=false{curves_query}'
try:
res = self._send_request("GET", get_welllog_data_url, None, None)
......@@ -150,8 +148,7 @@ class OsduClient:
:return: A dictionary that contains the curve family
:rtype: any
"""
recognize_family_url = f'{self._get_base_url("wellbore")}/api/os-wellbore-ddms/log-recognition/family'
#recognize_family_url = f"{self._base_url}/api/os-wellbore-ddms/log-recognition/family"
recognize_family_url = f'{self.get_base_url(self._wellbore_service)}/api/os-wellbore-ddms/log-recognition/family'
payload = {"label": mnemonic, "log_unit": unit}
return self._send_request_json_response("POST", recognize_family_url, None, payload)
......@@ -162,8 +159,7 @@ class OsduClient:
:return: A List that contains the matching wellbore ids
:rtype: List[str]
"""
#url = f"{self._base_url}/api/search/v2/query"
url = f'{self._get_base_url("search")}/api/search/v2/query'
url = f'{self.get_base_url(self._search_service)}/api/search/v2/query'
payload = {
"kind": "*:*:master-data--Wellbore:*",
......@@ -181,7 +177,6 @@ class OsduClient:
def _post_data_with_id_response(self, path: str, record: Record) -> List[any]:
payload = [record.get_raw_data()]
url = f"{path}"
#url = f"{self._base_url}{path}"
parsed_result = self._send_request_json_response("POST", url, None, payload)
......@@ -207,11 +202,10 @@ class OsduClient:
return res
def _get_base_url( self,service_name: str) -> str:
if self._csp_base_url_prefix == "yes":
if service_name == "wellbore":
return f"{self._base_url}/{self._csp_prefix_wellbore_service}"
if service_name == "search":
return f"{self._base_url}/{self._csp_prefix_search_service}"
def get_base_url( self,service_name: str) -> str:
if service_name == self._wellbore_service and self._wellbore_service_path_prefix is not None and len(self._wellbore_service_path_prefix) > 0:
return f"{self._base_url}/{self._wellbore_service_path_prefix}"
elif service_name == self._search_service and self._search_service_path_prefix is not None and len(self._search_service_path_prefix) > 0:
return f"{self._base_url}/{self._search_service_path_prefix}"
else:
return self._base_url
\ No newline at end of file
return self._base_url
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