Skip to content

Commit 46663aa

Browse files
committed
feat(gooddata-sdk): [AUTO] Add organization dataCenter and region diagnostic deployment fields
1 parent 4cb8139 commit 46663aa

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def from_api(cls, entity: dict[str, Any]) -> CatalogOrganization:
5353
allowed_origins=safeget(ea, ["allowed_origins"]),
5454
oauth_issuer_location=safeget(ea, ["oauth_issuer_location"]),
5555
oauth_client_id=safeget(ea, ["oauth_client_id"]),
56+
data_center=safeget(ea, ["data_center"]),
57+
region=safeget(ea, ["region"]),
5658
)
5759

5860
identity_provider_id = safeget(er, ["identityProvider", "data", "id"])
@@ -87,7 +89,24 @@ class CatalogOrganizationAttributes(Base):
8789
allowed_origins: list[str] | None = None
8890
oauth_issuer_location: str | None = None
8991
oauth_client_id: str | None = None
92+
data_center: str | None = None
93+
region: str | None = None
9094

9195
@staticmethod
9296
def client_class() -> type[JsonApiOrganizationInAttributes]:
9397
return JsonApiOrganizationInAttributes
98+
99+
def to_api(self) -> JsonApiOrganizationInAttributes:
100+
# data_center and region are read-only diagnostic fields — exclude them from write requests
101+
kwargs: dict[str, Any] = {}
102+
if self.name is not None:
103+
kwargs["name"] = self.name
104+
if self.hostname is not None:
105+
kwargs["hostname"] = self.hostname
106+
if self.allowed_origins is not None:
107+
kwargs["allowed_origins"] = self.allowed_origins
108+
if self.oauth_issuer_location is not None:
109+
kwargs["oauth_issuer_location"] = self.oauth_issuer_location
110+
if self.oauth_client_id is not None:
111+
kwargs["oauth_client_id"] = self.oauth_client_id
112+
return JsonApiOrganizationInAttributes(_check_type=False, **kwargs)

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from pathlib import Path
55

6+
import pytest
67
from gooddata_api_client.exceptions import NotFoundException
78
from gooddata_sdk import (
89
CatalogCspDirective,
@@ -14,6 +15,7 @@
1415
CatalogWebhook,
1516
GoodDataSdk,
1617
)
18+
from gooddata_sdk.catalog.organization.entity_model.organization import CatalogOrganizationAttributes
1719
from tests_support.vcrpy_utils import get_vcr
1820

1921
from .conftest import safe_delete
@@ -563,3 +565,89 @@ 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+
# Unit tests for deployment diagnostic fields (no cassettes needed)
571+
572+
573+
@pytest.mark.parametrize(
574+
"scenario, data_center, region",
575+
[
576+
("both_set", "us-east-1", "prod-cluster"),
577+
("only_data_center", "eu-west-1", None),
578+
("only_region", None, "staging"),
579+
("both_none", None, None),
580+
],
581+
)
582+
def test_organization_attributes_diagnostic_fields(scenario, data_center, region):
583+
"""data_center and region are stored on CatalogOrganizationAttributes."""
584+
attrs = CatalogOrganizationAttributes(
585+
name="TestOrg",
586+
hostname="test.gooddata.com",
587+
data_center=data_center,
588+
region=region,
589+
)
590+
assert attrs.data_center == data_center
591+
assert attrs.region == region
592+
593+
594+
@pytest.mark.parametrize(
595+
"scenario, data_center, region",
596+
[
597+
("both_set", "us-east-1", "prod-cluster"),
598+
("only_data_center", "eu-west-1", None),
599+
("only_region", None, "staging"),
600+
("both_none", None, None),
601+
],
602+
)
603+
def test_organization_attributes_to_api_excludes_diagnostic_fields(scenario, data_center, region):
604+
"""to_api() must not forward read-only diagnostic fields to the write model."""
605+
attrs = CatalogOrganizationAttributes(
606+
name="TestOrg",
607+
hostname="test.gooddata.com",
608+
data_center=data_center,
609+
region=region,
610+
)
611+
api_model = attrs.to_api()
612+
api_dict = api_model.to_dict()
613+
assert "dataCenter" not in api_dict
614+
assert "data_center" not in api_dict
615+
assert "region" not in api_dict
616+
617+
618+
def test_catalog_organization_from_api_reads_diagnostic_fields():
619+
"""CatalogOrganization.from_api() populates data_center and region from the response.
620+
621+
The keys use snake_case as exposed by the OpenApiModel __getitem__ accessor
622+
(camelCase keys are normalised to snake_case by the generated client).
623+
"""
624+
entity = {
625+
"id": "default",
626+
"type": "organization",
627+
"attributes": {
628+
"name": "TestOrg",
629+
"hostname": "test.gooddata.com",
630+
"data_center": "us-east-1",
631+
"region": "prod-cluster",
632+
},
633+
"relationships": {},
634+
}
635+
org = CatalogOrganization.from_api(entity)
636+
assert org.attributes.data_center == "us-east-1"
637+
assert org.attributes.region == "prod-cluster"
638+
639+
640+
def test_catalog_organization_from_api_handles_missing_diagnostic_fields():
641+
"""from_api() gracefully handles responses that lack data_center/region."""
642+
entity = {
643+
"id": "default",
644+
"type": "organization",
645+
"attributes": {
646+
"name": "TestOrg",
647+
"hostname": "test.gooddata.com",
648+
},
649+
"relationships": {},
650+
}
651+
org = CatalogOrganization.from_api(entity)
652+
assert org.attributes.data_center is None
653+
assert org.attributes.region is None

0 commit comments

Comments
 (0)