Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
[Fix] using Literal, allow Literal as params, fix aliases (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
cicharka authored Feb 15, 2024
1 parent b084b02 commit a133505
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 91 deletions.
8 changes: 4 additions & 4 deletions catalystwan/api/config_device_inventory_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ def unlock(self, device_uuid: str, device_type: str, device_details: list) -> Ta
devices = []
for device_detail in device_details:
unlock_device_detail = UnlockDeviceDetail(
deviceId=device_detail["deviceId"], deviceIP=device_detail["deviceIP"]
device_id=device_detail["deviceId"], device_ip=device_detail["deviceIP"]
)
devices.append(unlock_device_detail)

payload = DeviceUnlockPayload(deviceType=device_type, devices=devices)
payload = DeviceUnlockPayload(device_type=device_type, devices=devices)

task_id = self.endpoint.unlock(device_uuid=device_uuid, payload=payload).parentTaskId
return Task(self.session, task_id=task_id)

def generate_bootstrap_cfg(
self,
device_uuid: UUID,
configtype: ConfigType = ConfigType.CLOUDINIT,
configtype: ConfigType = "cloudinit",
incl_def_root_cert: bool = False,
version: str = "v1",
) -> BoostrapConfigurationDetails:
"""
Returns handy model of generated bootstrap config
"""
params = GenerateBoostrapConfigurationQueryParams(
configtype=configtype, inclDefRootCert=incl_def_root_cert, version=version
configtype=configtype, incl_def_root_cert=incl_def_root_cert, version=version
)
reponse = self.endpoint.generate_bootstrap_configuration(uuid=device_uuid, params=params)

Expand Down
14 changes: 13 additions & 1 deletion catalystwan/endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
Final,
Iterable,
List,
Literal,
Mapping,
Optional,
Protocol,
Expand Down Expand Up @@ -538,8 +539,19 @@ def check_params(self):
raise APIEndpointError(f"Missing parameters: {missing} to format url: {self.url}")

for parameter in [parameters.get(name) for name in self.url_field_names]:
# Check if 'params' is type of str, UUID or LIteral
if not (isclass(parameter.annotation) and issubclass(parameter.annotation, (str, UUID))):
raise APIEndpointError(f"Parameter {parameter} used for url formatting must be 'str' sub-type or UUID")
if not get_origin(parameter.annotation) == Literal:
raise APIEndpointError(
f"Parameter {parameter} used for url formatting must be 'str', UUID or Literal sub-type"
)

elif p_args := get_args(parameter.annotation):
# Check if all 'params' Literal values are str
if not all((isinstance(arg, str) for arg in p_args)):
raise APIEndpointError(
f"Literal values for parameter {parameter} used for url formatting must be 'str'"
)

no_purpose_params = {
parameters.get(name) for name in general_purpose_arg_names.difference(self.url_field_names)
Expand Down
Loading

0 comments on commit a133505

Please sign in to comment.