-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathconfig.py
More file actions
57 lines (50 loc) · 2.47 KB
/
Copy pathconfig.py
File metadata and controls
57 lines (50 loc) · 2.47 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
import logging
import os
from typing import Callable, Optional, Union
from feldera.rest._helpers import requests_verify_from_env
from feldera.rest.retry import RetryConfig
# Either a static bearer (e.g. `"apikey:..."`, a long-lived JWT) or a
# zero-arg callable resolved per-request — covers OIDC workload-identity
# flows that mint short-lived tokens (Kubernetes projected SA token,
# GitHub Actions OIDC, Tailscale tsidp, ...).
ApiKey = Union[str, Callable[[], str]]
class Config:
"""
:class:`.FelderaClient` configuration, which includes authentication information
and the address of the Feldera API the client will interact with.
"""
def __init__(
self,
url: Optional[str] = None,
api_key: Optional[ApiKey] = None,
version: Optional[str] = None,
timeout: Optional[float] = None,
connection_timeout: Optional[float] = None,
requests_verify: Optional[bool | str] = None,
retry_config: Optional[RetryConfig] = None,
tenant: Optional[str] = None,
) -> None:
"""
See documentation of the `FelderaClient` constructor for the other arguments.
:param version: (Optional) Version of the API to use.
Default: `v0`.
:param retry_config: (Optional) Retry behavior for transient HTTP failures.
Default: `RetryConfig()` — 3 retries with exponential backoff starting at 2 seconds.
:param tenant: (Optional) Tenant to act in, sent as the `Feldera-Tenant`
header. A platform owner uses this to select any tenant (by name or
UUID); a regular user, to disambiguate among the tenants their token
authorizes. Default: the token's own/home tenant.
"""
self.url: str = url or os.environ.get("FELDERA_HOST") or "http://localhost:8080"
self.api_key: Optional[ApiKey] = api_key or os.environ.get("FELDERA_API_KEY")
self.version: str = version or "v0"
self.tenant: Optional[str] = tenant or os.environ.get("FELDERA_TENANT")
self.timeout: Optional[float] = timeout
self.connection_timeout: Optional[float] = connection_timeout
self.retry_config: RetryConfig = retry_config or RetryConfig()
env_verify = requests_verify_from_env()
self.requests_verify: bool | str = (
requests_verify if requests_verify is not None else env_verify
)
if self.requests_verify is False:
logging.warning("Feldera client: TLS verification is disabled!")