Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ concurrency:

env:
PIP_AUDIT_VERSION: "2.10.1"
# The pinned SCCFM SDK requires urllib3<2.1; keep these explicit until the SDK
# permits a patched urllib3 release.
DEP002_PIP_AUDIT_EXCEPTIONS: >-
--ignore-vuln PYSEC-2026-141
--ignore-vuln PYSEC-2026-1994
--ignore-vuln PYSEC-2026-1995
--ignore-vuln PYSEC-2026-1996
--ignore-vuln PYSEC-2026-1998
--ignore-vuln PYSEC-2026-1999
--ignore-vuln PYSEC-2026-4175
--ignore-vuln PYSEC-2026-4177

jobs:
lint-and-test:
Expand Down Expand Up @@ -74,7 +63,6 @@ jobs:
| awk 'NF >= 2 {print $1 "==" $2}' \
> "${RUNTIME_REQUIREMENTS}"
test -s "${RUNTIME_REQUIREMENTS}"
read -r -a AUDIT_EXCEPTION_ARGS <<< "${DEP002_PIP_AUDIT_EXCEPTIONS}"
pipx run --spec "pip-audit==${PIP_AUDIT_VERSION}" pip-audit \
--strict \
--no-deps \
Expand All @@ -83,7 +71,6 @@ jobs:
--progress-spinner off \
--aliases on \
--desc off \
"${AUDIT_EXCEPTION_ARGS[@]}" \
--requirement "${RUNTIME_REQUIREMENTS}"

- name: License headers
Expand Down Expand Up @@ -422,7 +409,6 @@ jobs:
RELEASE_VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
read -r -a AUDIT_EXCEPTION_ARGS <<< "${DEP002_PIP_AUDIT_EXCEPTIONS}"

