airbyte.cloud.client_config

Cloud client configuration for Airbyte Cloud API authentication.

This module provides the CloudClientConfig class for managing authentication credentials and API configuration when connecting to Airbyte Cloud, OSS, or Enterprise instances.

Two authentication methods are supported (mutually exclusive):

  1. OAuth2 client credentials (client_id + client_secret)
  2. Bearer token authentication
Example usage with client credentials:
from airbyte.cloud.client_config import CloudClientConfig

config = CloudClientConfig(
    client_id="your-client-id",
    client_secret="your-client-secret",
)
Example usage with bearer token:
from airbyte.cloud.client_config import CloudClientConfig

config = CloudClientConfig(
    bearer_token="your-bearer-token",
)
Example using environment variables:
from airbyte.cloud.client_config import CloudClientConfig

# Resolves from AIRBYTE_CLOUD_CLIENT_ID, AIRBYTE_CLOUD_CLIENT_SECRET,
# AIRBYTE_CLOUD_BEARER_TOKEN, and AIRBYTE_CLOUD_API_URL environment variables
config = CloudClientConfig.from_env()
  1# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
  2"""Cloud client configuration for Airbyte Cloud API authentication.
  3
  4This module provides the CloudClientConfig class for managing authentication
  5credentials and API configuration when connecting to Airbyte Cloud, OSS, or
  6Enterprise instances.
  7
  8Two authentication methods are supported (mutually exclusive):
  91. OAuth2 client credentials (client_id + client_secret)
 102. Bearer token authentication
 11
 12Example usage with client credentials:
 13    ```python
 14    from airbyte.cloud.client_config import CloudClientConfig
 15
 16    config = CloudClientConfig(
 17        client_id="your-client-id",
 18        client_secret="your-client-secret",
 19    )
 20    ```
 21
 22Example usage with bearer token:
 23    ```python
 24    from airbyte.cloud.client_config import CloudClientConfig
 25
 26    config = CloudClientConfig(
 27        bearer_token="your-bearer-token",
 28    )
 29    ```
 30
 31Example using environment variables:
 32    ```python
 33    from airbyte.cloud.client_config import CloudClientConfig
 34
 35    # Resolves from AIRBYTE_CLOUD_CLIENT_ID, AIRBYTE_CLOUD_CLIENT_SECRET,
 36    # AIRBYTE_CLOUD_BEARER_TOKEN, and AIRBYTE_CLOUD_API_URL environment variables
 37    config = CloudClientConfig.from_env()
 38    ```
 39"""
 40
 41from __future__ import annotations
 42
 43from dataclasses import dataclass
 44
 45from airbyte._util import api_util
 46from airbyte.cloud.auth import (
 47    resolve_cloud_api_url,
 48    resolve_cloud_bearer_token,
 49    resolve_cloud_client_id,
 50    resolve_cloud_client_secret,
 51)
 52from airbyte.exceptions import PyAirbyteInputError
 53from airbyte.secrets.base import SecretString
 54
 55
 56@dataclass
 57class CloudClientConfig:
 58    """Client configuration for Airbyte Cloud API.
 59
 60    This class encapsulates the authentication and API configuration needed to connect
 61    to Airbyte Cloud, OSS, or Enterprise instances. It supports two mutually
 62    exclusive authentication methods:
 63
 64    1. OAuth2 client credentials flow (client_id + client_secret)
 65    2. Bearer token authentication
 66
 67    Exactly one authentication method must be provided. Providing both or neither
 68    will raise a validation error.
 69
 70    Attributes:
 71        client_id: OAuth2 client ID for client credentials flow.
 72        client_secret: OAuth2 client secret for client credentials flow.
 73        bearer_token: Pre-generated bearer token for direct authentication.
 74        api_root: The API root URL. Defaults to Airbyte Cloud API.
 75    """
 76
 77    client_id: SecretString | None = None
 78    """OAuth2 client ID for client credentials authentication."""
 79
 80    client_secret: SecretString | None = None
 81    """OAuth2 client secret for client credentials authentication."""
 82
 83    bearer_token: SecretString | None = None
 84    """Bearer token for direct authentication (alternative to client credentials)."""
 85
 86    api_root: str = api_util.CLOUD_API_ROOT
 87    """The API root URL. Defaults to Airbyte Cloud API."""
 88
 89    def __post_init__(self) -> None:
 90        """Validate credentials and ensure secrets are properly wrapped."""
 91        # Wrap secrets in SecretString if they aren't already
 92        if self.client_id is not None:
 93            self.client_id = SecretString(self.client_id)
 94        if self.client_secret is not None:
 95            self.client_secret = SecretString(self.client_secret)
 96        if self.bearer_token is not None:
 97            self.bearer_token = SecretString(self.bearer_token)
 98
 99        # Validate mutual exclusivity
