Skip to content

Commit f1f18d7

Browse files
mrm9084VenkataAnilKumar
authored andcommitted
App Configuration Provider Move load (#46370)
* Move load to it's own file * moving helper methods to utils * reorginizing tests * readding after merge * copilot review comments
1 parent 1237121 commit f1f18d7

13 files changed

Lines changed: 839 additions & 761 deletions

sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Licensed under the MIT License. See License.txt in the project root for
44
# license information.
55
# -------------------------------------------------------------------------
6-
7-
from ._azureappconfigurationprovider import load, AzureAppConfigurationProvider
6+
from ._load import load
7+
from ._azureappconfigurationprovider import AzureAppConfigurationProvider
88
from ._models import (
99
AzureAppConfigurationKeyVaultOptions,
1010
SettingSelector,

sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azureappconfigurationprovider.py

Lines changed: 3 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
Dict,
1313
Mapping,
1414
Optional,
15-
overload,
1615
List,
1716
Tuple,
1817
)
@@ -23,199 +22,22 @@
2322
)
2423
from azure.core.credentials import TokenCredential
2524
from azure.core.exceptions import AzureError, HttpResponseError
26-
from ._models import AzureAppConfigurationKeyVaultOptions, SettingSelector
2725
from ._key_vault._secret_provider import SecretProvider
2826
from ._constants import (
2927
FEATURE_MANAGEMENT_KEY,
3028
FEATURE_FLAG_KEY,
3129
DEFAULT_STARTUP_TIMEOUT,
3230
SNAPSHOT_REF_CONTENT_TYPE,
3331
)
34-
from ._azureappconfigurationproviderbase import (
35-
AzureAppConfigurationProviderBase,
36-
delay_failure,
37-
process_load_parameters,
38-
sdk_allowed_kwargs,
39-
_get_startup_backoff,
40-
)
32+
from ._azureappconfigurationproviderbase import AzureAppConfigurationProviderBase
4133
from ._client_manager import ConfigurationClientManager, _ConfigurationClientWrapper as ConfigurationClient
4234
from ._user_agent import USER_AGENT
35+
from ._utils import get_startup_backoff
4336

4437
JSON = Mapping[str, Any]
4538
logger = logging.getLogger(__name__)
4639

4740

