From 87d4569559d412e2f122e64d9afbb48104f56659 Mon Sep 17 00:00:00 2001 From: benrules3 <150701337+benrules3@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:14:03 -0400 Subject: [PATCH] Fix types for group delete action (#27) This pull request introduces a new `GroupDeleteResponse` class to the `compass_sdk` module, specifically in the `rbac.py` and `types.py` files. The changes are as follows: - In `compass_sdk/rbac.py`, the `delete_groups` function now returns a list of `GroupDeleteResponse` objects instead of `GroupUserDeleteResponse` objects. - In `compass_sdk/types.py`, a new `GroupDeleteResponse` class is added, which has a `name` attribute. --- compass_sdk/compass.py | 9 ++------- compass_sdk/rbac.py | 7 ++++--- compass_sdk/types.py | 4 ++++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compass_sdk/compass.py b/compass_sdk/compass.py index 50a7ea6..91e89e0 100644 --- a/compass_sdk/compass.py +++ b/compass_sdk/compass.py @@ -50,12 +50,7 @@ class CompassAuthError(Exception): def __init__( self, - message=( - "Unauthorized. Please check your username and password, " - "which can be passed into CompassClient or set with " - "COHERE_COMPASS_USERNAME and COHERE_COMPASS_PASSWORD " - "environment variables." - ), + message=(f"CompassAuthError - check your bearer token or username and password."), ): self.message = message super().__init__(self.message) @@ -547,7 +542,7 @@ def _send_request_with_retry(): except requests.exceptions.HTTPError as e: if e.response.status_code == 401: error = "Unauthorized. Please check your username and password." - raise CompassAuthError() + raise CompassAuthError(message=str(e)) else: error = str(e) + " " + e.response.text logger.error( diff --git a/compass_sdk/rbac.py b/compass_sdk/rbac.py index 1976dd3..c7529c1 100644 --- a/compass_sdk/rbac.py +++ b/compass_sdk/rbac.py @@ -8,6 +8,7 @@ from compass_sdk.types import ( GroupCreateRequest, GroupCreateResponse, + GroupDeleteResponse, GroupFetchResponse, GroupUserDeleteResponse, PolicyRequest, @@ -27,7 +28,7 @@ class CompassRootClient: def __init__(self, compass_url: str, root_user_token: str): - self.base_url = compass_url + "/security/admin/rbac" + self.base_url = compass_url + "/api/security/admin/rbac" self.headers = {"Authorization": f"Bearer {root_user_token}", "Content-Type": "application/json"} T = TypeVar("T", bound=BaseModel) @@ -104,8 +105,8 @@ def create_role_mappings(self, *, role_mappings: List[RoleMappingRequest]) -> Li def delete_users(self, *, user_names: List[str]) -> List[UserDeleteResponse]: return self._delete_entities(f"{self.base_url}/v1/users", self.headers, user_names, UserDeleteResponse) - def delete_groups(self, *, group_names: List[str]) -> List[GroupUserDeleteResponse]: - return self._delete_entities(f"{self.base_url}/v1/groups", self.headers, group_names, GroupUserDeleteResponse) + def delete_groups(self, *, group_names: List[str]) -> List[GroupDeleteResponse]: + return self._delete_entities(f"{self.base_url}/v1/groups", self.headers, group_names, GroupDeleteResponse) def delete_roles(self, *, role_ids: List[str]) -> List[RoleDeleteResponse]: return self._delete_entities(f"{self.base_url}/v1/roles", self.headers, role_ids, RoleDeleteResponse) diff --git a/compass_sdk/types.py b/compass_sdk/types.py index 62c2028..32f1d47 100644 --- a/compass_sdk/types.py +++ b/compass_sdk/types.py @@ -36,6 +36,10 @@ class GroupCreateResponse(BaseModel): user_name: str +class GroupDeleteResponse(BaseModel): + name: str + + class GroupUserDeleteResponse(BaseModel): group_name: str user_name: str