100        has_client_credentials = self.client_id is not None or self.client_secret is not None
101        has_bearer_token = self.bearer_token is not None
102
103        if has_client_credentials and has_bearer_token:
104            raise PyAirbyteInputError(
105                message="Cannot use both client credentials and bearer token authentication.",
106                guidance=(
107                    "Provide either client_id and client_secret together, "
108                    "or bearer_token alone, but not both."
109                ),
110            )
111
112        if has_client_credentials and (self.client_id is None or self.client_secret is None):
113            # If using client credentials, both must be provided
114            raise PyAirbyteInputError(
115                message="Incomplete client credentials.",
116                guidance=(
117                    "When using client credentials authentication, "
118                    "both client_id and client_secret must be provided."
119                ),
120            )
121
122        if not has_client_credentials and not has_bearer_token:
123            raise PyAirbyteInputError(
124                message="No authentication credentials provided.",
125                guidance=(
126                    "Provide either client_id and client_secret together for OAuth2 "
127                    "client credentials flow, or bearer_token for direct authentication."
128                ),
129            )
130
131    @property
132    def uses_bearer_token(self) -> bool:
133        """Return True if using bearer token authentication."""
134        return self.bearer_token is not None
135
136    @property
137    def uses_client_credentials(self) -> bool:
138        """Return True if using client credentials authentication."""
139        return self.client_id is not None and self.client_secret is not None
140
141    @classmethod
142    def from_env(
143        cls,
144        *,
145        api_root: str | None = None,
146    ) -> CloudClientConfig:
147        """Create CloudClientConfig from environment variables.
148
149        This factory method resolves credentials from environment variables,
150        providing a convenient way to create credentials without explicitly
151        passing secrets.
152
153        Environment variables used:
154            - `AIRBYTE_CLOUD_CLIENT_ID`: OAuth client ID (for client credentials flow).
155            - `AIRBYTE_CLOUD_CLIENT_SECRET`: OAuth client secret (for client credentials flow).
156            - `AIRBYTE_CLOUD_BEARER_TOKEN`: Bearer token (alternative to client credentials).
157            - `AIRBYTE_CLOUD_API_URL`: Optional. The API root URL (defaults to Airbyte Cloud).
158
159        The method will first check for a bearer token. If not found, it will
160        attempt to use client credentials.
161
162        Args:
163            api_root: The API root URL. If not provided, will be resolved from
164                the `AIRBYTE_CLOUD_API_URL` environment variable, or default to
165                the Airbyte Cloud API.
166
167        Returns:
168            A CloudClientConfig instance configured with credentials from the environment.
169
170        Raises:
171            PyAirbyteSecretNotFoundError: If required credentials are not found in
172                the environment.
173        """
174        resolved_api_root = resolve_cloud_api_url(api_root)
175
176        # Try bearer token first
177        bearer_token = resolve_cloud_bearer_token()
178        if bearer_token:
179            return cls(
180                bearer_token=bearer_token,
181                api_root=resolved_api_root,
182            )
183
184        # Fall back to client credentials
185        return cls(
186            client_id=resolve_cloud_client_id(),
187            client_secret=resolve_cloud_client_secret(),
188            api_root=resolved_api_root,
189        )
@dataclass
class CloudClientConfig:
 57@dataclass
 58class CloudClientConfig:
 59    """Client configuration for Airbyte Cloud API.
 60
 61    This class encapsulates the authentication and API configuration needed to connect
 62    to Airbyte Cloud, OSS, or Enterprise instances. It supports two mutually
 63    exclusive authentication methods:
 64
 65    1. OAuth2 client credentials flow (client_id + client_secret)
 66    2. Bearer token authentication
 67
 68    Exactly one authentication method must be provided. Providing both or neither
 69    will raise a validation error.
 70
 71    Attributes:
 72        client_id: OAuth2 client ID for client credentials flow.
 73        client_secret: OAuth2 client secret for client credentials flow.
 74        bearer_token: Pre-generated bearer token for direct authentication.
 75        api_root: The API root URL. Defaults to Airbyte Cloud API.
 76    """
 77
 78    client_id: SecretString | None = None
 79    """OAuth2 client ID for client credentials authentication."""
 80
 81    client_secret: SecretString | None = None
 82    """OAuth2 client secret for client credentials authentication."""
 83
 84    bearer_token: SecretString | None = None
 85    """Bearer token for direct authentication (alternative to client credentials)."""
 86
 87    api_root: str = api_util.CLOUD_API_ROOT
 88    """The API root URL. Defaults to Airbyte Cloud API."""
 89
 90    def __post_init__(self) -> None:
 91        """Validate credentials and ensure secrets are properly wrapped."""
 92        # Wrap secrets in SecretString if they aren't already
 93        if self.client_id is not None:
 94            self.client_id = SecretString(self.client_id)
 95        if self.client_secret is not None:
 96            self.client_secret = SecretString(self.client_secret)
 97        if self.bearer_token is not None:
 98            self.bearer_token = SecretString(self.bearer_token)
 99
