diff --git a/authomize/rest_api_client/client/__init__.py b/authomize/rest_api_client/client/__init__.py index 82bd2d7..2790c8d 100644 --- a/authomize/rest_api_client/client/__init__.py +++ b/authomize/rest_api_client/client/__init__.py @@ -1,3 +1,3 @@ -from authomize.rest_api_client.client.client import Client +from authomize.rest_api_client.client.async_client import Client __all__ = ['Client'] diff --git a/authomize/rest_api_client/client/async_base_client.py b/authomize/rest_api_client/client/async_base_client.py new file mode 100644 index 0000000..c3da90d --- /dev/null +++ b/authomize/rest_api_client/client/async_base_client.py @@ -0,0 +1,91 @@ +from typing import Optional + +import aiohttp +from furl import furl # type: ignore + +AUTHOMIZE_API_URL = 'https://api.authomize.com' +STATUS_OK: int = 200 + + +class AsyncClientError(Exception): + def __init__(self, message): + self.message = message + + +class AsyncBaseClient: + def __init__(self, auth_token: str, base_url: str = AUTHOMIZE_API_URL): + self.auth_token = auth_token + self.base_url = furl(base_url) + self.session = aiohttp.ClientSession() + self.session.headers.update({'Authorization': self.authorization_header or ""}) + + @property + def authorization_header(self) -> str: + raise NotImplementedError() + + async def http_get(self, url, params=None): + url = self.base_url.join(url).url + async with self.session.get(url, params=params) as response: + if response.status == STATUS_OK: + return await response.json() + try: + response_json = await response.json() + detail = response_json.get('detail') + except Exception: + detail = None + if detail: + raise AsyncClientError(str(detail)) + response.raise_for_status() + + async def http_post(self, url: str, body: Optional[str] = None): + url = self.base_url.join(url).url + async with self.session.post( + url, + headers={'Content-Type': 'application/json'}, + data=body, + ) as response: + if response.status == STATUS_OK: + return await response.json() + try: + response_json = await response.json() + detail = response_json.get('detail') + except Exception: + detail = None + if detail: + raise AsyncClientError(str(detail)) + response.raise_for_status() + + async def http_patch(self, url: str, body: Optional[str] = None): + url = self.base_url.join(url).url + async with self.session.patch( + url, + headers={'Content-Type': 'application/json'}, + data=body, + ) as response: + if response.status == STATUS_OK: + return await response.json() + try: + response_json = await response.json() + detail = response_json.get('detail') + except Exception: + detail = None + if detail: + raise AsyncClientError(str(detail)) + response.raise_for_status() + + async def http_delete(self, url: str, params=None): + url = self.base_url.join(url).url + async with self.session.delete(url, params=params) as response: + if response.status == STATUS_OK: + return await response.json() + try: + response_json = await response.json() + detail = response_json.get('detail') + except Exception: + detail = None + if detail: + raise AsyncClientError(str(detail)) + response.raise_for_status() + + async def close(self): + await self.session.close() diff --git a/authomize/rest_api_client/client/client.py b/authomize/rest_api_client/client/async_client.py similarity index 65% rename from authomize/rest_api_client/client/client.py rename to authomize/rest_api_client/client/async_client.py index 9cd4d88..142d803 100644 --- a/authomize/rest_api_client/client/client.py +++ b/authomize/rest_api_client/client/async_client.py @@ -1,11 +1,13 @@ +import asyncio +import functools from datetime import datetime from typing import Optional from apiclient_pydantic import serialize_all_methods, serialize_response -from authomize.rest_api_client.client.base_client import AUTHOMIZE_API_URL -from authomize.rest_api_client.client.connectors_client import ConnectorsClient -from authomize.rest_api_client.client.platform_client import PlatformClient +from authomize.rest_api_client.client.async_base_client import AUTHOMIZE_API_URL +from authomize.rest_api_client.client.async_connectors_client import AsyncConnectorsClient +from authomize.rest_api_client.client.async_platform_client import AsyncPlatformClient from authomize.rest_api_client.generated.connectors_rest_api.schemas import ( BundleTransactionSchema, ItemsBundleSchema, @@ -49,6 +51,14 @@ ) +def syncify(func): + @functools.wraps(func) + def wrapped(*args, **kwargs): + return asyncio.ensure_future(func(*args, **kwargs)) + + return wrapped + + @serialize_all_methods(decorator=serialize_response) class Client: def __init__( @@ -60,284 +70,313 @@ def __init__( ): self.auth_token = auth_token self.base_url = base_url - self.connectors_client = ConnectorsClient( + self.connectors_client = AsyncConnectorsClient( *args, auth_token=auth_token, base_url=base_url, **kwargs, ) - self.platform_client = PlatformClient( + self.platform_client = AsyncPlatformClient( *args, auth_token=auth_token, base_url=base_url, **kwargs, ) - def is_alive(self) -> IsAliveResponse: - return self.platform_client.is_alive() + @syncify + async def is_alive(self) -> IsAliveResponse: + return await self.platform_client.is_alive() - def me(self) -> MeResponse: - return self.platform_client.me() + @syncify + async def me(self) -> MeResponse: + return await self.platform_client.me() - def list_connectors( + @syncify + async def list_connectors( self, params=None, ) -> RestApiConnectorListSchema: - return self.connectors_client.list_connectors( + return await self.connectors_client.list_connectors( params=params, ) - def create_transaction( + @syncify + async def create_transaction( self, connector_id: str, ) -> BundleTransactionSchema: - return self.connectors_client.create_transaction( + return await self.connectors_client.create_transaction( connector_id=connector_id, ) - def retrieve_transaction( + @syncify + async def retrieve_transaction( self, connector_id: str, transaction_id: str, ) -> BundleTransactionSchema: - return self.connectors_client.retrieve_transaction( + return await self.connectors_client.retrieve_transaction( connector_id=connector_id, transaction_id=transaction_id, ) - def apply_transaction( + @syncify + async def apply_transaction( self, connector_id: str, transaction_id: str, ) -> BundleTransactionSchema: - return self.connectors_client.apply_transaction( + return await self.connectors_client.apply_transaction( connector_id=connector_id, transaction_id=transaction_id, ) - def extend_transaction_items( + @syncify + async def extend_transaction_items( self, connector_id: str, transaction_id: str, items: ItemsBundleSchema, ) -> SubmitResponse: - return self.connectors_client.extend_transaction_items( + return await self.connectors_client.extend_transaction_items( connector_id=connector_id, transaction_id=transaction_id, items=items, ) - def delete_app_data( + @syncify + async def delete_app_data( self, app_id: str, modified_before: Optional[datetime] = None, ) -> SubmitResponse: - return self.connectors_client.delete_app_data( + return await self.connectors_client.delete_app_data( app_id=app_id, modified_before=modified_before, ) - def search_users( + @syncify + async def search_users( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchUsersListResponseSchema: - return self.connectors_client.search_users( + return await self.connectors_client.search_users( app_id=app_id, start_date=start_date, ) - def create_users( + @syncify + async def create_users( self, app_id: str, body: NewUsersListRequestSchema, ) -> NewUserResponseSchema: - return self.connectors_client.create_users( + return await self.connectors_client.create_users( app_id=app_id, body=body, ) - def search_groupings( + @syncify + async def search_groupings( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchGroupingResponseSchema: - return self.connectors_client.search_groupings( + return await self.connectors_client.search_groupings( app_id=app_id, start_date=start_date, ) - def create_groupings( + @syncify + async def create_groupings( self, app_id: str, body: NewGroupingsListRequestSchema, ) -> NewGroupingResponseSchema: - return self.connectors_client.create_groupings( + return await self.connectors_client.create_groupings( app_id=app_id, body=body, ) - def search_permissions( + @syncify + async def search_permissions( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchPermissionResponseSchema: - return self.connectors_client.search_permissions( + return await self.connectors_client.search_permissions( app_id=app_id, start_date=start_date, ) - def create_permissions( + @syncify + async def create_permissions( self, app_id: str, body: NewPermissionsListRequestSchema, ) -> NewPermissionsResponseSchema: - return self.connectors_client.create_permissions( + return await self.connectors_client.create_permissions( app_id=app_id, body=body, ) - def search_privileges( + @syncify + async def search_privileges( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchPrivilegesListResponseSchema: - return self.connectors_client.search_privileges( + return await self.connectors_client.search_privileges( app_id=app_id, start_date=start_date, ) - def create_privileges( + @syncify + async def create_privileges( self, app_id: str, body: NewPrivilegesListRequestSchema, ) -> NewPrivilegesResponseSchema: - return self.connectors_client.create_privileges( + return await self.connectors_client.create_privileges( app_id=app_id, body=body, ) - def search_privileges_grants( + @syncify + async def search_privileges_grants( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchPrivilegeGrantsListResponseSchema: - return self.connectors_client.search_privileges_grants( + return await self.connectors_client.search_privileges_grants( app_id=app_id, start_date=start_date, ) - def create_privileges_grants( + @syncify + async def create_privileges_grants( self, app_id: str, body: NewPrivilegesGrantsListRequestSchema, ) -> NewPrivilegeGrantsResponseSchema: - return self.connectors_client.create_privileges_grants( + return await self.connectors_client.create_privileges_grants( app_id=app_id, body=body, ) - def search_accounts_association( + @syncify + async def search_accounts_association( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchAccountsAssociationsListResponseSchema: - return self.connectors_client.search_accounts_association( + return await self.connectors_client.search_accounts_association( app_id=app_id, start_date=start_date, ) - def create_accounts_association( + @syncify + async def create_accounts_association( self, app_id: str, body: NewAccountsAssociationsListRequestSchema, ) -> NewAccountsAssociationResponseSchema: - return self.connectors_client.create_accounts_association( + return await self.connectors_client.create_accounts_association( app_id=app_id, body=body, ) - def search_groupings_association( + @syncify + async def search_groupings_association( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchGroupingsAssociationsListResponseSchema: - return self.connectors_client.search_groupings_association( + return await self.connectors_client.search_groupings_association( app_id=app_id, start_date=start_date, ) - def create_groupings_association( + @syncify + async def create_groupings_association( self, app_id: str, body: NewGroupingsAssociationsListRequestSchema, ) -> NewGroupingsAssociationResponseSchema: - return self.connectors_client.create_groupings_association( + return await self.connectors_client.create_groupings_association( app_id=app_id, body=body, ) - def search_assets( + @syncify + async def search_assets( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchAssetsListResponseSchema: - return self.connectors_client.search_assets( + return await self.connectors_client.search_assets( app_id=app_id, start_date=start_date, ) - def create_assets( + @syncify + async def create_assets( self, app_id: str, body: NewAssetsListRequestSchema, ) -> NewAssetsResponseSchema: - return self.connectors_client.create_assets( + return await self.connectors_client.create_assets( app_id=app_id, body=body, ) - def search_assets_inheritance( + @syncify + async def search_assets_inheritance( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchAssetsInheritanceListResponseSchema: - return self.connectors_client.search_assets_inheritance( + return await self.connectors_client.search_assets_inheritance( app_id=app_id, start_date=start_date, ) - def create_assets_inheritance( + @syncify + async def create_assets_inheritance( self, app_id: str, body: NewAssetsInheritanceListRequestSchema, ) -> NewAssetsInheritanceResponseSchema: - return self.connectors_client.create_assets_inheritance( + return await self.connectors_client.create_assets_inheritance( app_id=app_id, body=body, ) - def search_identities( + @syncify + async def search_identities( self, app_id: str, start_date: Optional[datetime] = None, ) -> SearchIdentitiesListResponseSchema: - return self.connectors_client.search_identities( + return await self.connectors_client.search_identities( app_id=app_id, start_date=start_date, ) - def create_identities( + @syncify + async def create_identities( self, app_id: str, body: NewIdentitiesListRequestSchema, ) -> NewIdentityResponseSchema: - return self.connectors_client.create_identities( + return await self.connectors_client.create_identities( app_id=app_id, body=body, ) - def retrieve_incident( + @syncify + async def retrieve_incident( self, incident_id: str, expand: Optional[list[IncidentExpansion]] = None, @@ -346,3 +385,7 @@ def retrieve_incident( incident_id=incident_id, expand=expand, ) + + @syncify + async def close(self): + await asyncio.gather(self.connectors_client.close(), self.platform_client.close()) diff --git a/authomize/rest_api_client/client/connectors_client.py b/authomize/rest_api_client/client/async_connectors_client.py similarity index 82% rename from authomize/rest_api_client/client/connectors_client.py rename to authomize/rest_api_client/client/async_connectors_client.py index c810134..ee80ba8 100644 --- a/authomize/rest_api_client/client/connectors_client.py +++ b/authomize/rest_api_client/client/async_connectors_client.py @@ -4,7 +4,7 @@ from pydantic.json import pydantic_encoder -from authomize.rest_api_client.client.base_client import BaseClient +from authomize.rest_api_client.client.async_base_client import AsyncBaseClient from authomize.rest_api_client.generated.connectors_rest_api.schemas import ( BundleTransactionSchema, ItemsBundleSchema, @@ -43,7 +43,7 @@ ) -class ConnectorsClient(BaseClient): +class AsyncConnectorsClient(AsyncBaseClient): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -51,21 +51,21 @@ def __init__(self, *args, **kwargs): def authorization_header(self) -> str: return self.auth_token - def list_connectors( + async def list_connectors( self, params=None, ) -> RestApiConnectorListSchema: - return self.http_get('/v1/connectors', params=params) + return await self.http_get('/v1/connectors', params=params) - def create_transaction( + async def create_transaction( self, connector_id: str, ) -> BundleTransactionSchema: if not connector_id: raise ValueError('Missing connector_id') - return self.http_post(f'/v1/connectors/{connector_id}/transactions') + return await self.http_post(f'/v1/connectors/{connector_id}/transactions') - def retrieve_transaction( + async def retrieve_transaction( self, connector_id: str, transaction_id: str, @@ -74,9 +74,9 @@ def retrieve_transaction( raise ValueError('Missing connector_id') if not transaction_id: raise ValueError('Missing transaction_id') - return self.http_get(f'/v1/connectors/{connector_id}/transactions/{transaction_id}') + return await self.http_get(f'/v1/connectors/{connector_id}/transactions/{transaction_id}') - def apply_transaction( + async def apply_transaction( self, connector_id: str, transaction_id: str, @@ -85,9 +85,11 @@ def apply_transaction( raise ValueError('Missing connector_id') if not transaction_id: raise ValueError('Missing transaction_id') - return self.http_post(f'/v1/connectors/{connector_id}/transactions/{transaction_id}/apply') + return await self.http_post( + f'/v1/connectors/{connector_id}/transactions/{transaction_id}/apply' + ) - def extend_transaction_items( + async def extend_transaction_items( self, connector_id: str, transaction_id: str, @@ -97,12 +99,12 @@ def extend_transaction_items( raise ValueError('Missing connector_id') if not transaction_id: raise ValueError('Missing transaction_id') - return self.http_post( + return await self.http_post( f'/v1/connectors/{connector_id}/transactions/{transaction_id}/items', body=items.json(), ) - def delete_app_data( + async def delete_app_data( self, app_id: str, modified_before: Optional[datetime] = None, @@ -112,9 +114,9 @@ def delete_app_data( date_filter = '' if modified_before: date_filter = f'?modifiedBefore={str(modified_before)}' - return self.http_delete(url=f"/v2/apps/{app_id}/data{date_filter}") + return await self.http_delete(url=f"/v2/apps/{app_id}/data{date_filter}") - def search_users( + async def search_users( self, app_id: str, start_date: Optional[datetime] = None, @@ -124,21 +126,21 @@ def search_users( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/accounts/users', params={ **params, }, ) - def create_users( + async def create_users( self, app_id: str, body: NewUsersListRequestSchema, ) -> NewUserResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/accounts/users', body=json.dumps( body, @@ -146,7 +148,7 @@ def create_users( ), ) - def search_groupings( + async def search_groupings( self, app_id: str, start_date: Optional[datetime] = None, @@ -156,21 +158,21 @@ def search_groupings( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/access/grouping', params={ **params, }, ) - def create_groupings( + async def create_groupings( self, app_id: str, body: NewGroupingsListRequestSchema, ) -> NewGroupingResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/access/grouping', body=json.dumps( body, @@ -178,7 +180,7 @@ def create_groupings( ), ) - def search_permissions( + async def search_permissions( self, app_id: str, start_date: Optional[datetime] = None, @@ -188,21 +190,21 @@ def search_permissions( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/access/permissions', params={ **params, }, ) - def create_permissions( + async def create_permissions( self, app_id: str, body: NewPermissionsListRequestSchema, ) -> NewPermissionsResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/access/permissions', body=json.dumps( body, @@ -210,7 +212,7 @@ def create_permissions( ), ) - def search_privileges( + async def search_privileges( self, app_id: str, start_date: Optional[datetime] = None, @@ -220,21 +222,21 @@ def search_privileges( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/privileges', params={ **params, }, ) - def create_privileges( + async def create_privileges( self, app_id: str, body: NewPrivilegesListRequestSchema, ) -> NewPrivilegesResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/privileges', body=json.dumps( body, @@ -242,7 +244,7 @@ def create_privileges( ), ) - def search_privileges_grants( + async def search_privileges_grants( self, app_id: str, start_date: Optional[datetime] = None, @@ -252,21 +254,21 @@ def search_privileges_grants( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/privileges/grants', params={ **params, }, ) - def create_privileges_grants( + async def create_privileges_grants( self, app_id: str, body: NewPrivilegesGrantsListRequestSchema, ) -> NewPrivilegeGrantsResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/privileges/grants', body=json.dumps( body, @@ -274,7 +276,7 @@ def create_privileges_grants( ), ) - def search_accounts_association( + async def search_accounts_association( self, app_id: str, start_date: Optional[datetime] = None, @@ -284,21 +286,21 @@ def search_accounts_association( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/association/accounts', params={ **params, }, ) - def create_accounts_association( + async def create_accounts_association( self, app_id: str, body: NewAccountsAssociationsListRequestSchema, ) -> NewAccountsAssociationResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/association/accounts', body=json.dumps( body, @@ -306,7 +308,7 @@ def create_accounts_association( ), ) - def search_groupings_association( + async def search_groupings_association( self, app_id: str, start_date: Optional[datetime] = None, @@ -316,21 +318,21 @@ def search_groupings_association( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/association/groupings', params={ **params, }, ) - def create_groupings_association( + async def create_groupings_association( self, app_id: str, body: NewGroupingsAssociationsListRequestSchema, ) -> NewGroupingsAssociationResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/association/groupings', body=json.dumps( body, @@ -338,7 +340,7 @@ def create_groupings_association( ), ) - def search_assets( + async def search_assets( self, app_id: str, start_date: Optional[datetime] = None, @@ -348,21 +350,21 @@ def search_assets( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/assets', params={ **params, }, ) - def create_assets( + async def create_assets( self, app_id: str, body: NewAssetsListRequestSchema, ) -> NewAssetsResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/assets', body=json.dumps( body, @@ -370,7 +372,7 @@ def create_assets( ), ) - def search_assets_inheritance( + async def search_assets_inheritance( self, app_id: str, start_date: Optional[datetime] = None, @@ -380,21 +382,21 @@ def search_assets_inheritance( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/assets/inheritance', params={ **params, }, ) - def create_assets_inheritance( + async def create_assets_inheritance( self, app_id: str, body: NewAssetsInheritanceListRequestSchema, ) -> NewAssetsInheritanceResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/assets/inheritance', body=json.dumps( body, @@ -402,7 +404,7 @@ def create_assets_inheritance( ), ) - def search_identities( + async def search_identities( self, app_id: str, start_date: Optional[datetime] = None, @@ -412,21 +414,21 @@ def search_identities( params = dict( start_date=start_date, ) - return self.http_get( + return await self.http_get( url=f'/v2/apps/{app_id}/identities', params={ **params, }, ) - def create_identities( + async def create_identities( self, app_id: str, body: NewIdentitiesListRequestSchema, ) -> NewIdentityResponseSchema: if not app_id: raise ValueError('Missing app_id') - return self.http_post( + return await self.http_post( url=f'/v2/apps/{app_id}/identities', body=json.dumps( body, diff --git a/authomize/rest_api_client/client/platform_client.py b/authomize/rest_api_client/client/async_platform_client.py similarity index 64% rename from authomize/rest_api_client/client/platform_client.py rename to authomize/rest_api_client/client/async_platform_client.py index 5148e4d..144607f 100644 --- a/authomize/rest_api_client/client/platform_client.py +++ b/authomize/rest_api_client/client/async_platform_client.py @@ -1,6 +1,6 @@ from typing import Optional -from authomize.rest_api_client.client.base_client import BaseClient +from authomize.rest_api_client.client.async_base_client import AsyncBaseClient from authomize.rest_api_client.generated.external_rest_api.schemas import ( IncidentExpansion, IsAliveResponse, @@ -9,7 +9,7 @@ ) -class PlatformClient(BaseClient): +class AsyncPlatformClient(AsyncBaseClient): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -17,13 +17,13 @@ def __init__(self, *args, **kwargs): def authorization_header(self) -> str: return f'Bearer {self.auth_token}' - def is_alive(self) -> IsAliveResponse: - return self.http_get('/is_alive') + async def is_alive(self) -> IsAliveResponse: + return await self.http_get('/is_alive') - def me(self) -> MeResponse: - return self.http_get('/me') + async def me(self) -> MeResponse: + return await self.http_get('/me') - def retrieve_incident( + async def retrieve_incident( self, incident_id: str, expand: Optional[list[IncidentExpansion]] = None, @@ -35,4 +35,4 @@ def retrieve_incident( params = dict( expand=expand, ) - return self.http_get(f'/v2/incidents/{incident_id}', params=params) + return await self.http_get(f'/v2/incidents/{incident_id}', params=params) diff --git a/authomize/rest_api_client/client/base_client.py b/authomize/rest_api_client/client/base_client.py deleted file mode 100644 index 1f9f85f..0000000 --- a/authomize/rest_api_client/client/base_client.py +++ /dev/null @@ -1,68 +0,0 @@ -from typing import Optional - -import requests - -AUTHOMIZE_API_URL = 'https://api.authomize.com' - - -class ClientError(Exception): - def __init__(self, message): - self.message = message - - -class BaseClient: - def __init__(self, auth_token: str, base_url: str = AUTHOMIZE_API_URL): - self.auth_token = auth_token - self.base_url = base_url - self.session = requests.Session() - self.session.headers.update({'Authorization': self.authorization_header}) - - @property - def authorization_header(self) -> str: - raise NotImplementedError() - - def http_get(self, url, params=None): - url = self.base_url + url - response = self.session.get(url, params=params) - if response.ok: - return response.json() - try: - response_json = response.json() - detail = response_json.get('detail') - except Exception: - detail = None - if detail: - raise ClientError(str(detail)) - response.raise_for_status() - - def http_post(self, url: str, body: Optional[str] = None): - url = self.base_url + url - response = self.session.post( - url, - headers={'Content-Type': 'application/json'}, - data=body, - ) - if response.ok: - return response.json() - try: - response_json = response.json() - detail = response_json.get('detail') - except Exception: - detail = None - if detail: - raise ClientError(str(detail)) - response.raise_for_status() - - def http_delete(self, url: str, params=None): - url = self.base_url + url - response = self.session.delete(url, params=params) - if response.ok: - return response.json() - try: - response_json = response.json() - detail = response_json.get('detail') - except Exception: - detail = None - if detail: - raise ClientError(str(detail)) - response.raise_for_status() diff --git a/authomize/rest_api_client/generated/connectors_rest_api/schemas.py b/authomize/rest_api_client/generated/connectors_rest_api/schemas.py index f8f9896..eef0adf 100644 --- a/authomize/rest_api_client/generated/connectors_rest_api/schemas.py +++ b/authomize/rest_api_client/generated/connectors_rest_api/schemas.py @@ -792,9 +792,7 @@ class SearchAccountsAssociationsListResponseSchema(BaseModel): class SearchAssetsInheritanceListResponseSchema(BaseModel): - data: List[AssetInheritanceSchema] = Field( - ..., description='Assets Inheritance', title='Data' - ) + data: List[AssetInheritanceSchema] = Field(..., description='Assets Inheritance', title='Data') class SearchGroupingsAssociationsListResponseSchema(BaseModel): @@ -804,9 +802,7 @@ class SearchGroupingsAssociationsListResponseSchema(BaseModel): class SearchPrivilegeGrantsListResponseSchema(BaseModel): - data: List[PrivilegeGrantSchema] = Field( - ..., description='Privilege Grants', title='Data' - ) + data: List[PrivilegeGrantSchema] = Field(..., description='Privilege Grants', title='Data') class ServiceDescription(BaseModel): @@ -1132,18 +1128,12 @@ class IdentitySchema(BaseModel): title='Originid', ) name: Optional[str] = Field(None, description='Username', title='Name') - email: Optional[str] = Field( - None, description="User's work email address.\n", title='Email' - ) + email: Optional[str] = Field(None, description="User's work email address.\n", title='Email') personalEmail: Optional[str] = Field( None, description="User's personal email address.\n", title='Personalemail' ) - firstName: Optional[str] = Field( - None, description="User's first name\n", title='Firstname' - ) - lastName: Optional[str] = Field( - None, description="The user's last name.\n", title='Lastname' - ) + firstName: Optional[str] = Field(None, description="User's first name\n", title='Firstname') + lastName: Optional[str] = Field(None, description="The user's last name.\n", title='Lastname') employeeNumber: Optional[str] = Field( None, description='Employee number', title='Employeenumber' ) @@ -1163,9 +1153,7 @@ class IdentitySchema(BaseModel): description="The identity's division in their organization.\n", title='Division', ) - title: Optional[str] = Field( - None, description="The user's job title.\n", title='Title' - ) + title: Optional[str] = Field(None, description="The user's job title.\n", title='Title') managerId: Optional[str] = Field( None, description="The manager identity's ID.\n", title='Managerid' ) @@ -1196,9 +1184,7 @@ class ItemsBundleSchema(BaseModel): inheritanceIdentities: Optional[List[IdentitiesInheritance]] = Field( None, title='Inheritanceidentities' ) - inheritanceAssets: Optional[List[AssetsInheritance]] = Field( - None, title='Inheritanceassets' - ) + inheritanceAssets: Optional[List[AssetsInheritance]] = Field(None, title='Inheritanceassets') access: Optional[List[AccessDescription]] = Field(None, title='Access') @@ -1212,18 +1198,12 @@ class NewIdentityRequestSchema(BaseModel): title='Originid', ) name: Optional[str] = Field(None, description='Username', title='Name') - email: Optional[str] = Field( - None, description="User's work email address.\n", title='Email' - ) + email: Optional[str] = Field(None, description="User's work email address.\n", title='Email') personalEmail: Optional[str] = Field( None, description="User's personal email address.\n", title='Personalemail' ) - firstName: Optional[str] = Field( - None, description="User's first name\n", title='Firstname' - ) - lastName: Optional[str] = Field( - None, description="The user's last name.\n", title='Lastname' - ) + firstName: Optional[str] = Field(None, description="User's first name\n", title='Firstname') + lastName: Optional[str] = Field(None, description="The user's last name.\n", title='Lastname') employeeNumber: Optional[str] = Field( None, description='Employee number', title='Employeenumber' ) @@ -1243,9 +1223,7 @@ class NewIdentityRequestSchema(BaseModel): description="The identity's division in their organization.\n", title='Division', ) - title: Optional[str] = Field( - None, description="The user's job title.\n", title='Title' - ) + title: Optional[str] = Field(None, description="The user's job title.\n", title='Title') managerId: Optional[str] = Field( None, description="The manager identity's ID.\n", title='Managerid' ) @@ -1350,15 +1328,9 @@ class NewUserRequestSchema(BaseModel): title='Originid', ) name: Optional[str] = Field(None, description='Username\n', title='Name') - email: Optional[str] = Field( - None, description="User's email address.", title='Email' - ) - firstName: Optional[str] = Field( - None, description="User's first name\n", title='Firstname' - ) - lastName: Optional[str] = Field( - None, description="The user's last name.\n", title='Lastname' - ) + email: Optional[str] = Field(None, description="User's email address.", title='Email') + firstName: Optional[str] = Field(None, description="User's first name\n", title='Firstname') + lastName: Optional[str] = Field(None, description="The user's last name.\n", title='Lastname') status: Optional[UserStatus] = Field( None, description='User status must be: `Deleted`, `Disabled`, `Enabled`, `Staged`, `Suspended`, or `Unknown`.\n', @@ -1468,16 +1440,12 @@ class RequestsBundleSchema(BaseModel): description='This API enables you to establish inheritance between privileges, so that a single privilege contains a set of other privileges. For example, an Administrative privilege that contains read and write privileges.', title='New Privileges Grants', ) - new_accounts_association: Optional[ - List[NewAccountsAssociationRequestSchema] - ] = Field( + new_accounts_association: Optional[List[NewAccountsAssociationRequestSchema]] = Field( None, description='Create association between user accounts and groups.', title='New Accounts Association', ) - new_groupings_association: Optional[ - List[NewGroupingsAssociationRequestSchema] - ] = Field( + new_groupings_association: Optional[List[NewGroupingsAssociationRequestSchema]] = Field( None, description='Create associations between groups and other groups.\n', title='New Groupings Association', @@ -1551,18 +1519,12 @@ class UpdateIdentityRequestSchema(BaseModel): title='Originid', ) name: Optional[str] = Field(None, description='Username', title='Name') - email: Optional[str] = Field( - None, description="User's work email address.\n", title='Email' - ) + email: Optional[str] = Field(None, description="User's work email address.\n", title='Email') personalEmail: Optional[str] = Field( None, description="User's personal email address.\n", title='Personalemail' ) - firstName: Optional[str] = Field( - None, description="User's first name\n", title='Firstname' - ) - lastName: Optional[str] = Field( - None, description="The user's last name.\n", title='Lastname' - ) + firstName: Optional[str] = Field(None, description="User's first name\n", title='Firstname') + lastName: Optional[str] = Field(None, description="The user's last name.\n", title='Lastname') employeeNumber: Optional[str] = Field( None, description='Employee number', title='Employeenumber' ) @@ -1582,9 +1544,7 @@ class UpdateIdentityRequestSchema(BaseModel): description="The identity's division in their organization.\n", title='Division', ) - title: Optional[str] = Field( - None, description="The user's job title.\n", title='Title' - ) + title: Optional[str] = Field(None, description="The user's job title.\n", title='Title') managerId: Optional[str] = Field( None, description="The manager identity's ID.\n", title='Managerid' ) @@ -1620,15 +1580,9 @@ class UpdateUserRequestSchema(BaseModel): title='Originid', ) name: Optional[str] = Field(None, description='Username\n', title='Name') - email: Optional[str] = Field( - None, description="User's email address.", title='Email' - ) - firstName: Optional[str] = Field( - None, description="User's first name\n", title='Firstname' - ) - lastName: Optional[str] = Field( - None, description="The user's last name.\n", title='Lastname' - ) + email: Optional[str] = Field(None, description="User's email address.", title='Email') + firstName: Optional[str] = Field(None, description="User's first name\n", title='Firstname') + lastName: Optional[str] = Field(None, description="The user's last name.\n", title='Lastname') status: Optional[UserStatus] = Field( None, description='User status must be: `Deleted`, `Disabled`, `Enabled`, `Staged`, `Suspended`, or `Unknown`.\n', @@ -1668,15 +1622,9 @@ class UserSchema(BaseModel): title='Originid', ) name: Optional[str] = Field(None, description='Username\n', title='Name') - email: Optional[str] = Field( - None, description="User's email address.", title='Email' - ) - firstName: Optional[str] = Field( - None, description="User's first name\n", title='Firstname' - ) - lastName: Optional[str] = Field( - None, description="The user's last name.\n", title='Lastname' - ) + email: Optional[str] = Field(None, description="User's email address.", title='Email') + firstName: Optional[str] = Field(None, description="User's first name\n", title='Firstname') + lastName: Optional[str] = Field(None, description="The user's last name.\n", title='Lastname') status: Optional[UserStatus] = Field( None, description='User status must be: `Deleted`, `Disabled`, `Enabled`, `Staged`, `Suspended`, or `Unknown`.\n', diff --git a/setup.py b/setup.py index be2a60d..ec1a7ba 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,9 @@ 'pyhamcrest~=2.0', 'pytest~=6.2', 'pytest-html~=2.1', + 'furl~=2.1.3', 'types-requests~=2.28.7', + 'aiohttp~=3.8.4', ], 'codegen': [ 'datamodel-code-generator~=0.11', diff --git a/tests/test_import.py b/tests/test_import.py index c1aa00e..600231b 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,5 +1,5 @@ """Make sure we have single test""" -from authomize.rest_api_client import Client +from authomize.rest_api_client.client.async_client import Client def test_import():