From bcdf1b825bd1c7e9c0c0cdf91bcb957ac538cf4a Mon Sep 17 00:00:00 2001 From: Bruno Bonfils Date: Fri, 3 Jun 2022 14:28:08 +0200 Subject: [PATCH] feat: Add update_idp --- src/keycloak/keycloak_admin.py | 16 ++++++++++++++++ tests/test_keycloak_admin.py | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/src/keycloak/keycloak_admin.py b/src/keycloak/keycloak_admin.py index 57dfb47..7f82679 100644 --- a/src/keycloak/keycloak_admin.py +++ b/src/keycloak/keycloak_admin.py @@ -397,6 +397,22 @@ class KeycloakAdmin: ) return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201]) + def update_idp(self, idp_alias, payload): + """ + Update an ID Provider + + IdentityProviderRepresentation + https://www.keycloak.org/docs-api/15.0/rest-api/index.html#_identity_providers_resource + + :param: alias: alias for IdP to update + :param: payload: The IdentityProviderRepresentation + """ + params_path = {"realm-name": self.realm_name, "alias": idp_alias} + data_raw = self.raw_put( + urls_patterns.URL_ADMIN_IDP.format(**params_path), data=json.dumps(payload) + ) + return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204]) + def add_mapper_to_idp(self, idp_alias, payload): """ Create an ID Provider, diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index a2cd5d7..ad4e2ce 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -320,6 +320,11 @@ def test_idps(admin: KeycloakAdmin, realm: str): assert len(idps) == 1 assert "github" == idps[0]["alias"] + # Test IdP update + res = admin.update_idp(idp_alias="github", payload=idps[0]) + + assert res == {}, res + # Test adding a mapper res = admin.add_mapper_to_idp( idp_alias="github",