100        # Validate mutual exclusivity
101        has_client_credentials = self.client_id is not None or self.client_secret is not None
102        has_bearer_token = self.bearer_token is not None
103
104        if has_client_credentials and has_bearer_token:
105            raise PyAirbyteInputError(
106                message="Cannot use both client credentials and bearer token authentication.",
107                guidance=(
108                    "Provide either client_id and client_secret together, "
109                    "or bearer_token alone, but not both."
110                ),
111            )
112
113        if has_client_credentials and (self.client_id is None or self.client_secret is None):
114            # If using client credentials, both must be provided
115            raise PyAirbyteInputError(
116                message="Incomplete client credentials.",
117                guidance=(
118                    "When using client credentials authentication, "
119                    "both client_id and client_secret must be provided."
120                ),
121            )
122
123        if not has_client_credentials and not has_bearer_token:
124            raise PyAirbyteInputError(
125                message="No authentication credentials provided.",
126                guidance=(
127                    "Provide either client_id and client_secret together for OAuth2 "
128                    "client credentials flow, or bearer_token for direct authentication."
129                ),
130            )
131
132    @property
133    def uses_bearer_token(self) -> bool:
134        """Return True if using bearer token authentication."""
135        return self.bearer_token is not None
136
137    @property
138    def uses_client_credentials(self) -> bool:
139        """Return True if using client credentials authentication."""
140        return self.client_id is not None and self.client_secret is not None
141
142    @classmethod
143    def from_env(
144        cls,
145        *,
146        api_root: str | None = None,
147    ) -> CloudClientConfig:
148        """Create CloudClientConfig from environment variables.
149
150        This factory method resolves credentials from environment variables,
151        providing a convenient way to create credentials without explicitly
152        passing secrets.
153
154        Environment variables used:
155            - `AIRBYTE_CLOUD_CLIENT_ID`: OAuth client ID (for client credentials flow).
156            - `AIRBYTE_CLOUD_CLIENT_SECRET`: OAuth client secret (for client credentials flow).
157            - `AIRBYTE_CLOUD_BEARER_TOKEN`: Bearer token (alternative to client credentials).
158            - `AIRBYTE_CLOUD_API_URL`: Optional. The API root URL (defaults to Airbyte Cloud).
159
160        The method will first check for a bearer token. If not found, it will
161        attempt to use client credentials.
162
163        Args:
164            api_root: The API root URL. If not provided, will be resolved from
165                the `AIRBYTE_CLOUD_API_URL` environment variable, or default to
166                the Airbyte Cloud API.
167
168        Returns:
169            A CloudClientConfig instance configured with credentials from the environment.
170
171        Raises:
172            PyAirbyteSecretNotFoundError: If required credentials are not found in
173                the environment.
174        """
175        resolved_api_root = resolve_cloud_api_url(api_root)
176
177        # Try bearer token first
178        bearer_token = resolve_cloud_bearer_token()
179        if bearer_token:
180            return cls(
181                bearer_token=bearer_token,
182                api_root=resolved_api_root,
183            )
184
185        # Fall back to client credentials
186        return cls(
187            client_id=resolve_cloud_client_id(),
188            client_secret=resolve_cloud_client_secret(),
189            api_root=resolved_api_root,
190        )

Client configuration for Airbyte Cloud API.

This class encapsulates the authentication and API configuration needed to connect to Airbyte Cloud, OSS, or Enterprise instances. It supports two mutually exclusive authentication methods:

  1. OAuth2 client credentials flow (client_id + client_secret)
  2. Bearer token authentication

