Skip to content

Commit afca6b7

Browse files
feat: ability to patch existing IdP
Fixture updates as well as `oauthIssuerId` is no longer an attripute of IdP JIRA: TRIVIAL risk: low
1 parent 0052c9e commit afca6b7

File tree

8 files changed

+65
-33
lines changed

8 files changed

+65
-33
lines changed

gooddata-sdk/gooddata_sdk/catalog/organization/entity_model/identity_provider.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from gooddata_api_client.model.json_api_identity_provider_in import JsonApiIdentityProviderIn
88
from gooddata_api_client.model.json_api_identity_provider_in_attributes import JsonApiIdentityProviderInAttributes
99
from gooddata_api_client.model.json_api_identity_provider_in_document import JsonApiIdentityProviderInDocument
10+
from gooddata_api_client.model.json_api_identity_provider_patch import JsonApiIdentityProviderPatch
11+
from gooddata_api_client.model.json_api_identity_provider_patch_attributes import JsonApiIdentityProviderPatchAttributes
12+
from gooddata_api_client.model.json_api_identity_provider_patch_document import JsonApiIdentityProviderPatchDocument
1013

1114
from gooddata_sdk.catalog.base import Base
1215
from gooddata_sdk.utils import safeget
@@ -72,6 +75,14 @@ def from_api(cls, entity: dict[str, Any]) -> CatalogIdentityProvider:
7275
attributes=attr,
7376
)
7477

78+
@classmethod
79+
def to_api_patch(cls, identity_provider_id: str, attributes: dict) -> JsonApiIdentityProviderPatchDocument:
80+
return JsonApiIdentityProviderPatchDocument(
81+
data=JsonApiIdentityProviderPatch(
82+
id=identity_provider_id, attributes=JsonApiIdentityProviderPatchAttributes(**attributes)
83+
)
84+
)
85+
7586

7687
@attr.s(auto_attribs=True, kw_only=True)
7788
class CatalogIdentityProviderAttributes(Base):

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,23 @@ def update_identity_provider(self, identity_provider: CatalogIdentityProvider) -
407407
f"Can not update {identity_provider.id} identity provider. This identity provider does not exist."
408408
)
409409

410+
def patch_identity_provider_attributes(self, identity_provider_id: str, attributes: dict) -> None:
411+
"""Applies changes to the specified identity provider.
412+
413+
Args:
414+
identity_provider_id (str):
415+
Identity Provider identification string. e.g. "auth0"
416+
attributes (dict):
417+
A dictionary containing attributes of the identity provider to be changed.
418+
419+
Returns:
420+
None
421+
"""
422+
423+
self._entities_api.patch_entity_identity_providers(
424+
identity_provider_id, CatalogIdentityProvider.to_api_patch(identity_provider_id, attributes)
425+
)
426+
410427
# Layout APIs
411428

412429
def get_declarative_notification_channels(self) -> list[CatalogDeclarativeNotificationChannel]:

gooddata-sdk/tests/catalog/fixtures/organization/create_identity_provider.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interactions:
1515
- goodtesting.com
1616
oauthClientId: test_client_id
1717
oauthClientSecret: test_client_secret
18-
oauthIssuerId: test_issuer_id
1918
oauthIssuerLocation: https://issuer.goodtesting.com
2019
headers:
2120
Accept:
@@ -97,7 +96,6 @@ interactions:
9796
email: email
9897
oauthClientId: test_client_id
9998
oauthIssuerLocation: https://issuer.goodtesting.com
100-
oauthIssuerId: test_issuer_id
10199
links:
102100
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider
103101
- request:
@@ -181,7 +179,6 @@ interactions:
181179
email: email
182180
oauthClientId: test_client_id
183181
oauthIssuerLocation: https://issuer.goodtesting.com
184-
oauthIssuerId: test_issuer_id
185182
links:
186183
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider
187184
- request:

gooddata-sdk/tests/catalog/fixtures/organization/delete_identity_provider.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interactions:
1515
- goodtesting.com
1616
oauthClientId: test_client_id
1717
oauthClientSecret: test_client_secret
18-
oauthIssuerId: test_issuer_id
1918
oauthIssuerLocation: https://issuer.goodtesting.com
2019
headers:
2120
Accept:
@@ -97,7 +96,6 @@ interactions:
9796
email: email
9897
oauthClientId: test_client_id
9998
oauthIssuerLocation: https://issuer.goodtesting.com
100-
oauthIssuerId: test_issuer_id
10199
links:
102100
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider
103101
- request:

