Skip to content

Commit 89b9ce8

Browse files
committed
feat(gooddata-sdk): [AUTO] Add DeclarativeIpAllowlistPolicy schema to declarative org config
1 parent 1c4dfe4 commit 89b9ce8

4 files changed

Lines changed: 93 additions & 0 deletions

File tree

packages/gooddata-sdk/src/gooddata_sdk/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@
133133
from gooddata_sdk.catalog.organization.layout.export_template import (
134134
CatalogDeclarativeExportTemplate,
135135
)
136+
from gooddata_sdk.catalog.organization.layout.ip_allowlist_policy import (
137+
CatalogDeclarativeIpAllowlistPolicy,
138+
)
136139
from gooddata_sdk.catalog.organization.layout.notification_channel import (
137140
CatalogDeclarativeNotificationChannel,
138141
CatalogWebhook,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# (C) 2025 GoodData Corporation
2+
from __future__ import annotations
3+
4+
import builtins
5+
6+
from attrs import define, field
7+
from gooddata_api_client.model.declarative_ip_allowlist_policy import DeclarativeIpAllowlistPolicy
8+
9+
from gooddata_sdk.catalog.base import Base
10+
from gooddata_sdk.catalog.identifier import CatalogDeclarativeUserGroupIdentifier, CatalogUserIdentifier
11+
12+
13+
@define(kw_only=True)
14+
class CatalogDeclarativeIpAllowlistPolicy(Base):
15+
id: str
16+
allowed_sources: list[str] = field(factory=list)
17+
user_groups: list[CatalogDeclarativeUserGroupIdentifier] = field(factory=list)
18+
users: list[CatalogUserIdentifier] = field(factory=list)
19+
20+
@staticmethod
21+
def client_class() -> builtins.type[DeclarativeIpAllowlistPolicy]:
22+
return DeclarativeIpAllowlistPolicy

packages/gooddata-sdk/src/gooddata_sdk/catalog/organization/service.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
)
3232
from gooddata_sdk.catalog.organization.entity_model.setting import CatalogOrganizationSetting
3333
from gooddata_sdk.catalog.organization.layout.identity_provider import CatalogDeclarativeIdentityProvider
34+
from gooddata_sdk.catalog.organization.layout.ip_allowlist_policy import CatalogDeclarativeIpAllowlistPolicy
3435
from gooddata_sdk.catalog.organization.layout.notification_channel import CatalogDeclarativeNotificationChannel
3536
from gooddata_sdk.client import GoodDataApiClient
3637
from gooddata_sdk.utils import load_all_entities, load_all_entities_dict
@@ -742,3 +743,35 @@ def switch_active_identity_provider(self, identity_provider_id: str) -> None:
742743
)
743744
except Exception as e:
744745
raise ValueError(f"Error switching active identity provider: {str(e)}")
746+
747+
def get_declarative_ip_allowlist_policies(self) -> list[CatalogDeclarativeIpAllowlistPolicy]:
748+
"""Get all declarative IP allowlist policies for the current organization.
749+
750+
IP allowlist policies are returned as part of the full organization layout.
751+
752+
Returns:
753+
list[CatalogDeclarativeIpAllowlistPolicy]:
754+
List of declarative IP allowlist policies.
755+
"""
756+
org_layout = self._layout_api.get_organization_layout(_check_return_type=False)
757+
policies = getattr(org_layout, "ip_allowlist_policies", None) or []
758+
return [CatalogDeclarativeIpAllowlistPolicy.from_api(policy) for policy in policies]
759+
760+
def put_declarative_ip_allowlist_policies(
761+
self, ip_allowlist_policies: list[CatalogDeclarativeIpAllowlistPolicy]
762+
) -> None:
763+
"""Put declarative IP allowlist policies for the current organization.
764+
765+
Reads the full organization layout, replaces the ip_allowlist_policies field,
766+
and writes the full layout back. All other organization settings are preserved.
767+
768+
Args:
769+
ip_allowlist_policies (list[CatalogDeclarativeIpAllowlistPolicy]):
770+
List of declarative IP allowlist policies to set.
771+
772+
Returns:
773+
None
774+
"""
775+
org_layout = self._layout_api.get_organization_layout(_check_return_type=False)
776+
org_layout.ip_allowlist_policies = [policy.to_api() for policy in ip_allowlist_policies]
777+
self._layout_api.set_organization_layout(org_layout, _check_return_type=False)

packages/gooddata-sdk/tests/catalog/test_catalog_organization.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from gooddata_api_client.exceptions import NotFoundException
77
from gooddata_sdk import (
88
CatalogCspDirective,
9+
CatalogDeclarativeIpAllowlistPolicy,
910
CatalogDeclarativeNotificationChannel,
1011
CatalogJwk,
1112
CatalogOrganization,
@@ -14,6 +15,7 @@
1415
CatalogWebhook,
1516
GoodDataSdk,
1617
)
18+
from gooddata_sdk.catalog.identifier import CatalogDeclarativeUserGroupIdentifier, CatalogUserIdentifier
1719
from tests_support.vcrpy_utils import get_vcr
1820

1921
from .conftest import safe_delete
@@ -563,3 +565,36 @@ def test_layout_notification_channels(test_config, snapshot_notification_channel
563565
# sdk.catalog_organization.put_declarative_identity_providers([])
564566
# idps = sdk.catalog_organization.get_declarative_identity_providers()
565567
# assert len(idps) == 0
568+
569+
570+
@gd_vcr.use_cassette(str(_fixtures_dir / "layout_ip_allowlist_policies.yaml"))
571+
def test_layout_ip_allowlist_policies(test_config):
572+
sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"])
573+
574+
original_policies = sdk.catalog_organization.get_declarative_ip_allowlist_policies()
575+
576+
new_policies = [
577+
CatalogDeclarativeIpAllowlistPolicy(
578+
id="admin-vpn-only",
579+
allowed_sources=["203.0.113.10/32", "198.51.100.0/24"],
580+
user_groups=[
581+
CatalogDeclarativeUserGroupIdentifier(id="group.admins", type="userGroup"),
582+
],
583+
users=[
584+
CatalogUserIdentifier(id="employee123", type="user"),
585+
],
586+
),
587+
]
588+
589+
try:
590+
sdk.catalog_organization.put_declarative_ip_allowlist_policies(new_policies)
591+
result = sdk.catalog_organization.get_declarative_ip_allowlist_policies()
592+
assert len(result) == 1
593+
assert result[0].id == "admin-vpn-only"
594+
assert result[0].allowed_sources == ["203.0.113.10/32", "198.51.100.0/24"]
595+
assert len(result[0].user_groups) == 1
596+
assert result[0].user_groups[0].id == "group.admins"
597+
assert len(result[0].users) == 1
598+
assert result[0].users[0].id == "employee123"
599+
finally:
600+
sdk.catalog_organization.put_declarative_ip_allowlist_policies(original_policies)

0 commit comments

Comments
 (0)