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

Commit

Permalink
Advanced Inspection Profile v1 model (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
radkrawczyk authored May 8, 2024
1 parent ce762f7 commit 37b9888
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 0 deletions.
14 changes: 14 additions & 0 deletions catalystwan/api/policy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from catalystwan.endpoints.configuration.policy.definition.access_control_list_ipv6 import (
ConfigurationPolicyAclIPv6Definition,
)
from catalystwan.endpoints.configuration.policy.definition.aip import ConfigurationPolicyAIPDefinition
from catalystwan.endpoints.configuration.policy.definition.amp import ConfigurationPolicyAMPDefinition
from catalystwan.endpoints.configuration.policy.definition.control import ConfigurationPolicyControlDefinition
from catalystwan.endpoints.configuration.policy.definition.device_access import (
Expand Down Expand Up @@ -126,6 +127,10 @@
from catalystwan.models.policy.centralized import CentralizedPolicy, CentralizedPolicyEditPayload, CentralizedPolicyInfo
from catalystwan.models.policy.definition.access_control_list import AclPolicy, AclPolicyGetResponse
from catalystwan.models.policy.definition.access_control_list_ipv6 import AclIPv6Policy, AclIPv6PolicyGetResponse
from catalystwan.models.policy.definition.aip import (
AdvancedInspectionProfilePolicy,
AdvancedInspectionProfilePolicyGetResponse,
)
from catalystwan.models.policy.definition.amp import (
AdvancedMalwareProtectionPolicy,
AdvancedMalwareProtectionPolicyGetResponse,
Expand Down Expand Up @@ -235,6 +240,7 @@
AclIPv6Policy: ConfigurationPolicyAclIPv6Definition,
DeviceAccessPolicy: ConfigurationPolicyDeviceAccessDefinition,
DeviceAccessIPv6Policy: ConfigurationPolicyDeviceAccessIPv6Definition,
AdvancedInspectionProfilePolicy: ConfigurationPolicyAIPDefinition,
AdvancedMalwareProtectionPolicy: ConfigurationPolicyAMPDefinition,
IntrusionPreventionPolicy: ConfigurationPolicyIntrusionPreventionDefinition,
UrlFilteringPolicy: ConfigurationPolicyUrlFilteringDefinition,
Expand Down Expand Up @@ -673,6 +679,10 @@ def get(self, type: Type[TrafficDataPolicy]) -> DataSequence[PolicyDefinitionInf
def get(self, type: Type[UrlFilteringPolicy]) -> DataSequence[PolicyDefinitionInfo]:
...

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

@overload
def get(self, type: Type[AdvancedMalwareProtectionPolicy]) -> DataSequence[PolicyDefinitionInfo]:
...
Expand Down Expand Up @@ -742,6 +752,10 @@ def get(self, type: Type[TrafficDataPolicy], id: UUID) -> TrafficDataPolicyGetRe
def get(self, type: Type[UrlFilteringPolicy], id: UUID) -> UrlFilteringPolicyGetResponse:
...

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

@overload
def get(self, type: Type[AdvancedMalwareProtectionPolicy], id: UUID) -> AdvancedMalwareProtectionPolicyGetResponse:
...
Expand Down
52 changes: 52 additions & 0 deletions catalystwan/endpoints/configuration/policy/definition/aip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2024 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 PolicyDefinitionEndpoints
from catalystwan.models.policy.definition.aip import (
AdvancedInspectionProfilePolicy,
AdvancedInspectionProfilePolicyEditPayload,
AdvancedInspectionProfilePolicyGetResponse,
)
from catalystwan.models.policy.policy_definition import (
PolicyDefinitionEditResponse,
PolicyDefinitionId,
PolicyDefinitionInfo,
PolicyDefinitionPreview,
)
from catalystwan.typed_list import DataSequence


class ConfigurationPolicyAIPDefinition(APIEndpoints, PolicyDefinitionEndpoints):
@post("/template/policy/definition/advancedinspectionprofile")
def create_policy_definition(self, payload: AdvancedInspectionProfilePolicy) -> PolicyDefinitionId:
...

@delete("/template/policy/definition/advancedinspectionprofile/{id}")
def delete_policy_definition(self, id: UUID) -> None:
...

@put("/template/policy/definition/advancedinspectionprofile/{id}")
def edit_policy_definition(
self, id: UUID, payload: AdvancedInspectionProfilePolicyEditPayload
) -> PolicyDefinitionEditResponse:
...

@get("/template/policy/definition/advancedinspectionprofile", "data")
def get_definitions(self) -> DataSequence[PolicyDefinitionInfo]:
...

@get("/template/policy/definition/advancedinspectionprofile/{id}")
def get_policy_definition(self, id: UUID) -> AdvancedInspectionProfilePolicyGetResponse:
...

@post("/template/policy/definition/advancedinspectionprofile/preview")
def preview_policy_definition(self, payload: AdvancedInspectionProfilePolicy) -> PolicyDefinitionPreview:
...

@get("/template/policy/definition/advancedinspectionprofile/preview/{id}")
def preview_policy_definition_by_id(self, id: UUID) -> PolicyDefinitionPreview:
...
4 changes: 4 additions & 0 deletions catalystwan/models/policy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from .centralized import CentralizedPolicy, TrafficDataDirection
from .definition.access_control_list import AclPolicy, AclPolicyGetResponse
from .definition.access_control_list_ipv6 import AclIPv6Policy, AclIPv6PolicyGetResponse
from .definition.aip import AdvancedInspectionProfilePolicy, AdvancedInspectionProfilePolicyGetResponse
from .definition.amp import AdvancedMalwareProtectionPolicy, AdvancedMalwareProtectionPolicyGetResponse
from .definition.control import ControlPolicy, ControlPolicyGetResponse
from .definition.device_access import DeviceAccessPolicy, DeviceAccessPolicyGetResponse
Expand Down Expand Up @@ -77,6 +78,7 @@
Union[
AclIPv6Policy,
AclPolicy,
AdvancedInspectionProfilePolicy,
AdvancedMalwareProtectionPolicy,
ControlPolicy,
IntrusionPreventionPolicy,
Expand Down Expand Up @@ -172,6 +174,7 @@

AnyPolicyDefinitionInfo = Annotated[
Union[
AdvancedInspectionProfilePolicyGetResponse,
AdvancedMalwareProtectionPolicyGetResponse,
AclIPv6PolicyGetResponse,
AclPolicyGetResponse,
Expand All @@ -197,6 +200,7 @@
__all__ = (
"AclIPv6Policy",
"AclPolicy",
"AdvancedInspectionProfilePolicy",
"AdvancedMalwareProtectionPolicy",
"AnyPolicyList",
"AnyPolicyDefinitionInfo",
Expand Down
60 changes: 60 additions & 0 deletions catalystwan/models/policy/definition/aip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates

from typing import Literal, Optional

from pydantic import BaseModel, ConfigDict, Field, model_validator
from typing_extensions import Self

from catalystwan.models.policy.policy_definition import (
PolicyDefinitionBase,
PolicyDefinitionGetResponse,
PolicyDefinitionId,
Reference,
)

TlsDecryptionAction = Literal["decrypt", "neverDecrypt", "skipDecrypt"]


class AdvancedInspectionProfileDefinition(BaseModel):
model_config = ConfigDict(populate_by_name=True)

tls_decryption_action: TlsDecryptionAction = Field(
validation_alias="tlsDecryptionAction", serialization_alias="tlsDecryptionAction"
)

advanced_malware_protection: Optional[Reference] = Field(
default=None, validation_alias="advancedMalwareProtection", serialization_alias="advancedMalwareProtection"
)

intrusion_prevention: Optional[Reference] = Field(
default=None, validation_alias="intrusionPrevention", serialization_alias="intrusionPrevention"
)
url_filtering: Optional[Reference] = Field(
default=None, validation_alias="urlFiltering", serialization_alias="urlFiltering"
)

ssl_utd_decrypt_profile: Optional[Reference] = Field(
default=None, validation_alias="sslUtdDecryptProfile", serialization_alias="sslUtdDecryptProfile"
)

@model_validator(mode="after")
def check_at_least_one_optional_filled(self) -> Self:
if not any([self.advanced_malware_protection, self.intrusion_prevention, self.url_filtering]):
raise ValueError(
"At least one of Intrusion Prevention, URL Filtering, Advanced Malware Protection shall be filled."
)
return self


class AdvancedInspectionProfilePolicy(PolicyDefinitionBase):
type: Literal["advancedInspectionProfile"] = "advancedInspectionProfile"
mode: Literal["unified"] = "unified"
definition: AdvancedInspectionProfileDefinition


class AdvancedInspectionProfilePolicyEditPayload(AdvancedInspectionProfilePolicy, PolicyDefinitionId):
pass


class AdvancedInspectionProfilePolicyGetResponse(AdvancedInspectionProfilePolicy, PolicyDefinitionGetResponse):
pass

0 comments on commit 37b9888

Please sign in to comment.