Azure AppConfiguration extension for confeasy.
Project description
confeasy.azure_appc
Application configuration inspired by Microsoft.Extensions.Configuration (.NET).
See details in GitHub confeasy (PyPI).
This package is an extension to confeasy using Azure AppConfiguration service.
Getting started
Install required packages.
poetry add confeasy confeasy-azure-appc
# or similar command for your package manager of choice
In python, usually around application start:
# DbOptions class is an illustrative example of strongly typed configuration.
class DbOptions:
def __init__(self):
self.connnection_string: str = ""
self.max_connections: int = 100
from confeasy import Builder
from confeasy.envars import EnvironmentVariables
from confeasy.cmdline import CommandLine
from confeasy.azure_appc import AzureAppConfig
# Order of the configuration sources matters; later sources can overwrite values from earlier ones.
builder = (Builder()
.add_source(AzureAppConfig.from_base_url_in_envars(prefix="db.*"))
.add_source(EnvironmentVariables("MYAPP_"))
.add_source(CommandLine()))
config = builder.build()
# Bind configuration to a class instance and pass the instance to other objects.
options = config.bind(DbOptions(), prefix="db")
# OR pick up individual values:
db_conn_str = config.get_value("db.connection_string")
Authentication to Azure resources
Important Facts:
- The Python SDK for AppConfiguration allows authentication using both connection strings and credential providers from the azure-identity package.
- The Python SDK for KeyVault supports only credential providers from the azure-identity package, not connection strings.
- AppConfiguration can reference secrets from one or more key vaults.
- The most commonly used provider from azure-identity is DefaultAzureCredential, which combines several potential sources of authentication information, such as access tokens generated by az login or environment variables with conventional names.
[!IMPORTANT] This creates a somewhat complex situation where a simple approach, such as using a single connection string, may not work (unless you are using only AppConfiguration).
Suggestion:
In the most common scenario, where authentication is required for both AppConfiguration and one or more KeyVault resources, I recommend familiarizing yourself with managed identities and service principals in Azure and creating a specialized "account" for your application.
An example of how to do this is available in tests/app_service_principal.sh (a PowerShell variant is also available).
Once the service principal has been created, ensure the following environment variables are present in the environment:
AZURE_APPC_BASE_URL: Set this to the URL of the Azure AppConfiguration resource, e.g., https://{name}.azconfig.io.AZURE_CLIENT_ID: Set this to the Application (client) ID of the service principal.AZURE_CLIENT_SECRET: Set this to the Client Secret of the service principal.AZURE_TENANT_ID: Set this to the Directory (tenant) ID.
This setup allows you to use the factory method AzureAppConfig.from_base_url_in_envars, enabling it to work both
in local environments (such as a developer's machine) and after deployment, such as in a GitHub Action or on the final host.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file confeasy_azure_appc-1.0.0.tar.gz.
File metadata
- Download URL: confeasy_azure_appc-1.0.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd08086cf28ebd0eb53e8f49531801f335a47f78785ed6d0388271dea1adf0a4
|
|
| MD5 |
3826b0426737cd9695255422e339d8e9
|
|
| BLAKE2b-256 |
c8dc008041606d90dc7e27cc6ec6e7f7030fbf6e5a6f4e6a6530226149ffb35a
|
File details
Details for the file confeasy_azure_appc-1.0.0-py3-none-any.whl.
File metadata
- Download URL: confeasy_azure_appc-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91fa63835dd94d1bcd2e6b9a0cba47ea42052a67799e275bc8df4c903db311dc
|
|
| MD5 |
1d9784c3c6121585bb291cd9e4beb954
|
|
| BLAKE2b-256 |
a8e10688978faa2218ad9992c296ddcb11fe9b54f31df7e490c95217facdcf50
|