from external_api.base.clients.notifications_client import NotificationsClient from external_api.base.clients.apollo_client import ApolloClient from external_api.base.clients.auth_strategies.delphi_auth_strategy import DelphiAuthStrategy, DelphiCredentials from external_api.base.clients.auth_strategies.legacy_apollo_auth_strategy import LegacyApolloAuthStrategy from external_api.base.clients.client import ApiClient, FivetranApiClient from external_api.base.clients.delphi_client import DelphiClient from external_api.base.clients.atlas_client import AtlasApiClient from external_api.base.clients.fivetran_client import FivetranClient from external_api.base.clients.auth_strategies.atlas_auth_strategy import AtlasCredentials, AtlasAuthStrategy from external_api.base.clients.auth_strategies.fivetran_auth_strategy import FivetranCredentials, FivetranAuthStrategy from config import ( APOLLO_API_DOMAIN, DELPHI_API_DOMAIN, DELPHI_API_CLIENT_ID, DELPHI_API_CLIENT_SECRET, APOLLO_M2M_TOKEN_DOMAIN, APOLLO_API_CLIENT_ID, APOLLO_API_CLIENT_SECRET, APOLLO_API_AUDIENCE, APOLLO_REDIS_TOKEN_KEY, APOLLO_TOKEN_CACHE_LIFESPAN, ATLAS_API_DOMAIN, ATLAS_API_CLIENT_ID, ATLAS_API_CLIENT_SECRET, ATLAS_API_AUDIENCE, ATLAS_API_VERSION, ATLAS_API_REDIS_TOKEN_KEY, ATLAS_API_TOKEN_CACHE_LIFESPAN, NOTIFICATIONS_API_DOMAIN, NOTIFICATIONS_API_CLIENT_ID, NOTIFICATIONS_API_CLIENT_SECRET, NOTIFICATIONS_API_AUDIENCE, NOTIFICATIONS_API_VERSION, NOTIFICATIONS_API_TOKEN_CACHE_LIFESPAN, NOTIFICATIONS_API_REDIS_TOKEN_KEY, FIVETRAN_API_DOMAIN, FIVETRAN_API_VERSION, FIVETRAN_API_CLIENT_ID, FIVETRAN_API_CLIENT_SECRET ) class ApiClientFactory: @staticmethod def legacy_apollo_api_client() -> ApolloClient: auth_strategy = LegacyApolloAuthStrategy() return ApolloClient(ApiClient(APOLLO_API_DOMAIN, auth_strategy)) @staticmethod def apollo_api_client() -> ApolloClient: auth_strategy_client = ApiClient(APOLLO_M2M_TOKEN_DOMAIN) credentials = AtlasCredentials( clientId=APOLLO_API_CLIENT_ID, clientSecret=APOLLO_API_CLIENT_SECRET, audience=APOLLO_API_AUDIENCE ) auth_strategy = AtlasAuthStrategy( client=auth_strategy_client, credentials=credentials, redis_token_key=APOLLO_REDIS_TOKEN_KEY, token_cache_lifespan=APOLLO_TOKEN_CACHE_LIFESPAN, ) return ApolloClient(ApiClient(APOLLO_API_DOMAIN, auth_strategy)) @staticmethod def delphi_client() -> DelphiClient: auth_strategy_client = ApiClient(DELPHI_API_DOMAIN) credentials = DelphiCredentials(clientId=DELPHI_API_CLIENT_ID, clientSecret=DELPHI_API_CLIENT_SECRET) auth_strategy = DelphiAuthStrategy(auth_strategy_client, credentials) return DelphiClient(ApiClient(DELPHI_API_DOMAIN, auth_strategy)) @staticmethod def atlas_api_client() -> AtlasApiClient: auth_strategy_client = ApiClient(ATLAS_API_DOMAIN) credentials = AtlasCredentials( clientId=ATLAS_API_CLIENT_ID, clientSecret=ATLAS_API_CLIENT_SECRET, audience=ATLAS_API_AUDIENCE ) auth_strategy = AtlasAuthStrategy( client=auth_strategy_client, credentials=credentials, redis_token_key=ATLAS_API_REDIS_TOKEN_KEY, token_cache_lifespan=ATLAS_API_TOKEN_CACHE_LIFESPAN, ) atlas_api_url = ATLAS_API_DOMAIN + ATLAS_API_VERSION return AtlasApiClient(ApiClient(atlas_api_url, auth_strategy)) @staticmethod def notifications_client(): auth_strategy_client = ApiClient(ATLAS_API_DOMAIN) credentials = AtlasCredentials( clientId=NOTIFICATIONS_API_CLIENT_ID, clientSecret=NOTIFICATIONS_API_CLIENT_SECRET, audience=NOTIFICATIONS_API_AUDIENCE, ) auth_strategy = AtlasAuthStrategy( client=auth_strategy_client, credentials=credentials, redis_token_key=NOTIFICATIONS_API_REDIS_TOKEN_KEY, token_cache_lifespan=NOTIFICATIONS_API_TOKEN_CACHE_LIFESPAN, ) notifications_api_url = NOTIFICATIONS_API_DOMAIN + NOTIFICATIONS_API_VERSION return NotificationsClient(ApiClient(notifications_api_url, auth_strategy)) @staticmethod def fivetran_client(): credentials = FivetranCredentials( clientId=FIVETRAN_API_CLIENT_ID, clientSecret=FIVETRAN_API_CLIENT_SECRET, ) auth_strategy = FivetranAuthStrategy( credentials=credentials, ) fivetran_api_url = FIVETRAN_API_DOMAIN + FIVETRAN_API_VERSION return FivetranClient(FivetranApiClient(fivetran_api_url, auth_strategy))