systemprompt_models/profile/
mod.rs1mod cloud;
15mod database;
16mod error;
17mod from_env;
18mod governance;
19mod info;
20mod paths;
21mod rate_limits;
22mod runtime;
23mod secrets;
24mod security;
25mod server;
26mod services;
27mod site;
28mod storage;
29mod style;
30mod validation;
31
32pub use cloud::{CloudConfig, CloudValidationMode};
33pub use database::{DatabaseConfig, PoolConfig};
34pub use error::{ProfileError, ProfileResult};
35pub use governance::{
36 AuthzConfig, AuthzHookConfig, AuthzMode, GovernanceConfig, UNRESTRICTED_ACKNOWLEDGEMENT,
37};
38pub use info::ProfileInfo;
39pub use paths::{PathsConfig, expand_home, resolve_path, resolve_with_home};
40pub use rate_limits::{
41 RateLimitsConfig, default_agent_registry, default_agents, default_artifacts, default_burst,
42 default_content, default_contexts, default_mcp, default_mcp_registry, default_oauth_auth,
43 default_oauth_public, default_stream, default_tasks,
44};
45pub use runtime::{Environment, LogLevel, OutputFormat, RuntimeConfig};
46pub use secrets::{SecretsConfig, SecretsSource, SecretsValidationMode};
47pub use security::{
48 DEFAULT_ID_JAG_TTL_SECS, GATEWAY_REQUIRED_RESOURCE_AUDIENCES, SecurityConfig, TrustedIssuer,
49 default_resource_audiences,
50};
51pub use server::{
52 ContentNegotiationConfig, FrameOptions, ReferrerPolicy, SecurityHeadersConfig, ServerConfig,
53};
54pub use services::ServicesProfileConfig;
55pub use site::SiteConfig;
56pub use storage::{StorageBackend, StorageConfig};
57pub use style::ProfileStyle;
58
59use serde::{Deserialize, Serialize};
60use std::path::Path;
61
62use crate::env::{interpolate, read_env_optional};
63
64#[derive(Debug, Clone, Default, Serialize, Deserialize, schemars::JsonSchema)]
65#[serde(deny_unknown_fields)]
66pub struct ExtensionsConfig {
67 #[serde(default)]
68 pub disabled: Vec<String>,
69}
70
71impl ExtensionsConfig {
72 pub fn is_disabled(&self, extension_id: &str) -> bool {
73 self.disabled.iter().any(|id| id == extension_id)
74 }
75}
76
77#[derive(
78 Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Default, schemars::JsonSchema,
79)]
80#[serde(rename_all = "lowercase")]
81pub enum ProfileType {
82 #[default]
83 Local,
84 Cloud,
85}
86
87impl ProfileType {
88 pub const fn is_cloud(&self) -> bool {
89 matches!(self, Self::Cloud)
90 }
91
92 pub const fn is_local(&self) -> bool {
93 matches!(self, Self::Local)
94 }
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize, schemars::JsonSchema)]
98#[serde(deny_unknown_fields)]
99pub struct Profile {
100 pub name: String,
101
102 pub display_name: String,
103
104 #[serde(default)]
105 pub target: ProfileType,
106
107 pub site: SiteConfig,
108
109 pub database: DatabaseConfig,
110
111 pub server: ServerConfig,
112
113 pub paths: PathsConfig,
114
115 pub security: SecurityConfig,
116
117 pub rate_limits: RateLimitsConfig,
118
119 pub system_admin: crate::services::SystemAdminConfig,
120
121 #[serde(default)]
122 pub runtime: RuntimeConfig,
123
124 #[serde(default)]
125 pub cloud: Option<CloudConfig>,
126
127 #[serde(default)]
128 pub secrets: Option<SecretsConfig>,
129
130 #[serde(default)]
131 pub extensions: ExtensionsConfig,
132
133 #[serde(default)]
134 pub governance: Option<GovernanceConfig>,
135
136 #[serde(default)]
137 pub services: ServicesProfileConfig,
138
139 #[serde(default)]
140 pub storage: StorageConfig,
141}
142
143const MOVED_SECTIONS: &[(&str, &str)] = &[
144 ("providers", "services/ai/providers.yaml"),
145 ("gateway", "services/ai/gateway.yaml"),
146];
147
148fn reject_moved_sections(content: &str, profile_path: &Path) -> ProfileResult<()> {
149 let Ok(serde_yaml::Value::Mapping(map)) = serde_yaml::from_str::<serde_yaml::Value>(content)
150 else {
151 return Ok(());
152 };
153 for (key, destination) in MOVED_SECTIONS {
154 if map.contains_key(serde_yaml::Value::String((*key).to_owned())) {
155 return Err(ProfileError::MovedToServices {
156 path: profile_path.to_path_buf(),
157 key: (*key).to_owned(),
158 destination: (*destination).to_owned(),
159 });
160 }
161 }
162 Ok(())
163}
164
165impl Profile {
166 #[must_use]
167 pub fn is_local_trial(&self) -> bool {
168 self.cloud.as_ref().is_none_or(CloudConfig::is_local_trial)
169 }
170
171 #[must_use]
172 pub const fn path_resolution(&self) -> crate::paths::PathResolution {
173 if self.target.is_cloud() {
174 crate::paths::PathResolution::Lexical
175 } else {
176 crate::paths::PathResolution::Canonicalize
177 }
178 }
179
180 pub fn from_yaml(content: &str, profile_path: &Path) -> ProfileResult<Self> {
181 let content = interpolate(content, &|name| read_env_optional(name));
182
183 reject_moved_sections(&content, profile_path)?;
184
185 let mut profile: Self =
186 serde_yaml::from_str(&content).map_err(|source| ProfileError::ParseYaml {
187 path: profile_path.to_path_buf(),
188 source,
189 })?;
190
191 let profile_dir =
192 profile_path
193 .parent()
194 .ok_or_else(|| ProfileError::InvalidProfilePath {
195 path: profile_path.to_path_buf(),
196 })?;
197
198 profile.paths.resolve_relative_to(profile_dir);
199
200 Ok(profile)
201 }
202
203 pub fn to_yaml(&self) -> ProfileResult<String> {
204 serde_yaml::to_string(self).map_err(ProfileError::SerializeYaml)
205 }
206
207 pub fn profile_style(&self) -> ProfileStyle {
208 match self.name.to_lowercase().as_str() {
209 "dev" | "development" | "local" => ProfileStyle::Development,
210 "prod" | "production" => ProfileStyle::Production,
211 "staging" | "stage" => ProfileStyle::Staging,
212 "test" | "testing" => ProfileStyle::Test,
213 _ => ProfileStyle::Custom,
214 }
215 }
216
217 pub fn mask_secret(value: &str, visible_chars: usize) -> String {
218 if value.is_empty() {
219 return "(not set)".to_owned();
220 }
221 if value.len() <= visible_chars {
222 return "***".to_owned();
223 }
224 format!("{}...", &value[..visible_chars])
225 }
226
227 pub fn mask_database_url(url: &str) -> String {
228 if let Some(at_pos) = url.find('@')
229 && let Some(colon_pos) = url[..at_pos].rfind(':')
230 {
231 let prefix = &url[..=colon_pos];
232 let suffix = &url[at_pos..];
233 return format!("{}***{}", prefix, suffix);
234 }
235 url.to_owned()
236 }
237
238 pub fn is_masked_database_url(url: &str) -> bool {
239 url.contains(":***@") || url.contains(":********@")
240 }
241}