|
1 | 1 | # Webex BYODS Python SDK |
2 | 2 |
|
3 | 3 | Reusable Python utilities for managing Webex Bring Your Own Data Source (BYODS) |
4 | | -data sources. The SDK supports data source registration, retrieval, updates, |
5 | | -schema discovery, JWT claim inspection, service-app authentication, and data |
6 | | -source token extension. |
| 4 | +data sources. The SDK supports registration, retrieval, updates, schema |
| 5 | +discovery, JWT claim inspection, service-app authentication, and data source |
| 6 | +token extension. |
7 | 7 |
|
8 | | -This repository is the source of truth for the SDK. The companion CLI project |
9 | | -uses this package as a consumer. |
| 8 | +The SDK does not read credentials from files, environment variables, or cloud |
| 9 | +secret managers. The host application owns secret retrieval and provides an |
| 10 | +explicit token provider to the SDK. |
10 | 11 |
|
11 | 12 | ## Install |
12 | 13 |
|
13 | | -Until the package is published, install it directly from a local checkout: |
| 14 | +Until publication, install from a local checkout: |
14 | 15 |
|
15 | 16 | ```bash |
16 | 17 | python3 -m pip install -e . |
17 | 18 | ``` |
18 | 19 |
|
19 | | -Install AWS Secrets Manager support when running in Lambda or supplying a |
20 | | -secret name: |
| 20 | +## Authenticate |
21 | 21 |
|
22 | | -```bash |
23 | | -python3 -m pip install -e ".[aws]" |
24 | | -``` |
25 | | - |
26 | | -## Configure authentication |
| 22 | +For an already-issued service-app token, use a static provider: |
27 | 23 |
|
28 | | -Copy the safe template and provide service-app credentials plus a personal |
29 | | -token that can request service-app tokens: |
| 24 | +```python |
| 25 | +from webex_byods import StaticAccessTokenProvider, WebexDataSourceClient |
30 | 26 |
|
31 | | -```bash |
32 | | -cp token-config.json.template token-config.json |
| 27 | +client = WebexDataSourceClient( |
| 28 | + token_provider=StaticAccessTokenProvider("service-app-access-token") |
| 29 | +) |
33 | 30 | ``` |
34 | 31 |
|
35 | | -Do not commit `token-config.json`. |
36 | | - |
37 | | -## Use the SDK |
| 32 | +For automatic service-app token acquisition, the host application supplies |
| 33 | +credentials and a personal-token provider. It can obtain those values from its |
| 34 | +own configuration, AWS Secrets Manager, or another secret system. |
38 | 35 |
|
39 | 36 | ```python |
40 | | -from webex_byods import TokenManager, WebexDataSourceManager |
41 | | - |
42 | | -token_manager = TokenManager(config_path="token-config.json") |
43 | | -client = WebexDataSourceManager( |
44 | | - token_manager.get_service_app_token(), token_manager=token_manager |
| 37 | +from webex_byods import ( |
| 38 | + ServiceAppCredentials, |
| 39 | + StaticAccessTokenProvider, |
| 40 | + WebexDataSourceClient, |
| 41 | + WebexServiceAppTokenProvider, |
45 | 42 | ) |
46 | 43 |
|
47 | | -data_sources = client.list_all_data_sources() |
48 | | -schemas = client.get_data_source_schemas() |
| 44 | +credentials = ServiceAppCredentials( |
| 45 | + app_id="service-app-id", |
| 46 | + client_id="service-app-client-id", |
| 47 | + client_secret="service-app-client-secret", |
| 48 | + target_org_id="target-org-id", |
| 49 | +) |
| 50 | +service_token_provider = WebexServiceAppTokenProvider( |
| 51 | + credentials, |
| 52 | + StaticAccessTokenProvider("personal-access-token"), |
| 53 | +) |
| 54 | +client = WebexDataSourceClient(token_provider=service_token_provider) |
49 | 55 | ``` |
50 | 56 |
|
51 | | -BYODS API operations preserve a dictionary result contract containing |
52 | | -`success`, `data` or `error`, and `status_code`. If a data-source API request |
53 | | -returns HTTP 401, the client obtains a fresh service-app token and retries the |
54 | | -request once. |
| 57 | +`OAuthRefreshTokenProvider` is available when the host application manages an |
| 58 | +OAuth refresh token. Providers use `InMemoryTokenStore` by default; applications |
| 59 | +that need persistence can supply their own `TokenStore` implementation. |
55 | 60 |
|
56 | | -To rotate a data source nonce and obtain a fresh JWS token: |
| 61 | +## Use the client |
57 | 62 |
|
58 | 63 | ```python |
59 | | -result = token_manager.extend_data_source_token( |
| 64 | +data_sources = client.list_all_data_sources() |
| 65 | +schemas = client.get_data_source_schemas() |
| 66 | + |
| 67 | +result = client.extend_data_source_token( |
60 | 68 | data_source_id="data-source-id", |
61 | 69 | token_lifetime_minutes=1440, |
62 | 70 | ) |
63 | 71 | ``` |
64 | 72 |
|
| 73 | +BYODS API operations return dictionaries containing `success`, `data` or |
| 74 | +`error`, and `status_code`. A 401 response causes one retry with |
| 75 | +`token_provider.get_access_token(force_refresh=True)`. |
| 76 | + |
| 77 | +`WebexDataSourceManager` remains an alias for `WebexDataSourceClient` during |
| 78 | +the transition. `TokenManager` is deprecated; use |
| 79 | +`WebexServiceAppTokenProvider` instead. |
| 80 | + |
65 | 81 | ## Development |
66 | 82 |
|
67 | 83 | ```bash |
68 | | -python3 -m pip install -e ".[aws]" |
69 | | -python3 -m pip install pytest ruff |
| 84 | +python3 -m pip install -e ".[dev]" |
70 | 85 | python3 -m pytest -q |
71 | 86 | ruff check . |
72 | 87 | ``` |
|
0 commit comments