confeasy-azure-appc


Nameconfeasy-azure-appc JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/jdvor/confeasy-azure-appc
SummaryAzure AppConfiguration extension for confeasy.
upload_time2024-11-04 10:30:07
maintainerNone
docs_urlNone
authorjan Dvorak
requires_python<4.0,>=3.12
licenseMIT
keywords configuration azure appconfiguration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # confeasy.azure_appc

Application configuration inspired by Microsoft.Extensions.Configuration (.NET).<br/>
See details in GitHub [confeasy][confeasy_gh] ([PyPI][confeasy_pypi]).

This package is an extension to confeasy using [Azure AppConfiguration][azure] service.

## Getting started

Install required packages.

```shell
poetry add confeasy confeasy-azure-appc
# or similar command for your package manager of choice
```

In python, usually around application start:
```python

# 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][dac], 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.

[azure]: https://learn.microsoft.com/en-us/azure/azure-app-configuration/overview
[confeasy_gh]: https://github.com/jdvor/confeasy
[confeasy_pypi]: https://pypi.org/project/confeasy
[dac]: https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jdvor/confeasy-azure-appc",
    "name": "confeasy-azure-appc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.12",
    "maintainer_email": null,
    "keywords": "configuration, azure, AppConfiguration",
    "author": "jan Dvorak",
    "author_email": "jandvorak.public@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c8/dc/008041606d90dc7e27cc6ec6e7f7030fbf6e5a6f4e6a6530226149ffb35a/confeasy_azure_appc-1.0.0.tar.gz",
    "platform": null,
    "description": "# confeasy.azure_appc\n\nApplication configuration inspired by Microsoft.Extensions.Configuration (.NET).<br/>\nSee details in GitHub [confeasy][confeasy_gh] ([PyPI][confeasy_pypi]).\n\nThis package is an extension to confeasy using [Azure AppConfiguration][azure] service.\n\n## Getting started\n\nInstall required packages.\n\n```shell\npoetry add confeasy confeasy-azure-appc\n# or similar command for your package manager of choice\n```\n\nIn python, usually around application start:\n```python\n\n# DbOptions class is an illustrative example of strongly typed configuration.\nclass DbOptions:\n    def __init__(self):\n        self.connnection_string: str = \"\"\n        self.max_connections: int = 100\n\nfrom confeasy import Builder\nfrom confeasy.envars import EnvironmentVariables\nfrom confeasy.cmdline import CommandLine\nfrom confeasy.azure_appc import AzureAppConfig\n\n# Order of the configuration sources matters; later sources can overwrite values from earlier ones.\nbuilder = (Builder()\n           .add_source(AzureAppConfig.from_base_url_in_envars(prefix=\"db.*\"))\n           .add_source(EnvironmentVariables(\"MYAPP_\"))\n           .add_source(CommandLine()))\n\nconfig = builder.build()\n\n# Bind configuration to a class instance and pass the instance to other objects.\noptions = config.bind(DbOptions(), prefix=\"db\")\n\n# OR pick up individual values:\ndb_conn_str = config.get_value(\"db.connection_string\")\n```\n\n## Authentication to Azure resources\n\n#### Important Facts:\n\n* The Python SDK for AppConfiguration allows authentication using both connection strings and credential providers from the azure-identity package.\n* The Python SDK for KeyVault supports only credential providers from the azure-identity package, not connection strings.\n* AppConfiguration can reference secrets from one or more key vaults.\n* The most commonly used provider from azure-identity is [DefaultAzureCredential][dac], which combines several\n  potential sources of authentication information, such as access tokens generated by az login or environment variables with conventional names.\n\n> [!IMPORTANT]\n> This creates a somewhat complex situation where a simple approach, such as using a single connection string,\n> may not work (unless you are using only AppConfiguration).\n\n#### Suggestion:\n\nIn the most common scenario, where authentication is required for both AppConfiguration and one or more KeyVault resources,\nI recommend familiarizing yourself with managed identities and service principals in Azure and creating a specialized \"account\" for your application.\n\nAn example of how to do this is available in `tests/app_service_principal.sh` (a PowerShell variant is also available).\n\nOnce the service principal has been created, ensure the following environment variables are present in the environment:\n\n* `AZURE_APPC_BASE_URL`: Set this to the URL of the Azure AppConfiguration resource, e.g., https://{name}.azconfig.io.\n* `AZURE_CLIENT_ID`: Set this to the Application (client) ID of the service principal.\n* `AZURE_CLIENT_SECRET`: Set this to the Client Secret of the service principal.\n* `AZURE_TENANT_ID`: Set this to the Directory (tenant) ID.\n\nThis setup allows you to use the factory method `AzureAppConfig.from_base_url_in_envars`, enabling it to work both\nin local environments (such as a developer's machine) and after deployment, such as in a GitHub Action or on the final host.\n\n[azure]: https://learn.microsoft.com/en-us/azure/azure-app-configuration/overview\n[confeasy_gh]: https://github.com/jdvor/confeasy\n[confeasy_pypi]: https://pypi.org/project/confeasy\n[dac]: https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.defaultazurecredential?view=azure-python",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Azure AppConfiguration extension for confeasy.",
    "version": "1.0.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/jdvor/confeasy-azure-appc/issues",
        "Homepage": "https://github.com/jdvor/confeasy-azure-appc",
        "Repository": "https://github.com/jdvor/confeasy-azure-appc"
    },
    "split_keywords": [
        "configuration",
        " azure",
        " appconfiguration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8e10688978faa2218ad9992c296ddcb11fe9b54f31df7e490c95217facdcf50",
                "md5": "1d9784c3c6121585bb291cd9e4beb954",
                "sha256": "91fa63835dd94d1bcd2e6b9a0cba47ea42052a67799e275bc8df4c903db311dc"
            },
            "downloads": -1,
            "filename": "confeasy_azure_appc-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1d9784c3c6121585bb291cd9e4beb954",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.12",
            "size": 5837,
            "upload_time": "2024-11-04T10:30:05",
            "upload_time_iso_8601": "2024-11-04T10:30:05.338772Z",
            "url": "https://files.pythonhosted.org/packages/a8/e1/0688978faa2218ad9992c296ddcb11fe9b54f31df7e490c95217facdcf50/confeasy_azure_appc-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c8dc008041606d90dc7e27cc6ec6e7f7030fbf6e5a6f4e6a6530226149ffb35a",
                "md5": "3826b0426737cd9695255422e339d8e9",
                "sha256": "bd08086cf28ebd0eb53e8f49531801f335a47f78785ed6d0388271dea1adf0a4"
            },
            "downloads": -1,
            "filename": "confeasy_azure_appc-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3826b0426737cd9695255422e339d8e9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.12",
            "size": 6919,
            "upload_time": "2024-11-04T10:30:07",
            "upload_time_iso_8601": "2024-11-04T10:30:07.258515Z",
            "url": "https://files.pythonhosted.org/packages/c8/dc/008041606d90dc7e27cc6ec6e7f7030fbf6e5a6f4e6a6530226149ffb35a/confeasy_azure_appc-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-04 10:30:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jdvor",
    "github_project": "confeasy-azure-appc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "confeasy-azure-appc"
}
        
Elapsed time: 0.46580s