fix issue where you couldn't update ports
Build and Push Container / build-and-push (push) Successful in 22s
Build and Push Container / build-and-push (push) Successful in 22s
This commit is contained in:
@@ -332,3 +332,87 @@ def get_source_ip_from_policy(policy: FirewallPolicy) -> str | None:
|
||||
|
||||
value: str | None = first_item.get("value") if isinstance(first_item.get("value"), str) else None
|
||||
return value
|
||||
|
||||
|
||||
def get_dest_ports_from_policy(policy: FirewallPolicy) -> tuple[list[int], list[dict[str, Any]]] | None:
|
||||
"""Extract destination port numbers and ranges from a firewall policy.
|
||||
|
||||
Returns (dest_ports_list, dest_port_ranges_list) or None if no port filter exists.
|
||||
"""
|
||||
destination = policy.get("destination")
|
||||
if not destination:
|
||||
return None
|
||||
|
||||
traffic_filter = destination.get("trafficFilter")
|
||||
if not traffic_filter:
|
||||
return None
|
||||
|
||||
port_filter: dict[str, Any] | None = traffic_filter.get("portFilter")
|
||||
if not port_filter:
|
||||
return None
|
||||
|
||||
items: list[Any] | None = port_filter.get("items")
|
||||
if not items:
|
||||
return None
|
||||
|
||||
dest_ports: list[int] = []
|
||||
dest_port_ranges: list[dict[str, Any]] = []
|
||||
|
||||
for item in items:
|
||||
item_dict = cast(dict[str, Any], item) if isinstance(item, dict) else None
|
||||
if not item_dict:
|
||||
continue
|
||||
|
||||
item_type = item_dict.get("type")
|
||||
if not isinstance(item_type, str):
|
||||
continue
|
||||
|
||||
if item_type == "PORT_NUMBER":
|
||||
value = item_dict.get("value")
|
||||
if isinstance(value, int):
|
||||
dest_ports.append(value)
|
||||
elif item_type == "PORT_NUMBER_RANGE":
|
||||
start = item_dict.get("start")
|
||||
stop = item_dict.get("stop")
|
||||
if isinstance(start, int) and isinstance(stop, int):
|
||||
dest_port_ranges.append({"start": start, "stop": stop})
|
||||
|
||||
return (dest_ports, dest_port_ranges)
|
||||
|
||||
|
||||
def get_protocol_from_policy(policy: FirewallPolicy) -> str | None:
|
||||
"""Extract protocol name from a firewall policy."""
|
||||
ip_protocol_scope = policy.get("ipProtocolScope")
|
||||
if not ip_protocol_scope:
|
||||
return None
|
||||
|
||||
protocol_filter: dict[str, Any] | None = ip_protocol_scope.get("protocolFilter")
|
||||
if not protocol_filter:
|
||||
return None
|
||||
|
||||
protocol: dict[str, Any] | None = protocol_filter.get("protocol")
|
||||
if not protocol:
|
||||
return None
|
||||
|
||||
name: str | None = protocol.get("name") if isinstance(protocol.get("name"), str) else None
|
||||
return name
|
||||
|
||||
|
||||
def get_action_from_policy(policy: FirewallPolicy) -> tuple[str, bool] | None:
|
||||
"""Extract action type and allowReturnTraffic from a firewall policy.
|
||||
|
||||
Returns (action_type, allow_return_traffic) or None if action is missing.
|
||||
"""
|
||||
action = policy.get("action")
|
||||
if not action:
|
||||
return None
|
||||
|
||||
action_type = action.get("type")
|
||||
if not action_type:
|
||||
return None
|
||||
|
||||
allow_return_traffic: bool = False
|
||||
if action_type == "ALLOW":
|
||||
allow_return_traffic = bool(action.get("allowReturnTraffic", False))
|
||||
|
||||
return (action_type, allow_return_traffic)
|
||||
|
||||
Reference in New Issue
Block a user