Skip to content

Commit

Permalink
Merge pull request #28 from permitio/shaul/per-3975-fix-python-v1-sdk…
Browse files Browse the repository at this point in the history
…-not-raising-errors

Fix server errors getting ignored by write functions.
  • Loading branch information
asafc authored Feb 28, 2023
2 parents a35e780 + 44c6835 commit ac9c4f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ repos:
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
29 changes: 25 additions & 4 deletions permit/mutations/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ async def run(self) -> T:


class ReadOperation(Operation[Dict]):
pass
...


class WriteOperation(Operation[Dict]):
pass
...


class ReadApis:
Expand Down Expand Up @@ -82,7 +82,7 @@ def unassign_role(


class PermitApi(ReadApis, WriteApis):
pass
...


class PermitApiClient(PermitApi):
Expand All @@ -105,8 +105,10 @@ async def _get_user() -> dict:
try:
async with session.get(
f"{self._base_url}/cloud/users/{user_key}",
raise_for_status=True,
) as response:
return await response.json()

except aiohttp.ClientError as err:
self._logger.error(
f"tried to get user with key: {user_key}, got error: {err}"
Expand All @@ -124,8 +126,10 @@ async def _get_role() -> dict:
try:
async with session.get(
f"{self._base_url}/cloud/roles/{role_key}",
raise_for_status=True,
) as response:
return await response.json()

except aiohttp.ClientError as err:
self._logger.error(
f"tried to get role with id: {role_key}, got error: {err}"
Expand All @@ -143,8 +147,10 @@ async def _get_tenant() -> dict:
try:
async with session.get(
f"{self._base_url}/cloud/tenants/{tenant_key}",
raise_for_status=True,
) as response:
return await response.json()

except aiohttp.ClientError as err:
self._logger.error(
f"tried to get tenant with id: {tenant_key}, got error: {err}"
Expand All @@ -167,8 +173,9 @@ async def _get_assigned_roles() -> dict:
if tenant_key is not None:
url += f"&tenant={tenant_key}"
try:
async with session.get(url) as response:
async with session.get(url, raise_for_status=True) as response:
return await response.json()

except aiohttp.ClientError as err:
self._logger.error(
f"could not get user roles for user {user_key}, got error: {err}"
Expand All @@ -193,8 +200,10 @@ async def _sync_user() -> dict:
async with session.put(
f"{self._base_url}/cloud/users",
data=json.dumps(user.dict(exclude_none=True)),
raise_for_status=True,
) as response:
return await response.json()

except aiohttp.ClientError as err:
self._logger.error(
f"tried to sync user with key: {user.key}, got error: {err}"
Expand All @@ -212,8 +221,10 @@ async def _delete_user() -> dict:
try:
async with session.delete(
f"{self._base_url}/cloud/users/{user_key}",
raise_for_status=True,
) as response:
return dict(status=response.status)

except aiohttp.ClientError as err:
self._logger.error(
f"tried to delete user with key: {user_key}, got error: {err}"
Expand Down Expand Up @@ -241,8 +252,10 @@ async def _create_tenant() -> dict:
async with session.put(
f"{self._base_url}/cloud/tenants",
data=json.dumps(data),
raise_for_status=True,
) as response:
return await response.json()

except aiohttp.ClientError as err:
self._logger.error(
f"tried to create tenant with key: {tenant.key}, got error: {err}"
Expand Down Expand Up @@ -270,8 +283,10 @@ async def _update_tenant() -> dict:
async with session.patch(
f"{self._base_url}/cloud/tenants/{tenant.key}",
data=json.dumps(data),
raise_for_status=True,
) as response:
return await response.json()

except aiohttp.ClientError as err:
self._logger.error(
f"tried to update tenant with key: {tenant.key}, got error: {err}"
Expand All @@ -289,8 +304,10 @@ async def _delete_tenant() -> dict:
try:
async with session.delete(
f"{self._base_url}/cloud/tenants/{tenant_key}",
raise_for_status=True,
) as response:
return dict(status=response.status)

except aiohttp.ClientError as err:
self._logger.error(
f"tried to delete tenant with key: {tenant_key}, got error: {err}"
Expand All @@ -312,8 +329,10 @@ async def _assign_role() -> dict:
async with session.post(
f"{self._base_url}/cloud/role_assignments",
data=json.dumps(data),
raise_for_status=True,
) as response:
return await response.json()

except aiohttp.ClientError as err:
self._logger.error(
f"could not assign role {role_key} to {user_key} in tenant {tenant_key}, got error: {err}"
Expand All @@ -334,8 +353,10 @@ async def _unassign_role() -> dict:
try:
async with session.delete(
f"{self._base_url}/cloud/role_assignments?role={role_key}&user={user_key}&scope={tenant_key}",
raise_for_status=True,
) as response:
return await response.json()

except aiohttp.ClientError as err:
self._logger.error(
f"could not unassign role {role_key} of {user_key} in tenant {tenant_key}, got error: {err}"
Expand Down

0 comments on commit ac9c4f5

Please sign in to comment.