# EdpConfigProvider

A configuration provider library that abstracts fetching configuration from multiple backends (local JSON files, AWS AppConfig, AWS SSM Parameter Store) behind a unified interface.

## Installation

```bash
poetry install
```

For AWS support (AppConfig, SSM Parameter Store):

```bash
pip install edpconfigprovider[aws]
```

## Configuration Provider Type

The application uses the `CONFIG_PROVIDER_TYPE` environment variable to determine how configuration is loaded. Supported values are:

### JSON (local configuration)

- **json**: Loads configuration from a static JSON folder located beside the project folder. Use this for local development or static configuration scenarios.
    - **CONFIG_PATH**: path to `config.json`
    - **TENANT_CONFIG_PATH**: path to a JSON file mapping tenant names to their config paths. Ex: `config/tenant.json`

### AWS AppConfig

- **aws_appconfig**: Loads configuration dynamically from AWS AppConfig. Recommended for production or dynamic configuration needs.
- **aws_appconfig_agent**: Uses AWS AppConfig as a Lambda agent for configuration management, enabling advanced AppConfig features and integration.
    - General Configuration
        - **AWS_APPCONFIG_APPLICATION_NAME**: AWS AppConfig Application Name
        - **AWS_APPCONFIG_PROFILE_NAME**: AWS AppConfig Profile Name
        - **AWS_APPCONFIG_ENVIRONMENT_NAME**: AWS AppConfig Environment Name
    - Tenant configuration
        - **AWS_APPCONFIG_TENANT_APPLICATION_NAME_FORMAT**: AWS AppConfig Application Name for a tenant_name. Ex: `sample-app-tenant-{}`, where the `{}` will be replaced for the `tenant_name` variable
        - **AWS_APPCONFIG_TENANT_PROFILE_NAME**: AWS AppConfig Profile Name for tenant configuration
        - **AWS_APPCONFIG_TENANT_ENVIRONMENT_NAME**: AWS AppConfig Environment Name for tenant configuration

### AWS SSM Parameter Store

- **aws_ssm**: Loads configuration from AWS SSM Parameter Store by path. All parameters under the given path are fetched recursively and returned as a nested dictionary (path segments become nested keys). SecureString values are decrypted automatically. `StringList` values are split by comma, and values that are valid JSON are parsed into their corresponding Python types.
    - **AWS_SSM_PARAMETER_PATH**: The SSM parameter path prefix to fetch (e.g., `/myapp/config/`)
    - **AWS_SSM_RECURSIVE**: Whether to fetch parameters recursively under the path (default: `true`)
    - **AWS_SSM_SPLIT_PATH**: Whether to split parameter path segments into nested dictionary keys (default: `true`). When `false`, parameters are returned as a flat dictionary keyed by their path relative to `AWS_SSM_PARAMETER_PATH`.
    - **AWS_SSM_DECRYPT**: Whether to decrypt SecureString parameters (default: `true`)

Set the `CONFIG_PROVIDER_TYPE` variable in your environment or `.env` file to control the configuration source.

## Scripts

Setup Claude Code skills (symlinks `.claude/skills/*` into `~/.claude/skills/`):

```bash
poetry run task setup-skills
```

## Usage

### Simple configuration

```python
from edpconfigprovider.builder import ConfigProviderBuilder

builder = ConfigProviderBuilder(transform_method=lambda data: MyConfig(**data))
config = builder.build_config()
```

### Tenant-based (multi-tenant) configuration

```python
from edpconfigprovider.builder import TenantConfigProviderBuilder

builder = TenantConfigProviderBuilder(transform_method=lambda name, data: MyTenantConfig(**data))
config = builder.build_config(tenant_name="my-tenant")
```

### Custom providers

```python
from edpconfigprovider.builder._builder_registry import set_provider

set_provider("my_custom_type", my_provider_factory)
```