packages/ak-common/config: fix string load broken after previous fix (#21854)

This commit is contained in:
Marc 'risson' Schmitt
2026-04-27 16:03:55 +02:00
committed by GitHub
parent 620387f294
commit 3e75278052
2 changed files with 33 additions and 8 deletions
+26 -8
View File
@@ -16,7 +16,10 @@ use url::Url;
pub mod schema;
pub use schema::Config;
use crate::arbiter::{Arbiter, Event, Tasks};
use crate::{
arbiter::{Arbiter, Event, Tasks},
config::schema::KEYS_TO_PARSE_AS_LIST,
};
static DEFAULT_CONFIG: &str = include_str!("../../../../authentik/lib/default.yml");
static CONFIG_MANAGER: OnceLock<ConfigManager> = OnceLock::new();
@@ -75,13 +78,15 @@ impl Config {
config_rs::File::from(path.as_path()).format(config_rs::FileFormat::Yaml),
);
}
builder = builder.add_source(
config_rs::Environment::with_prefix("AUTHENTIK")
.prefix_separator("_")
.separator("__")
.try_parsing(true)
.list_separator(","),
);
let mut env_source = config_rs::Environment::with_prefix("AUTHENTIK")
.prefix_separator("_")
.separator("__")
.try_parsing(true)
.list_separator(",");
for key in KEYS_TO_PARSE_AS_LIST {
env_source = env_source.with_list_parse_key(key);
}
builder = builder.add_source(env_source);
if let Some(overrides) = overrides {
builder = builder.add_source(config_rs::File::from_str(
&overrides.to_string(),
@@ -532,4 +537,17 @@ mod tests {
]
);
}
#[test]
fn env_string() {
#[expect(unsafe_code, reason = "testing")]
// SAFETY: testing
unsafe {
env::set_var("AUTHENTIK_SECRET_KEY", "my_secret_key");
}
let (config, _) = super::Config::load(&[], None).expect("failed to load config");
assert_eq!(config.secret_key, "my_secret_key",);
}
}
+7
View File
@@ -3,6 +3,13 @@ use std::{collections::HashMap, net::SocketAddr, num::NonZeroUsize};
use ipnet::IpNet;
use serde::{Deserialize, Serialize};
pub(super) const KEYS_TO_PARSE_AS_LIST: [&str; 4] = [
"listen.http",
"listen.metrics",
"listen.trusted_proxy_cidrs",
"log.http_headers",
];
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
pub postgresql: PostgreSQLConfig,