diff --git a/src/pipedream/client.py b/src/pipedream/client.py index 58505a9..bb9de62 100644 --- a/src/pipedream/client.py +++ b/src/pipedream/client.py @@ -1,5 +1,6 @@ # This file was auto-generated by Fern from our API Definition. +import os import typing import httpx @@ -8,6 +9,7 @@ from .app_categories.client import AppCategoriesClient, AsyncAppCategoriesClient from .apps.client import AppsClient, AsyncAppsClient from .components.client import AsyncComponentsClient, ComponentsClient +from .core.api_error import ApiError from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from .core.oauth_token_provider import OAuthTokenProvider from .deployed_triggers.client import AsyncDeployedTriggersClient, DeployedTriggersClient @@ -40,8 +42,8 @@ class Client: project_id : str x_pd_environment : typing.Optional[str] - client_id : str - client_secret : str + client_id : typing.Optional[str] + client_secret : typing.Optional[str] _token_getter_override : typing.Optional[typing.Callable[[], str]] timeout : typing.Optional[float] The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced. @@ -71,8 +73,8 @@ def __init__( environment: PipedreamEnvironment = PipedreamEnvironment.PROD, project_id: str, x_pd_environment: typing.Optional[str] = None, - client_id: str, - client_secret: str, + client_id: typing.Optional[str] = os.getenv("PIPEDREAM_CLIENT_ID"), + client_secret: typing.Optional[str] = os.getenv("PIPEDREAM_CLIENT_SECRET"), _token_getter_override: typing.Optional[typing.Callable[[], str]] = None, timeout: typing.Optional[float] = None, follow_redirects: typing.Optional[bool] = True, @@ -81,6 +83,14 @@ def __init__( _defaulted_timeout = ( timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read ) + if client_id is None: + raise ApiError( + body="The client must be instantiated be either passing in client_id or setting PIPEDREAM_CLIENT_ID" + ) + if client_secret is None: + raise ApiError( + body="The client must be instantiated be either passing in client_secret or setting PIPEDREAM_CLIENT_SECRET" + ) oauth_token_provider = OAuthTokenProvider( client_id=client_id, client_secret=client_secret, @@ -140,8 +150,8 @@ class AsyncClient: project_id : str x_pd_environment : typing.Optional[str] - client_id : str - client_secret : str + client_id : typing.Optional[str] + client_secret : typing.Optional[str] _token_getter_override : typing.Optional[typing.Callable[[], str]] timeout : typing.Optional[float] The timeout to be used, in seconds, for requests. By default the timeout is 60 seconds, unless a custom httpx client is used, in which case this default is not enforced. @@ -171,8 +181,8 @@ def __init__( environment: PipedreamEnvironment = PipedreamEnvironment.PROD, project_id: str, x_pd_environment: typing.Optional[str] = None, - client_id: str, - client_secret: str, + client_id: typing.Optional[str] = os.getenv("PIPEDREAM_CLIENT_ID"), + client_secret: typing.Optional[str] = os.getenv("PIPEDREAM_CLIENT_SECRET"), _token_getter_override: typing.Optional[typing.Callable[[], str]] = None, timeout: typing.Optional[float] = None, follow_redirects: typing.Optional[bool] = True, @@ -181,6 +191,14 @@ def __init__( _defaulted_timeout = ( timeout if timeout is not None else 60 if httpx_client is None else httpx_client.timeout.read ) + if client_id is None: + raise ApiError( + body="The client must be instantiated be either passing in client_id or setting PIPEDREAM_CLIENT_ID" + ) + if client_secret is None: + raise ApiError( + body="The client must be instantiated be either passing in client_secret or setting PIPEDREAM_CLIENT_SECRET" + ) oauth_token_provider = OAuthTokenProvider( client_id=client_id, client_secret=client_secret, diff --git a/src/pipedream/pipedream.py b/src/pipedream/pipedream.py index c6b0ccd..14b426f 100644 --- a/src/pipedream/pipedream.py +++ b/src/pipedream/pipedream.py @@ -18,12 +18,8 @@ def __init__( client_id: Optional[str] = None, client_secret: Optional[str] = None, ): - self.client_id = client_id or os.getenv("PIPEDREAM_CLIENT_ID") - self.client_secret = client_secret or os.getenv( - "PIPEDREAM_CLIENT_SECRET") - - if not self.client_id or not self.client_secret: - raise ValueError("OAuth client ID and secret are required") + self.client_id = client_id + self.client_secret = client_secret class Pipedream(Client): @@ -41,9 +37,6 @@ def __init__( if not project_id: raise ValueError("Project ID is required") - if not credentials.client_id or not credentials.client_secret: - raise ValueError("OAuth client ID and secret are required") - super().__init__( client_id=credentials.client_id, client_secret=credentials.client_secret, @@ -69,9 +62,6 @@ def __init__( if not project_id: raise ValueError("Project ID is required") - if not credentials.client_id or not credentials.client_secret: - raise ValueError("OAuth client ID and secret are required") - super().__init__( client_id=credentials.client_id, client_secret=credentials.client_secret,