mirror of
https://github.com/kanidm/kanidm.git
synced 2025-05-21 08:23:55 +02:00
Fix toml issues with strings
During the toml library upgrade, strings were not parsing correctly in the x509 replication handler. This fixes both the string parse, but also improves our error handling to clearly show the mistake in the config if one exists.
This commit is contained in:
parent
2256c79b9c
commit
8189bc0bc4
|
@ -74,10 +74,10 @@ pub mod x509b64 {
|
|||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let raw = <&str>::deserialize(des)?;
|
||||
let raw = <String>::deserialize(des)?;
|
||||
let s = general_purpose::URL_SAFE_NO_PAD
|
||||
.decode(raw)
|
||||
.or_else(|_| general_purpose::URL_SAFE.decode(raw))
|
||||
.decode(&raw)
|
||||
.or_else(|_| general_purpose::URL_SAFE.decode(&raw))
|
||||
.map_err(|err| {
|
||||
error!(?err, "base64 url-safe invalid");
|
||||
D::Error::custom("base64 url-safe invalid")
|
||||
|
|
|
@ -20,24 +20,29 @@ use url::Url;
|
|||
|
||||
use crate::repl::config::ReplicationConfiguration;
|
||||
|
||||
// Allowed as the large enum is only short lived at startup to the true config
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
// These structures allow us to move to version tagging of the configuration structure.
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum VersionDetection {
|
||||
Version(Version),
|
||||
Legacy,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(tag = "version")]
|
||||
pub enum Version {
|
||||
#[serde(rename = "2")]
|
||||
V2,
|
||||
}
|
||||
|
||||
// Allowed as the large enum is only short lived at startup to the true config
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum ServerConfigUntagged {
|
||||
Version(ServerConfigVersion),
|
||||
Legacy(ServerConfig),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(tag = "version")]
|
||||
pub enum ServerConfigVersion {
|
||||
#[serde(rename = "2")]
|
||||
V2 {
|
||||
#[serde(flatten)]
|
||||
values: ServerConfigV2,
|
||||
},
|
||||
V2 { values: ServerConfigV2 },
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
|
@ -295,8 +300,27 @@ impl ServerConfigUntagged {
|
|||
eprintln!("{}", diag);
|
||||
})?;
|
||||
|
||||
// if we *can* load the config we'll set config to that.
|
||||
toml::from_str::<ServerConfigUntagged>(contents.as_str()).map_err(|err| {
|
||||
// First, can we detect the config version?
|
||||
let config_version =
|
||||
toml::from_str::<VersionDetection>(contents.as_str()).map_err(|err| {
|
||||
eprintln!(
|
||||
"Unable to parse config version from '{:?}': {:?}",
|
||||
config_path.as_ref(),
|
||||
err
|
||||
);
|
||||
std::io::Error::new(std::io::ErrorKind::InvalidData, err)
|
||||
})?;
|
||||
|
||||
match config_version {
|
||||
VersionDetection::Version(Version::V2) => {
|
||||
toml::from_str::<ServerConfigV2>(contents.as_str())
|
||||
.map(|values| ServerConfigUntagged::Version(ServerConfigVersion::V2 { values }))
|
||||
}
|
||||
VersionDetection::Legacy => {
|
||||
toml::from_str::<ServerConfig>(contents.as_str()).map(ServerConfigUntagged::Legacy)
|
||||
}
|
||||
}
|
||||
.map_err(|err| {
|
||||
eprintln!(
|
||||
"Unable to parse config from '{:?}': {:?}",
|
||||
config_path.as_ref(),
|
||||
|
@ -310,6 +334,8 @@ impl ServerConfigUntagged {
|
|||
#[derive(Debug, Deserialize, Default)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct ServerConfigV2 {
|
||||
#[allow(dead_code)]
|
||||
version: String,
|
||||
domain: Option<String>,
|
||||
origin: Option<String>,
|
||||
db_path: Option<PathBuf>,
|
||||
|
|
|
@ -21,7 +21,6 @@ log_level = "trace"
|
|||
|
||||
domain = "localhost"
|
||||
origin = "https://localhost:8443"
|
||||
trust_x_forward_for = true
|
||||
|
||||
[online_backup]
|
||||
# defaults to db_path
|
||||
|
|
Loading…
Reference in a new issue