Skip to content

Commit

Permalink
fix: policy mode default to security
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan committed Nov 21, 2024
1 parent 0beb2c8 commit b174f42
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
13 changes: 12 additions & 1 deletion catalystwan/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,18 @@ def str_as_interface_list(val: Union[str, Sequence[InterfaceStr]]) -> Sequence[I
"umbrella",
]

PolicyModeType = Literal["security", "unified"]
_PolicyModeType = Literal["security", "unified"]

def parse_policy_mode(val: Optional[str]) -> _PolicyModeType:
if isinstance(val, str) and val == "unified":
return "unified"
return "security"

PolicyModeType = Annotated[
_PolicyModeType,
BeforeValidator(parse_policy_mode)
]


CoreRegion = Literal[
"core",
Expand Down
12 changes: 4 additions & 8 deletions catalystwan/models/policy/definition/zone_based_firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pydantic import BaseModel, ConfigDict, Field
from typing_extensions import Annotated

from catalystwan.models.common import PolicyModeType
from catalystwan.models.misc.application_protocols import ApplicationProtocol
from catalystwan.models.policy.policy_definition import (
AdvancedInspectionProfileAction,
Expand Down Expand Up @@ -220,12 +221,6 @@ class ZoneBasedFWPolicyEntry(BaseModel):
model_config = ConfigDict(populate_by_name=True)


class ZoneBasedFWPolicyHeader(PolicyDefinitionBase):
type: Literal["zoneBasedFW"] = "zoneBasedFW"
mode: str = Field(default="security")
model_config = ConfigDict(populate_by_name=True)


class ZoneBasedFWPolicyDefinition(DefinitionWithSequencesCommonBase):
default_action: ZoneBasedFirewallDefaultAction = Field(
default=ZoneBasedFirewallDefaultAction(type="drop"),
Expand All @@ -236,9 +231,10 @@ class ZoneBasedFWPolicyDefinition(DefinitionWithSequencesCommonBase):
entries: List[ZoneBasedFWPolicyEntry] = []


class ZoneBasedFWPolicy(ZoneBasedFWPolicyHeader):
class ZoneBasedFWPolicy(PolicyDefinitionBase):
model_config = ConfigDict(populate_by_name=True)
type: Literal["zoneBasedFW"] = "zoneBasedFW"
mode: Literal["security", "unified"] = "security"
mode: PolicyModeType = "security"
definition: ZoneBasedFWPolicyDefinition = ZoneBasedFWPolicyDefinition()

def add_ipv4_rule(
Expand Down

0 comments on commit b174f42

Please sign in to comment.