Browse Source

fix: raise correct errors

pull/309/head
Richard Nemeth 3 years ago
parent
commit
8d19ea8180
No known key found for this signature in database GPG Key ID: 21C39470DF3DEC39
  1. 7
      keycloak/__init__.py
  2. 164
      keycloak/keycloak_admin.py

7
keycloak/__init__.py

@ -21,5 +21,8 @@
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from .keycloak_admin import *
from .keycloak_openid import *
from ._version import __version__
from .keycloak_admin import KeycloakAdmin
from .keycloak_openid import KeycloakOpenID
__all__ = ["KeycloakAdmin", "KeycloakOpenID", "__version__"]

164
keycloak/keycloak_admin.py

@ -29,7 +29,13 @@ from builtins import isinstance
from typing import Iterable
from .connection import ConnectionManager
from .exceptions import KeycloakGetError, raise_error_from_response
from .exceptions import (
KeycloakDeleteError,
KeycloakGetError,
KeycloakPostError,
KeycloakPutError,
raise_error_from_response,
)
from .keycloak_openid import KeycloakOpenID
from .urls_patterns import (
URL_ADMIN_AUTHENTICATOR_CONFIG,
@ -341,7 +347,7 @@ class KeycloakAdmin:
"""
data_raw = self.raw_post(URL_ADMIN_REALMS, data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
def export_realm(self, export_clients=False, export_groups_and_role=False):
"""
@ -361,7 +367,7 @@ class KeycloakAdmin:
"export-groups-and-roles": export_groups_and_role,
}
data_raw = self.raw_post(URL_ADMIN_REALM_EXPORT.format(**params_path), data="")
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakPostError)
def get_realms(self):
"""
@ -386,7 +392,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(URL_ADMIN_REALMS, data=json.dumps(payload))
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def update_realm(self, realm_name, payload):
@ -404,7 +410,7 @@ class KeycloakAdmin:
params_path = {"realm-name": realm_name}
data_raw = self.raw_put(URL_ADMIN_REALM.format(**params_path), data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def delete_realm(self, realm_name):
"""
@ -416,7 +422,7 @@ class KeycloakAdmin:
params_path = {"realm-name": realm_name}
data_raw = self.raw_delete(URL_ADMIN_REALM.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_users(self, query=None):
"""
@ -448,7 +454,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name}
data_raw = self.raw_post(URL_ADMIN_IDPS.format(**params_path), data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
def add_mapper_to_idp(self, idp_alias, payload):
"""
@ -464,7 +470,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_IDP_MAPPERS.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
def get_idps(self):
"""
@ -487,7 +493,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "alias": idp_alias}
data_raw = self.raw_delete(URL_ADMIN_IDP.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def create_user(self, payload, exist_ok=True):
"""
@ -510,7 +516,7 @@ class KeycloakAdmin:
return str(exists)
data_raw = self.raw_post(URL_ADMIN_USERS.format(**params_path), data=json.dumps(payload))
raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201])
raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
_last_slash_idx = data_raw.headers["Location"].rindex("/")
return data_raw.headers["Location"][_last_slash_idx + 1 :]
@ -578,7 +584,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": user_id}
data_raw = self.raw_put(URL_ADMIN_USER.format(**params_path), data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def delete_user(self, user_id):
"""
@ -590,7 +596,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": user_id}
data_raw = self.raw_delete(URL_ADMIN_USER.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def set_user_password(self, user_id, password, temporary=True):
"""
@ -611,7 +617,7 @@ class KeycloakAdmin:
data_raw = self.raw_put(
URL_ADMIN_RESET_PASSWORD.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def get_credentials(self, user_id):
"""
@ -663,7 +669,7 @@ class KeycloakAdmin:
"credential_id": credential_id,
}
data_raw = self.raw_delete(URL_ADMIN_USER_CREDENTIAL.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakDeleteError)
def logout(self, user_id):
"""
@ -676,7 +682,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": user_id}
data_raw = self.raw_post(URL_ADMIN_USER_LOGOUT.format(**params_path), data="")
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[204])
def consents_user(self, user_id):
"""
@ -719,6 +725,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_USER_FEDERATED_IDENTITY.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakPostError)
def delete_user_social_login(self, user_id, provider_id):
@ -730,7 +737,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": user_id, "provider": provider_id}
data_raw = self.raw_delete(URL_ADMIN_USER_FEDERATED_IDENTITY.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def send_update_account(
self, user_id, payload, client_id=None, lifespan=None, redirect_uri=None
@ -754,7 +761,7 @@ class KeycloakAdmin:
data=json.dumps(payload),
**params_query
)
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakPutError)
def send_verify_email(self, user_id, client_id=None, redirect_uri=None):
"""
@ -772,7 +779,7 @@ class KeycloakAdmin:
data_raw = self.raw_put(
URL_ADMIN_SEND_VERIFY_EMAIL.format(**params_path), data={}, **params_query
)
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakPutError)
def get_sessions(self, user_id):
"""
@ -931,7 +938,7 @@ class KeycloakAdmin:
)
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def update_group(self, group_id, payload):
@ -949,7 +956,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": group_id}
data_raw = self.raw_put(URL_ADMIN_GROUP.format(**params_path), data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def group_set_permissions(self, group_id, enabled=True):
"""
@ -965,7 +972,7 @@ class KeycloakAdmin:
URL_ADMIN_GROUP_PERMISSIONS.format(**params_path),
data=json.dumps({"enabled": enabled}),
)
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakPutError)
def group_user_add(self, user_id, group_id):
"""
@ -978,7 +985,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": user_id, "group-id": group_id}
data_raw = self.raw_put(URL_ADMIN_USER_GROUP.format(**params_path), data=None)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def group_user_remove(self, user_id, group_id):
"""
@ -991,7 +998,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": user_id, "group-id": group_id}
data_raw = self.raw_delete(URL_ADMIN_USER_GROUP.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def delete_group(self, group_id):
"""
@ -1003,7 +1010,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": group_id}
data_raw = self.raw_delete(URL_ADMIN_GROUP.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_clients(self):
"""
@ -1063,7 +1070,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": client_id}
data_raw = self.raw_get(URL_ADMIN_CLIENT_AUTHZ_SETTINGS.format(**params_path))
return data_raw
return raise_error_from_response(data_raw, KeycloakGetError)
def create_client_authz_resource(self, client_id, payload, skip_exists=False):
"""
@ -1083,7 +1090,7 @@ class KeycloakAdmin:
URL_ADMIN_CLIENT_AUTHZ_RESOURCES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def get_client_authz_resources(self, client_id):
@ -1129,7 +1136,7 @@ class KeycloakAdmin:
data=json.dumps(payload),
)
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def create_client_authz_resource_based_permission(self, client_id, payload, skip_exists=False):
@ -1163,7 +1170,7 @@ class KeycloakAdmin:
data=json.dumps(payload),
)
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def get_client_authz_scopes(self, client_id):
@ -1177,7 +1184,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": client_id}
data_raw = self.raw_get(URL_ADMIN_CLIENT_AUTHZ_SCOPES.format(**params_path))
return data_raw
return raise_error_from_response(data_raw, KeycloakGetError)
def get_client_authz_permissions(self, client_id):
"""
@ -1190,7 +1197,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": client_id}
data_raw = self.raw_get(URL_ADMIN_CLIENT_AUTHZ_PERMISSIONS.format(**params_path))
return data_raw
return raise_error_from_response(data_raw, KeycloakGetError)
def get_client_authz_policies(self, client_id):
"""
@ -1203,7 +1210,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": client_id}
data_raw = self.raw_get(URL_ADMIN_CLIENT_AUTHZ_POLICIES.format(**params_path))
return data_raw
return raise_error_from_response(data_raw, KeycloakGetError)
def get_client_service_account_user(self, client_id):
"""
@ -1232,7 +1239,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name}
data_raw = self.raw_post(URL_ADMIN_CLIENTS.format(**params_path), data=json.dumps(payload))
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def update_client(self, client_id, payload):
@ -1246,7 +1253,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": client_id}
data_raw = self.raw_put(URL_ADMIN_CLIENT.format(**params_path), data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def delete_client(self, client_id):
"""
@ -1261,7 +1268,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": client_id}
data_raw = self.raw_delete(URL_ADMIN_CLIENT.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_client_installation_provider(self, client_id, provider_id):
"""
@ -1374,7 +1381,7 @@ class KeycloakAdmin:
URL_ADMIN_CLIENT_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def add_composite_client_roles_to_role(self, client_role_id, role_name, roles):
@ -1393,7 +1400,7 @@ class KeycloakAdmin:
URL_ADMIN_CLIENT_ROLES_COMPOSITE_CLIENT_ROLE.format(**params_path),
data=json.dumps(payload),
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[204])
def delete_client_role(self, client_role_id, role_name):
"""
@ -1407,7 +1414,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": client_role_id, "role-name": role_name}
data_raw = self.raw_delete(URL_ADMIN_CLIENT_ROLE.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def assign_client_role(self, user_id, client_id, roles):
"""
@ -1424,7 +1431,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_USER_CLIENT_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[204])
def get_client_role_members(self, client_id, role_name, **query):
"""
@ -1451,7 +1458,7 @@ class KeycloakAdmin:
URL_ADMIN_REALM_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def get_realm_role(self, role_name):
@ -1479,7 +1486,7 @@ class KeycloakAdmin:
data_raw = self.raw_put(
URL_ADMIN_REALM_ROLES_ROLE_BY_NAME.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def delete_realm_role(self, role_name):
"""
@ -1490,7 +1497,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "role-name": role_name}
data_raw = self.raw_delete(URL_ADMIN_REALM_ROLES_ROLE_BY_NAME.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def add_composite_realm_roles_to_role(self, role_name, roles):
"""
@ -1507,7 +1514,7 @@ class KeycloakAdmin:
URL_ADMIN_REALM_ROLES_COMPOSITE_REALM_ROLE.format(**params_path),
data=json.dumps(payload),
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[204])
def remove_composite_realm_roles_to_role(self, role_name, roles):
"""
@ -1524,7 +1531,7 @@ class KeycloakAdmin:
URL_ADMIN_REALM_ROLES_COMPOSITE_REALM_ROLE.format(**params_path),
data=json.dumps(payload),
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_composite_realm_roles_of_role(self, role_name):
"""
@ -1552,7 +1559,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_USER_REALM_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[204])
def delete_realm_roles_of_user(self, user_id, roles):
"""
@ -1568,7 +1575,7 @@ class KeycloakAdmin:
data_raw = self.raw_delete(
URL_ADMIN_USER_REALM_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_realm_roles_of_user(self, user_id):
"""
@ -1616,7 +1623,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_GROUPS_REALM_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[204])
def delete_group_realm_roles(self, group_id, roles):
"""
@ -1632,7 +1639,7 @@ class KeycloakAdmin:
data_raw = self.raw_delete(
URL_ADMIN_GROUPS_REALM_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_group_realm_roles(self, group_id):
"""
@ -1660,7 +1667,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_GROUPS_CLIENT_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[204])
def get_group_client_roles(self, group_id, client_id):
"""
@ -1690,7 +1697,7 @@ class KeycloakAdmin:
data_raw = self.raw_delete(
URL_ADMIN_GROUPS_CLIENT_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_client_roles_of_user(self, user_id, client_id):
"""
@ -1745,7 +1752,7 @@ class KeycloakAdmin:
data_raw = self.raw_delete(
URL_ADMIN_USER_CLIENT_ROLES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_authentication_flows(self):
"""
@ -1789,7 +1796,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name}
data_raw = self.raw_post(URL_ADMIN_FLOWS.format(**params_path), data=json.dumps(payload))
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def copy_authentication_flow(self, payload, flow_alias):
@ -1805,7 +1812,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_FLOWS_COPY.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
def delete_authentication_flow(self, flow_id):
"""
@ -1819,7 +1826,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": flow_id}
data_raw = self.raw_delete(URL_ADMIN_FLOW.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_authentication_flow_executions(self, flow_alias):
"""
@ -1848,7 +1855,7 @@ class KeycloakAdmin:
data_raw = self.raw_put(
URL_ADMIN_FLOWS_EXECUTIONS.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[202, 204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[202, 204])
def get_authentication_flow_execution(self, execution_id):
"""
@ -1880,7 +1887,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_FLOWS_EXECUTIONS_EXECUTION.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
def delete_authentication_flow_execution(self, execution_id):
"""
@ -1894,7 +1901,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": execution_id}
data_raw = self.raw_delete(URL_ADMIN_FLOWS_EXECUTION.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def create_authentication_flow_subflow(self, payload, flow_alias, skip_exists=False):
"""
@ -1914,7 +1921,7 @@ class KeycloakAdmin:
URL_ADMIN_FLOWS_EXECUTIONS_FLOW.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def get_authenticator_config(self, config_id):
@ -1943,7 +1950,7 @@ class KeycloakAdmin:
data_raw = self.raw_put(
URL_ADMIN_AUTHENTICATOR_CONFIG.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def delete_authenticator_config(self, config_id):
"""
@ -1956,8 +1963,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": config_id}
data_raw = self.raw_delete(URL_ADMIN_AUTHENTICATOR_CONFIG.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def sync_users(self, storage_id, action):
"""
@ -1974,7 +1980,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_USER_STORAGE.format(**params_path), data=json.dumps(data), **params_query
)
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakPostError)
def get_client_scopes(self):
"""
@ -2017,7 +2023,7 @@ class KeycloakAdmin:
URL_ADMIN_CLIENT_SCOPES.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(
data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists
data_raw, KeycloakPostError, expected_codes=[201], skip_exists=skip_exists
)
def update_client_scope(self, client_scope_id, payload):
@ -2035,7 +2041,7 @@ class KeycloakAdmin:
data_raw = self.raw_put(
URL_ADMIN_CLIENT_SCOPE.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def add_mapper_to_client_scope(self, client_scope_id, payload):
"""
@ -2053,7 +2059,7 @@ class KeycloakAdmin:
URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
def delete_mapper_from_client_scope(self, client_scope_id, protocol_mppaer_id):
"""
@ -2072,8 +2078,7 @@ class KeycloakAdmin:
}
data_raw = self.raw_delete(URL_ADMIN_CLIENT_SCOPES_MAPPERS.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def update_mapper_in_client_scope(self, client_scope_id, protocol_mapper_id, payload):
"""
@ -2097,7 +2102,7 @@ class KeycloakAdmin:
URL_ADMIN_CLIENT_SCOPES_MAPPERS.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def get_default_default_client_scopes(self):
"""
@ -2118,7 +2123,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": scope_id}
data_raw = self.raw_delete(URL_ADMIN_DEFAULT_DEFAULT_CLIENT_SCOPE.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def add_default_default_client_scope(self, scope_id):
"""
@ -2132,7 +2137,7 @@ class KeycloakAdmin:
data_raw = self.raw_put(
URL_ADMIN_DEFAULT_DEFAULT_CLIENT_SCOPE.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def get_default_optional_client_scopes(self):
"""
@ -2153,7 +2158,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "id": scope_id}
data_raw = self.raw_delete(URL_ADMIN_DEFAULT_OPTIONAL_CLIENT_SCOPE.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def add_default_optional_client_scope(self, scope_id):
"""
@ -2167,7 +2172,7 @@ class KeycloakAdmin:
data_raw = self.raw_put(
URL_ADMIN_DEFAULT_OPTIONAL_CLIENT_SCOPE.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def add_mapper_to_client(self, client_id, payload):
"""
@ -2185,7 +2190,7 @@ class KeycloakAdmin:
URL_ADMIN_CLIENT_PROTOCOL_MAPPERS.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
def update_client_mapper(self, client_id, mapper_id, payload):
"""
@ -2206,7 +2211,7 @@ class KeycloakAdmin:
URL_ADMIN_CLIENT_PROTOCOL_MAPPER.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def remove_client_mapper(self, client_id, client_mapper_id):
"""
@ -2224,8 +2229,7 @@ class KeycloakAdmin:
}
data_raw = self.raw_delete(URL_ADMIN_CLIENT_PROTOCOL_MAPPER.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def generate_client_secrets(self, client_id):
"""
@ -2239,7 +2243,7 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name, "id": client_id}
data_raw = self.raw_post(URL_ADMIN_CLIENT_SECRETS.format(**params_path), data=None)
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakPostError)
def get_client_secrets(self, client_id):
"""
@ -2285,7 +2289,7 @@ class KeycloakAdmin:
data_raw = self.raw_post(
URL_ADMIN_COMPONENTS.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201])
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201])
def get_component(self, component_id):
"""
@ -2316,7 +2320,7 @@ class KeycloakAdmin:
data_raw = self.raw_put(
URL_ADMIN_COMPONENT.format(**params_path), data=json.dumps(payload)
)
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def delete_component(self, component_id):
"""
@ -2328,7 +2332,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name, "component-id": component_id}
data_raw = self.raw_delete(URL_ADMIN_COMPONENT.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204])
def get_keys(self):
"""
@ -2367,7 +2371,7 @@ class KeycloakAdmin:
"""
params_path = {"realm-name": self.realm_name}
data_raw = self.raw_put(URL_ADMIN_EVENTS.format(**params_path), data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
return raise_error_from_response(data_raw, KeycloakPutError, expected_codes=[204])
def raw_get(self, *args, **kwargs):
"""

Loading…
Cancel
Save