verify_python_distribution() {
local artifact_path="$1"
Expand Down Expand Up @@ -450,7 +436,6 @@ jobs:
--progress-spinner off \
--aliases on \
--desc off \
"${AUDIT_EXCEPTION_ARGS[@]}" \
--requirement "${requirements}"
"${smoke_python}" -I - "${artifact_kind}" <<'PY'
import importlib
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ def test_should_promote_override_to_default_and_remove_it(
"update_request"
]
# New default should be the promoted override value
assert update_request.value.default_content.actual_instance.literal == "11.14.11.14"
assert update_request.value.default_content.literal == "11.14.11.14"
# Promoted target's override should be removed
assert len(update_request.value.overrides) == 1
remaining = update_request.value.overrides[0]
assert remaining.target_id == "0b2f5a0d-6ccb-45e6-a65c-7d9dd48d7b55"
assert remaining.content.actual_instance.literal == "11.10.11.122"
assert remaining.content.literal == "11.10.11.122"

def test_should_send_null_overrides_when_only_override_promoted(
self, monkeypatch: MonkeyPatch
Expand Down Expand Up @@ -351,7 +351,7 @@ def test_should_send_null_overrides_when_only_override_promoted(
update_request = mock_api.modify_object_without_preload_content.call_args.kwargs[
"update_request"
]
assert update_request.value.default_content.actual_instance.literal == "5.5.5.5"
assert update_request.value.default_content.literal == "5.5.5.5"
assert update_request.value.overrides is None

def test_should_raise_when_override_not_found(self, monkeypatch: MonkeyPatch) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_should_delete_matching_override_and_preserve_others(
assert len(update_request.value.overrides) == 1
remaining = update_request.value.overrides[0]
assert remaining.target_id == "device-789"
assert remaining.content.actual_instance.literal == "6.6.6.6"
assert remaining.content.literal == "6.6.6.6"

def test_should_send_null_overrides_when_last_override_deleted(
self, monkeypatch: MonkeyPatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ def test_should_edit_matching_override_and_preserve_others(
]
assert len(update_request.value.overrides) == 2
edited = next(o for o in update_request.value.overrides if o.target_id == "device-456")
assert edited.content.actual_instance.literal == "10.10.10.10"
assert edited.content.literal == "10.10.10.10"
untouched = next(o for o in update_request.value.overrides if o.target_id == "device-789")
assert untouched.content.actual_instance.literal == "6.6.6.6"
assert untouched.content.literal == "6.6.6.6"

def test_should_raise_when_override_not_found(self, monkeypatch: MonkeyPatch) -> None:
mock_api = Mock()
Expand Down Expand Up @@ -402,7 +402,7 @@ def test_should_edit_url_object_override(self, monkeypatch: MonkeyPatch) -> None
"update_request"
]
edited = update_request.value.overrides[0]
assert edited.content.actual_instance.url == "new.example.com"
assert edited.content.url == "new.example.com"

def test_should_raise_for_unsupported_object_type(self, monkeypatch: MonkeyPatch) -> None:
mock_api = Mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
from typing import Any, Literal

from scc_firewall_manager_sdk.models.create_request import CreateRequest
from scc_firewall_manager_sdk.models.group_content import GroupContent
from scc_firewall_manager_sdk.models.network_object_content import NetworkObjectContent
from scc_firewall_manager_sdk.models.object_content import ObjectContent
from scc_firewall_manager_sdk.models.shared_object_value import SharedObjectValue
from scc_firewall_manager_sdk.models.single_content import SingleContent
from scc_firewall_manager_sdk.models.update_request import UpdateRequest
from scc_firewall_manager_sdk.models.url_object_content import UrlObjectContent

from cisco_sccfm_core.errors import NotFoundError
from cisco_sccfm_core.services.object_management.network_object_service import NetworkObjectService
Expand Down Expand Up @@ -509,13 +506,12 @@ def _build_shared_value(
referenced_object_uids: UIDs of existing objects to reference.

Returns:
A SharedObjectValue wrapping the GroupContent.
A SharedObjectValue wrapping the group content.
"""
group_content = GroupContent(
object_content = ObjectContent(
literals=single_contents if single_contents else None,
referenced_object_uids=referenced_object_uids if referenced_object_uids else None,
)
object_content = ObjectContent(actual_instance=group_content)
return SharedObjectValue(
defaultContent=object_content,
objectType=self.OBJECT_TYPE,
Expand All @@ -534,13 +530,13 @@ def _build_literal_contents(
url_literals: URL literal strings.

Returns:
A list of SingleContent wrapping the appropriate content type.
A list of SingleContent with the network or URL value set.
"""
contents: list[SingleContent] = []
for lit in network_literals:
contents.append(SingleContent(actual_instance=NetworkObjectContent(literal=lit)))
contents.append(SingleContent(literal=lit))
for url in url_literals:
contents.append(SingleContent(actual_instance=UrlObjectContent(url=url)))
contents.append(SingleContent(url=url))
return contents

@staticmethod
Expand All @@ -557,7 +553,7 @@ def _rebuild_literal_contents(

Inspects each literal dict to determine whether it is a network
literal (has ``literal`` key) or a URL literal (has ``url`` key)
and wraps it in the appropriate SDK model.
and sets the matching SDK model field.

Args:
raw_content: The raw ``defaultContent`` dict from the API.
Expand All @@ -569,15 +565,9 @@ def _rebuild_literal_contents(
contents: list[SingleContent] = []
for item in raw_literals:
if item.get("url"):
contents.append(
SingleContent(actual_instance=UrlObjectContent(url=item["url"])),
)
contents.append(SingleContent(url=item["url"]))
elif item.get("literal"):
contents.append(
SingleContent(
actual_instance=NetworkObjectContent(literal=item["literal"]),
),
)
contents.append(SingleContent(literal=item["literal"]))
return contents

def _resolve_referenced_object_uids(self, referenced_objects: list[str]) -> list[str]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Any

from scc_firewall_manager_sdk.models.create_request import CreateRequest
from scc_firewall_manager_sdk.models.network_object_content import NetworkObjectContent
from scc_firewall_manager_sdk.models.object_content import ObjectContent
from scc_firewall_manager_sdk.models.shared_object_value import SharedObjectValue
from scc_firewall_manager_sdk.models.update_request import UpdateRequest
Expand Down Expand Up @@ -308,9 +307,7 @@ def _build_shared_value(self, value: str) -> SharedObjectValue:
Returns:
A SharedObjectValue wrapping the network content.
"""
network_content = NetworkObjectContent(literal=value)
object_content = ObjectContent(actual_instance=network_content)
return SharedObjectValue(
defaultContent=object_content,
defaultContent=ObjectContent(literal=value),
objectType=self.OBJECT_TYPE,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
from dataclasses import dataclass
from typing import Any

from scc_firewall_manager_sdk.models.network_object_content import NetworkObjectContent
from scc_firewall_manager_sdk.models.object_content import ObjectContent
from scc_firewall_manager_sdk.models.override import Override
from scc_firewall_manager_sdk.models.shared_object_value import SharedObjectValue
from scc_firewall_manager_sdk.models.update_request import UpdateRequest
from scc_firewall_manager_sdk.models.url_object_content import UrlObjectContent

from cisco_sccfm_core.services.object_management.object_api_helper import ObjectApiHelper
from cisco_sccfm_core.types import ConfigLike


def _string_or_empty(value: Any) -> str:
"""Normalize missing API values to the response model's empty-string sentinel."""
return str(value or "")


_SUPPORTED_TYPES = {"NETWORK_OBJECT", "URL_OBJECT"}


Expand All @@ -34,9 +38,9 @@ class ObjectTargetItem:
@classmethod
def from_dict(cls, data: dict[str, Any]) -> "ObjectTargetItem":
return cls(
id=str(data.get("id") or ""),
display_name=str(data.get("displayName") or ""),
type=str(data.get("type") or ""),
id=_string_or_empty(data.get("id")),
display_name=_string_or_empty(data.get("displayName")),
type=_string_or_empty(data.get("type")),
)

def to_dict(self) -> dict[str, Any]:
Expand All @@ -55,8 +59,8 @@ class ObjectTargetsResponse:
def from_dict(cls, data: dict[str, Any]) -> "ObjectTargetsResponse":
raw_targets: list[dict[str, Any]] = data.get("targets") or []
return cls(
uid=str(data.get("uid") or ""),
name=str(data.get("name") or ""),
uid=_string_or_empty(data.get("uid")),
name=_string_or_empty(data.get("name")),
targets=[ObjectTargetItem.from_dict(t) for t in raw_targets],
)

Expand All @@ -83,9 +87,9 @@ def from_dict(cls, data: dict[str, Any]) -> "UpdateDefaultValueResponse":
default_content: dict[str, Any] = value.get("defaultContent") or {}
literal = default_content.get("literal") or default_content.get("url") or ""
return cls(
uid=str(data.get("uid") or ""),
name=str(data.get("name") or ""),
object_type=str(value.get("objectType") or ""),
uid=_string_or_empty(data.get("uid")),
name=_string_or_empty(data.get("name")),
object_type=_string_or_empty(value.get("objectType")),
default_value=str(literal),
)

Expand All @@ -112,9 +116,9 @@ def from_dict(cls, data: dict[str, Any]) -> "ObjectOverrideResponse":
value: dict[str, Any] = data.get("value") or {}
overrides: list[Any] = value.get("overrides") or []
return cls(
uid=str(data.get("uid") or ""),
name=str(data.get("name") or ""),
object_type=str(value.get("objectType") or ""),
uid=_string_or_empty(data.get("uid")),
name=_string_or_empty(data.get("name")),
object_type=_string_or_empty(value.get("objectType")),
overrides_count=len(overrides),
)

Expand All @@ -138,7 +142,7 @@ class ObjectOverrideItem:
def from_dict(cls, data: dict[str, Any]) -> "ObjectOverrideItem":
content: dict[str, Any] = data.get("content") or {}
value = str(content.get("literal") or content.get("url") or "")
return cls(target_id=str(data.get("targetId") or ""), value=value)
return cls(target_id=_string_or_empty(data.get("targetId")), value=value)

def to_dict(self) -> dict[str, Any]:
return {"target_id": self.target_id, "value": self.value}
Expand All @@ -164,10 +168,10 @@ def from_dict(cls, data: dict[str, Any]) -> "ObjectDetailsResponse":
raw_overrides: list[dict[str, Any]] = value.get("overrides") or []
raw_targets: list[dict[str, Any]] = data.get("targets") or []
return cls(
uid=str(data.get("uid") or ""),
name=str(data.get("name") or ""),
description=str(data.get("description") or ""),
object_type=str(value.get("objectType") or ""),
uid=_string_or_empty(data.get("uid")),
name=_string_or_empty(data.get("name")),
description=_string_or_empty(data.get("description")),
object_type=_string_or_empty(value.get("objectType")),
default_value=default_value,
overrides=[ObjectOverrideItem.from_dict(o) for o in raw_overrides],
targets=[ObjectTargetItem.from_dict(t) for t in raw_targets],
Expand Down Expand Up @@ -559,25 +563,23 @@ def update_default_value(
def _build_object_content(self, raw_content: dict[str, Any], object_type: str) -> ObjectContent:
"""Reconstruct an ObjectContent SDK model from a raw dict."""
if object_type == "NETWORK_OBJECT":
return ObjectContent(
actual_instance=NetworkObjectContent(literal=str(raw_content["literal"]))
)
return ObjectContent(literal=str(raw_content["literal"]))
if object_type == "URL_OBJECT":
return ObjectContent(actual_instance=UrlObjectContent(url=str(raw_content["url"])))
return ObjectContent(url=str(raw_content["url"]))
raise ValueError(f"Unsupported object type: {object_type}")

def _build_content_from_value(self, value: str, object_type: str) -> ObjectContent:
"""Build an ObjectContent from the CLI override value string."""
if object_type == "NETWORK_OBJECT":
return ObjectContent(actual_instance=NetworkObjectContent(literal=value))
return ObjectContent(literal=value)
if object_type == "URL_OBJECT":
return ObjectContent(actual_instance=UrlObjectContent(url=value))
return ObjectContent(url=value)
raise ValueError(f"Unsupported object type: {object_type}")

def _build_override_from_raw(self, raw_override: dict[str, Any], object_type: str) -> Override:
"""Reconstruct an Override SDK object from a raw dict."""
raw_content: dict[str, Any] = raw_override.get("content") or {}
return Override(
content=self._build_object_content(raw_content, object_type),
targetId=raw_override.get("targetId"),
target_id=raw_override.get("targetId"),
)
8 changes: 4 additions & 4 deletions cisco_sccfm_core/tests/test_network_group_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_update_preserves_existing_literals(self, monkeypatch: MonkeyPatch) -> N

call_kwargs = mock_api.modify_object_without_preload_content.call_args
update_req = call_kwargs.kwargs["update_request"]
content = update_req.value.default_content.actual_instance
content = update_req.value.default_content
assert content.referenced_object_uids == [new_ref]
assert len(content.literals) == 2

Expand Down Expand Up @@ -239,7 +239,7 @@ def test_update_preserves_existing_url_literals(self, monkeypatch: MonkeyPatch)

call_kwargs = mock_api.modify_object_without_preload_content.call_args
update_req = call_kwargs.kwargs["update_request"]
content = update_req.value.default_content.actual_instance
content = update_req.value.default_content
assert len(content.literals) == 1
assert content.referenced_object_uids == [new_ref]

Expand Down Expand Up @@ -313,7 +313,7 @@ def test_add_members_preserves_literals_and_appends_in_order(self) -> None:

call_kwargs = mock_api.modify_object_without_preload_content.call_args
update_req = call_kwargs.kwargs["update_request"]
content = update_req.value.default_content.actual_instance
content = update_req.value.default_content
assert content.referenced_object_uids == [old_ref, new_ref]
assert len(content.literals) == 1

Expand Down Expand Up @@ -386,7 +386,7 @@ def test_remove_members_by_name_preserves_url_literals(self) -> None:

call_kwargs = mock_api.modify_object_without_preload_content.call_args
update_req = call_kwargs.kwargs["update_request"]
content = update_req.value.default_content.actual_instance
content = update_req.value.default_content
assert content.referenced_object_uids == [keep_ref]
assert len(content.literals) == 1

Expand Down
Loading
Loading