gooddata-sdk/tests/catalog/fixtures/organization/layout_identity_providers.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ interactions:
8484
- goodtesting.com
8585
oauthClientId: test_client_id
8686
oauthClientSecret: test_client_secret
87-
oauthIssuerId: test_issuer_id
8887
oauthIssuerLocation: https://issuer.goodtesting.com
8988
headers:
9089
Accept-Encoding:
@@ -228,7 +227,6 @@ interactions:
228227
identifiers:
229228
- goodtesting.com
230229
oauthClientId: test_client_id
231-
oauthIssuerId: test_issuer_id
232230
oauthIssuerLocation: https://issuer.goodtesting.com
233231
- request:
234232
method: PUT

gooddata-sdk/tests/catalog/fixtures/organization/list_identity_providers.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interactions:
1515
- goodtesting.com
1616
oauthClientId: test_client_id_1
1717
oauthClientSecret: test_client_secret_1
18-
oauthIssuerId: test_issuer_id_1
1918
oauthIssuerLocation: https://issuer.goodtesting.com
2019
headers:
2120
Accept:
@@ -97,7 +96,6 @@ interactions:
9796
email: email
9897
oauthClientId: test_client_id_1
9998
oauthIssuerLocation: https://issuer.goodtesting.com
100-
oauthIssuerId: test_issuer_id_1
10199
links:
102100
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider_1
103101
- request:
@@ -114,7 +112,6 @@ interactions:
114112
- goodtesting.com
115113
oauthClientId: test_client_id_2
116114
oauthClientSecret: test_client_secret_2
117-
oauthIssuerId: test_issuer_id_2
118115
oauthIssuerLocation: https://issuer.goodtesting.com
119116
headers:
120117
Accept:
@@ -195,7 +192,6 @@ interactions:
195192
email: email
196193
oauthClientId: test_client_id_2
197194
oauthIssuerLocation: https://issuer.goodtesting.com
198-
oauthIssuerId: test_issuer_id_2
199195
links:
200196
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider_2
201197
- request:
@@ -279,7 +275,6 @@ interactions:
279275
email: email
280276
oauthClientId: test_client_id_1
281277
oauthIssuerLocation: https://issuer.goodtesting.com
282-
oauthIssuerId: test_issuer_id_1
283278
links:
284279
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider_1
285280
- id: test_identity_provider_2
@@ -291,7 +286,6 @@ interactions:
291286
email: email
292287
oauthClientId: test_client_id_2
293288
oauthIssuerLocation: https://issuer.goodtesting.com
294-
oauthIssuerId: test_issuer_id_2
295289
links:
296290
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider_2
297291
links:

gooddata-sdk/tests/catalog/fixtures/organization/update_identity_provider.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interactions:
1515
- goodtesting.com
1616
oauthClientId: test_client_id
1717
oauthClientSecret: test_client_secret
18-
oauthIssuerId: test_issuer_id
1918
oauthIssuerLocation: https://issuer.goodtesting.com
2019
headers:
2120
Accept:
@@ -97,7 +96,6 @@ interactions:
9796
email: email
9897
oauthClientId: test_client_id
9998
oauthIssuerLocation: https://issuer.goodtesting.com
100-
oauthIssuerId: test_issuer_id
10199
links:
102100
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider
103101
- request:
@@ -115,7 +113,6 @@ interactions:
115113
- anotheridentifier.com
116114
oauthClientId: test_client_id
117115
oauthClientSecret: test_client_secret
118-
oauthIssuerId: test_issuer_id
119116
oauthIssuerLocation: https://issuer.goodtesting.com
120117
headers:
121118
Accept:
@@ -197,7 +194,6 @@ interactions:
197194
email: email
198195
oauthClientId: test_client_id
199196
oauthIssuerLocation: https://issuer.goodtesting.com
200-
oauthIssuerId: test_issuer_id
201197
links:
202198
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider
203199
- request:
@@ -282,7 +278,6 @@ interactions:
282278
email: email
283279
oauthClientId: test_client_id
284280
oauthIssuerLocation: https://issuer.goodtesting.com
285-
oauthIssuerId: test_issuer_id
286281
links:
287282
self: http://localhost:3000/api/v1/entities/identityProviders/test_identity_provider
288283
- request:

