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

Commit

Permalink
Add ux1 endpoints and models. Add converters
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrajewski committed Jul 24, 2024
1 parent e3c5528 commit 9e3ac83
Show file tree
Hide file tree
Showing 11 changed files with 250 additions and 26 deletions.
22 changes: 22 additions & 0 deletions catalystwan/api/policy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from catalystwan.endpoints.configuration.policy.list.extended_community import ConfigurationPolicyExtendedCommunityList
from catalystwan.endpoints.configuration.policy.list.fqdn import ConfigurationPolicyFQDNList, FQDNListInfo
from catalystwan.endpoints.configuration.policy.list.geo_location import ConfigurationPolicyGeoLocationList
from catalystwan.endpoints.configuration.policy.list.identity import ConfigurationPolicyIdentityList
from catalystwan.endpoints.configuration.policy.list.ips_signature import ConfigurationPolicyIPSSignatureList
from catalystwan.endpoints.configuration.policy.list.ipv6_prefix import ConfigurationPolicyIPv6PrefixList
from catalystwan.endpoints.configuration.policy.list.local_app import ConfigurationPolicyLocalAppList, LocalAppListInfo
Expand All @@ -77,6 +78,7 @@
ProtocolNameListInfo,
)
from catalystwan.endpoints.configuration.policy.list.region import ConfigurationPolicyRegionList, RegionListInfo
from catalystwan.endpoints.configuration.policy.list.scalable_group_tag import ConfigurationPolicyScalableGroupTagList
from catalystwan.endpoints.configuration.policy.list.site import ConfigurationPolicySiteList, SiteListInfo
from catalystwan.endpoints.configuration.policy.list.sla import ConfigurationPolicySLAClassList, SLAClassListInfo
from catalystwan.endpoints.configuration.policy.list.threat_grid_api_key import ConfigurationPolicyThreatGridApiKeyList
Expand Down Expand Up @@ -183,9 +185,11 @@
from catalystwan.models.policy.list.data_ipv6_prefix import DataIPv6PrefixListInfo
from catalystwan.models.policy.list.data_prefix import DataPrefixListInfo
from catalystwan.models.policy.list.geo_location import GeoLocationListInfo
from catalystwan.models.policy.list.identity import IdentityList, IdentityListInfo
from catalystwan.models.policy.list.ips_signature import IPSSignatureListInfo
from catalystwan.models.policy.list.ipv6_prefix import IPv6PrefixListInfo
from catalystwan.models.policy.list.local_domain import LocalDomainListInfo
from catalystwan.models.policy.list.scalable_group_tag import ScalableGroupTagList, ScalableGroupTagListInfo
from catalystwan.models.policy.list.threat_grid_api_key import ThreatGridApiKeyList, ThreatGridApiKeyListInfo
from catalystwan.models.policy.list.trunkgroup import TrunkGroupList, TrunkGroupListInfo
from catalystwan.models.policy.list.umbrella_data import UmbrellaDataList, UmbrellaDataListInfo
Expand Down Expand Up @@ -233,6 +237,7 @@
LocalDomainList: ConfigurationPolicyLocalDomainList,
MirrorList: ConfigurationPolicyMirrorList,
PolicerList: ConfigurationPolicyPolicerClassList,
ScalableGroupTagList: ConfigurationPolicyScalableGroupTagList,
PortList: ConfigurationPolicyPortList,
PreferredColorGroupList: ConfigurationPreferredColorGroupList,
PrefixList: ConfigurationPolicyPrefixList,
Expand All @@ -248,6 +253,7 @@
URLAllowList: ConfigurationPolicyURLAllowList,
VPNList: ConfigurationPolicyVPNList,
ZoneList: ConfigurationPolicyZoneList,
IdentityList: ConfigurationPolicyIdentityList,
}

