0.34.13_cleaup_code
This commit is contained in:
1 parent
ec46a96a29
commit
5c2e50ec06
87 files changed
+4890
-1338
No files matched your search
+108
-62
@@ -1,6 +1,3 @@
|
||||
// GET and PUT resolve exactly the same named sections. All writes go through
|
||||
// App::update_as: full validation, revision check under the update lock, and
|
||||
// one durable transaction. These handlers do not implement partial patches.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
enum ConfigSection {
|
||||
Listeners,
|
||||
@@ -93,66 +90,109 @@ impl ConfigSection {
|
||||
}
|
||||
}
|
||||
|
||||
fn replace(self, config: &mut crate::config::Config, name: &str, value: Value) -> Result<(), ApiError> {
|
||||
fn replace(
|
||||
self,
|
||||
config: &mut crate::config::Config,
|
||||
name: &str,
|
||||
value: Value,
|
||||
) -> Result<(), ApiError> {
|
||||
match self {
|
||||
Self::Listeners => config.listeners = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::DockerAgents => config.docker_agents = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Http2 => config.http2 = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Pages => config.pages = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Cache => config.cache = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Transform => config.transform = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Forwarding => config.forwarding = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Headers => config.headers = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Prometheus => config.prometheus = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Geoip => config.geoip_updates = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Administration => config.administration = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Tls => config.tls = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Vhosts => config.vhosts = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::WebServices => config.web_services = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::PhpFpmProfiles => config.php_fpm_profiles = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Redirects => config.redirects = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::NotFoundHosts => config.not_found_hosts = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Streams => config.streams = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::AclProfiles => config.acl_profiles = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::HostPolicies => config.host_policies = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?,
|
||||
Self::Listeners => {
|
||||
config.listeners =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::DockerAgents => {
|
||||
config.docker_agents =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Http2 => {
|
||||
config.http2 =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Pages => {
|
||||
config.pages =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Cache => {
|
||||
config.cache =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Transform => {
|
||||
config.transform =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Forwarding => {
|
||||
config.forwarding =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Headers => {
|
||||
config.headers =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Prometheus => {
|
||||
config.prometheus =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Geoip => {
|
||||
config.geoip_updates =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Administration => {
|
||||
config.administration =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Tls => {
|
||||
config.tls =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Vhosts => {
|
||||
config.vhosts =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::WebServices => {
|
||||
config.web_services =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::PhpFpmProfiles => {
|
||||
config.php_fpm_profiles =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Redirects => {
|
||||
config.redirects =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::NotFoundHosts => {
|
||||
config.not_found_hosts =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Streams => {
|
||||
config.streams =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::AclProfiles => {
|
||||
config.acl_profiles =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::HostPolicies => {
|
||||
config.host_policies =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?
|
||||
}
|
||||
Self::Response => {
|
||||
let part: ResponseSection = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?;
|
||||
let part: ResponseSection =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?;
|
||||
config.server_header = part.server_header;
|
||||
config.diagnostic_headers = part.diagnostic_headers;
|
||||
config.compression = part.compression;
|
||||
}
|
||||
Self::Logging => {
|
||||
// A logging save must include both sinks; there is no implicit fallback
|
||||
// to a single-field payload that could reset error_log accidentally.
|
||||
let part: LoggingSection = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?;
|
||||
let part: LoggingSection =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?;
|
||||
config.logging = part.logging;
|
||||
config.error_log = part.error_log;
|
||||
}
|
||||
Self::GlobalSecurity => {
|
||||
let part: crate::config::GlobalSecurity = serde_json::from_value(value)
|
||||
.map_err(|error| invalid_section(name, error))?;
|
||||
let part: crate::config::GlobalSecurity =
|
||||
serde_json::from_value(value).map_err(|error| invalid_section(name, error))?;
|
||||
if part.user_agent_blocking.is_none() {
|
||||
return Err(ApiError(
|
||||
StatusCode::BAD_REQUEST,
|
||||
@@ -167,10 +207,12 @@ impl ConfigSection {
|
||||
}
|
||||
|
||||
fn requested_config_section(name: &str) -> Result<ConfigSection, ApiError> {
|
||||
ConfigSection::from_name(name).ok_or_else(|| ApiError(
|
||||
StatusCode::NOT_FOUND,
|
||||
"unknown configuration section".into(),
|
||||
))
|
||||
ConfigSection::from_name(name).ok_or_else(|| {
|
||||
ApiError(
|
||||
StatusCode::NOT_FOUND,
|
||||
"unknown configuration section".into(),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async fn configuration_section(
|
||||
@@ -192,7 +234,6 @@ async fn update_section(
|
||||
Path(section): Path<String>,
|
||||
Json(input): Json<SectionUpdate>,
|
||||
) -> Result<Json<crate::config::Envelope>, ApiError> {
|
||||
// Resolve the name before taking the snapshot, including for stale requests.
|
||||
let selected = requested_config_section(§ion)?;
|
||||
let current = state.config.load_full();
|
||||
if current.envelope.revision != input.expected_revision {
|
||||
@@ -203,12 +244,18 @@ async fn update_section(
|
||||
}
|
||||
let mut config = current.envelope.config.clone();
|
||||
selected.replace(&mut config, §ion, input.value)?;
|
||||
state.update_as(Update { expected_revision: input.expected_revision, config }, session.username)
|
||||
.await.map(Json)
|
||||
state
|
||||
.update_as(
|
||||
Update {
|
||||
expected_revision: input.expected_revision,
|
||||
config,
|
||||
},
|
||||
session.username,
|
||||
)
|
||||
.await
|
||||
.map(Json)
|
||||
}
|
||||
|
||||
// GeoIP is an explicit side-effecting action within the geoip settings section.
|
||||
// GET and PUT are only for desired settings; POST refreshes external data.
|
||||
async fn geoip_update(
|
||||
State(state): State<Arc<App>>,
|
||||
Extension(session): Extension<Session>,
|
||||
@@ -239,4 +286,3 @@ async fn geoip_update(
|
||||
.map_err(auth::internal)?;
|
||||
Ok(Json(result))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user