AppConfiguration icon indicating copy to clipboard operation
AppConfiguration copied to clipboard

Azure App Configuration Python Provider - Design Proposal

Open mrm9084 opened this issue 2 years ago • 0 comments

We are planning to build App Config Provider for Python, same as .Net and Spring. We will love for you to share your Python expertise and comment on our initial API design for the provider.

Usage Design

API

class AzureAppConfigurationProvider: 

    @staticmethod 
    def load(cls, connection_string=None, endpoint=None, credential=None, **kwargs):  
       # type: (**Any) -> AzureAppConfigurationProvider  
       """ 
       Requires either a connection-string, or an Endpoint with a Credential. Loads the selected configuration settings into itself for usage. 
       Optional parameters:  
       selectors (List of SettingSelector for selecting which applicationconfiguration settings to load),. If not specified, all key-values with the empty label will be loaded.  
       trimmed_key_prefixes (remove prefixes in key name, list of what to trim),  
       key_vault_options (Configurations for connecting to Key Vault(s)) 
       """ 

class AzureAppConfigurationKeyVaultOptions: 

    def __init__(self, credential=None, secret_clients=None, secret_resolver=None): 
    """ 
    credential, secret_clients (clients for connecting to multiple key vaults with different credentials), secret_resolver  
    """

class SettingSelector: 

    def __init__(self, key_filter, label_filter): 

Usage

This will load all configuration settings with empty label in the store via connection string

connection_string = "my connection string"  

configuration = AzureAppConfigurationProvider.load(connection_string=connection_string) 

configuration["app.message"] 

This will load all configuration settings in the store with Azure AD authentication via a token credential

credential = DefaultAzureCredential()  

endpoint = "my config store endpoint"  

configuration = AzureAppConfigurationProvider.load(endpoint=endpoint, credential=credential)  

  This will load configuration settings with the key prefix “myService.” and the “common” label first and then overridden by the “dev” label in the store via a connection string

selectors = [SettingSelector(" myService.*","common"), SettingSelector("myService.*","dev")] 

configuration = AzureAppConfigurationProvider.load(connection_string=connection_string, selectors= selectors) 

This will load all configuration settings but will trim "app." and “myService.” from the key prefix

trim = ["app.","myService."] 

configuration = AzureAppConfigurationProvider.load(connection_string=connection_string, trimmed_key_prefixes=trim) 

configuration["message"] 
configuration["map"]  

This will load all configuration settings and set up a key vault for references

configuration = AzureAppConfigurationProvider.load(connection_string=connection_string,  key_vault_options=AppConfigurationKeyVaultOptions( 
        credential=DefaultAzureCredential()) 

configuration["app.message"]  
configuration["myService.map"]  
configuration["app.fromKeyVault"] # This will show the actual value from Key Vault 

This will load all configuration settings and a provided key vault for references

secret_clients = [SecretClient(vault_url=”my vault uri”, credential= DefaultAzureCredential()] 

configuration = AzureAppConfigurationProvider.load(connection_string=connection_string, 
    key_vault_options=AppConfigurationKeyVaultOptions(            
        secret_clients=clients) 

configuration["app.message"]  
configuration["myService.map"]  
configuration["app.fromKeyVault"] # This will show the actual value from Key Vault 

This will load all configuration settings and use a secret resolver instead of loading from key vault

def my_resolver(mySecret): 
    return "Secret Value from Resolver" 

configuration = AzureAppConfigurationProvider.load(connection_string=connection_string, 
    key_vault_options=AppConfigurationKeyVaultOptions( secret_resolver=my_resolver)) 

configuration["app.message"]  
configuration["myService.map"]  
configuration["app.fromKeyVault"] # This will show the value returned by the secret resolver 

mrm9084 avatar Jun 10 '22 19:06 mrm9084