POLICY_DEFINITION_ENDPOINTS_MAP: Mapping[type, type] = {
Expand Down Expand Up @@ -544,6 +550,14 @@ def get(self, type: Type[VPNList]) -> DataSequence[VPNListInfo]:
def get(self, type: Type[ZoneList]) -> DataSequence[ZoneListInfo]:
...

@overload
def get(self, type: Type[ScalableGroupTagList]) -> DataSequence[ScalableGroupTagListInfo]:
...

@overload
def get(self, type: Type[IdentityList]) -> DataSequence[IdentityListInfo]:
...

# get by id

@overload
Expand Down Expand Up @@ -678,6 +692,14 @@ def get(self, type: Type[VPNList], id: UUID) -> VPNListInfo:
def get(self, type: Type[ZoneList], id: UUID) -> ZoneListInfo:
...

@overload
def get(self, type: Type[ScalableGroupTagList], id: UUID) -> ScalableGroupTagListInfo:
...

@overload
def get(self, type: Type[IdentityList], id: UUID) -> IdentityListInfo:
...

def get(self, type: Type[AnyPolicyList], id: Optional[UUID] = None) -> Any:
endpoints = self.__get_list_endpoints_instance(type)
if id is not None:
Expand Down
48 changes: 48 additions & 0 deletions catalystwan/endpoints/configuration/policy/list/identity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Copyright 2023 Cisco Systems, Inc. and its affiliates

# mypy: disable-error-code="empty-body"
from uuid import UUID

from catalystwan.endpoints import APIEndpoints, delete, get, post, put
from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints
from catalystwan.models.policy.list.identity import IdentityList, IdentityListEditPayload, IdentityListInfo
from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview
from catalystwan.typed_list import DataSequence


class ConfigurationPolicyIdentityList(APIEndpoints, PolicyListEndpoints):
@post("/template/policy/list/identity")
def create_policy_list(self, payload: IdentityList) -> PolicyListId:
...

@delete("/template/policy/list/identity/{id}")
def delete_policy_list(self, id: UUID) -> None:
...

@delete("/template/policy/list/identity")
def delete_policy_lists_with_info_tag(self, params: InfoTag) -> None:
...

@put("/template/policy/list/identity/{id}")
def edit_policy_list(self, id: UUID, payload: IdentityListEditPayload) -> None:
...

@get("/template/policy/list/identity/{id}")
def get_lists_by_id(self, id: UUID) -> IdentityListInfo:
...

@get("/template/policy/list/identity", "data")
def get_policy_lists(self) -> DataSequence[IdentityListInfo]:
...

@get("/template/policy/list/identity/filtered", "data")
def get_policy_lists_with_info_tag(self, params: InfoTag) -> DataSequence[IdentityListInfo]:
...

@post("/template/policy/list/identity/preview")
def preview_policy_list(self, payload: IdentityList) -> PolicyListPreview:
...

@get("/template/policy/list/identity/preview/{id}")
def preview_policy_list_by_id(self, id: UUID) -> PolicyListPreview:
...
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2023 Cisco Systems, Inc. and its affiliates

# mypy: disable-error-code="empty-body"
from uuid import UUID

from catalystwan.endpoints import APIEndpoints, delete, get, post, put
from catalystwan.endpoints.configuration.policy.abstractions import PolicyListEndpoints
from catalystwan.models.policy.list.scalable_group_tag import (
ScalableGroupTagList,
ScalableGroupTagListEditPayload,
ScalableGroupTagListInfo,
)
from catalystwan.models.policy.policy_list import InfoTag, PolicyListId, PolicyListPreview
from catalystwan.typed_list import DataSequence


class ConfigurationPolicyScalableGroupTagList(APIEndpoints, PolicyListEndpoints):
@post("/template/policy/list/scalablegrouptag")
def create_policy_list(self, payload: ScalableGroupTagList) -> PolicyListId:
...

@delete("/template/policy/list/scalablegrouptag/{id}")
def delete_policy_list(self, id: UUID) -> None:
...

@delete("/template/policy/list/scalablegrouptag")
def delete_policy_lists_with_info_tag(self, params: InfoTag) -> None:
...

@put("/template/policy/list/scalablegrouptag/{id}")
def edit_policy_list(self, id: UUID, payload: ScalableGroupTagListEditPayload) -> None:
...

@get("/template/policy/list/scalablegrouptag/{id}")
def get_lists_by_id(self, id: UUID) -> ScalableGroupTagListInfo:
...

@get("/template/policy/list/scalablegrouptag", "data")
def get_policy_lists(self) -> DataSequence[ScalableGroupTagListInfo]:
...

@get("/template/policy/list/scalablegrouptag/filtered", "data")
def get_policy_lists_with_info_tag(self, params: InfoTag) -> DataSequence[ScalableGroupTagListInfo]:
...

@post("/template/policy/list/scalablegrouptag/preview")
def preview_policy_list(self, payload: ScalableGroupTagList) -> PolicyListPreview:
...

@get("/template/policy/list/scalablegrouptag/preview/{id}")
def preview_policy_list_by_id(self, id: UUID) -> PolicyListPreview:
...
12 changes: 7 additions & 5 deletions catalystwan/models/configuration/feature_profile/parcel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"bfd",
"bgp",
"cellular-controller",
"cellular-profile",
"class",
"color",
"config",
Expand Down Expand Up @@ -63,6 +64,7 @@
"omp",
"policer",
"policy-settings",
"policy",
"preferred-color-group",
"prefix",
"qos-policy",
Expand All @@ -74,11 +76,13 @@
"routing/ospfv3/ipv6",
"security-fqdn",
"security-geolocation",
"security-identity",
"security-ipssignature",
"security-localapp",
"security-localdomain",
"security-port",
"security-protocolname",
"security-scalablegrouptag",
"security-urllist",
"security-zone",
"security",
Expand All @@ -90,9 +94,11 @@
"tloc",
"tracker",
"trackergroup",
"traffic-policy",
"unified/advanced-inspection-profile",
"unified/advanced-malware-protection",
"unified/intrusion-prevention",
"unified/ngfirewall",
"unified/ssl-decryption-profile",
"unified/ssl-decryption",
"unified/url-filtering",
Expand All @@ -102,15 +108,11 @@
"wan/vpn/interface/dsl-pppoa",
"wan/vpn/interface/dsl-pppoe",
"wan/vpn/interface/ethernet",
"wan/vpn/interface/ethpppoe",
"wan/vpn/interface/gre",
"wan/vpn/interface/multilink",
"traffic-policy",
"wan/vpn/interface/serial",
"wirelesslan",
"cellular-profile",
"wan/vpn/interface/ethpppoe",
"unified/ngfirewall",
"policy",
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@
from .security.data_prefix import SecurityDataPrefixEntry, SecurityDataPrefixParcel
from .security.fqdn import FQDNDomainParcel, FQDNListEntry
from .security.geolocation_list import GeoLocationListEntry, GeoLocationListParcel
from .security.identity import IdentityEntries, IdentityParcel
from .security.identity import IdentityEntry, IdentityParcel
from .security.intrusion_prevention import IntrusionPreventionParcel
from .security.ips_signature import IPSSignatureListEntry, IPSSignatureParcel
from .security.local_domain import LocalDomainListEntry, LocalDomainParcel
from .security.protocol_list import ProtocolListEntry, ProtocolListParcel
from .security.scalable_group_tag import ScalableGroupTagEntry, ScalableGroupTagParcel
from .security.security_port import SecurityPortListEntry, SecurityPortParcel
from .security.ssl_decryption import SslDecryptionParcel
from .security.ssl_decryption_profile import SslDecryptionProfileParcel
Expand All @@ -57,38 +58,40 @@
ExtendedCommunityParcel,
FowardingClassParcel,
FQDNDomainParcel,
FQDNDomainParcel,
GeoLocationListParcel,
GeoLocationListParcel,
IdentityParcel,
IdentityParcel,
IntrusionPreventionParcel,
IPSSignatureParcel,
IPSSignatureParcel,
IPv6DataPrefixParcel,
IPv6PrefixListParcel,
LocalDomainParcel,
LocalDomainParcel,
MirrorParcel,
PolicerParcel,
PreferredColorGroupParcel,
PrefixListParcel,
SLAClassParcel,
TlocParcel,
StandardCommunityParcel,
LocalDomainParcel,
FQDNDomainParcel,
IPSSignatureParcel,
SecurityPortParcel,
ProtocolListParcel,
GeoLocationListParcel,
SecurityZoneListParcel,
ScalableGroupTagParcel,
SecurityApplicationListParcel,
SecurityDataPrefixParcel,
SecurityPortParcel,
SecurityPortParcel,
SecurityZoneListParcel,
SecurityZoneListParcel,
SLAClassParcel,
SLAClassParcel,
SslDecryptionParcel,
SslDecryptionProfileParcel,
StandardCommunityParcel,
StandardCommunityParcel,
TlocParcel,
TlocParcel,
URLParcel,
UrlFilteringParcel,
URLParcel,
],
Field(discriminator="type_"),
]
Expand Down Expand Up @@ -118,8 +121,10 @@
"FQDNListEntry",
"GeoLocationListEntry",
"GeoLocationListParcel",
"IdentityEntry",
"IdentityEntry",
"IdentityParcel",
"IdentityParcel",
"IdentityEntries",
"IntrusionPreventionParcel",
"IPSSignatureListEntry",
"IPSSignatureParcel",
Expand All @@ -139,6 +144,8 @@
"PrefixListParcel",
"ProtocolListEntry",
"ProtocolListParcel",
"ScalableGroupTagEntry",
"ScalableGroupTagParcel",
"SecurityApplicationFamilyListEntry",
"SecurityApplicationListEntry",
"SecurityApplicationListParcel",
Expand All @@ -158,9 +165,9 @@
"StandardCommunityParcel",
"TlocEntry",
"TlocParcel",
"URLParcel",
"URLAllowParcel",
"URLBlockParcel",
"URLParcel",
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from catalystwan.api.configuration_groups.parcel import Global, _ParcelBase, as_optional_global


