From 6d67a78ca44c584aad8165b833f4a91d5e5763e8 Mon Sep 17 00:00:00 2001 From: sbasan Date: Wed, 13 Sep 2023 15:47:14 +0200 Subject: [PATCH] fix validators --- ENDPOINTS.md | 36 +++++++++---------- ...uration_policy_data_prefix_list_builder.py | 11 ++++-- .../configuration_policy_vpn_list_builder.py | 5 ++- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/ENDPOINTS.md b/ENDPOINTS.md index e685d67a7..515399152 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -52,15 +52,15 @@ GET /template/policy/definition/data||[**ConfigurationPolicyDataDefinitionBuilde GET /template/policy/definition/data/{id}||[**ConfigurationPolicyDataDefinitionBuilder.get_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L248)||[**DataDefinition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L223)| POST /template/policy/definition/data/preview||[**ConfigurationPolicyDataDefinitionBuilder.preview_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L252)|[**DataDefinitionCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L215)|[**PolicyDefinitionPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L46)| GET /template/policy/definition/data/preview/{id}||[**ConfigurationPolicyDataDefinitionBuilder.preview_policy_definition_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L256)||[**PolicyDefinitionPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L46)| -POST /template/policy/list/dataprefix||[**ConfigurationPolicyDataPrefixListBuilder.create_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L44)|[**DataPrefixListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L31)|[**PolicyListId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L11)| -DELETE /template/policy/list/dataprefix/{id}||[**ConfigurationPolicyDataPrefixListBuilder.delete_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L48)||None| -DELETE /template/policy/list/dataprefix||[**ConfigurationPolicyDataPrefixListBuilder.delete_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L52)||None| -PUT /template/policy/list/dataprefix/{id}||[**ConfigurationPolicyDataPrefixListBuilder.edit_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L59)|[**DataPrefixListEditPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L35)|None| -GET /template/policy/list/dataprefix/{id}||[**ConfigurationPolicyDataPrefixListBuilder.get_lists_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L63)||[**DataPrefixList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L39)| -GET /template/policy/list/dataprefix||[**ConfigurationPolicyDataPrefixListBuilder.get_policy_lists**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L67)||DataSequence[[**DataPrefixList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L39)]| -GET /template/policy/list/dataprefix/filtered||[**ConfigurationPolicyDataPrefixListBuilder.get_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L71)||DataSequence[[**DataPrefixList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L39)]| -POST /template/policy/list/dataprefix/preview||[**ConfigurationPolicyDataPrefixListBuilder.preview_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L78)|[**DataPrefixListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L31)|[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| -GET /template/policy/list/dataprefix/preview/{id}||[**ConfigurationPolicyDataPrefixListBuilder.preview_policy_list_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L83)||[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| +POST /template/policy/list/dataprefix||[**ConfigurationPolicyDataPrefixListBuilder.create_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L51)|[**DataPrefixListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L38)|[**PolicyListId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L11)| +DELETE /template/policy/list/dataprefix/{id}||[**ConfigurationPolicyDataPrefixListBuilder.delete_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L55)||None| +DELETE /template/policy/list/dataprefix||[**ConfigurationPolicyDataPrefixListBuilder.delete_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L59)||None| +PUT /template/policy/list/dataprefix/{id}||[**ConfigurationPolicyDataPrefixListBuilder.edit_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L66)|[**DataPrefixListEditPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L42)|None| +GET /template/policy/list/dataprefix/{id}||[**ConfigurationPolicyDataPrefixListBuilder.get_lists_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L70)||[**DataPrefixList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L46)| +GET /template/policy/list/dataprefix||[**ConfigurationPolicyDataPrefixListBuilder.get_policy_lists**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L74)||DataSequence[[**DataPrefixList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L46)]| +GET /template/policy/list/dataprefix/filtered||[**ConfigurationPolicyDataPrefixListBuilder.get_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L78)||DataSequence[[**DataPrefixList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L46)]| +POST /template/policy/list/dataprefix/preview||[**ConfigurationPolicyDataPrefixListBuilder.preview_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L85)|[**DataPrefixListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L38)|[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| +GET /template/policy/list/dataprefix/preview/{id}||[**ConfigurationPolicyDataPrefixListBuilder.preview_policy_list_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L90)||[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| POST /template/policy/list/site/defaultsite||[**ConfigurationPolicySiteListBuilder.create_default_site_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L43)|[**SiteListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L30)|[**PolicyListId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L11)| POST /template/policy/list/site||[**ConfigurationPolicySiteListBuilder.create_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L47)|[**SiteListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L30)|[**PolicyListId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L11)| DELETE /template/policy/list/site/{id}||[**ConfigurationPolicySiteListBuilder.delete_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L51)||None| @@ -71,15 +71,15 @@ GET /template/policy/list/site||[**ConfigurationPolicySiteListBuilder.get_policy GET /template/policy/list/site/filtered||[**ConfigurationPolicySiteListBuilder.get_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L74)||DataSequence[[**SiteList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L38)]| POST /template/policy/list/site/preview||[**ConfigurationPolicySiteListBuilder.preview_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L81)|[**SiteListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L30)|[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| GET /template/policy/list/site/preview/{id}||[**ConfigurationPolicySiteListBuilder.preview_policy_list_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_site_list_builder.py#L85)||[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| -POST /template/policy/list/vpn||[**ConfigurationPolicyVPNListBuilder.create_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L56)|[**VPNListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L43)|[**PolicyListId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L11)| -DELETE /template/policy/list/vpn/{id}||[**ConfigurationPolicyVPNListBuilder.delete_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L60)||None| -DELETE /template/policy/list/vpn||[**ConfigurationPolicyVPNListBuilder.delete_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L64)||None| -PUT /template/policy/list/vpn/{id}||[**ConfigurationPolicyVPNListBuilder.edit_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L71)|[**VPNListEditPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L47)|None| -GET /template/policy/list/vpn/{id}||[**ConfigurationPolicyVPNListBuilder.get_lists_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L75)||[**VPNList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L51)| -GET /template/policy/list/vpn||[**ConfigurationPolicyVPNListBuilder.get_policy_lists**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L79)||DataSequence[[**VPNList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L51)]| -GET /template/policy/list/vpn/filtered||[**ConfigurationPolicyVPNListBuilder.get_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L83)||DataSequence[[**VPNList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L51)]| -POST /template/policy/list/vpn/preview||[**ConfigurationPolicyVPNListBuilder.preview_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L90)|[**VPNListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L43)|[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| -GET /template/policy/list/vpn/preview/{id}||[**ConfigurationPolicyVPNListBuilder.preview_policy_list_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L94)||[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| +POST /template/policy/list/vpn||[**ConfigurationPolicyVPNListBuilder.create_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L55)|[**VPNListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L42)|[**PolicyListId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L11)| +DELETE /template/policy/list/vpn/{id}||[**ConfigurationPolicyVPNListBuilder.delete_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L59)||None| +DELETE /template/policy/list/vpn||[**ConfigurationPolicyVPNListBuilder.delete_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L63)||None| +PUT /template/policy/list/vpn/{id}||[**ConfigurationPolicyVPNListBuilder.edit_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L70)|[**VPNListEditPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L46)|None| +GET /template/policy/list/vpn/{id}||[**ConfigurationPolicyVPNListBuilder.get_lists_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L74)||[**VPNList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L50)| +GET /template/policy/list/vpn||[**ConfigurationPolicyVPNListBuilder.get_policy_lists**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L78)||DataSequence[[**VPNList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L50)]| +GET /template/policy/list/vpn/filtered||[**ConfigurationPolicyVPNListBuilder.get_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L82)||DataSequence[[**VPNList**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L50)]| +POST /template/policy/list/vpn/preview||[**ConfigurationPolicyVPNListBuilder.preview_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L89)|[**VPNListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L42)|[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| +GET /template/policy/list/vpn/preview/{id}||[**ConfigurationPolicyVPNListBuilder.preview_policy_list_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_vpn_list_builder.py#L93)||[**PolicyListPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L39)| GET /settings/configuration/{setting_type}||[**ConfigurationSettings.get_configuration_by_setting_type**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L208)||dict| GET /settings/configuration/organization||[**ConfigurationSettings.get_organizations**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L212)||DataSequence[[**Organization**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L29)]| GET /settings/configuration/device||[**ConfigurationSettings.get_devices**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L216)||DataSequence[[**Device**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_settings.py#L35)]| diff --git a/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py b/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py index 2d7a15cb0..58ae9f97e 100644 --- a/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py +++ b/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py @@ -2,7 +2,7 @@ from ipaddress import IPv4Network from typing import List -from pydantic import BaseModel, Field +from pydantic import BaseModel, Field, validator from vmngclient.endpoints import APIEndpoints, delete, get, post, put from vmngclient.model.policy_list import ( @@ -20,7 +20,14 @@ class DataPrefixListEntry(BaseModel): class Config: allow_population_by_field_name = True - ip_prefix: IPv4Network = Field(alias="ipPrefix") + ip_prefix: str = Field(alias="ipPrefix", description="IP4 network prefixes separated by comma") + + @validator("ip_prefix") + def check_network_prefixes(cls, ip_prefix: str): + nets = [IPv4Network(net.strip()) for net in ip_prefix.split(",")] + if len(nets) < 1: + raise ValueError("No network prefix provided") + return ip_prefix class DataPrefixPayload(BaseModel): diff --git a/vmngclient/endpoints/configuration_policy_vpn_list_builder.py b/vmngclient/endpoints/configuration_policy_vpn_list_builder.py index ac824bdf5..4dba42b9b 100644 --- a/vmngclient/endpoints/configuration_policy_vpn_list_builder.py +++ b/vmngclient/endpoints/configuration_policy_vpn_list_builder.py @@ -19,11 +19,10 @@ class VPNListEntry(BaseModel): class Config: allow_population_by_field_name = True - vpn: str = Field(alias="vpn", description="") + vpn: str = Field(alias="vpn", description="0-65530 range or single number") @validator("vpn") - def ckeck_range(cls, vpns_str): - # could be string containing single integer "100" or range "1000-2000" + def check_vpn_range(cls, vpns_str: str): vpns = [int(vpn) for vpn in vpns_str.split("-")] if len(vpns) > 2: raise ValueError("VPN range should consist two integers separated by hyphen")