gooddata-sdk/tests/catalog/test_catalog_organization.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ def test_create_identity_provider(test_config):
387387
identifiers = ["goodtesting.com"]
388388
oauth_client_id = "test_client_id"
389389
oauth_client_secret = "test_client_secret"
390-
oauth_issuer_id = "test_issuer_id"
391390
oauth_issuer_location = "https://issuer.goodtesting.com"
392391

393392
new_identity_provider = CatalogIdentityProvider.init(
@@ -396,7 +395,6 @@ def test_create_identity_provider(test_config):
396395
identifiers=identifiers,
397396
oauth_client_id=oauth_client_id,
398397
oauth_client_secret=oauth_client_secret,
399-
oauth_issuer_id=oauth_issuer_id,
400398
oauth_issuer_location=oauth_issuer_location,
401399
)
402400

@@ -408,7 +406,6 @@ def test_create_identity_provider(test_config):
408406
assert identity_provider.attributes.identifiers == identifiers
409407
assert identity_provider.attributes.oauth_client_id == oauth_client_id
410408
assert identity_provider.attributes.oauth_client_secret is None # oauth_client_secret is not returned
411-
assert identity_provider.attributes.oauth_issuer_id == oauth_issuer_id
412409
assert identity_provider.attributes.oauth_issuer_location == oauth_issuer_location
413410
finally:
414411
sdk.catalog_organization.delete_identity_provider(identity_provider_id)
@@ -424,7 +421,6 @@ def test_list_identity_providers(test_config):
424421
identifiers = ["goodtesting.com"]
425422
oauth_client_id = "test_client_id"
426423
oauth_client_secret = "test_client_secret"
427-
oauth_issuer_id = "test_issuer_id"
428424
oauth_issuer_location = "https://issuer.goodtesting.com"
429425

430426
new_identity_provider_1 = CatalogIdentityProvider.init(
@@ -433,7 +429,6 @@ def test_list_identity_providers(test_config):
433429
identifiers=identifiers,
434430
oauth_client_id=oauth_client_id + "_1",
435431
oauth_client_secret=oauth_client_secret + "_1",
436-
oauth_issuer_id=oauth_issuer_id + "_1",
437432
oauth_issuer_location=oauth_issuer_location,
438433
)
439434
new_identity_provider_2 = CatalogIdentityProvider.init(
@@ -442,7 +437,6 @@ def test_list_identity_providers(test_config):
442437
identifiers=identifiers,
443438
oauth_client_id=oauth_client_id + "_2",
444439
oauth_client_secret=oauth_client_secret + "_2",
445-
oauth_issuer_id=oauth_issuer_id + "_2",
446440
oauth_issuer_location=oauth_issuer_location,
447441
)
448442

@@ -471,7 +465,6 @@ def test_delete_identity_provider(test_config):
471465
identifiers = ["goodtesting.com"]
472466
oauth_client_id = "test_client_id"
473467
oauth_client_secret = "test_client_secret"
474-
oauth_issuer_id = "test_issuer_id"
475468
oauth_issuer_location = "https://issuer.goodtesting.com"
476469

477470
new_identity_provider = CatalogIdentityProvider.init(
@@ -480,7 +473,6 @@ def test_delete_identity_provider(test_config):
480473
identifiers=identifiers,
481474
oauth_client_id=oauth_client_id,
482475
oauth_client_secret=oauth_client_secret,
483-
oauth_issuer_id=oauth_issuer_id,
484476
oauth_issuer_location=oauth_issuer_location,
485477
)
486478

@@ -503,7 +495,6 @@ def test_update_identity_provider(test_config):
503495
identifiers = ["goodtesting.com"]
504496
oauth_client_id = "test_client_id"
505497
oauth_client_secret = "test_client_secret"
506-
oauth_issuer_id = "test_issuer_id"
507498
oauth_issuer_location = "https://issuer.goodtesting.com"
508499

509500
new_identity_provider = CatalogIdentityProvider.init(
@@ -512,7 +503,6 @@ def test_update_identity_provider(test_config):
512503
identifiers=identifiers,
513504
oauth_client_id=oauth_client_id,
514505
oauth_client_secret=oauth_client_secret,
515-
oauth_issuer_id=oauth_issuer_id,
516506
oauth_issuer_location=oauth_issuer_location,
517507
)
518508
update_identity_provider = CatalogIdentityProvider.init(
@@ -521,7 +511,6 @@ def test_update_identity_provider(test_config):
521511
identifiers=identifiers + ["anotheridentifier.com"],
522512
oauth_client_id=oauth_client_id,
523513
oauth_client_secret=oauth_client_secret,
524-
oauth_issuer_id=oauth_issuer_id,
525514
oauth_issuer_location=oauth_issuer_location,
526515
)
527516

