Metadata-Version: 2.3
Name: nextpertise-envy-settings
Version: 0.4.0
Summary: Reusable settings loader for Keycloak-secured Envy environments
License: MIT
Author: Len van Essen
Author-email: len@wndr.digital
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Dist: pydantic (>=2.10.1,<3.0.0)
Requires-Dist: pydantic-settings (>=2.0.0,<3.0.0)
Requires-Dist: requests (>=2.31,<3.0)
Description-Content-Type: text/markdown

# nextpertise-envy-loader

A reusable helper for Pydantic that fetches environment variables from an Envy API using a Keycloak-secured token. It automatically writes these variables to a `.env.envy` file and prepends it to your environment configuration.

---

## 📦 Installation

Install via Poetry:

```bash
poetry add nextpertise-envy-settings
```

Or with pip:

```bash
pip install nextpertise-envy-settings
```

⸻

## 🚀 Usage

To load your environment configuration into a `.env.envy` file:

```python
from nextpertise_envy_settings import EnvySettingsLoader

EnvySettingsLoader.load_env_file(
    envy_env="SCORE_DEVELOPMENT"
)
```

This will:

- Check for required settings in environment variables (or fall back to defaults).
- Load `client_id` and `client_secret` from environment or `~/.envy/auth.json` if not passed explicitly.
- Fetch remote settings from the configured Envy environment.
- Write them to `.env.envy` in the current directory.

### Optional overrides

You can override default URLs or encoding directly:

```python
EnvySettingsLoader.load_env_file(
    envy_env="SCORE_DEVELOPMENT",
    envy_url="https://custom-envy.example.com",
    keycloak_url="https://keycloak.example.com/realms/envy",
    filename=".env.generated",
    encoding="utf-8"
)
```

> ✅ If `client_id` and `client_secret` are not passed or set in environment variables, they are loaded from `~/.envy/auth.json`.

⸻

🔧 Environment Variables (optional)

Instead of hardcoding the config, you can also use these environment variables:

| Variable                        | Description               |
|---------------------------------|---------------------------|
| `ENV_API_BASE_URL`              | Base URL for Envy API     |
| `ENV_API_KEYCLOAK_URL`          | Keycloak realm URL        |
| `ENV_API_KEYCLOAK_CLIENT_ID`    | OAuth2 client ID          |
| `ENV_API_KEYCLOAK_TOKEN`        | OAuth2 client secret      |
| `ENV_API_ENVIRONMENT`           | Target environment name   |


⸻

📁 Example .env.envy

MYSQL_USER=abc
MYSQL_PASSWORD=xyz
REDIS_HOST=localhost

