8000 Fix minor issue with untagged version handling by Firstyear · Pull Request #3634 · kanidm/kanidm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix minor issue with untagged version handling #3634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions server/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ use url::Url;
use crate::repl::config::ReplicationConfiguration;

#[derive(Debug, Deserialize)]
#[serde(untagged)]
enum VersionDetection {
Version(Version),
Legacy,
struct VersionDetection {
#[serde(default)]
version: Version,
}

#[derive(Debug, Deserialize)]
#[serde(tag = "version")]
#[derive(Debug, Deserialize, Default)]
// #[serde(tag = "version")]
pub enum Version {
#[serde(rename = "2")]
V2,

#[default]
Legacy,
}

// Allowed as the large enum is only short lived at startup to the true config
Expand Down Expand Up @@ -303,8 +305,9 @@ impl ServerConfigUntagged {
})?;

// First, can we detect the config version?
let config_version =
toml::from_str::<VersionDetection>(contents.as_str()).map_err(|err| {
let config_version = toml::from_str::<VersionDetection>(contents.as_str())
.map(|vd| vd.version)
.map_err(|err| {
eprintln!(
"Unable to parse config version from '{:?}': {:?}",
config_path.as_ref(),
Expand All @@ -314,11 +317,9 @@ impl ServerConfigUntagged {
})?;

match config_version {
VersionDetection::Version(Version::V2) => {
toml::from_str::<ServerConfigV2>(contents.as_str())
.map(|values| ServerConfigUntagged::Version(ServerConfigVersion::V2 { values }))
}
VersionDetection::Legacy => {
Version::V2 => toml::from_str::<ServerConfigV2>(contents.as_str())
.map(|values| ServerConfigUntagged::Version(ServerConfigVersion::V2 { values })),
Version::Legacy => {
toml::from_str::<ServerConfig>(contents.as_str()).map(ServerConfigUntagged::Legacy)
}
}
Expand Down
Loading
0