@@ -534,13 +523,49 @@ def test_update_identity_provider(test_config):
534523
assert identity_provider.attributes.identifiers == identifiers + ["anotheridentifier.com"]
535524
assert identity_provider.attributes.oauth_client_id == oauth_client_id
536525
assert identity_provider.attributes.oauth_client_secret is None # oauth_client_secret is not returned
537-
assert identity_provider.attributes.oauth_issuer_id == oauth_issuer_id
538526
assert identity_provider.attributes.oauth_issuer_location == oauth_issuer_location
539527
finally:
540528
sdk.catalog_organization.delete_identity_provider(identity_provider_id)
541529
assert len(sdk.catalog_organization.list_identity_providers()) == 0
542530

543531

532+
@gd_vcr.use_cassette(str(_fixtures_dir / "patch_identity_provider.yaml"))
533+
def test_patch_identity_provider(test_config):
534+
sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"])
535+
536+
identity_provider_id = "test_identity_provider"
537+
custom_claim_mapping = {"email": "email"}
538+
identifiers = ["goodtesting.com"]
539+
oauth_client_id = "test_client_id"
540+
oauth_client_secret = "test_client_secret"
541+
oauth_issuer_location = "https://issuer.goodtesting.com"
542+
543+
new_identity_provider = CatalogIdentityProvider.init(
544+
identity_provider_id=identity_provider_id,
545+
custom_claim_mapping=custom_claim_mapping,
546+
identifiers=identifiers,
547+
oauth_client_id=oauth_client_id,
548+
oauth_client_secret=oauth_client_secret,
549+
oauth_issuer_location=oauth_issuer_location,
550+
)
551+
552+
try:
553+
sdk.catalog_organization.create_identity_provider(new_identity_provider)
554+
sdk.catalog_organization.patch_identity_provider_attributes(
555+
identity_provider_id, {"identifiers": identifiers + ["anotheridentifier.com"]}
556+
)
557+
patched_identity_provider = sdk.catalog_organization.get_identity_provider(identity_provider_id)
558+
assert patched_identity_provider.id == identity_provider_id
559+
assert patched_identity_provider.attributes.custom_claim_mapping == custom_claim_mapping
560+
assert patched_identity_provider.attributes.identifiers == identifiers + ["anotheridentifier.com"]
561+
assert patched_identity_provider.attributes.oauth_client_id == oauth_client_id
562+
assert patched_identity_provider.attributes.oauth_client_secret is None # oauth_client_secret is not returned
563+
assert patched_identity_provider.attributes.oauth_issuer_location == oauth_issuer_location
564+
finally:
565+
sdk.catalog_organization.delete_identity_provider(identity_provider_id)
566+
assert len(sdk.catalog_organization.list_identity_providers()) == 0
567+
568+
544569
@gd_vcr.use_cassette(str(_fixtures_dir / "layout_identity_providers.yaml"))
545570
def test_layout_identity_providers(test_config):
546571
sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"])
@@ -554,7 +579,6 @@ def test_layout_identity_providers(test_config):
554579
identifiers = ["goodtesting.com"]
555580
oauth_client_id = "test_client_id"
556581
oauth_client_secret = "test_client_secret"
557-
oauth_issuer_id = "test_issuer_id"
558582
oauth_issuer_location = "https://issuer.goodtesting.com"
559583

560584
identity_providers_e = [
@@ -564,7 +588,6 @@ def test_layout_identity_providers(test_config):
564588
identifiers=identifiers,
565589
oauth_client_id=oauth_client_id,
566590
oauth_client_secret=oauth_client_secret,
567-
oauth_issuer_id=oauth_issuer_id,
568591
oauth_issuer_location=oauth_issuer_location,
569592
),
570593
]
@@ -575,7 +598,6 @@ def test_layout_identity_providers(test_config):
575598
assert identity_providers_o[0].identifiers == identity_providers_e[0].identifiers
576599
assert identity_providers_o[0].oauth_client_id == identity_providers_e[0].oauth_client_id
577600
assert identity_providers_o[0].oauth_client_secret is None
578-
assert identity_providers_o[0].oauth_issuer_id == identity_providers_o[0].oauth_issuer_id
579601
assert identity_providers_o[0].oauth_issuer_location == identity_providers_e[0].oauth_issuer_location
580602
finally:
581603
sdk.catalog_organization.put_declarative_identity_providers([])

0 commit comments

Comments
 (0)