Exactly one authentication method must be provided. Providing both or neither will raise a validation error.

Attributes:
  • client_id: OAuth2 client ID for client credentials flow.
  • client_secret: OAuth2 client secret for client credentials flow.
  • bearer_token: Pre-generated bearer token for direct authentication.
  • api_root: The API root URL. Defaults to Airbyte Cloud API.
CloudClientConfig( client_id: airbyte.secrets.SecretString | None = None, client_secret: airbyte.secrets.SecretString | None = None, bearer_token: airbyte.secrets.SecretString | None = None, api_root: str = 'https://api.airbyte.com/v1')
client_id: airbyte.secrets.SecretString | None = None

OAuth2 client ID for client credentials authentication.

client_secret: airbyte.secrets.SecretString | None = None

OAuth2 client secret for client credentials authentication.

bearer_token: airbyte.secrets.SecretString | None = None

Bearer token for direct authentication (alternative to client credentials).

api_root: str = 'https://api.airbyte.com/v1'

The API root URL. Defaults to Airbyte Cloud API.

uses_bearer_token: bool
132    @property
133    def uses_bearer_token(self) -> bool:
134        """Return True if using bearer token authentication."""
135        return self.bearer_token is not None

Return True if using bearer token authentication.

uses_client_credentials: bool
137    @property
138    def uses_client_credentials(self) -> bool:
139        """Return True if using client credentials authentication."""
140        return self.client_id is not None and self.client_secret is not None

Return True if using client credentials authentication.

@classmethod
def from_env( cls, *, api_root: str | None = None) -> CloudClientConfig:
142    @classmethod
143    def from_env(
144        cls,
145        *,
146        api_root: str | None = None,
147    ) -> CloudClientConfig:
148        """Create CloudClientConfig from environment variables.
149
150        This factory method resolves credentials from environment variables,
151        providing a convenient way to create credentials without explicitly
152        passing secrets.
153
154        Environment variables used:
155            - `AIRBYTE_CLOUD_CLIENT_ID`: OAuth client ID (for client credentials flow).
156            - `AIRBYTE_CLOUD_CLIENT_SECRET`: OAuth client secret (for client credentials flow).
157            - `AIRBYTE_CLOUD_BEARER_TOKEN`: Bearer token (alternative to client credentials).
158            - `AIRBYTE_CLOUD_API_URL`: Optional. The API root URL (defaults to Airbyte Cloud).
159
160        The method will first check for a bearer token. If not found, it will
161        attempt to use client credentials.
162
163        Args:
164            api_root: The API root URL. If not provided, will be resolved from
165                the `AIRBYTE_CLOUD_API_URL` environment variable, or default to
166                the Airbyte Cloud API.
167
168        Returns:
169            A CloudClientConfig instance configured with credentials from the environment.
170
171        Raises:
172            PyAirbyteSecretNotFoundError: If required credentials are not found in
173                the environment.
174        """
175        resolved_api_root = resolve_cloud_api_url(api_root)
176
177        # Try bearer token first
178        bearer_token = resolve_cloud_bearer_token()
179        if bearer_token:
180            return cls(
181                bearer_token=bearer_token,
182                api_root=resolved_api_root,
183            )
184
185        # Fall back to client credentials
186        return cls(
187            client_id=resolve_cloud_client_id(),
188            client_secret=resolve_cloud_client_secret(),
189            api_root=resolved_api_root,
190        )

Create CloudClientConfig from environment variables.

This factory method resolves credentials from environment variables, providing a convenient way to create credentials without explicitly passing secrets.

Environment variables used:
  • AIRBYTE_CLOUD_CLIENT_ID: OAuth client ID (for client credentials flow).
  • AIRBYTE_CLOUD_CLIENT_SECRET: OAuth client secret (for client credentials flow).
  • AIRBYTE_CLOUD_BEARER_TOKEN: Bearer token (alternative to client credentials).
  • AIRBYTE_CLOUD_API_URL: Optional. The API root URL (defaults to Airbyte Cloud).

The method will first check for a bearer token. If not found, it will attempt to use client credentials.

Arguments:
  • api_root: The API root URL. If not provided, will be resolved from the AIRBYTE_CLOUD_API_URL environment variable, or default to the Airbyte Cloud API.
Returns:

A CloudClientConfig instance configured with credentials from the environment.

Raises:
  • PyAirbyteSecretNotFoundError: If required credentials are not found in the environment.