-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathauth.py
More file actions
66 lines (51 loc) · 2.12 KB
/
auth.py
File metadata and controls
66 lines (51 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Copyright (c) 2024 Airbyte, Inc., all rights reserved.
"""Authentication-related constants and utilities for the Airbyte Cloud."""
from airbyte import constants
from airbyte.secrets import SecretString
from airbyte.secrets.util import get_secret, try_get_secret
def resolve_cloud_bearer_token(
input_value: str | SecretString | None = None,
/,
) -> SecretString | None:
"""Get the Airbyte Cloud bearer token from the environment.
Unlike other resolve functions, this returns None if no bearer token is found,
since bearer token authentication is optional (client credentials can be used instead).
Args:
input_value: Optional explicit bearer token value. If provided, it will be
returned directly (wrapped in SecretString if needed).
Returns:
The bearer token as a SecretString, or None if not found.
"""
if input_value is not None:
return SecretString(input_value)
result = try_get_secret(constants.CLOUD_BEARER_TOKEN_ENV_VAR, default=None)
if result:
return SecretString(result)
return None
def resolve_cloud_client_secret(
input_value: str | SecretString | None = None,
/,
) -> SecretString:
"""Get the Airbyte Cloud client secret from the environment."""
return get_secret(constants.CLOUD_CLIENT_SECRET_ENV_VAR, default=input_value)
def resolve_cloud_client_id(
input_value: str | SecretString | None = None,
/,
) -> SecretString:
"""Get the Airbyte Cloud client ID from the environment."""
return get_secret(constants.CLOUD_CLIENT_ID_ENV_VAR, default=input_value)
def resolve_cloud_api_url(
input_value: str | None = None,
/,
) -> str:
"""Get the Airbyte Cloud API URL from the environment, or return the default."""
return str(
try_get_secret(constants.CLOUD_API_ROOT_ENV_VAR, default=input_value)
or constants.CLOUD_API_ROOT
)
def resolve_cloud_workspace_id(
input_value: str | None = None,
/,
) -> str:
"""Get the Airbyte Cloud workspace ID from the environment, or return None if not set."""
return str(get_secret(constants.CLOUD_WORKSPACE_ID_ENV_VAR, default=input_value))