use serde::Serialize; #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)] #[serde(rename_all = "snake_case")] pub enum ProcessScope { Shared, AdminApi, McpServer, } #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)] #[serde(rename_all = "snake_case")] pub enum Sensitivity { Public, Internal, Secret, } #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)] #[serde(rename_all = "snake_case")] pub enum FieldMode { Effective, DeprecatedNoEffect, } #[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)] pub struct FieldSpec { pub semantic_path: &'static str, pub env_name: &'static str, pub process: ProcessScope, pub value_type: &'static str, pub unit: Option<&'static str>, pub default: Option<&'static str>, pub required: bool, pub minimum: Option, pub maximum: Option, pub sensitivity: Sensitivity, pub mode: FieldMode, pub compatibility: Option<&'static str>, pub rules: &'static [&'static str], } impl FieldSpec { pub fn default_for(self, process: ProcessScope) -> Option<&'static str> { match (self.env_name, process) { ("CRANK_BASE_URL", ProcessScope::AdminApi) => Some("http://localhost:3000"), ("CRANK_LOG_LEVEL", ProcessScope::AdminApi) => Some("admin_api=info,tower_http=info"), ("CRANK_LOG_LEVEL", ProcessScope::McpServer) => Some("mcp_server=info,tower_http=info"), _ => self.default, } } } pub(crate) fn semantic_path_for(env_name: &str) -> &str { field_registry() .iter() .find(|field| field.env_name == env_name) .map_or(env_name, |field| field.semantic_path) } macro_rules! f { ($path:literal,$name:literal,$proc:ident,$type:literal,$unit:expr,$default:expr,$min:expr,$max:expr,$sensitivity:ident) => { FieldSpec { semantic_path: $path, env_name: $name, process: ProcessScope::$proc, value_type: $type, unit: $unit, default: $default, required: false, minimum: $min, maximum: $max, sensitivity: Sensitivity::$sensitivity, mode: FieldMode::Effective, compatibility: None, rules: &[], } }; } static FIELDS: [FieldSpec; 65] = [ FieldSpec { compatibility: Some("legacy URL form"), rules: &[ "takes precedence over generated default-valued POSTGRES_HOST/PORT/DB/USER/PASSWORD", "conflicts with any non-default decomposed database value", ], ..f!( "database.url", "CRANK_DATABASE_URL", Shared, "url", None, None, None, None, Secret ) }, f!( "database.host", "POSTGRES_HOST", Shared, "string", None, Some("postgres"), None, None, Internal ), f!( "database.port", "POSTGRES_PORT", Shared, "u16", Some("port"), Some("5432"), Some(1), Some(65535), Public ), f!( "database.name", "POSTGRES_DB", Shared, "string", None, Some("crank"), None, None, Internal ), f!( "database.user", "POSTGRES_USER", Shared, "string", None, Some("crank"), None, None, Internal ), f!( "database.password", "POSTGRES_PASSWORD", Shared, "secret", None, Some("configured"), None, None, Secret ), FieldSpec { rules: &["must be >= min_connections"], ..f!( "database.pool.max_connections", "POSTGRES_MAX_CONNECTIONS", Shared, "u32", Some("connections"), Some("20"), Some(1), Some(1024), Public ) }, FieldSpec { rules: &["must be <= max_connections"], ..f!( "database.pool.min_connections", "POSTGRES_MIN_CONNECTIONS", Shared, "u32", Some("connections"), Some("2"), Some(0), Some(1024), Public ) }, f!( "database.pool.acquire_timeout_ms", "POSTGRES_ACQUIRE_TIMEOUT_MS", Shared, "u64", Some("milliseconds"), Some("5000"), Some(1), Some(300000), Public ), f!( "database.pool.idle_timeout_ms", "POSTGRES_IDLE_TIMEOUT_MS", Shared, "u64", Some("milliseconds"), Some("600000"), Some(1000), Some(86400000), Public ), f!( "database.pool.max_lifetime_ms", "POSTGRES_MAX_LIFETIME_MS", Shared, "u64", Some("milliseconds"), Some("1800000"), Some(1000), Some(86400000), Public ), FieldSpec { required: true, ..f!( "runtime.master_key", "CRANK_MASTER_KEY", Shared, "secret", None, None, Some(32), None, Secret ) }, f!( "runtime.base_url", "CRANK_BASE_URL", Shared, "url", None, None, None, None, Internal ), f!( "runtime.max_concurrent_unary", "CRANK_RUNTIME_MAX_CONCURRENT_UNARY", Shared, "u32", Some("requests"), Some("64"), Some(1), Some(65535), Public ), FieldSpec { compatibility: Some("redis value is deprecated in favor of valkey"), rules: &["external backend requires cache.url"], ..f!( "cache.backend", "CRANK_CACHE_BACKEND", Shared, "enum", None, Some("memory"), None, None, Public ) }, FieldSpec { rules: &["forbidden with memory backend"], ..f!( "cache.url", "CRANK_CACHE_URL", Shared, "url", None, None, None, None, Secret ) }, FieldSpec { mode: FieldMode::DeprecatedNoEffect, ..f!( "cache.default_ttl_ms", "CRANK_CACHE_DEFAULT_TTL_MS", Shared, "u64", Some("milliseconds"), None, Some(1), Some(86400000), Public ) }, f!( "outbound.allowed_hosts", "CRANK_OUTBOUND_ALLOWED_HOSTS", Shared, "host_list", None, Some(""), None, None, Internal ), FieldSpec { rules: &["deny entries override allow entries"], ..f!( "outbound.denied_hosts", "CRANK_OUTBOUND_DENIED_HOSTS", Shared, "host_list", None, Some(""), None, None, Internal ) }, f!( "outbound.max_request_bytes", "CRANK_OUTBOUND_MAX_REQUEST_BYTES", Shared, "u64", Some("bytes"), Some("4194304"), Some(1), Some(67108864), Public ), f!( "outbound.max_response_bytes", "CRANK_OUTBOUND_MAX_RESPONSE_BYTES", Shared, "u64", Some("bytes"), Some("4194304"), Some(1), Some(67108864), Public ), FieldSpec { rules: &[ "empty list disables external OpenAPI reference fetching", "each prefix must be canonical HTTP(S) without userinfo, query, or fragment", ], ..f!( "import.external_references.allowed_url_prefixes", "CRANK_IMPORT_EXTERNAL_REFERENCE_ALLOWED_URL_PREFIXES", AdminApi, "url_prefix_list", None, Some(""), None, None, Internal ) }, f!( "import.external_references.max_depth", "CRANK_IMPORT_EXTERNAL_REFERENCE_MAX_DEPTH", AdminApi, "u32", Some("edges"), Some("8"), Some(1), Some(32), Public ), f!( "import.external_references.max_documents", "CRANK_IMPORT_EXTERNAL_REFERENCE_MAX_DOCUMENTS", AdminApi, "u32", Some("documents"), Some("32"), Some(1), Some(32), Public ), f!( "import.external_references.max_fetch_bytes", "CRANK_IMPORT_EXTERNAL_REFERENCE_MAX_FETCH_BYTES", AdminApi, "u64", Some("bytes"), Some("262144"), Some(1), Some(4194304), Public ), f!( "import.external_references.fetch_timeout_ms", "CRANK_IMPORT_EXTERNAL_REFERENCE_FETCH_TIMEOUT_MS", AdminApi, "u64", Some("milliseconds"), Some("10000"), Some(1), Some(300000), Public ), f!( "import.external_references.max_expanded_nodes", "CRANK_IMPORT_EXTERNAL_REFERENCE_MAX_EXPANDED_NODES", AdminApi, "u32", Some("nodes"), Some("10000"), Some(1), Some(100000), Public ), f!( "observability.environment", "CRANK_ENVIRONMENT", Shared, "label", None, Some("development"), None, None, Public ), f!( "observability.log_filter", "CRANK_LOG_LEVEL", Shared, "string", None, None, None, None, Public ), f!( "observability.sentry_dsn", "CRANK_SENTRY_DSN", Shared, "url", None, None, None, None, Secret ), FieldSpec { compatibility: Some("yes/no/on/off spellings are deprecated"), ..f!( "observability.metrics.enabled", "CRANK_METRICS_ENABLED", Shared, "bool", None, Some("true"), None, None, Public ) }, FieldSpec { rules: &["required when an enabled metrics bind is non-loopback"], ..f!( "observability.metrics.bearer_token", "CRANK_METRICS_BEARER_TOKEN", Shared, "secret", None, None, None, None, Secret ) }, f!( "observability.otlp.endpoint", "OTEL_EXPORTER_OTLP_ENDPOINT", Shared, "url", None, None, None, None, Internal ), FieldSpec { rules: &["overrides generic OTLP endpoint"], ..f!( "observability.otlp.traces_endpoint", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", Shared, "url", None, None, None, None, Internal ) }, f!( "observability.otlp.protocol", "OTEL_EXPORTER_OTLP_PROTOCOL", Shared, "enum", None, Some("http/protobuf"), None, None, Public ), f!( "observability.otlp.traces_protocol", "OTEL_EXPORTER_OTLP_TRACES_PROTOCOL", Shared, "enum", None, None, None, None, Public ), f!( "observability.otlp.timeout", "OTEL_EXPORTER_OTLP_TIMEOUT", Shared, "duration", Some("milliseconds"), Some("10000"), Some(1), Some(300000), Public ), f!( "observability.otlp.traces_timeout", "OTEL_EXPORTER_OTLP_TRACES_TIMEOUT", Shared, "duration", Some("milliseconds"), None, Some(1), Some(300000), Public ), f!( "observability.otlp.headers", "OTEL_EXPORTER_OTLP_HEADERS", Shared, "headers", None, None, None, None, Secret ), f!( "observability.otlp.traces_headers", "OTEL_EXPORTER_OTLP_TRACES_HEADERS", Shared, "headers", None, None, None, None, Secret ), f!( "observability.otlp.max_queue_size", "OTEL_BSP_MAX_QUEUE_SIZE", Shared, "u32", Some("spans"), Some("2048"), Some(1), Some(65536), Public ), FieldSpec { rules: &["must be <= max_queue_size"], ..f!( "observability.otlp.max_export_batch_size", "OTEL_BSP_MAX_EXPORT_BATCH_SIZE", Shared, "u32", Some("spans"), Some("512"), Some(1), Some(65536), Public ) }, f!( "observability.otlp.schedule_delay", "OTEL_BSP_SCHEDULE_DELAY", Shared, "duration", Some("milliseconds"), Some("5000"), Some(1), Some(300000), Public ), f!( "observability.otlp.export_timeout", "OTEL_BSP_EXPORT_TIMEOUT", Shared, "duration", Some("milliseconds"), Some("30000"), Some(1), Some(300000), Public ), f!( "admin.bind", "CRANK_ADMIN_BIND", AdminApi, "socket", None, Some("0.0.0.0:3001"), None, None, Internal ), f!( "admin.metrics_bind", "CRANK_ADMIN_METRICS_BIND", AdminApi, "socket", None, Some("127.0.0.1:9464"), None, None, Internal ), f!( "admin.storage_root", "CRANK_STORAGE_ROOT", Shared, "absolute_path", None, Some("/var/lib/crank/storage"), None, None, Internal ), f!( "admin.rate_limit.rps", "CRANK_ADMIN_RATE_LIMIT_RPS", AdminApi, "u32", Some("requests_per_second"), Some("30"), Some(1), Some(100000), Public ), FieldSpec { rules: &["must be >= admin rate RPS"], ..f!( "admin.rate_limit.burst", "CRANK_ADMIN_RATE_LIMIT_BURST", AdminApi, "u32", Some("requests"), Some("60"), Some(1), Some(1000000), Public ) }, f!( "admin.invocation_log_retention_days", "CRANK_INVOCATION_LOG_RETENTION_DAYS", AdminApi, "u32", Some("days"), Some("30"), Some(1), Some(36500), Public ), FieldSpec { required: true, ..f!( "admin.session.secret", "CRANK_SESSION_SECRET", AdminApi, "secret", None, None, None, None, Secret ) }, FieldSpec { required: true, ..f!( "admin.password_pepper", "CRANK_PASSWORD_PEPPER", AdminApi, "secret", None, None, None, None, Secret ) }, f!( "admin.session.ttl_hours", "CRANK_SESSION_TTL_HOURS", AdminApi, "u32", Some("hours"), Some("24"), Some(1), Some(8760), Public ), FieldSpec { mode: FieldMode::DeprecatedNoEffect, compatibility: Some("deprecated boolean proxy trust; use CRANK_TRUSTED_PROXY_IPS"), ..f!( "admin.trust_forwarded_headers", "CRANK_TRUST_FORWARDED_HEADERS", AdminApi, "bool", None, None, None, None, Public ) }, FieldSpec { rules: &[ "only listed immediate peer IPs may supply X-Real-IP/X-Forwarded-For client identity", "empty value disables forwarded-header trust", ], ..f!( "admin.trusted_proxy_ips", "CRANK_TRUSTED_PROXY_IPS", AdminApi, "ip_list", None, Some(""), None, None, Internal ) }, FieldSpec { required: true, ..f!( "admin.bootstrap.email", "CRANK_BOOTSTRAP_ADMIN_EMAIL", AdminApi, "string", None, None, None, None, Internal ) }, FieldSpec { compatibility: Some("deprecated startup-bootstrap password; use local bootstrap contract"), ..f!( "admin.bootstrap.password", "CRANK_BOOTSTRAP_ADMIN_PASSWORD", AdminApi, "secret", None, None, None, None, Secret ) }, f!( "admin.bootstrap.display_name", "CRANK_BOOTSTRAP_ADMIN_DISPLAY_NAME", AdminApi, "string", None, Some("Crank Owner"), None, None, Internal ), FieldSpec { compatibility: Some("yes/no/on/off spellings are deprecated"), ..f!( "admin.demo_seed", "CRANK_DEMO_SEED", AdminApi, "bool", None, Some("false"), None, None, Public ) }, f!( "mcp.bind", "CRANK_MCP_BIND", McpServer, "socket", None, Some("0.0.0.0:3002"), None, None, Internal ), f!( "mcp.metrics_bind", "CRANK_MCP_METRICS_BIND", McpServer, "socket", None, Some("127.0.0.1:9465"), None, None, Internal ), f!( "mcp.refresh_ms", "CRANK_MCP_REFRESH_MS", McpServer, "u64", Some("milliseconds"), Some("5000"), Some(100), Some(3600000), Public ), f!( "mcp.rate_limit.rps", "CRANK_MCP_RATE_LIMIT_RPS", McpServer, "u32", Some("requests_per_second"), Some("60"), Some(1), Some(100000), Public ), FieldSpec { rules: &["must be >= MCP rate RPS"], ..f!( "mcp.rate_limit.burst", "CRANK_MCP_RATE_LIMIT_BURST", McpServer, "u32", Some("requests"), Some("120"), Some(1), Some(1000000), Public ) }, f!( "runtime.max_concurrent_sessions", "CRANK_RUNTIME_MAX_CONCURRENT_SESSIONS", McpServer, "u32", Some("sessions"), Some("16"), Some(1), Some(65535), Public ), ]; pub fn field_registry() -> &'static [FieldSpec] { &FIELDS } static DEPLOYMENT_FIELDS: [&str; 12] = [ "COMPOSE_PROJECT_NAME", "POSTGRES_PUBLISH_BIND", "POSTGRES_PUBLISH_PORT", "CRANK_ADMIN_API_IMAGE", "CRANK_MCP_SERVER_IMAGE", "CRANK_UI_IMAGE", "CRANK_PUBLISH_BIND", "CRANK_ADMIN_PUBLISH_PORT", "CRANK_MCP_PUBLISH_PORT", "CRANK_UI_PUBLISH_PORT", "VALKEY_PUBLISH_BIND", "VALKEY_PUBLISH_PORT", ]; pub fn deployment_field_registry() -> &'static [&'static str] { &DEPLOYMENT_FIELDS }