|
| 1 | +--- |
| 2 | +title: Declarative Configuration |
| 3 | +description: Understanding secretspec.toml and its declarative approach |
| 4 | +--- |
| 5 | + |
| 6 | +SecretSpec uses `secretspec.toml` to declare what secrets your application needs, separating requirements from storage mechanisms for portability across environments. |
| 7 | + |
| 8 | +## Basic Structure |
| 9 | + |
| 10 | +```toml |
| 11 | +[project] |
| 12 | +name = "my-app" |
| 13 | +revision = "1.0" |
| 14 | +extends = ["../shared/common"] # Optional: inherit from other configs |
| 15 | + |
| 16 | +[profiles.default] |
| 17 | +DATABASE_URL = { description = "PostgreSQL connection string", required = true } |
| 18 | +API_KEY = { description = "External API key", required = true } |
| 19 | +LOG_LEVEL = { description = "Logging verbosity", required = false, default = "info" } |
| 20 | +``` |
| 21 | + |
| 22 | +## Secret Declarations |
| 23 | + |
| 24 | +Each secret is declared with configuration options: |
| 25 | + |
| 26 | +```toml |
| 27 | +SECRET_NAME = { |
| 28 | + description = "Human-readable explanation", # Required: shown in prompts |
| 29 | + required = true, # Optional: defaults to true |
| 30 | + default = "value" # Optional: fallback if not set |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +**Options:** |
| 35 | +- `description`: Explains the secret's purpose (required) |
| 36 | +- `required`: Whether the secret must be provided (default: `true`) |
| 37 | +- `default`: Fallback value for optional secrets |
| 38 | + |
| 39 | +## Configuration Inheritance |
| 40 | + |
| 41 | +SecretSpec supports sharing common secrets across projects through the `extends` field. |
| 42 | + |
| 43 | +### Basic Example |
| 44 | + |
| 45 | +```toml |
| 46 | +# shared/common/secretspec.toml |
| 47 | +[project] |
| 48 | +name = "common" |
| 49 | + |
| 50 | +[profiles.default] |
| 51 | +DATABASE_URL = { description = "Main database", required = true } |
| 52 | +LOG_LEVEL = { description = "Log verbosity", required = false, default = "info" } |
| 53 | +``` |
| 54 | + |
| 55 | +```toml |
| 56 | +# myapp/secretspec.toml |
| 57 | +[project] |
| 58 | +name = "myapp" |
| 59 | +extends = ["../shared/common"] |
| 60 | + |
| 61 | +[profiles.default] |
| 62 | +DATABASE_URL = { description = "MyApp database", required = true } # Override |
| 63 | +API_KEY = { description = "External API key", required = true } # Add new |
| 64 | +``` |
| 65 | + |
| 66 | +### Monorepo Structure |
| 67 | + |
| 68 | +``` |
| 69 | +monorepo/ |
| 70 | +├── shared/ |
| 71 | +│ ├── base/secretspec.toml # Common secrets |
| 72 | +│ └── database/secretspec.toml # DB-specific (extends base) |
| 73 | +└── services/ |
| 74 | + ├── api/secretspec.toml # API service (extends database) |
| 75 | + └── frontend/secretspec.toml # Frontend (extends base) |
| 76 | +``` |
| 77 | + |
| 78 | +### Multiple Inheritance |
| 79 | + |
| 80 | +```toml |
| 81 | +[project] |
| 82 | +name = "api-service" |
| 83 | +extends = ["../../shared/base", "../../shared/database", "../../shared/auth"] |
| 84 | +``` |
| 85 | + |
| 86 | +**Rules:** |
| 87 | +- Child definitions completely replace parent definitions |
| 88 | +- Later sources in `extends` override earlier ones |
| 89 | +- Each profile is merged independently |
| 90 | +- Paths are relative to the containing file |
| 91 | + |
| 92 | +## Best Practices |
| 93 | + |
| 94 | +1. **Descriptive names**: Use `STRIPE_API_KEY` instead of generic `API_KEY` |
| 95 | +2. **Clear descriptions**: Help developers understand each secret's purpose |
| 96 | +3. **Sensible defaults**: Provide development defaults, require production values |
| 97 | +4. **Modular inheritance**: Create reusable base configurations for common patterns |
| 98 | + |
| 99 | +## Complete Example |
| 100 | + |
| 101 | +```toml |
| 102 | +[project] |
| 103 | +name = "web-api" |
| 104 | +revision = "2.1.0" |
| 105 | +extends = ["../shared/base", "../shared/auth"] |
| 106 | + |
| 107 | +[profiles.default] |
| 108 | +# Inherits DATABASE_URL, LOG_LEVEL from base |
| 109 | +# Inherits JWT_SECRET, SESSION_SECRET from auth |
| 110 | +# Service-specific additions: |
| 111 | +STRIPE_API_KEY = { description = "Stripe payment API", required = true } |
| 112 | +REDIS_URL = { description = "Redis cache connection", required = true } |
| 113 | +PORT = { description = "Server port", required = false, default = "3000" } |
| 114 | +``` |
0 commit comments