fix: update NginxSettings to be non-optional and improve validation logic

This commit is contained in:
GW_MC
2026-04-27 07:15:09 +00:00
parent 98e07715fa
commit 984334c232
2 changed files with 35 additions and 34 deletions

View File

@@ -18,7 +18,8 @@ pub struct Settings {
pub grpc: GrpcSettings,
#[serde(default)]
pub log: LogSettings,
pub nginx: Option<NginxSettings>,
#[serde(default)]
pub nginx: NginxSettings,
}
/// gRPC client settings
@@ -79,7 +80,7 @@ impl Default for LogSettings {
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct NginxSettings {
#[serde(default = "default_nginx_config_path")]
pub nginx_config_path: String,
@@ -101,9 +102,7 @@ pub struct NginxSettings {
impl Validate for Settings {
fn validate(&self) -> Result<(), ValidationError> {
self.grpc.validate()?;
if let Some(nginx) = &self.nginx {
nginx.validate()?;
}
self.nginx.validate()?;
Ok(())
}
}
@@ -125,35 +124,37 @@ impl Settings {
settings.validate().map_err(ConfigError::Message)?;
if let Some(nginx) = &mut settings.nginx {
nginx.validate().map_err(ConfigError::Message)?;
settings.nginx.validate().map_err(ConfigError::Message)?;
// replace binary path template in commands with actual binary path, if the template is present
nginx
settings
.nginx
.override_nginx_reload_command
.iter_mut()
.for_each(|cmd| {
*cmd = cmd.replace(
NGINX_BINARY_PATH_TEMPLATE,
&nginx
&settings
.nginx
.nginx_binary_path
.clone()
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
);
});
nginx
settings
.nginx
.override_nginx_test_command
.iter_mut()
.for_each(|cmd| {
*cmd = cmd.replace(
NGINX_BINARY_PATH_TEMPLATE,
&nginx
&settings
.nginx
.nginx_binary_path
.clone()
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
);
});
}
Ok(settings)
}

View File

@@ -89,7 +89,7 @@ mod tests {
cors: None,
},
log: LogSettings::default(),
nginx: None,
nginx: Default::default(),
}
}