class IdentityEntries(BaseModel):
class IdentityEntry(BaseModel):
user: Optional[Global[str]] = Field(default=None)
user_group: Optional[Global[str]] = Field(
default=None, validation_alias="userGroup", serialization_alias="userGroup"
Expand All @@ -14,15 +14,15 @@ class IdentityEntries(BaseModel):

class IdentityParcel(_ParcelBase):
type_: Literal["security-identity"] = Field(default="security-identity", exclude=True)
entries: List[IdentityEntries] = Field(
entries: List[IdentityEntry] = Field(
validation_alias=AliasPath("data", "entries"),
default_factory=list,
description="Array of Users and User Groups",
)

def add_entry(self, user: Optional[str] = None, user_group: Optional[str] = None):
self.entries.append(
IdentityEntries(
IdentityEntry(
user=as_optional_global(user),
user_group=as_optional_global(user_group),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from typing import List, Optional
from typing import List, Literal, Optional

from pydantic import AliasPath, BaseModel, Field

from catalystwan.api.configuration_groups.parcel import Global, _ParcelBase, as_optional_global


class ScalableGroupTagEntries(BaseModel):
class ScalableGroupTagEntry(BaseModel):
sgt_name: Optional[Global[str]] = Field(default=None, validation_alias="sgtName", serialization_alias="sgtName")
tag: Optional[Global[str]] = Field(default=None)


class ScalableGroupTagParcel(_ParcelBase):
entries: List[ScalableGroupTagEntries] = Field(validation_alias=AliasPath("data", "entries"), default_factory=list)
type_: Literal["security-scalablegrouptag"] = Field(default="security-scalablegrouptag")
entries: List[ScalableGroupTagEntry] = Field(validation_alias=AliasPath("data", "entries"), default_factory=list)

def add_entry(self, sgt_name: Optional[str] = None, tag: Optional[str] = None):
self.entries.append(
ScalableGroupTagEntries(
ScalableGroupTagEntry(
sgt_name=as_optional_global(sgt_name),
tag=as_optional_global(tag),
)
Expand Down
Loading

0 comments on commit 9e3ac83

Please sign in to comment.