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,
|
pub grpc: GrpcSettings,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub log: LogSettings,
|
pub log: LogSettings,
|
||||||
pub nginx: Option<NginxSettings>,
|
#[serde(default)]
|
||||||
|
pub nginx: NginxSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// gRPC client settings
|
/// 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 {
|
pub struct NginxSettings {
|
||||||
#[serde(default = "default_nginx_config_path")]
|
#[serde(default = "default_nginx_config_path")]
|
||||||
pub nginx_config_path: String,
|
pub nginx_config_path: String,
|
||||||
@@ -101,9 +102,7 @@ pub struct NginxSettings {
|
|||||||
impl Validate for Settings {
|
impl Validate for Settings {
|
||||||
fn validate(&self) -> Result<(), ValidationError> {
|
fn validate(&self) -> Result<(), ValidationError> {
|
||||||
self.grpc.validate()?;
|
self.grpc.validate()?;
|
||||||
if let Some(nginx) = &self.nginx {
|
self.nginx.validate()?;
|
||||||
nginx.validate()?;
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -125,35 +124,37 @@ impl Settings {
|
|||||||
|
|
||||||
settings.validate().map_err(ConfigError::Message)?;
|
settings.validate().map_err(ConfigError::Message)?;
|
||||||
|
|
||||||
if let Some(nginx) = &mut settings.nginx {
|
settings.nginx.validate().map_err(ConfigError::Message)?;
|
||||||
nginx.validate().map_err(ConfigError::Message)?;
|
|
||||||
|
|
||||||
// replace binary path template in commands with actual binary path, if the template is present
|
// replace binary path template in commands with actual binary path, if the template is present
|
||||||
nginx
|
settings
|
||||||
.override_nginx_reload_command
|
.nginx
|
||||||
.iter_mut()
|
.override_nginx_reload_command
|
||||||
.for_each(|cmd| {
|
.iter_mut()
|
||||||
*cmd = cmd.replace(
|
.for_each(|cmd| {
|
||||||
NGINX_BINARY_PATH_TEMPLATE,
|
*cmd = cmd.replace(
|
||||||
&nginx
|
NGINX_BINARY_PATH_TEMPLATE,
|
||||||
.nginx_binary_path
|
&settings
|
||||||
.clone()
|
.nginx
|
||||||
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
|
.nginx_binary_path
|
||||||
);
|
.clone()
|
||||||
});
|
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
|
||||||
nginx
|
);
|
||||||
.override_nginx_test_command
|
});
|
||||||
.iter_mut()
|
settings
|
||||||
.for_each(|cmd| {
|
.nginx
|
||||||
*cmd = cmd.replace(
|
.override_nginx_test_command
|
||||||
NGINX_BINARY_PATH_TEMPLATE,
|
.iter_mut()
|
||||||
&nginx
|
.for_each(|cmd| {
|
||||||
.nginx_binary_path
|
*cmd = cmd.replace(
|
||||||
.clone()
|
NGINX_BINARY_PATH_TEMPLATE,
|
||||||
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
|
&settings
|
||||||
);
|
.nginx
|
||||||
});
|
.nginx_binary_path
|
||||||
}
|
.clone()
|
||||||
|
.unwrap_or_else(|| NGINX_DEFAULT_BINARY.into()),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
Ok(settings)
|
Ok(settings)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ mod tests {
|
|||||||
cors: None,
|
cors: None,
|
||||||
},
|
},
|
||||||
log: LogSettings::default(),
|
log: LogSettings::default(),
|
||||||
nginx: None,
|
nginx: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user