Skip to content

Commit

Permalink
fix: Removed tenant from clients
Browse files Browse the repository at this point in the history
  • Loading branch information
micmurawski committed Jul 15, 2024
1 parent 478cb36 commit 5f7d30d
Show file tree
Hide file tree
Showing 45 changed files with 1,284 additions and 4,177 deletions.
19 changes: 9 additions & 10 deletions gen/client_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import json
import os
import re
Expand Down Expand Up @@ -32,7 +34,6 @@

SPECIAL_HEADERS = (
"data-partition-id",
"tenant",
)

FORBIDDEN_NAMES = {
Expand Down Expand Up @@ -170,8 +171,8 @@ def create_headers_block(required_header_params_without_special, optional_header
"headers = self.auth.get_headers()",
"if data_partition_id:",
f"{INDENT}headers['data-partition-id'] = data_partition_id",
"if tenant:",
f"{INDENT}headers['tenant'] = tenant"
#"if tenant:",
#f"{INDENT}headers['tenant'] = tenant"
]
if required_header_params_without_special:
lines.append(
Expand Down Expand Up @@ -517,18 +518,16 @@ def create_method_sig(swagger: dict, name: str, params: list[str], body_required
p for p in params if p['name'] not in SPECIAL_HEADERS and p["in"] != "body"
]
elements = [name, ]

sig = ""
_input_parameters_strings = []

if body_required:
_input_parameters_strings += parse_request_body(swagger, body_required)

if body_not_required:
_input_parameters_strings += parse_request_body(swagger, body_not_required)

_input_parameters_strings += [param_to_function_argument(p) for p in path_params]

_input_parameters_strings += [param_to_function_argument(p) for p in sorted(path_params, key=lambda x: 0 if x.get("required") else 1)]
if _input_parameters_strings:
sig += ", ".join(_input_parameters_strings)

Expand All @@ -537,9 +536,9 @@ def create_method_sig(swagger: dict, name: str, params: list[str], body_required

try:
if len(elements) > 1:
sig = "def %s(self, *, %s, data_partition_id: str | None = None, tenant: str | None = None) -> dict:" % tuple(elements)
sig = "def %s(self, *, %s, data_partition_id: str | None = None) -> dict:" % tuple(elements)
else:
sig = "def %s(self, data_partition_id: str | None = None, tenant: str | None = None) -> dict:" % tuple(elements)
sig = "def %s(self, data_partition_id: str | None = None) -> dict:" % tuple(elements)
return sig
except Exception as e:
raise Exception(elements, len(elements)) from e
Expand Down
71 changes: 15 additions & 56 deletions osdu_client/services/dataset/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,21 @@ class DatasetClient(OSDUAPIClient):
service_path = "/api/dataset/v1/"

def create_or_update_dataset_registry(
self,
*,
dataset_registries: list[dict],
data_partition_id: str | None = None,
tenant: str | None = None,
self, *, dataset_registries: list[dict], data_partition_id: str | None = None
) -> dict:
headers = self.auth.get_headers()
if data_partition_id:
headers["data-partition-id"] = data_partition_id
if tenant:
headers["tenant"] = tenant

data = {
request_data = {
"datasetRegistries": dataset_registries,
}

if self.validation:
validate_data(data, CreateDatasetRegistryRequest, DatasetAPIError)
validate_data(request_data, CreateDatasetRegistryRequest, DatasetAPIError)

url = urljoin(self.base_url, self.service_path, "registerDataset")
response = requests.put(url, headers=headers, json=data)
response = requests.put(url, headers=headers, json=request_data)
if not response.ok:
raise DatasetAPIError(response.text, response.status_code)
return response.json()
Expand All @@ -49,13 +43,10 @@ def get_storage_instructions(
kind_sub_type: str,
expiry_time: str | None = None,
data_partition_id: str | None = None,
tenant: str | None = None,
) -> dict:
headers = self.auth.get_headers()
if data_partition_id:
headers["data-partition-id"] = data_partition_id
if tenant:
headers["tenant"] = tenant

params = {
"kindSubType": kind_sub_type,
Expand All @@ -70,17 +61,11 @@ def get_storage_instructions(
return response.json()

def get_revoke_url(
self,
*,
kind_sub_type: str,
data_partition_id: str | None = None,
tenant: str | None = None,
self, *, kind_sub_type: str, data_partition_id: str | None = None
) -> dict:
headers = self.auth.get_headers()
if data_partition_id:
headers["data-partition-id"] = data_partition_id
if tenant:
headers["tenant"] = tenant

params = {
"kindSubType": kind_sub_type,
Expand All @@ -98,13 +83,10 @@ def get_retrieval_instructions(
id: str,
expiry_time: str | None = None,
data_partition_id: str | None = None,
tenant: str | None = None,
) -> dict:
headers = self.auth.get_headers()
if data_partition_id:
headers["data-partition-id"] = data_partition_id
if tenant:
headers["tenant"] = tenant

params = {
"id": id,
Expand All @@ -124,43 +106,34 @@ def get_retrieval_instructions_for_multiple_datasets(
dataset_registry_ids: list[str],
expiry_time: str | None = None,
data_partition_id: str | None = None,
tenant: str | None = None,
) -> dict:
headers = self.auth.get_headers()
if data_partition_id:
headers["data-partition-id"] = data_partition_id
if tenant:
headers["tenant"] = tenant

params = {}
if expiry_time is not None:
params["expiryTime"] = expiry_time

data = {
request_data = {
"datasetRegistryIds": dataset_registry_ids,
}

if self.validation:
validate_data(data, GetDatasetRegistryRequest, DatasetAPIError)
validate_data(request_data, GetDatasetRegistryRequest, DatasetAPIError)

url = urljoin(self.base_url, self.service_path, "retrievalInstructions")
response = requests.post(url, headers=headers, params=params, json=data)
response = requests.post(url, headers=headers, params=params, json=request_data)
if not response.ok:
raise DatasetAPIError(response.text, response.status_code)
return response.json()

def get_dataset_registry(
self,
*,
id: str,
data_partition_id: str | None = None,
tenant: str | None = None,
self, *, id: str, data_partition_id: str | None = None
) -> dict:
headers = self.auth.get_headers()
if data_partition_id:
headers["data-partition-id"] = data_partition_id
if tenant:
headers["tenant"] = tenant

params = {
"id": id,
Expand All @@ -173,54 +146,40 @@ def get_dataset_registry(
return response.json()

def get_dataset_registries(
self,
*,
dataset_registry_ids: list[str],
data_partition_id: str | None = None,
tenant: str | None = None,
self, *, dataset_registry_ids: list[str], data_partition_id: str | None = None
) -> dict:
headers = self.auth.get_headers()
if data_partition_id:
headers["data-partition-id"] = data_partition_id
if tenant:
headers["tenant"] = tenant

data = {
request_data = {
"datasetRegistryIds": dataset_registry_ids,
}

if self.validation:
validate_data(data, GetDatasetRegistryRequest, DatasetAPIError)
validate_data(request_data, GetDatasetRegistryRequest, DatasetAPIError)

url = urljoin(self.base_url, self.service_path, "getDatasetRegistry")
response = requests.post(url, headers=headers, json=data)
response = requests.post(url, headers=headers, json=request_data)
if not response.ok:
raise DatasetAPIError(response.text, response.status_code)
return response.json()

def get_liveness_check(
self, data_partition_id: str | None = None, tenant: str | None = None
) -> dict:
def get_liveness_check(self, data_partition_id: str | None = None) -> dict:
headers = self.auth.get_headers()
if data_partition_id:
headers["data-partition-id"] = data_partition_id
if tenant:
headers["tenant"] = tenant

url = urljoin(self.base_url, self.service_path, "liveness_check")
response = requests.get(url, headers=headers)
if not response.ok:
raise DatasetAPIError(response.text, response.status_code)
return response.json()

def get_info(
self, data_partition_id: str | None = None, tenant: str | None = None
) -> dict:
def get_info(self, data_partition_id: str | None = None) -> dict:
headers = self.auth.get_headers()
if data_partition_id:
headers["data-partition-id"] = data_partition_id
if tenant:
headers["tenant"] = tenant

url = urljoin(self.base_url, self.service_path, "info")
response = requests.get(url, headers=headers)
Expand Down
Loading

0 comments on commit 5f7d30d

Please sign in to comment.