|
1 | 1 | import typing |
| 2 | +from collections.abc import Callable |
2 | 3 |
|
3 | | -_config: dict[str, typing.Any] = { |
| 4 | +_static_config: dict[str, str | None] = { |
4 | 5 | "data_api_root_url": None, |
5 | 6 | "api_key": None, |
6 | 7 | } |
7 | 8 |
|
| 9 | +_config_provider: Callable[[], dict[str, str | None]] | None = None |
| 10 | + |
8 | 11 |
|
9 | 12 | def configure(data_api_root_url: str, api_key: str) -> None: |
10 | | - """Configure the Bubble Data API client.""" |
11 | | - _config["data_api_root_url"] = data_api_root_url |
12 | | - _config["api_key"] = api_key |
| 13 | + """Configure the Bubble Data API client with static values.""" |
| 14 | + global _config_provider |
| 15 | + _config_provider = None |
| 16 | + _static_config["data_api_root_url"] = data_api_root_url |
| 17 | + _static_config["api_key"] = api_key |
| 18 | + |
| 19 | + |
| 20 | +def set_config_provider(provider: Callable[[], dict[str, str | None]]) -> None: |
| 21 | + """Set a provider function for dynamic configuration.""" |
| 22 | + global _config_provider |
| 23 | + _config_provider = provider |
13 | 24 |
|
14 | 25 |
|
15 | 26 | def get_config() -> typing.Mapping[str, str | None]: |
16 | | - """Get the current configuration.""" |
17 | | - return _config |
| 27 | + """Get current configuration from provider if set, otherwise static config.""" |
| 28 | + if _config_provider is not None: |
| 29 | + return _config_provider() |
| 30 | + return _static_config |
0 commit comments