Skip to content

Commit

Permalink
Fix types for group delete action (#27)
Browse files Browse the repository at this point in the history
<!-- begin-generated-description -->

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.

<!-- end-generated-description -->
  • Loading branch information
benrules3 authored Oct 18, 2024
1 parent 063f866 commit 87d4569
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
9 changes: 2 additions & 7 deletions compass_sdk/compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down
7 changes: 4 additions & 3 deletions compass_sdk/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from compass_sdk.types import (
GroupCreateRequest,
GroupCreateResponse,
GroupDeleteResponse,
GroupFetchResponse,
GroupUserDeleteResponse,
PolicyRequest,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions compass_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class GroupCreateResponse(BaseModel):
user_name: str


class GroupDeleteResponse(BaseModel):
name: str


class GroupUserDeleteResponse(BaseModel):
group_name: str
user_name: str
Expand Down

0 comments on commit 87d4569

Please sign in to comment.