Commit b34bdd47 authored by Vadzim Kulyba (EPAM)'s avatar Vadzim Kulyba (EPAM) Committed by harshit aggarwal
Browse files

feat(dataset_dms): add new retrieval instruction aproach

parent 88c2f409
......@@ -124,7 +124,7 @@ class BaseClient:
data: str,
headers: dict,
params: dict,
):
) -> requests.Response:
bearer_token = self.service_principal_token
if bearer_token is not None and 'Bearer ' not in bearer_token:
bearer_token = 'Bearer ' + bearer_token
......@@ -179,9 +179,16 @@ class BaseClient:
response.raise_for_status()
return response
@authorize()
def _send_request_with_token_refresher(self, headers: dict, method: HttpMethod, url: str, data: str, params: dict):
def _send_request_with_token_refresher(
self,
headers: dict,
method: HttpMethod,
url: str,
data: str,
params: dict
) -> requests.Response:
return self._send_request(method, url, data, headers, params)
def make_request(
......@@ -192,7 +199,7 @@ class BaseClient:
add_headers: dict = None,
params: dict = None,
bearer_token = None
):
) -> requests.Response:
"""
Makes a request using python's built in requests library. Takes additional headers if
necessary
......
......@@ -11,8 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
from typing import List
import requests
from osdu_api.clients.base_client import BaseClient
from osdu_api.model.dataset.get_dataset_registry_request import GetDatasetRegistryRequest
......@@ -23,16 +22,33 @@ class DatasetDmsClient(BaseClient):
"""
Holds the logic for interfacing with Data Registry Service's DMS api
"""
def get_storage_instructions(self, kind_sub_type: str, bearer_token=None):
params = {'kindSubType': kind_sub_type}
return self.make_request(method=HttpMethod.GET, url='{}{}'.format(self.dataset_url, '/getStorageInstructions'),
def _get_instructions(self, slug: str, params: dict, bearer_token=None) -> requests.Response:
return self.make_request(method=HttpMethod.GET, url='{}{}'.format(self.dataset_url, slug),
params=params, bearer_token=bearer_token)
def get_retrieval_instructions(self, record_id: str, bearer_token=None):
params = {'id': record_id}
return self.make_request(method=HttpMethod.GET, url='{}{}'.format(self.dataset_url, '/getRetrievalInstructions'),
params=params, bearer_token=bearer_token)
def get_multiple_retrieval_instructions(self, get_dataset_registry_request: GetDatasetRegistryRequest, bearer_token=None):
return self.make_request(method=HttpMethod.POST, url='{}{}'.format(self.dataset_url, '/getRetrievalInstructions'),
data=get_dataset_registry_request.to_JSON(), bearer_token=bearer_token)
def _post_instructions(self, slug: str, data: GetDatasetRegistryRequest, bearer_token=None) -> requests.Response:
return self.make_request(method=HttpMethod.POST, url='{}{}'.format(self.dataset_url, slug),
data=data.to_JSON(), bearer_token=bearer_token)
def get_storage_instructions(self, kind_sub_type: str, bearer_token=None) -> requests.Response:
return self._get_instructions('/getStorageInstructions', {'kindSubType': kind_sub_type}, bearer_token)
def get_retrieval_instructions(self, record_id: str, bearer_token=None) -> requests.Response:
return self._get_instructions('/getRetrievalInstructions', {'id': record_id}, bearer_token)
def get_multiple_retrieval_instructions(
self,
get_dataset_registry_request: GetDatasetRegistryRequest,
bearer_token=None
) -> requests.Response:
return self._post_instructions('/getRetrievalInstructions', get_dataset_registry_request, bearer_token)
def retrieval_instructions(self, record_id: str, bearer_token=None) -> requests.Response:
return self._get_instructions('/retrievalInstructions', {'id': record_id}, bearer_token)
def multiple_retrieval_instructions(
self,
get_dataset_registry_request: GetDatasetRegistryRequest,
bearer_token=None
) -> requests.Response:
return self._post_instructions('/retrievalInstructions', get_dataset_registry_request, bearer_token)
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