Open source · spec draft v1alpha1
Your environment variables are an API. Give them a contract.
docuconf turns the config your app already declares, with the library you already use (caarlos0/env, T3 Env, NestJS config, the .NET Options pattern, pydantic-settings, anyway_config and 10 more), into a contract (contract.cue, or JSON) that your Kubernetes platform checks before anything deploys. From it, docuconf generates the Helm values schema, the pod config and the docs.
docuconf vet checks the values a platform proposes against the app's contract.
$ cat values.yaml DATABASE_URL: "postgres://orders:hunter2@db:5432/orders" DATABSE_URL: "postgres://orders@db:5432/orders" PORT: 70000 $ docuconf vet -contract contract.cue -values values.yaml DATABASE_URL: is secret, so it must come from a secretKeyRef, written {secretKeyRef: {name: <secret>, key: <key>}}, or an injector, never a literal or another reference DATABSE_URL: is not declared in the contract (check the spelling) PORT: 70000 is above max 65535
The Go SDK checks the real environment when the app starts.
$ PORT=0 go run . docuconf: 2 configuration problems: PORT: 0 is below min 1 (out_of_range) DATABASE_URL: is required but not set (missing_required) exit status 1
The problem
Config is the API nobody wrote down.
Today
- Environment variables are undocumented, untyped strings.
- A typo in
DATABSE_URLis found by a crash loop, often in production. - Every service invents its own validation, in every language.
- The platform team guesses what each app needs from READMEs and Slack threads.
With docuconf
- Every variable has a type, constraints and a description, declared in code.
- A bad value is rejected before a pod starts, with a precise reason.
- One contract format, whatever the app is written in.
- Platform policy is layered on top, without editing the app.
How it works
Declared once. Checked before deploy, and again at boot.
- 1
Declare
Describe your variables in the env library you already use. docuconf adds descriptions, secrets and constraints.
- 2
Export
The SDK exports a contract (contract.cue, or JSON) from the same declaration. From it, docuconf generates the Helm values schema, the pod config and the docs.
- 3
Validate
docuconf vet, the Helm chart or CUE in your pipeline checks the values for each environment, plus platform policy, before anything renders.
- 4
Boot
At startup the SDK checks the real environment, including secret contents, and hands your code typed values.
From your code to the platform
Keep your library. Get a contract.
The same service, orders, declared with each SDK, the contract it exports, and what docuconf generates from that contract. Pick your language; every snippet is checked against that SDK's main branch in CI.
1 · Your declaration, as you write it today
// Package config is the orders service's configuration: an ordinary
// caarlos0/env struct with docuconf's tags. It lives in its own package
// because `docuconf export` imports it, and package main cannot be imported.
package config
import (
"time"
"github.com/docuconf/docuconf-go"
)
// Config is everything the orders service reads at boot.
// Doc comments become the descriptions in the contract: the first
// paragraph is the description, and any later paragraphs are its details.
type Config struct {
// HTTP listen port.
Port int `env:"PORT" envDefault:"8080" min:"1" max:"65535"`
// Minimum log level emitted.
LogLevel string `env:"LOG_LEVEL" envDefault:"info" values:"debug,info,warn,error"`
// Postgres connection string for the orders database.
DatabaseURL docuconf.Secret `env:"DATABASE_URL,required" schemes:"postgres" maxLength:"2048"`
// Origins allowed to call the API from a browser.
AllowedOrigins []string `env:"ALLOWED_ORIGINS" envDefault:"http://localhost:3000" minItems:"1"`
// Time limit for handling one request.
RequestTimeout time.Duration `env:"REQUEST_TIMEOUT" envDefault:"30s" min:"1s" max:"5m"`
// Number of background workers processing orders.
//
// Each worker holds one database connection, so keep it below the
// database's connection limit divided by the number of replicas.
// Raise it when the order queue grows faster than it drains.
WorkerCount int `env:"WORKER_COUNT" envDefault:"4" min:"1" max:"64"`
// Keys that verify the signature on incoming payment webhooks.
//
// A webhook is accepted when it is signed with any key in the set, so
// the key can be rotated without turning webhooks away. Each key is 32
// to 256 characters, so an empty or truncated key fails at boot.
// Without this variable, the service rejects every webhook.
WebhookKeys docuconf.KeySet `env:"WEBHOOK_KEYS" keyMinLength:"32" keyMaxLength:"256"`
// Certificate to serve HTTPS with. Without it, the service serves HTTP.
TLS docuconf.TLSKeyPair `file:"serving-tls" path:"/etc/orders/tls" dnsNames:"orders.example.com" minRemaining:"720h" reload:"watch"`
// Discount codes accepted at checkout.
Discounts docuconf.ConfigFile[Discounts] `file:"discounts" path:"/etc/orders/discounts/discounts.yaml"`
}
// Discounts is the content of the discounts file.
type Discounts struct {
// Percent off for each discount code.
Codes map[string]int `json:"codes" yaml:"codes"`
}2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders-api"
generator: {
language: "go"
sdk: "docuconf-go"
version: "0.2.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins allowed to call the API from a browser"
default: ["http://localhost:3000"]
items: "string"
encoding: "csv"
separator: ","
minItems: 1
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string for the orders database"
required: true
secret: true
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level emitted"
default: "info"
values: ["debug", "info", "warn", "error"]
}
PORT: {
type: "int"
description: "HTTP listen port"
default: 8080
min: 1
max: 65535
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Time limit for handling one request"
default: "30s"
min: "1s"
max: "5m"
encoding: "go"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so the key can be rotated without turning webhooks away. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of background workers processing orders"
details: "Each worker holds one database connection, so keep it below the database's connection limit divided by the number of replicas. Raise it when the order queue grows faster than it drains."
default: 4
min: 1
max: 64
}
}
files: {
discounts: {
type: "config"
format: "yaml"
description: "Discount codes accepted at checkout"
path: "/etc/orders/discounts/discounts.yaml"
schema: {
type: "object"
required: ["codes"]
additionalProperties: false
properties: {
codes: {
type: "object"
description: "Percent off for each discount code"
additionalProperties: {
type: "integer"
}
}
}
}
}
"serving-tls": {
type: "tls"
description: "Certificate to serve HTTPS with. Without it, the service serves HTTP"
secret: true
path: "/etc/orders/tls"
reload: "watch"
dnsNames: ["orders.example.com"]
minRemaining: "720h"
}
}
}1 · Your declaration, as you write it today
// The service's configuration: a T3 Env declaration with docuconf's helpers
// for what Zod has no word for (secrets, URL schemes, durations, lists,
// and a key set).
import { z } from "zod";
import { createEnv, duration, keySet, list, secret, url } from "@docuconf/t3";
export const env = createEnv({
name: "orders",
server: {
PORT: z.coerce.number().int().min(1).max(65535).default(8080).describe("Port the HTTP server listens on"),
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]).default("info").describe("Minimum log level emitted"),
DATABASE_URL: secret(url({ schemes: ["postgres"], maxLength: 2048 })).describe("Postgres connection string for the orders database"),
ALLOWED_ORIGINS: list(z.string(), { minItems: 1 })
.default(["http://localhost:3000"])
.describe("Comma-separated CORS origins allowed to call the API"),
REQUEST_TIMEOUT: duration({ min: "1s", max: "5m", default: "30s" }).describe("Timeout for a single request"),
/**
* Number of background order workers.
*
* Each worker holds one database connection, so keep this below the
* pool size of {@link DATABASE_URL}'s server.
*
* - Raise it when the order queue backs up.
* - Lower it when the database is the bottleneck.
*/
WORKER_COUNT: z.coerce.number().int().min(1).max(64).default(4).describe("Number of background order workers"),
/**
* Keys that verify the signature on incoming payment webhooks.
*
* A webhook is accepted when it is signed with any key in the set, so the key can be rotated without turning webhooks away. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook.
*/
WEBHOOK_KEYS: keySet({ keyMinLength: 32, keyMaxLength: 256 }).optional().describe("Keys that verify the signature on incoming payment webhooks"),
},
runtimeEnv: process.env,
// On invalid configuration: print every problem and exit 1.
exitOnError: true,
});2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
generator: {
language: "typescript"
sdk: "@docuconf/t3"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Comma-separated CORS origins allowed to call the API"
items: "string"
encoding: "csv"
separator: ","
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string for the orders database"
required: true
secret: true
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level emitted"
values: ["debug", "info", "warn", "error"]
default: "info"
}
PORT: {
type: "int"
description: "Port the HTTP server listens on"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Timeout for a single request"
encoding: "go"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so the key can be rotated without turning webhooks away. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of background order workers"
details: "Each worker holds one database connection, so keep this below the\npool size of `DATABASE_URL`'s server.\n\n- Raise it when the order queue backs up.\n- Lower it when the database is the bottleneck."
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
// The service's configuration: the class-validator class @nestjs/config
// validates the environment with, plus docuconf's decorators for what
// class-validator has no word for (descriptions, secrets, URL schemes,
// durations, lists, and a key set).
import { ArrayMinSize, IsEnum, IsInt, IsOptional, IsString, Max, MaxLength, Min } from "class-validator";
import { Describe, Duration, KeySet, List, Secret, UrlSchemes, docuconfValidate } from "@docuconf/nestjs";
export enum LogLevel {
Debug = "debug",
Info = "info",
Warn = "warn",
Error = "error",
}
export class OrdersConfig {
@IsInt() @Min(1) @Max(65535) @Describe("Port the HTTP server listens on")
PORT: number = 8080;
@IsEnum(LogLevel) @Describe("Minimum log level emitted")
LOG_LEVEL: LogLevel = LogLevel.Info;
@Secret() @UrlSchemes("postgres") @MaxLength(2048) @Describe("Postgres connection string for the orders database")
DATABASE_URL!: string;
@List() @IsString({ each: true }) @ArrayMinSize(1) @Describe("Comma-separated CORS origins allowed to call the API")
ALLOWED_ORIGINS: string[] = ["http://localhost:3000"];
@Duration({ min: "1s", max: "5m", default: "30s" }) @Describe("Timeout for a single request")
REQUEST_TIMEOUT!: number;
/**
* Number of background order workers.
*
* Each worker holds one database connection, so keep this below the
* pool size of {@link DATABASE_URL}'s server.
*
* - Raise it when the order queue backs up.
* - Lower it when the database is the bottleneck.
*/
@IsInt() @Min(1) @Max(64) @Describe("Number of background order workers")
WORKER_COUNT: number = 4;
/**
* Keys that verify the signature on incoming payment webhooks.
*
* A webhook is accepted when it is signed with any key in the set, so the key can be rotated without turning webhooks away. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook.
*/
@IsOptional() @KeySet({ keyMinLength: 32, keyMaxLength: 256 })
@Describe("Keys that verify the signature on incoming payment webhooks")
WEBHOOK_KEYS?: KeySet;
}
// exitOnError: on invalid configuration, print every problem and exit 1.
export const validate = docuconfValidate(OrdersConfig, { name: "orders", exitOnError: true });2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
generator: {
language: "typescript"
sdk: "@docuconf/nestjs"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Comma-separated CORS origins allowed to call the API"
items: "string"
encoding: "csv"
separator: ","
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string for the orders database"
required: true
secret: true
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level emitted"
values: ["debug", "info", "warn", "error"]
default: "info"
}
PORT: {
type: "int"
description: "Port the HTTP server listens on"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Timeout for a single request"
encoding: "go"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so the key can be rotated without turning webhooks away. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of background order workers"
details: "Each worker holds one database connection, so keep this below the\npool size of `DATABASE_URL`'s server.\n\n- Raise it when the order queue backs up.\n- Lower it when the database is the bottleneck."
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Docuconf;
namespace Orders.Api;
// The Orders section: Orders:Port is the environment variable ORDERS__PORT, and so on.
// Initializers are the defaults the contract records.
[ConfigContract("orders-api", Section = "Orders")]
public sealed class OrdersOptions
{
[Range(1, 65535)]
[Description("HTTP listen port")]
public int Port { get; set; } = 8080;
[AllowedValues("debug", "info", "warn", "error")]
[Description("Minimum level of log messages to write")]
public string LogLevel { get; set; } = "info";
// [Secret]: the platform must supply it from a Kubernetes Secret, and docuconf never prints it.
// [MaxLength] bounds the URL in characters; a longer one fails startup with out_of_range.
[Required, Secret, UrlSchemes("postgres"), MaxLength(2048)]
[Description("Postgres connection string for the orders database")]
public string DatabaseUrl { get; set; } = "";
// A list arrives as ORDERS__ALLOWEDORIGINS__0, ORDERS__ALLOWEDORIGINS__1, ...
[MinLength(1)]
[Description("Origins allowed to call the API from a browser")]
public List<string> AllowedOrigins { get; set; } = ["http://localhost:3000"];
// A TimeSpan arrives as hh:mm:ss (00:00:30); the platform writes "30s" and renders it that way.
[Range(typeof(TimeSpan), "00:00:01", "00:05:00")]
[Description("Time allowed to handle one request")]
public TimeSpan RequestTimeout { get; set; } = TimeSpan.FromSeconds(30);
// An XML doc comment works instead of [Description]: the <summary> is the description, and the <remarks> are the
// details, longer docs for docuconf docs (the project sets GenerateDocumentationFile).
/// <summary>Background workers that process new orders.</summary>
/// <remarks>
/// <para>
/// Each worker holds one connection from the pool of <see cref="DatabaseUrl"/>, so keep this below the database's
/// connection limit.
/// </para>
/// <list type="bullet">
/// <item><description>Raise it when the order queue backs up.</description></item>
/// <item><description>Lower it when the database is the bottleneck.</description></item>
/// </list>
/// </remarks>
[Range(1, 64)]
public int WorkerCount { get; set; } = 4;
// A key set (SPEC §4.3, §6.1): every key in it is valid at once, so a key can be rotated without turning webhooks
// away. One Kubernetes Secret key holds "old,new" during a rotation, and [EnvName] gives it a name of its own. A
// KeySet is always secret, so it has no initializer, and it never prints its keys.
/// <summary>Keys that verify the signature on incoming payment webhooks.</summary>
/// <remarks>
/// <para>
/// A webhook is accepted when it is signed with any key in the set. Each key is 32 to 256 characters, so an empty or
/// truncated key fails at boot. Without this variable, the service rejects every webhook.
/// </para>
/// </remarks>
[KeySet(KeyMinLength = 32, KeyMaxLength = 256), EnvName("WEBHOOK_KEYS")]
public KeySet? WebhookKeys { get; set; }
}2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders_api
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders-api"
generator: {language: "dotnet", sdk: "Docuconf.Options", version: "0.1.0-alpha.1"}
}
vars: {
ORDERS__ALLOWEDORIGINS: {
type: "list"
description: "Origins allowed to call the API from a browser"
configKey: "Orders:AllowedOrigins"
items: "string"
encoding: "indexed"
minItems: 1
default: ["http://localhost:3000"]
}
ORDERS__DATABASEURL: {
type: "url"
description: "Postgres connection string for the orders database"
required: true
secret: true
configKey: "Orders:DatabaseUrl"
schemes: ["postgres"]
maxLength: 2048
}
ORDERS__LOGLEVEL: {
type: "enum"
description: "Minimum level of log messages to write"
configKey: "Orders:LogLevel"
values: ["debug", "info", "warn", "error"]
default: "info"
}
ORDERS__PORT: {
type: "int"
description: "HTTP listen port"
configKey: "Orders:Port"
min: 1
max: 65535
default: 8080
}
ORDERS__REQUESTTIMEOUT: {
type: "duration"
description: "Time allowed to handle one request"
configKey: "Orders:RequestTimeout"
encoding: "timespan"
min: "1s"
max: "5m"
default: "30s"
}
ORDERS__WORKERCOUNT: {
type: "int"
description: "Background workers that process new orders"
details: "Each worker holds one connection from the pool of `OrdersOptions.DatabaseUrl`, so keep this below the database's connection limit.\n\n- Raise it when the order queue backs up.\n- Lower it when the database is the bottleneck."
configKey: "Orders:WorkerCount"
min: 1
max: 64
default: 4
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook."
secret: true
configKey: "Orders:WebhookKeys"
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
}
}1 · Your declaration, as you write it today
class Settings(DocuconfSettings):
# metadata.name in the exported contract.
docuconf_service: ClassVar[str] = "orders"
port: int = Field(8080, ge=1, le=65535, description="HTTP listen port")
log_level: Literal["debug", "info", "warn", "error"] = Field("info", description="Minimum log level")
# SecretStr makes it a secret in the contract, and keeps it out of reprs and error messages.
database_url: Annotated[SecretStr, Url(schemes=("postgres",))] = Field(
max_length=2048, description="Postgres connection string for orders"
)
# NoDecode + Csv: read "a,b" rather than pydantic-settings' default JSON list.
allowed_origins: Annotated[list[str], NoDecode, Csv()] = Field(
["http://localhost:3000"], min_length=1, description="CORS origins allowed to call the API"
)
# pydantic reads durations as ISO 8601 (PT45S); the contract says so, and the platform converts "45s".
request_timeout: timedelta = Field(
timedelta(seconds=30),
ge=timedelta(seconds=1),
le=timedelta(minutes=5),
description="Timeout for a request to finish",
)
"""How long a request may take before the server gives up on it.
Raise it when clients upload large order batches. Keep it below the load balancer's idle timeout, or the
client sees a reset rather than a ``504``.
The platform writes Go durations such as ``45s``; docuconf converts them to ISO 8601 for pydantic.
"""
worker_count: int = Field(4, ge=1, le=64, description="Workers processing orders")2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
generator: {
language: "python"
sdk: "docuconf-pydantic"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "CORS origins allowed to call the API"
items: "string"
encoding: "csv"
separator: ","
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string for orders"
required: true
secret: true
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level"
values: ["debug", "info", "warn", "error"]
default: "info"
}
PORT: {
type: "int"
description: "HTTP listen port"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Timeout for a request to finish"
details: "How long a request may take before the server gives up on it.\n\nRaise it when clients upload large order batches. Keep it below the load balancer's idle timeout, or the\nclient sees a reset rather than a `504`.\n\nThe platform writes Go durations such as `45s`; docuconf converts them to ISO 8601 for pydantic."
encoding: "iso8601"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so the key can be rotated without turning\nwebhooks away. An empty or truncated key fails at boot. Without this variable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Workers processing orders"
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
# frozen_string_literal: true
require "docuconf/anyway"
class OrdersConfig < Anyway::Config
include Docuconf::Anyway
# Read PORT, DATABASE_URL, ... with no ORDERS_ prefix.
env_prefix ""
attr_config :database_url, :webhook_keys,
port: 8080, log_level: "info", allowed_origins: ["http://localhost:3000"],
request_timeout: "30s", worker_count: 4
required :database_url
describe :port, "HTTP listen port", min: 1, max: 65_535
describe :log_level, "Minimum log level", values: %w[debug info warn error]
describe :database_url, "Postgres connection string for orders", type: :url, schemes: %w[postgres],
max_length: 2048, secret: true # never printed, and the contract marks it secret
describe :allowed_origins, "CORS origins allowed to call the API", min_items: 1
# How long the server works on one request before it gives up.
#
# Raise it when clients upload large order batches. Keep it below the load
# balancer's idle timeout, or the client sees a reset rather than a +504+.
describe :request_timeout, "Time allowed to handle one request", min: "1s", max: "5m"
describe :worker_count, "Background workers processing orders", min: 1, max: 64
# A webhook is accepted when it is signed with any key in the set. Each key
# is 32 to 256 characters, so an empty or truncated key fails at boot.
# Without this variable, the service rejects every webhook.
describe :webhook_keys, "Keys that verify the signature on incoming payment webhooks", type: :key_set,
key_min_length: 32, key_max_length: 256
end2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders-api"
generator: {
language: "ruby"
sdk: "docuconf-anyway"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "CORS origins allowed to call the API"
configKey: "orders.allowed_origins"
items: "string"
encoding: "csv"
separator: ","
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string for orders"
required: true
secret: true
configKey: "orders.database_url"
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level"
configKey: "orders.log_level"
values: ["debug", "info", "warn", "error"]
default: "info"
}
PORT: {
type: "int"
description: "HTTP listen port"
configKey: "orders.port"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Time allowed to handle one request"
details: "How long the server works on one request before it gives up.\n\nRaise it when clients upload large order batches. Keep it below the load\nbalancer's idle timeout, or the client sees a reset rather than a `504`."
configKey: "orders.request_timeout"
encoding: "iso8601"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set. Each key\nis 32 to 256 characters, so an empty or truncated key fails at boot.\nWithout this variable, the service rejects every webhook."
secret: true
configKey: "orders.webhook_keys"
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Background workers processing orders"
configKey: "orders.worker_count"
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
package dev.docuconf.examples.orders;
import dev.docuconf.Docuconf;
import dev.docuconf.EnumCase;
import dev.docuconf.MaxLength;
import dev.docuconf.Redacted;
import dev.docuconf.Secret;
import dev.docuconf.UrlSchemes;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.net.URI;
import java.time.Duration;
import java.util.List;
import org.hibernate.validator.constraints.time.DurationMax;
import org.hibernate.validator.constraints.time.DurationMin;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.validation.annotation.Validated;
/**
* Settings of the orders service. Each property is the environment variable Spring binds to it: {@code port} is
* {@code ORDERS_PORT}, {@code databaseUrl} is {@code ORDERS_DATABASEURL}. The first sentence of each property's
* Javadoc is the contract's description, and the rest is its details, longer docs for {@code docuconf docs}.
*
* @param port HTTP listen port
* @param logLevel Minimum level of the log lines the service writes
* @param databaseUrl Postgres connection URL for the orders database
* @param allowedOrigins Origins allowed to call the API from a browser
* @param requestTimeout Time allowed to answer one request
* @param workerCount Background workers that process new orders
* <p>Each worker holds one connection from the pool of {@code databaseUrl}, so keep this below the
* database's connection limit.
* <ul>
* <li>Raise it when the order queue backs up.</li>
* <li>Lower it when the database is the bottleneck.</li>
* </ul>
*/
@Docuconf(service = "orders", enumCase = EnumCase.LOWER)
@Validated
@ConfigurationProperties("orders")
public record OrdersProperties(
@Min(1) @Max(65535) @DefaultValue("8080") int port,
@DefaultValue("INFO") LogLevel logLevel,
// @Secret: the platform must supply it from a Secret, and docuconf never prints it. @MaxLength bounds the
// URL in characters; a longer one fails startup with out_of_range.
@NotNull @Secret @UrlSchemes("postgres") @MaxLength(2048) URI databaseUrl,
@NotEmpty @DefaultValue("http://localhost:3000") List<String> allowedOrigins,
@DurationMin(seconds = 1) @DurationMax(minutes = 5) @DefaultValue("30s") Duration requestTimeout,
@Min(1) @Max(64) @DefaultValue("4") int workerCount) {
/** Log levels. The contract spells them in lower case (enumCase); the app accepts any case, as Spring does. */
public enum LogLevel { DEBUG, INFO, WARN, ERROR }
/** Prints the secret as [redacted]; a record's generated toString() would print it. */
@Override
public String toString() {
return Redacted.toString(this);
}
}2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
appVersion: "1.0.0"
generator: {language: "java", sdk: "docuconf-spring", version: "0.1.0-SNAPSHOT"}
}
vars: {
ORDERS_ALLOWEDORIGINS: {
type: "list"
description: "Origins allowed to call the API from a browser"
configKey: "orders.allowed-origins"
items: "string"
encoding: "csv"
minItems: 1
default: ["http://localhost:3000"]
}
ORDERS_DATABASEURL: {
type: "url"
description: "Postgres connection URL for the orders database"
required: true
secret: true
configKey: "orders.database-url"
schemes: ["postgres"]
maxLength: 2048
}
ORDERS_LOGLEVEL: {
type: "enum"
description: "Minimum level of the log lines the service writes"
configKey: "orders.log-level"
values: ["debug", "info", "warn", "error"]
default: "info"
}
ORDERS_PORT: {
type: "int"
description: "HTTP listen port"
configKey: "orders.port"
min: 1
max: 65535
default: 8080
}
ORDERS_REQUESTTIMEOUT: {
type: "duration"
description: "Time allowed to answer one request"
configKey: "orders.request-timeout"
encoding: "iso8601"
min: "1s"
max: "5m"
default: "30s"
}
ORDERS_WORKERCOUNT: {
type: "int"
description: "Background workers that process new orders"
details: "Each worker holds one connection from the pool of `databaseUrl`, so keep this below the database's connection limit.\n\n- Raise it when the order queue backs up.\n- Lower it when the database is the bottleneck."
configKey: "orders.worker-count"
min: 1
max: 64
default: 4
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook."
secret: true
configKey: "webhook.keys"
encoding: "csv"
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
}
}1 · Your declaration, as you write it today
@DocuconfService(name = "orders")
data class OrdersConfig(
@Doc("HTTP listen port") @Min(1) @Max(65535) val port: Int = 8080,
@Doc("Minimum level of log messages") val logLevel: LogLevel = LogLevel.INFO,
// A Hoplite Secret is exported with `secret: true`; its value never appears in errors or toString.
// @Length(max) on a URL is its maxLength in characters; a longer one fails the boot with out_of_range.
@Doc("Postgres connection URL for the orders database") @Schemes("postgres") @Length(max = 2048) val databaseUrl: Secret,
@Doc("Origins allowed to call the API (CORS)") @Items(min = 1) val allowedOrigins: List<String> = listOf("http://localhost:3000"),
@Doc("Time limit for handling one request") @DurationMin("1s") @DurationMax("5m") val requestTimeout: Duration = Duration.ofSeconds(30),
/**
* Number of background workers that process orders
*
* A KDoc works instead of @Doc: its first sentence is the description, and the rest is the details,
* longer docs for `docuconf docs`. Each worker holds one connection from the pool of [databaseUrl],
* so keep this below the database's connection limit.
*
* - Raise it when the order queue backs up.
* - Lower it when the database is the bottleneck.
*/
@Min(1) @Max(64) val workerCount: Int = 4,
// A KeySet is a key set (contract type keySet, always secret): one comma-separated variable, so
// one Kubernetes Secret key holds "old,new" while a key is rotated (SPEC §6.1). It holds 1 or 2
// keys by default (@Keys changes that). No default, as for every secret.
/**
* Keys that verify the signature on incoming payment webhooks
*
* A webhook is accepted when it is signed with any key in the set, so the key can be rotated
* without turning webhooks away; the generated docs list the rotation steps. Each key is 32 to
* 256 characters, so an empty or truncated key fails at boot. Without this variable, the service
* rejects every webhook.
*/
@KeyLength(min = 32, max = 256) val webhookKeys: KeySet? = null,
)2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
generator: {language: "kotlin", sdk: "docuconf-hoplite", version: "0.1.0"}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins allowed to call the API (CORS)"
configKey: "allowedOrigins"
items: "string"
encoding: "csv"
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Postgres connection URL for the orders database"
required: true
secret: true
configKey: "databaseUrl"
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum level of log messages"
configKey: "logLevel"
values: ["debug", "info", "warn", "error"]
default: "info"
}
PORT: {
type: "int"
description: "HTTP listen port"
configKey: "port"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Time limit for handling one request"
configKey: "requestTimeout"
encoding: "iso8601"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so the key can be rotated\nwithout turning webhooks away; the generated docs list the rotation steps. Each key is 32 to\n256 characters, so an empty or truncated key fails at boot. Without this variable, the service\nrejects every webhook."
secret: true
configKey: "webhookKeys"
encoding: "csv"
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of background workers that process orders"
details: "A KDoc works instead of @Doc: its first sentence is the description, and the rest is the details,\nlonger docs for `docuconf docs`. Each worker holds one connection from the pool of `databaseUrl`,\nso keep this below the database's connection limit.\n\n- Raise it when the order queue backs up.\n- Lower it when the database is the bottleneck."
configKey: "workerCount"
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
/// The service's configuration. The first paragraph of each `///` comment
/// is the variable's description in the contract and the rest its details,
/// and the Rust type picks its contract type.
#[derive(Debug, Deserialize, Docuconf)]
struct Config {
/// HTTP listen port.
#[docuconf(default = 8080, min = 1)]
port: u16,
/// Minimum log level emitted.
#[docuconf(default = "info")]
log_level: LogLevel,
/// Postgres connection string for the orders database.
// `Secret` marks it `secret: true`; `schemes` makes it a `url`, and
// `max_length` caps it in characters.
#[docuconf(schemes("postgres"), max_length = 2048)]
database_url: Secret<String>,
/// Browser origins allowed to call the API.
#[docuconf(default = ["http://localhost:3000"], min_items = 1)]
allowed_origins: Vec<String>,
/// Time allowed to read and answer one request.
#[docuconf(default = "30s", min = "1s", max = "5m")]
#[serde(with = "docuconf::humantime_serde")]
request_timeout: Duration,
/// Threads serving requests.
///
/// Each worker answers one connection at a time, so this is also the
/// number of requests served at once. Raise it when requests queue up;
/// each worker holds a [`std::thread`] stack.
///
/// Keep it at or below the database pool size:
///
/// - one connection per worker;
/// - plus one for migrations.
#[docuconf(default = 4, min = 1, max = 64)]
worker_count: u8,
/// Keys that verify the signature on incoming payment webhooks.
///
/// A webhook is accepted when it is signed with any key in the set, so
/// the key can be rotated without turning webhooks away. Each key is 32
/// to 256 characters, so an empty or truncated key fails at boot.
/// Without this variable, the service rejects every webhook.
// A `KeySet` is always secret, keeps every key out of `Debug` and serde
// output, and reads `old,new` (csv). It holds 1 or 2 keys by default.
#[docuconf(key_min_length = 32, key_max_length = 256)]
webhook_keys: Option<KeySet>,
}2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders-api"
generator: {
language: "rust"
sdk: "docuconf"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Browser origins allowed to call the API"
default: ["http://localhost:3000"]
items: "string"
encoding: "json"
minItems: 1
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string for the orders database"
required: true
secret: true
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level emitted"
default: "info"
values: ["debug", "info", "warn", "error"]
}
PORT: {
type: "int"
description: "HTTP listen port"
default: 8080
min: 1
max: 65535
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Time allowed to read and answer one request"
default: "30s"
encoding: "go"
min: "1s"
max: "5m"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so\nthe key can be rotated without turning webhooks away. Each key is 32\nto 256 characters, so an empty or truncated key fails at boot.\nWithout this variable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Threads serving requests"
details: "Each worker answers one connection at a time, so this is also the\nnumber of requests served at once. Raise it when requests queue up;\neach worker holds a `std::thread` stack.\n\nKeep it at or below the database pool size:\n\n- one connection per worker;\n- plus one for migrations."
default: 4
min: 1
max: 64
}
}
}1 · Your declaration, as you write it today
enum LogLevel: String, ConfigEnum {
case debug, info, warn, error
}2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
generator: {language: "swift", sdk: "docuconf-swift", version: "0.1.0"}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins allowed to call the API (CORS)"
configKey: "allowed.origins"
items: "string"
encoding: "csv"
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string for the orders database"
required: true
secret: true
configKey: "database.url"
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level"
configKey: "log.level"
values: ["debug", "info", "warn", "error"]
default: "info"
}
PORT: {
type: "int"
description: "HTTP listen port"
configKey: "port"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Timeout for one request"
configKey: "request.timeout"
encoding: "seconds"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so the key can be rotated without\nturning webhooks away. Each key is 32 to 256 characters, so an empty or truncated key fails at boot.\nWithout this variable, the service rejects every webhook."
secret: true
configKey: "webhook.keys"
encoding: "csv"
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of background order workers"
details: "Each worker takes one order at a time from the queue and holds one database connection, so keep this\nat or below the pool size:\n\n- one connection per worker;\n- plus one for the HTTP handlers."
configKey: "worker.count"
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
defmodule Orders.Env do
@moduledoc "Every environment variable the orders service reads."
use Docuconf, name: "orders"
env :port, :integer, description: "HTTP listen port", default: 8080, min: 1, max: 65535
# Atom values come back as atoms, ready for Logger.
env :log_level, {:in, [:debug, :info, :warning, :error]},
description: "Minimum log level",
default: :info
# A secret: docuconf never prints its value (not in errors, and not when
# Orders.Env is inspected or logged), and the contract tells the platform
# to supply it from a Kubernetes Secret.
secret :database_url, :url,
description: "Postgres connection string",
required: true,
schemes: ["postgres"],
max_length: 2048
env :allowed_origins, {:list, :string},
description: "Origins allowed to call the API (CORS)",
min_items: 1,
default: ["http://localhost:3000"]
@doc """
Time limit for one request.
Raise it when clients upload large order batches. Keep it below the load
balancer's idle timeout, or the client sees a reset rather than a `504`.
"""
env :request_timeout, :duration,
min: "1s",
max: "5m",
default: "30s"
env :worker_count, :integer,
description: "Order processing workers",
min: 1,
max: 64,
default: 4
@doc """
Keys that verify the signature on incoming payment webhooks.
A webhook is accepted when it is signed with any key in the set, so the
key can be rotated without turning webhooks away. Each key is 32 to 256
characters, so an empty or truncated key fails at boot. Without this
variable, the service rejects every webhook.
"""
secret :webhook_keys, :key_set,
key_min_length: 32,
key_max_length: 256
end2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
appVersion: "1.0.0"
generator: {
language: "elixir"
sdk: "docuconf"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins allowed to call the API (CORS)"
items: "string"
encoding: "csv"
separator: ","
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string"
required: true
secret: true
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level"
values: ["debug", "info", "warning", "error"]
default: "info"
}
PORT: {
type: "int"
description: "HTTP listen port"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Time limit for one request"
details: "Raise it when clients upload large order batches. Keep it below the load\nbalancer's idle timeout, or the client sees a reset rather than a `504`."
encoding: "go"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so the\nkey can be rotated without turning webhooks away. Each key is 32 to 256\ncharacters, so an empty or truncated key fails at boot. Without this\nvariable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Order processing workers"
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
pub fn spec() -> docuconf.Spec(Config) {
use port <- docuconf.env(
docuconf.int("PORT", "HTTP listen port")
|> docuconf.min_int(1)
|> docuconf.max_int(65_535)
|> docuconf.default(8080),
)
use log_level <- docuconf.env(
docuconf.enum("LOG_LEVEL", "Minimum log level emitted", log_levels)
|> docuconf.default(wisp.InfoLevel),
)
// A secret is exported as `secret: true`: the platform supplies it from a
// Secret. docuconf never prints its value, and the app gets a
// `docuconf.Secret`, which prints redacted; `docuconf.reveal` reads it.
use database_url <- docuconf.env(
docuconf.url("DATABASE_URL", "Primary Postgres connection string")
|> docuconf.schemes(["postgres"])
// At most 2048 characters; a longer URL fails the boot with out_of_range.
|> docuconf.max_length(2048)
|> docuconf.secret
|> docuconf.required,
)
use allowed_origins <- docuconf.env(
docuconf.string_list(
"ALLOWED_ORIGINS",
"Origins allowed to call the API (CORS), comma-separated",
separator: ",",
)
|> docuconf.min_items(1)
|> docuconf.default(["http://localhost:3000"]),
)
use request_timeout <- docuconf.env(
docuconf.duration("REQUEST_TIMEOUT", "Timeout for one API request")
// Longer docs for `docuconf docs`, in Markdown. Never read at runtime.
|> docuconf.details(
"Raise it when clients upload large order batches. Keep it below the
load balancer's idle timeout, or the client sees a reset rather than a
`504`.",
)
|> docuconf.min_duration(duration.seconds(1))
|> docuconf.max_duration(duration.minutes(5))
|> docuconf.default(duration.seconds(30)),
)
use worker_count <- docuconf.env(
docuconf.int("WORKER_COUNT", "Background workers that process orders")
|> docuconf.min_int(1)
|> docuconf.max_int(64)
|> docuconf.default(4),
)
// A key set (SPEC §4.3, §6.1): one or two secret keys, all valid at once,
// so a key can be rotated with an overlap in which both are valid. It is
// always secret; the generated docs print the rotation steps.
use webhook_keys <- docuconf.env(
docuconf.key_set(
"WEBHOOK_KEYS",
"Keys that verify the signature on incoming payment webhooks",
)
|> docuconf.details(
"A webhook is accepted when it is signed with any key in the set. Without this variable, the service rejects every webhook.",
)
|> docuconf.key_min_length(32)
|> docuconf.key_max_length(256)
|> docuconf.optional,
)
// Each `use` above bound a handle; `build` reads the values once they
// have all loaded and passed their checks.
use v <- docuconf.build
Config(
port: port(v),
log_level: log_level(v),
database_url: database_url(v),
allowed_origins: allowed_origins(v),
request_timeout: request_timeout(v),
worker_count: worker_count(v),
webhook_keys: webhook_keys(v),
)
}2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
generator: {
language: "gleam"
sdk: "docuconf"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins allowed to call the API (CORS), comma-separated"
items: "string"
encoding: "csv"
separator: ","
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Primary Postgres connection string"
required: true
secret: true
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level emitted"
values: ["debug", "info", "warn", "error"]
default: "info"
}
PORT: {
type: "int"
description: "HTTP listen port"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Timeout for one API request"
details: "Raise it when clients upload large order batches. Keep it below the\nload balancer's idle timeout, or the client sees a reset rather than a\n`504`."
encoding: "go"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set. Without this variable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Background workers that process orders"
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
CLI::App app{"orders: a small HTTP service configured with docuconf"};
// The service name becomes the contract's metadata.name.
docuconf::Declaration config{app, "orders"};
// Each variable is read from its environment variable and checked at
// boot; --help lists them all. PORT is also a command-line flag (--port)
// for local runs; the platform only ever sets the environment.
int port = 0;
config.add_var("PORT", port, "HTTP listen port").range(1, 65535).default_val(8080).flag();
std::string log_level;
config.add_var("LOG_LEVEL", log_level, "Minimum log level emitted")
.values({"debug", "info", "warn", "error"})
.default_val("info");
// A secret: never printed, never given a default, supplied by the
// platform from a Kubernetes Secret.
std::string database_url;
config.add_var("DATABASE_URL", database_url, "Primary Postgres connection string")
.secret()
.required()
.schemes({"postgres"})
.max_length(2048);
std::vector<std::string> allowed_origins;
config.add_var("ALLOWED_ORIGINS", allowed_origins, "Origins allowed to call the API (CORS)")
.min_items(1)
.default_val({"http://localhost:3000"});
std::chrono::milliseconds request_timeout{};
config.add_var("REQUEST_TIMEOUT", request_timeout, "Time allowed to read a request")
.range("1s", "5m")
.default_val("30s");
int worker_count = 0;
config.add_var("WORKER_COUNT", worker_count)
.doc(R"(
/// Number of request worker threads.
///
/// Each worker answers one connection at a time, so this is also the
/// number of requests served at once. Raise it when requests queue up.
///
/// Keep it at or below the database pool size:
/// @li one connection per worker;
/// @li plus one for migrations.
)")
.range(1, 64)
.default_val(4);2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
generator: {
language: "cpp"
sdk: "docuconf-cpp"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins allowed to call the API (CORS)"
default: ["http://localhost:3000"]
items: "string"
encoding: "csv"
separator: ","
minItems: 1
}
DATABASE_URL: {
type: "url"
description: "Primary Postgres connection string"
required: true
secret: true
maxLength: 2048
schemes: ["postgres"]
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level emitted"
default: "info"
values: ["debug", "info", "warn", "error"]
}
PORT: {
type: "int"
description: "HTTP listen port"
default: 8080
min: 1
max: 65535
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Time allowed to read a request"
default: "30s"
min: "1s"
max: "5m"
encoding: "go"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so the\nkey can be rotated without turning webhooks away. Each key is 32 to 256\ncharacters, so an empty or truncated key fails at boot. Without this\nvariable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of request worker threads"
details: "Each worker answers one connection at a time, so this is also the\nnumber of requests served at once. Raise it when requests queue up.\n\nKeep it at or below the database pool size:\n- one connection per worker;\n- plus one for migrations."
default: 4
min: 1
max: 64
}
}
}1 · Your declaration, as you write it today
<?php
use Docuconf\Laravel\Env;
// Env:: is env() with a type, rules and a description. Each call returns the
// typed value, and the app refuses to boot if any of them is wrong.
return [
'port' => Env::int('PORT', 'HTTP listen port', default: 8080, min: 1, max: 65535),
// ORDERS_, not LOG_LEVEL: Laravel's own config/logging.php reads LOG_LEVEL.
'log_level' => Env::enum('ORDERS_LOG_LEVEL', 'Minimum level the orders code logs', ['debug', 'info', 'warn', 'error'], default: 'info'),
// A secret: never printed, and the platform must supply it from a Secret.
'database_url' => Env::url('DATABASE_URL', 'Orders database connection string', required: true, schemes: ['postgres', 'postgresql'], secret: true, maxLength: 2048),
'allowed_origins' => Env::list('ALLOWED_ORIGINS', 'Origins allowed to call the API (CORS)', default: ['http://localhost:3000'], minItems: 1),
// A Docuconf\Duration; written "30s", "1m30s" in the env. The PHPDoc
// comment documents it: its first paragraph is the description, and the
// rest is exported as details, for `docuconf docs`.
/**
* Timeout for each request.
*
* Raise it when clients upload large order batches. Keep it below the
* load balancer's idle timeout, or the client sees a reset rather than
* a `504`.
*/
'request_timeout' => Env::duration('REQUEST_TIMEOUT', default: '30s', min: '1s', max: '5m'),
'worker_count' => Env::int('WORKER_COUNT', 'Number of background workers', default: 4, min: 1, max: 64),
// A key set (SPEC §4.3): "old,new" in one Secret key while a key is
// rotated. Always secret, never printed; an empty or truncated key fails
// at boot. The handler reads it as a Docuconf\KeySet from the validated
// values (routes/web.php).
/**
* Keys that verify the signature on incoming payment webhooks
*
* A webhook is accepted when it is signed with any key in the set. Each
* key is 32 to 256 characters, so an empty or truncated key fails at
* boot. Without this variable, the service rejects every webhook.
*/
'webhook_keys' => Env::keySet('WEBHOOK_KEYS', keyMinLength: 32, keyMaxLength: 256),
];2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders"
generator: {
language: "php"
sdk: "docuconf/docuconf"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins allowed to call the API (CORS)"
items: "string"
encoding: "csv"
separator: ","
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Orders database connection string"
required: true
secret: true
schemes: ["postgres", "postgresql"]
maxLength: 2048
}
ORDERS_LOG_LEVEL: {
type: "enum"
description: "Minimum level the orders code logs"
values: ["debug", "info", "warn", "error"]
default: "info"
}
PORT: {
type: "int"
description: "HTTP listen port"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Timeout for each request"
details: "Raise it when clients upload large order batches. Keep it below the\nload balancer's idle timeout, or the client sees a reset rather than\na `504`."
encoding: "go"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set. Each\nkey is 32 to 256 characters, so an empty or truncated key fails at\nboot. Without this variable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of background workers"
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
# Every variable the service reads, written as in contract.cue. Read them
# with %env(docuconf:NAME)%: the value docuconf validated, typed.
docuconf:
name: orders-symfony
vars:
PORT: {type: int, description: HTTP listen port, min: 1, max: 65535, default: 8080}
LOG_LEVEL: {type: enum, description: Minimum log level, values: [debug, info, warn, error], default: info}
DATABASE_URL: {type: url, description: Orders database connection string, required: true, secret: true, schemes: [postgres, postgresql], maxLength: 2048}
ALLOWED_ORIGINS: {type: list, description: Origins allowed to call the API (CORS), items: string, minItems: 1, default: ['http://localhost:3000']}
REQUEST_TIMEOUT: {type: duration, description: Timeout for each request, min: 1s, max: 5m, default: 30s}
WORKER_COUNT: {type: int, description: Number of background workers, min: 1, max: 64, default: 4}
# A key set (SPEC 4.3): "old,new" in one Secret key while a key is rotated. Always secret.
WEBHOOK_KEYS:
type: keySet
description: Keys that verify the signature on incoming payment webhooks
details: |-
A webhook is accepted when it is signed with any key in the set. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook.
keyMinLength: 32
keyMaxLength: 256
parameters:
orders.port: '%env(docuconf:PORT)%'
orders.request_timeout_seconds: '%env(docuconf_seconds:REQUEST_TIMEOUT)%'2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders_symfony
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders-symfony"
generator: {
language: "php"
sdk: "docuconf/docuconf"
version: "0.1.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins allowed to call the API (CORS)"
items: "string"
encoding: "csv"
separator: ","
minItems: 1
default: ["http://localhost:3000"]
}
DATABASE_URL: {
type: "url"
description: "Orders database connection string"
required: true
secret: true
schemes: ["postgres", "postgresql"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level"
values: ["debug", "info", "warn", "error"]
default: "info"
}
PORT: {
type: "int"
description: "HTTP listen port"
min: 1
max: 65535
default: 8080
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Timeout for each request"
encoding: "go"
min: "1s"
max: "5m"
default: "30s"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of background workers"
min: 1
max: 64
default: 4
}
}
}1 · Your declaration, as you write it today
*> Configuration of the ORDERS-BATCH job, read from the
*> environment by the generated loader ORDCFG.
*> @service orders-batch @prefix CFG- @program ORDCFG
01 ORDERS-CONFIG.
*> Port of the Prometheus metrics endpoint
*> @min 1 @max 65535 @default 8080
05 CFG-PORT PIC 9(5).
*> Log verbosity
*> @default info
05 CFG-LOG-LEVEL PIC X(5).
88 LOG-DEBUG VALUE "debug".
88 LOG-INFO VALUE "info".
88 LOG-WARN VALUE "warn".
88 LOG-ERROR VALUE "error".
*> Postgres connection string of the orders database
*> @type url @schemes postgres @secret @required
05 CFG-DATABASE-URL PIC X(200).
*> Origins whose orders the job accepts
*> @min-items 1 @default "http://localhost:3000"
*> @count CFG-ORIGIN-COUNT
05 CFG-ALLOWED-ORIGINS PIC X(64) OCCURS 8 TIMES.
05 CFG-ORIGIN-COUNT PIC 9(2).
*> Time allowed for each database call, in milliseconds
*> @unit ms @min 1s @max 5m @default 30s
05 CFG-REQUEST-TIMEOUT PIC 9(6).
*> Number of workers that share the input
*>
*> Each worker reads its share of the orders file and holds
*> one database connection, so keep this at or below the
*> pool size:
*>
*> - one connection per worker;
*> - plus one for the summary step.
*> @min 1 @max 64 @default 4
05 CFG-WORKER-COUNT PIC 9(2).
*> Keys that verify the signature on incoming payment webhooks
*>
*> A webhook is accepted when it is signed with any key in the
*> set, so the key can be rotated without turning webhooks
*> away. Each key is 32 to 256 characters, so an empty or
*> truncated key fails at boot. Without this variable, the
*> service rejects every webhook.
*> @type keySet @key-min-length 32
*> @count CFG-WEBHOOK-KEY-COUNT
05 CFG-WEBHOOK-KEYS PIC X(256) OCCURS 2 TIMES.
05 CFG-WEBHOOK-KEY-COUNT PIC 9.
*> The orders to summarise, one per line
*> @file orders text @path /data/orders.txt
*> @path-env ORDERS_FILE @required @max-size 1Mi
05 CFG-ORDERS-PATH PIC X(256).2 · The contract it exports
// Code generated by docuconf. DO NOT EDIT.
package orders_batch
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders-batch"
generator: {
language: "cobol"
sdk: "docuconf-cobol"
version: "0.2.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins whose orders the job accepts"
default: ["http://localhost:3000"]
encoding: "csv"
items: "string"
separator: ","
minItems: 1
maxItems: 8
itemMaxLength: 64
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string of the orders database"
required: true
secret: true
maxLength: 200
schemes: ["postgres"]
}
LOG_LEVEL: {
type: "enum"
description: "Log verbosity"
default: "info"
values: ["debug", "info", "warn", "error"]
}
PORT: {
type: "int"
description: "Port of the Prometheus metrics endpoint"
default: 8080
min: 1
max: 65535
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Time allowed for each database call, in milliseconds"
default: "30s"
min: "1s"
max: "5m"
encoding: "go"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the\nset, so the key can be rotated without turning webhooks\naway. Each key is 32 to 256 characters, so an empty or\ntruncated key fails at boot. Without this variable, the\nservice rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of workers that share the input"
details: "Each worker reads its share of the orders file and holds\none database connection, so keep this at or below the\npool size:\n\n- one connection per worker;\n- plus one for the summary step."
default: 4
min: 1
max: 64
}
}
files: {
orders: {
type: "text"
description: "The orders to summarise, one per line"
required: true
path: "/data/orders.txt"
pathEnv: "ORDERS_FILE"
maxSize: 1048576
}
}
}3 · What docuconf generates from the contract (the Go example)
What the SDK exports from your declaration. The platform team, CUE and every tool below read it.
Made by: docuconf export -pkg ./internal/config -type Config -name orders-api -package orders -o contract.cue
// Code generated by docuconf. DO NOT EDIT.
package orders
import "docuconf.dev/contract"
contract.#Contract & {
apiVersion: "docuconf.dev/v1alpha1"
kind: "ConfigContract"
metadata: {
name: "orders-api"
generator: {
language: "go"
sdk: "docuconf-go"
version: "0.2.0"
}
}
vars: {
ALLOWED_ORIGINS: {
type: "list"
description: "Origins allowed to call the API from a browser"
default: ["http://localhost:3000"]
items: "string"
encoding: "csv"
separator: ","
minItems: 1
}
DATABASE_URL: {
type: "url"
description: "Postgres connection string for the orders database"
required: true
secret: true
schemes: ["postgres"]
maxLength: 2048
}
LOG_LEVEL: {
type: "enum"
description: "Minimum log level emitted"
default: "info"
values: ["debug", "info", "warn", "error"]
}
PORT: {
type: "int"
description: "HTTP listen port"
default: 8080
min: 1
max: 65535
}
REQUEST_TIMEOUT: {
type: "duration"
description: "Time limit for handling one request"
default: "30s"
min: "1s"
max: "5m"
encoding: "go"
}
WEBHOOK_KEYS: {
type: "keySet"
description: "Keys that verify the signature on incoming payment webhooks"
details: "A webhook is accepted when it is signed with any key in the set, so the key can be rotated without turning webhooks away. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook."
secret: true
encoding: "csv"
separator: ","
minKeys: 1
maxKeys: 2
keyMinLength: 32
keyMaxLength: 256
}
WORKER_COUNT: {
type: "int"
description: "Number of background workers processing orders"
details: "Each worker holds one database connection, so keep it below the database's connection limit divided by the number of replicas. Raise it when the order queue grows faster than it drains."
default: 4
min: 1
max: 64
}
}
files: {
discounts: {
type: "config"
format: "yaml"
description: "Discount codes accepted at checkout"
path: "/etc/orders/discounts/discounts.yaml"
schema: {
type: "object"
required: ["codes"]
additionalProperties: false
properties: {
codes: {
type: "object"
description: "Percent off for each discount code"
additionalProperties: {
type: "integer"
}
}
}
}
}
"serving-tls": {
type: "tls"
description: "Certificate to serve HTTPS with. Without it, the service serves HTTP"
secret: true
path: "/etc/orders/tls"
reload: "watch"
dnsNames: ["orders.example.com"]
minRemaining: "720h"
}
}
}The same contract as JSON, with defaults filled in, for tools without CUE (`cue export` gives the same data). The Helm library chart reads it.
Made by: docuconf helm -contract contract.cue -chart chart
{
"apiVersion": "docuconf.dev/v1alpha1",
"kind": "ConfigContract",
"metadata": {
"name": "orders-api",
"generator": {
"language": "go",
"sdk": "docuconf-go",
"version": "0.2.0"
}
},
"vars": {
"ALLOWED_ORIGINS": {
"name": "ALLOWED_ORIGINS",
"description": "Origins allowed to call the API from a browser",
"required": false,
"secret": false,
"separator": ",",
"type": "list",
"items": "string",
"encoding": "csv",
"minItems": 1,
"default": [
"http://localhost:3000"
]
},
"DATABASE_URL": {
"name": "DATABASE_URL",
"description": "Postgres connection string for the orders database",
"required": true,
"secret": true,
"type": "url",
"schemes": [
"postgres"
],
"maxLength": 2048
},
"LOG_LEVEL": {
"name": "LOG_LEVEL",
"description": "Minimum log level emitted",
"required": false,
"secret": false,
"type": "enum",
"values": [
"debug",
"info",
"warn",
"error"
],
"default": "info"
},
"PORT": {
"name": "PORT",
"description": "HTTP listen port",
"required": false,
"secret": false,
"type": "int",
"default": 8080,
"min": 1,
"max": 65535
},
"REQUEST_TIMEOUT": {
"name": "REQUEST_TIMEOUT",
"description": "Time limit for handling one request",
"required": false,
"secret": false,
"type": "duration",
"encoding": "go",
"default": "30s",
"min": "1s",
"max": "5m"
},
"WEBHOOK_KEYS": {
"name": "WEBHOOK_KEYS",
"description": "Keys that verify the signature on incoming payment webhooks",
"details": "A webhook is accepted when it is signed with any key in the set, so the key can be rotated without turning webhooks away. Each key is 32 to 256 characters, so an empty or truncated key fails at boot. Without this variable, the service rejects every webhook.",
"required": false,
"separator": ",",
"type": "keySet",
"secret": true,
"encoding": "csv",
"minKeys": 1,
"maxKeys": 2,
"keyMinLength": 32,
"keyMaxLength": 256
},
"WORKER_COUNT": {
"name": "WORKER_COUNT",
"description": "Number of background workers processing orders",
"details": "Each worker holds one database connection, so keep it below the database's connection limit divided by the number of replicas. Raise it when the order queue grows faster than it drains.",
"required": false,
"secret": false,
"type": "int",
"default": 4,
"min": 1,
"max": 64
}
},
"files": {
"discounts": {
"name": "discounts",
"description": "Discount codes accepted at checkout",
"required": false,
"secret": false,
"path": "/etc/orders/discounts/discounts.yaml",
"reload": "restart",
"type": "config",
"format": "yaml",
"schema": {
"type": "object",
"required": [
"codes"
],
"additionalProperties": false,
"properties": {
"codes": {
"type": "object",
"description": "Percent off for each discount code",
"additionalProperties": {
"type": "integer"
}
}
}
}
},
"serving-tls": {
"name": "serving-tls",
"description": "Certificate to serve HTTPS with. Without it, the service serves HTTP",
"required": false,
"type": "tls",
"secret": true,
"dnsNames": [
"orders.example.com"
],
"minRemaining": "720h",
"path": "/etc/orders/tls",
"reload": "watch",
"requireCA": false
}
}
}Helm checks the chart’s values against it on every lint, template, install and upgrade.
Made by: docuconf helm -contract contract.cue -chart chart
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"docuconf": {
"type": "object",
"description": "Inputs for orders-api, checked against its docuconf contract.",
"additionalProperties": false,
"properties": {
"global": {
"description": "Set by Helm for the docuconf library chart; ignored."
},
"values": {
"type": "object",
"description": "Environment variables, as typed values.",
…
"DATABASE_URL": {
"description": "Postgres connection string for the orders database (secret: supply a secretKeyRef or injected)",
"oneOf": [
{
"type": "object",
"required": [
"secretKeyRef"
],
"additionalProperties": {
"type": "null"
},
"properties": {
"secretKeyRef": {
"type": "object",
"required": [
"name",
"key"
],
"additionalProperties": true,
"properties": {
"name": {
"type": "string"
},
"key": {
"type": "string"
}
}
}
}
},
…
"PORT": {
"description": "HTTP listen port",
"anyOf": [
{
"maximum": 65535,
"minimum": 1,
"type": "integer"
…The pod’s env, volumes, mounts, ConfigMaps, restart triggers and injector annotations, rendered from valid values at deploy time.
Made by: docuconf render -contract contract.cue -values deploy/values.yaml -files deploy/files.yaml
env:
- name: ALLOWED_ORIGINS
value: https://shop.example.com
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: orders-db
key: url
- name: LOG_LEVEL
value: warn
- name: WEBHOOK_KEYS
valueFrom:
secretKeyRef:
name: orders-webhooks
key: keys
- name: WORKER_COUNT
value: "8"
volumes:
- configMap:
name: orders-api-discounts-7c44d96990
defaultMode: 292
items:
- key: discounts.yaml
path: discounts.yaml
name: dc-discounts
- name: dc-serving-tls
secret:
secretName: orders-tls
defaultMode: 256
volumeMounts:
- name: dc-discounts
mountPath: /etc/orders/discounts
readOnly: true
- name: dc-serving-tls
mountPath: /etc/orders/tls
readOnly: true
configMaps:
- apiVersion: v1
kind: ConfigMap
metadata:
name: orders-api-discounts-7c44d96990
immutable: true
data:
discounts.yaml: |
codes:
WELCOME10: 10
SPRING25: 25
restartTriggers: []
podAnnotations: {}
podLabels: {}Docs for the developers who run and change the app, committed next to the contract.
Made by: docuconf docs contract.cue -o CONFIG.md
# orders-api configuration
Generated by docuconf from the configuration contract of `orders-api`, exported by `docuconf-go` `0.2.0` (go). Do not edit this file: change the app's declaration, export the contract again, then run `docuconf docs`.
`orders-api` reads 7 environment variables and 2 files. 1 is required, and 3 are secret.
## Contents
**[Environment variables](#environment-variables)**
- [`ALLOWED_ORIGINS`](#allowed_origins): Origins allowed to call the API from a browser
- [`DATABASE_URL`](#database_url): Postgres connection string for the orders database (required, secret)
- [`LOG_LEVEL`](#log_level): Minimum log level emitted
- [`PORT`](#port): HTTP listen port
- [`REQUEST_TIMEOUT`](#request_timeout): Time limit for handling one request
- [`WEBHOOK_KEYS`](#webhook_keys): Keys that verify the signature on incoming payment webhooks (secret)
- [`WORKER_COUNT`](#worker_count): Number of background workers processing orders
**[Files](#files)**
- [`discounts`](#discounts): Discount codes accepted at checkout
- [`serving-tls`](#serving-tls): Certificate to serve HTTPS with. Without it, the service serves HTTP (secret)
**Also:** [Sources](#sources) · [Boot errors](#boot-errors)
## Environment variables
### `ALLOWED_ORIGINS`
Origins allowed to call the API from a browser
| Property | Value |
|---|---|
| Type | `list` (list of strings) |
| Required | no |
| Secret | no |
| Default | `["http://localhost:3000"]`; in the environment: `ALLOWED_ORIGINS=http://localhost:3000` |
| Constraints | at least 1 item |
| Wire format | the items joined by `,` with nothing around it, such as `a,b` |
| In a values file | a list of strings, such as `[a, b]`; docuconf writes it in the wire format |
| Sources | `literal`, `injected` |
| Boot errors | `invalid_type`, `too_few_items` |
### `DATABASE_URL`
Postgres connection string for the orders database
| Property | Value |
|---|---|
| Type | `url` (URL) |
| Required | yes |
| Secret | yes: never write its value in code, docs or a values file |
| Constraints | at most 2048 characters (Unicode code points); `postgres` URL |
| Wire format | an absolute URL, `scheme://...`, as is |
| In a values file | a `secretKeyRef` or `injected` reference, never the value |
| Sources | `secretKeyRef`, `injected` |
| Boot errors | `missing_required`, `invalid_type`, `out_of_range`, `invalid_scheme` |
…Excerpt. Full CONFIG.md on GitHub
Rules for coding and ops agents that change the app or set its deployment values.
Made by: docuconf docs contract.cue --format agents -o CONFIG.agents.md
# orders-api configuration: rules for agents
This file lists every configuration input `orders-api` reads, from its docuconf contract. It is for coding agents changing the app and for agents setting its deployment values. Generated by docuconf from the contract; do not edit it. To change an input, change the app's declaration, export the contract again, then run `docuconf docs`.
## Hard rules
1. Never put a secret value in code, a `.env` file, a values file, a ConfigMap, an annotation, a commit, a log or a message. Supply a secret variable only as a `secretKeyRef` or `injected`, and a secret file only from a `secret`, `certificate` or `csi` source or `injected`. Secret inputs: `DATABASE_URL`, `WEBHOOK_KEYS` and `serving-tls`.
2. Use each input's declared wire format when writing a raw environment value (a `.env` file, a shell, `docker run -e`): list and duration formats differ between apps. In a platform values file, write typed values instead (lists as lists, durations in Go syntax such as `90s`); docuconf renders the wire format.
3. Validate before proposing a change: `docuconf vet -contract contract.cue -values values.yaml -files files.yaml` for platform values, and `docuconf check -contract contract.cue` in a running environment. Both print every problem and exit 1.
4. Do not invent inputs. `orders-api` reads only the 7 environment variables and 2 files below; `vet` rejects a value for anything else. A new input needs a change to the app's declaration and a new contract export.
5. Set every required input that has no default: `DATABASE_URL`.
…Excerpt. Full CONFIG.agents.md on GitHub
The docs model both renderers read; a portal, a Backstage plugin or an MCP server can render from it too.
Made by: docuconf docs contract.cue --format model -o docs.json
{
"apiVersion": "docs.docuconf.dev/v1alpha1",
"kind": "ConfigDocs",
"service": {
"name": "orders-api",
"generator": {
"language": "go",
"sdk": "docuconf-go",
"version": "0.2.0"
}
},
"groups": [
{
"name": "",
"title": "General",
"inputs": [
{
"name": "ALLOWED_ORIGINS",
"kind": "var",
"type": "list",
"typeLabel": "list of strings",
"required": false,
"secret": false,
"description": "Origins allowed to call the API from a browser",
"default": [
"http://localhost:3000"
],
"defaultEnv": [
{
"name": "ALLOWED_ORIGINS",
"value": "http://localhost:3000"
}
],
"wire": {
"encoding": "csv",
"separator": ",",
"text": "the items joined by `,` with nothing around it, such as `a,b`",
"platform": "a list of strings, such as `[a, b]`; docuconf writes it in the wire format"
},
"constraints": [
{
"rule": "itemCount",
"params": {
"minItems": 1
},
"text": "at least 1 item"
…Excerpt. Full docs.json on GitHub
What CI prints when proposed values break the contract: every problem, exit 1, and never the secret value itself.
$ cat values.yaml
DATABASE_URL: "postgres://orders:hunter2@db:5432/orders"
DATABSE_URL: "postgres://orders@db:5432/orders"
PORT: 70000
$ docuconf vet -contract contract.cue -values values.yaml
DATABASE_URL: is secret, so it must come from a secretKeyRef, written {secretKeyRef: {name: <secret>, key: <key>}}, or an injector, never a literal or another reference
DATABSE_URL: is not declared in the contract (check the spelling)
PORT: 70000 is above max 65535Every file comes from docuconf-go's orders example and is checked against its main branch in CI. Every output, and its status →
Principles
What docuconf believes.
Your library, not ours
docuconf extends the leading env library in each language. Adopting it means adding a package and some metadata, not rewriting your config.
One contract, any language
A Rails app and a .NET service produce the same kind of contract, so the platform validates both the same way. 16 SDKs pass one shared conformance suite.
Fail before deploy
Missing, mistyped and out-of-range values are caught at composition time, not at 2 a.m. by a crash loop.
Secrets stay secret
Contracts never hold secret values. The platform supplies secrets only as references, and errors never print them.
Policy stays with the platform
The app says what it accepts; the platform says what each environment allows. Neither edits the other.
Open by design
A specification first, with a conformance suite so independently built SDKs provably agree.
Languages
Built for platform teams running many languages.
| SDK | Builds on | Status |
|---|---|---|
| Go | caarlos0/env v11 | v0.1 alpha · conformance 316/316 |
| TypeScript (T3 Env) | T3 Env + Zod 4 | v0.1 alpha · conformance 316/316 |
| TypeScript (NestJS) | @nestjs/config + class-validator | v0.1 alpha · conformance 316/316 |
| .NET | Options pattern + appsettings | v0.1 alpha · conformance 316/316 |
| Python | pydantic-settings 2 | v0.1 alpha · conformance 316/316 |
| Ruby | anyway_config 2 | v0.1 alpha · conformance 316/316 |
| Java (Spring Boot) | Spring Boot 3 / 4 @ConfigurationProperties | v0.1 alpha · conformance 316/316 |
| Kotlin | Hoplite 3 | v0.1 alpha · conformance 316/316 |
| Rust | figment + serde | v0.1 alpha · conformance 316/316 |
| Swift | swift-configuration | v0.1 alpha · conformance 316/316 |
| Elixir | config/runtime.exs | v0.1 alpha · conformance 316/316 |
| Gleam | envoy + gleam/dynamic/decode | v0.1 alpha · conformance 316/316 |
| C++ | CLI11 | v0.1 alpha · conformance 316/316 |
| PHP (Laravel) | Laravel config + vlucas/phpdotenv | v0.1 alpha · conformance 316/316 |
| PHP (Symfony) | Symfony config + %env()% processors | v0.1 alpha · conformance 316/316 |
| COBOL | GnuCOBOL copybooks + docuconf exec | v0.1 alpha · conformance 316/316 |
None is on a package registry yet; each Get started page installs from git. Conformance is the shared suite of 316 cases every SDK runs. Compare what each SDK supports.
A deliberate boundary
Config is not feature flags.
A variable belongs in a contract if, and only if, changing it needs a rollout. Runtime toggles belong in a flag system such as OpenFeature.
Why the line matters →Early days
Help shape the spec.
The contract specification is a draft and every SDK is a v0.1 alpha. One good comment can still change the design.