48-
@overload
49-
def load( # pylint: disable=docstring-keyword-should-match-keyword-only
50-
endpoint: str,
51-
credential: "TokenCredential",
52-
*,
53-
selects: Optional[List[SettingSelector]] = None,
54-
trim_prefixes: Optional[List[str]] = None,
55-
keyvault_credential: Optional["TokenCredential"] = None,
56-
keyvault_client_configs: Optional[Mapping[str, JSON]] = None,
57-
secret_resolver: Optional[Callable[[str], str]] = None,
58-
key_vault_options: Optional[AzureAppConfigurationKeyVaultOptions] = None,
59-
refresh_on: Optional[List[Tuple[str, str]]] = None,
60-
refresh_interval: int = 30,
61-
refresh_enabled: Optional[bool] = None,
62-
on_refresh_success: Optional[Callable] = None,
63-
on_refresh_error: Optional[Callable[[Exception], None]] = None,
64-
feature_flag_enabled: bool = False,
65-
feature_flag_selectors: Optional[List[SettingSelector]] = None,
66-
feature_flag_refresh_enabled: bool = False,
67-
startup_timeout: int = DEFAULT_STARTUP_TIMEOUT,
68-
**kwargs,
69-
) -> "AzureAppConfigurationProvider":
70-
"""
71-
Loads configuration settings from Azure App Configuration into a Python application.
72-
73-
:param str endpoint: Endpoint for App Configuration resource.
74-
:param ~azure.core.credentials.TokenCredential credential: Credential for App Configuration resource.
75-
:keyword Optional[List[~azure.appconfiguration.provider.SettingSelector]] selects: List of setting selectors to
76-
filter configuration settings
77-
:keyword Optional[List[str]] trim_prefixes: List of prefixes to trim from configuration keys
78-
:keyword ~azure.core.credentials.TokenCredential keyvault_credential: A credential for authenticating with the key
79-
vault. This is optional if keyvault_client_configs is provided.
80-
:keyword Mapping[str, Mapping] keyvault_client_configs: A Mapping of SecretClient endpoints to client
81-
configurations from azure-keyvault-secrets. This is optional if keyvault_credential is provided. If a credential
82-
isn't provided a credential will need to be in each set for each.
83-
:keyword Callable[[str], str] secret_resolver: A function that takes a URI and returns a value.
84-
:keyword List[Tuple[str, str]] refresh_on: One or more settings whose modification will trigger a full refresh
85-
after a fixed interval. This should be a list of Key-Label pairs for specific settings (filters and wildcards are
86-
not supported).
87-
:keyword int refresh_interval: The minimum time in seconds between when a call to `refresh` will actually trigger a
88-
service call to update the settings. Default value is 30 seconds.
89-
:keyword refresh_enabled: Optional flag to enable or disable refreshing of configuration settings. Defaults to
90-
True if ``refresh_on`` is set, otherwise False.
91-
:paramtype refresh_enabled: Optional[bool]
92-
:keyword on_refresh_success: Optional callback to be invoked when a change is found and a successful refresh has
93-
happened.
94-
:paramtype on_refresh_success: Optional[Callable]
95-
:keyword on_refresh_error: Optional callback to be invoked when an error occurs while refreshing settings. If not
96-
specified, errors will be raised.
97-
:paramtype on_refresh_error: Optional[Callable[[Exception], None]]
98-
:keyword feature_flag_enabled: Optional flag to enable or disable the loading of feature flags. Default is False.
99-
:paramtype feature_flag_enabled: bool
100-
:keyword feature_flag_selectors: Optional list of selectors to filter feature flags. By default will load all
101-
feature flags without a label.
102-
:paramtype feature_flag_selectors: List[SettingSelector]
103-
:keyword feature_flag_refresh_enabled: Optional flag to enable or disable the refresh of feature flags. Default is
104-
False.
105-
:paramtype feature_flag_refresh_enabled: bool
106-
:keyword replica_discovery_enabled: Optional flag to enable or disable the discovery of replica endpoints. Default
107-
is True.
108-
:paramtype replica_discovery_enabled: bool
109-
:keyword load_balancing_enabled: Optional flag to enable or disable the load balancing of replica endpoints. Default
110-
is False.
111-
:paramtype load_balancing_enabled: bool
112-
:keyword configuration_mapper: Optional function to map configuration settings. Enables transformation of
113-
configurations before they are added to the provider.
114-
:paramtype configuration_mapper: Optional[Callable[[ConfigurationSetting], None]]
115-
:keyword startup_timeout: The amount of time in seconds allowed to load data from Azure App Configuration on
116-
startup. The default value is 100 seconds.
117-
:paramtype startup_timeout: int
118-
"""
119-
120-
121-
@overload
122-
def load( # pylint: disable=docstring-keyword-should-match-keyword-only
123-
*,
124-
connection_string: str,
125-
selects: Optional[List[SettingSelector]] = None,
126-
trim_prefixes: Optional[List[str]] = None,
127-
keyvault_credential: Optional["TokenCredential"] = None,
128-
keyvault_client_configs: Optional[Mapping[str, JSON]] = None,
129-
secret_resolver: Optional[Callable[[str], str]] = None,
130-
key_vault_options: Optional[AzureAppConfigurationKeyVaultOptions] = None,
131-
refresh_on: Optional[List[Tuple[str, str]]] = None,
132-
refresh_interval: int = 30,
133-
refresh_enabled: Optional[bool] = None,
134-
on_refresh_success: Optional[Callable] = None,
135-
on_refresh_error: Optional[Callable[[Exception], None]] = None,
136-
feature_flag_enabled: bool = False,
137-
feature_flag_selectors: Optional[List[SettingSelector]] = None,
138-
feature_flag_refresh_enabled: bool = False,
139-
startup_timeout: int = DEFAULT_STARTUP_TIMEOUT,
140-
**kwargs,
141-
) -> "AzureAppConfigurationProvider":
142-
"""
143-
Loads configuration settings from Azure App Configuration into a Python application.
144-
145-
:keyword str connection_string: Connection string for App Configuration resource.
146-
:keyword Optional[List[~azure.appconfiguration.provider.SettingSelector]] selects: List of setting selectors to
147-
filter configuration settings
148-
:keyword trim_prefixes: Optional[List[str]] trim_prefixes: List of prefixes to trim from configuration keys
149-
:keyword ~azure.core.credentials.TokenCredential keyvault_credential: A credential for authenticating with the key
150-
vault. This is optional if keyvault_client_configs is provided.
151-
:keyword Mapping[str, Mapping] keyvault_client_configs: A Mapping of SecretClient endpoints to client
152-
configurations from azure-keyvault-secrets. This is optional if keyvault_credential is provided. If a credential
153-
isn't provided a credential will need to be in each set for each.
154-
:keyword Callable[[str], str] secret_resolver: A function that takes a URI and returns a value.
155-
:keyword List[Tuple[str, str]] refresh_on: One or more settings whose modification will trigger a full refresh
156-
after a fixed interval. This should be a list of Key-Label pairs for specific settings (filters and wildcards are
157-
not supported).
158-
:keyword refresh_on: One or more settings whose modification will trigger a full refresh after a fixed interval.
159-
This should be a list of Key-Label pairs for specific settings (filters and wildcards are not supported).
160-
:paramtype refresh_on: List[Tuple[str, str]]
161-
:keyword int refresh_interval: The minimum time in seconds between when a call to `refresh` will actually trigger a
162-
service call to update the settings. Default value is 30 seconds.
163-
:keyword refresh_enabled: Optional flag to enable or disable refreshing of configuration settings. Defaults to
164-
True if ``refresh_on`` is set, otherwise False.
165-
:paramtype refresh_enabled: Optional[bool]
166-
:keyword on_refresh_success: Optional callback to be invoked when a change is found and a successful refresh has
167-
happened.
168-
:paramtype on_refresh_success: Optional[Callable]
169-
:keyword on_refresh_error: Optional callback to be invoked when an error occurs while refreshing settings. If not
170-
specified, errors will be raised.
171-
:paramtype on_refresh_error: Optional[Callable[[Exception], None]]
172-
:keyword feature_flag_enabled: Optional flag to enable or disable the loading of feature flags. Default is False.
173-
:paramtype feature_flag_enabled: bool
174-
:keyword feature_flag_selectors: Optional list of selectors to filter feature flags. By default will load all
175-
feature flags without a label.
176-
:paramtype feature_flag_selectors: List[SettingSelector]
177-
:keyword feature_flag_refresh_enabled: Optional flag to enable or disable the refresh of feature flags. Default is
178-
False.
179-
:paramtype feature_flag_refresh_enabled: bool
180-
:keyword replica_discovery_enabled: Optional flag to enable or disable the discovery of replica endpoints. Default
181-
is True.
182-
:paramtype replica_discovery_enabled: bool
183-
:keyword load_balancing_enabled: Optional flag to enable or disable the load balancing of replica endpoints. Default
184-
is False.
185-
:paramtype load_balancing_enabled: bool
186-
:keyword configuration_mapper: Optional function to map configuration settings. Enables transformation of
187-
configurations before they are added to the provider.
188-
:paramtype configuration_mapper: Optional[Callable[[ConfigurationSetting], None]]
189-
:keyword startup_timeout: The amount of time in seconds allowed to load data from Azure App Configuration on
190-
startup. The default value is 100 seconds.
191-
:paramtype startup_timeout: int
192-
"""
193-
194-
195-
def load(*args, **kwargs) -> "AzureAppConfigurationProvider":
196-
start_time = datetime.datetime.now()
197-
198-
# Process common load parameters using shared logic
199-
params = process_load_parameters(*args, **kwargs)
200-
201-
provider = _buildprovider(
202-
params["connection_string"],
203-
params["endpoint"],
204-
params["credential"],
205-
uses_key_vault=params["uses_key_vault"],
206-
startup_timeout=params["startup_timeout"],
207-
**params["kwargs"],
208-
)
209-
kwargs = sdk_allowed_kwargs(params["kwargs"])
210-
211-
try:
212-
provider._load_all(**kwargs) # pylint:disable=protected-access
213-
except Exception as e:
214-
delay_failure(start_time)
215-
raise e
216-
return provider
217-
218-
21941
def _buildprovider(
22042
connection_string: Optional[str], endpoint: Optional[str], credential: Optional[TokenCredential], **kwargs
22143
) -> "AzureAppConfigurationProvider":
@@ -407,7 +229,7 @@ def _load_all(self, **kwargs: Any) -> None:
407229

408230
# Calculate delay before next retry attempt
409231
elapsed_seconds = (datetime.datetime.now() - startup_start_time).total_seconds()
410-
delay, is_exponential_backoff = _get_startup_backoff(elapsed_seconds, exponential_backoff_attempts)
232+
delay, is_exponential_backoff = get_startup_backoff(elapsed_seconds, exponential_backoff_attempts)
411233

412234
if is_exponential_backoff:
413235
exponential_backoff_attempts += 1

0 commit comments

Comments
 (0)