fix: update NginxSettings to be non-optional and improve validation logic
This commit is contained in:
@@ -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
|
||||
.override_nginx_reload_command
|
||||
.iter_mut()
|
||||
.for_each(|cmd| {
|
||||
*cmd = cmd.replace(
|
||||
NGINX_BINARY_PATH_TEMPLATE,
|
||||
&nginx
|
||||
.nginx_binary_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
|
||||
);
|
||||
});
|
||||
nginx
|
||||
.override_nginx_test_command
|
||||
.iter_mut()
|
||||
.for_each(|cmd| {
|
||||
*cmd = cmd.replace(
|
||||
NGINX_BINARY_PATH_TEMPLATE,
|
||||
&nginx
|
||||
.nginx_binary_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
|
||||
);
|
||||
});
|
||||
}
|
||||
// replace binary path template in commands with actual binary path, if the template is present
|
||||
settings
|
||||
.nginx
|
||||
.override_nginx_reload_command
|
||||
.iter_mut()
|
||||
.for_each(|cmd| {
|
||||
*cmd = cmd.replace(
|
||||
NGINX_BINARY_PATH_TEMPLATE,
|
||||
&settings
|
||||
.nginx
|
||||
.nginx_binary_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
|
||||
);
|
||||
});
|
||||
settings
|
||||
.nginx
|
||||
.override_nginx_test_command
|
||||
.iter_mut()
|
||||
.for_each(|cmd| {
|
||||
*cmd = cmd.replace(
|
||||
NGINX_BINARY_PATH_TEMPLATE,
|
||||
&settings
|
||||
.nginx
|
||||
.nginx_binary_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
|
||||
);
|
||||
});
|
||||
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ mod tests {
|
||||
cors: None,
|
||||
},
|
||||
log: LogSettings::default(),
|
||||
nginx: None,
|
||||
nginx: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user