diff --git a/sdk/appconfiguration/azure-appconfiguration-provider/CHANGELOG.md b/sdk/appconfiguration/azure-appconfiguration-provider/CHANGELOG.md index 3007731bf9e6..653714f62e07 100644 --- a/sdk/appconfiguration/azure-appconfiguration-provider/CHANGELOG.md +++ b/sdk/appconfiguration/azure-appconfiguration-provider/CHANGELOG.md @@ -3,15 +3,17 @@ ## 1.0.0b2 (Unreleased) ### Features Added - +* Added missing methods for Mapping API * Made load method properties unordered. ### Breaking Changes +* Removed custom Key Vault Error +* Removed unneeded __repr__ and copy methods. ### Bugs Fixed ### Other Changes - +* Updated method docs * Fixed load doc that used `selector` instead of `selects`. * Fixed CLI link in Readme. diff --git a/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azure_appconfiguration_provider_error.py b/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azure_appconfiguration_provider_error.py deleted file mode 100644 index 3c7021cb71ba..000000000000 --- a/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azure_appconfiguration_provider_error.py +++ /dev/null @@ -1,9 +0,0 @@ -# ------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# ------------------------------------------------------------------------- - - -class KeyVaultReferenceError(ValueError): - """Raised when a Key Vault reference is invalid.""" diff --git a/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azureappconfigurationkeyvaultoptions.py b/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azureappconfigurationkeyvaultoptions.py index 7a6519e1b9be..b48df1cb64ab 100644 --- a/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azureappconfigurationkeyvaultoptions.py +++ b/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azureappconfigurationkeyvaultoptions.py @@ -6,6 +6,7 @@ class AzureAppConfigurationKeyVaultOptions: + """ Options for connecting to Key Vault. @@ -16,11 +17,10 @@ class AzureAppConfigurationKeyVaultOptions: provided. :type secret_clients: list[~azure.keyvault.secrets.SecretClient] :param secret_resolver: A function that takes a URI and returns a value. - :type secret_resolver: callable + :type secret_resolver: Callable[[str], str] """ - - def __init__(self, credential=None, secret_clients=None, secret_resolver=None): - # type: (TokenCredential, List[SecretClient], Callable) -> None + def __init__(self, *, credential=None, secret_clients=None, secret_resolver=None): + # type: (TokenCredential, List[SecretClient], Callable[[str], str]) -> None self.credential = credential self.secret_clients = secret_clients self.secret_resolver = secret_resolver diff --git a/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azureappconfigurationprovider.py b/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azureappconfigurationprovider.py index 85ca819d5a01..21297150f434 100644 --- a/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azureappconfigurationprovider.py +++ b/sdk/appconfiguration/azure-appconfiguration-provider/azure/appconfiguration/provider/_azureappconfigurationprovider.py @@ -7,21 +7,18 @@ import json from azure.appconfiguration import AzureAppConfigurationClient from azure.keyvault.secrets import SecretClient, KeyVaultSecretIdentifier -from azure.core.exceptions import ResourceNotFoundError from ._settingselector import SettingSelector -from ._azure_appconfiguration_provider_error import KeyVaultReferenceError from ._constants import KEY_VAULT_REFERENCE_CONTENT_TYPE from ._user_agent import USER_AGENT - class AzureAppConfigurationProvider: + """ Provides a dictionary-like interface to Azure App Configuration settings. Enables loading of sets of configuration settings from Azure App Configuration into a Python application. Enables trimming of prefixes from configuration keys. Enables resolution of Key Vault references in configuration settings. """ - def __init__(self): # type: () -> None self._dict = {} @@ -130,19 +127,12 @@ def __resolve_keyvault_reference(config, key_vault_options, secret_clients): secret_clients[key_vault_identifier.vault_url] = referenced_client if referenced_client: - try: - return referenced_client.get_secret( - key_vault_identifier.name, version=key_vault_identifier.version - ).value - except ResourceNotFoundError: - raise KeyVaultReferenceError( - "Key Vault %s does not contain secret %s" - % (key_vault_identifier.vault_url, key_vault_identifier.name) - ) + return referenced_client.get_secret(key_vault_identifier.name, version=key_vault_identifier.version).value if key_vault_options.secret_resolver is not None: return key_vault_options.secret_resolver(config.secret_id) - raise KeyVaultReferenceError( + + raise AttributeError( "No Secret Client found for Key Vault reference %s" % (key_vault_identifier.vault_url) ) @@ -169,22 +159,18 @@ def __is_json_content_type(content_type): return False def __getitem__(self, key): + """ + Returns the value of the specified key. + type: (str) -> object + """ return self._dict[key] - def __repr__(self): - return repr(self._dict) + def __iter__(self): + return self._dict.__iter__() def __len__(self): return len(self._dict) - def copy(self): - """ - Returns a copy of the configuration settings - - type: () -> dict - """ - return self._dict.copy() - def __contains__(self, __x: object): """ Returns True if the configuration settings contains the specified key @@ -201,6 +187,15 @@ def keys(self): """ return self._dict.keys() + def items(self): + """ + Returns a list of key-value pairs loaded from Azure App Configuration. Any values that are Key Vault references + will be resolved. + + type: () -> list + """ + return self._dict.items() + def values(self): """ Returns a list of values loaded from Azure App Configuration. Any values that are Key Vault references will be @@ -209,3 +204,25 @@ def values(self): type: () -> list """ return self._dict.values() + + def get(self, key, default=None): + """ + Returns the value of the specified key. If the key does not exist, returns the default value. + + type: (str, object) -> object + """ + return self._dict.get(key, default) + + def __eq__(self, other): + if not isinstance(other, AzureAppConfigurationProvider): + return False + if self._dict != other._dict: + return False + if self._trim_prefixes != other._trim_prefixes: + return False + if self._client != other._client: + return False + return True + + def __ne__(self, other): + return not self == other