mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-16 06:42:14 +00:00
refactor
This commit is contained in:
1 parent
41fe0866d4
commit
ac4ffb4f34
11 files changed
+23
-6
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+7
@@ -41,6 +41,10 @@ impl ExactMatchEndpointDisablements {
|
||||
pub fn endpoint_is_disabled(&self, endpoint: &str) -> bool {
|
||||
self.endpoints.contains(endpoint)
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.endpoints.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -62,5 +66,8 @@ pub mod tests {
|
||||
assert_eq!(endpoints.endpoint_is_disabled("/foo/"), false);
|
||||
assert_eq!(endpoints.endpoint_is_disabled("/foo/bar"), false);
|
||||
assert_eq!(endpoints.endpoint_is_disabled("/this/is/a/test/again"), false);
|
||||
|
||||
// Stats
|
||||
assert_eq!(endpoints.len(), 2);
|
||||
}
|
||||
}
|
||||
+7
@@ -42,6 +42,10 @@ impl PrefixEndpointDisablements {
|
||||
self.endpoint_prefixes.iter()
|
||||
.any(|prefix| endpoint.starts_with(prefix))
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.endpoint_prefixes.len()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -67,5 +71,8 @@ pub mod tests {
|
||||
assert_eq!(endpoints.endpoint_is_disabled("/"), false);
|
||||
assert_eq!(endpoints.endpoint_is_disabled("/bar"), false);
|
||||
assert_eq!(endpoints.endpoint_is_disabled("/this/is/not/a/test"), false);
|
||||
|
||||
// Metadata
|
||||
assert_eq!(endpoints.len(), 2);
|
||||
}
|
||||
}
|
||||
@@ -493,28 +493,31 @@ fn read_static_api_tokens() -> StaticApiTokenSet {
|
||||
StaticApiTokenSet::from_file(&filename)
|
||||
}
|
||||
|
||||
fn read_endpoint_disablements() -> DisabledEndpoints {
|
||||
fn read_disabled_endpoints() -> DisabledEndpoints {
|
||||
let exact_filename = easyenv::get_env_string_or_default(
|
||||
"DISABLED_ENDPOINTS_FILE_EXACT_MATCH",
|
||||
"./container_includes/endpoint_disablement/endpoint_exact_matches.txt");
|
||||
"./container_includes/disabled_endpoints/endpoint_exact_matches.txt");
|
||||
|
||||
let exact = ExactMatchEndpointDisablements::load_from_file(exact_filename)
|
||||
.unwrap_or(ExactMatchEndpointDisablements::new()); // NB: Fail open
|
||||
|
||||
let prefix_filename = easyenv::get_env_string_or_default(
|
||||
"DISABLED_ENDPOINTS_FILE_PREFIX_MATCH",
|
||||
"./container_includes/endpoint_disablement/endpoint_prefixes.txt");
|
||||
"./container_includes/disabled_endpoints/endpoint_prefixes.txt");
|
||||
|
||||
let prefix = PrefixEndpointDisablements::load_from_file(prefix_filename)
|
||||
.unwrap_or(PrefixEndpointDisablements::new()); // NB: Fail open
|
||||
|
||||
info!("Disabled endpoints by exact match: {}", exact.len());
|
||||
info!("Disabled endpoints by prefix: {}", prefix.len());
|
||||
|
||||
DisabledEndpoints::new(exact, prefix)
|
||||
}
|
||||
|
||||
fn load_static_container_ip_bans() -> IpBanList {
|
||||
let ip_ban_directory = easyenv::get_env_string_or_default(
|
||||
"IP_BAN_DIRECTORY",
|
||||
"./container_includes/ip_bans"
|
||||
"./container_includes/banned_ip_addresses"
|
||||
);
|
||||
|
||||
let ip_ban_list = load_ip_ban_list_from_directory(ip_ban_directory)
|
||||
@@ -578,7 +581,7 @@ pub async fn serve(server_state: ServerState) -> AnyhowResult<()>
|
||||
|
||||
let server_state_arc = web::Data::new(Arc::new(server_state));
|
||||
|
||||
let disablements = read_endpoint_disablements();
|
||||
let disabled_endpoints = read_disabled_endpoints();
|
||||
|
||||
info!("Starting HTTP service.");
|
||||
|
||||
@@ -624,7 +627,7 @@ pub async fn serve(server_state: ServerState) -> AnyhowResult<()>
|
||||
.header("X-Backend-Hostname", &hostname)
|
||||
.header("X-Build-Sha", server_state_arc.server_info.build_sha.clone()))
|
||||
.wrap(PushbackFilter::new(&server_state_arc.flags.clone()))
|
||||
.wrap(EndpointDisablementFilter::new(disablements.clone()))
|
||||
.wrap(EndpointDisablementFilter::new(disabled_endpoints.clone()))
|
||||
.wrap(BannedIpFilter::new(ip_ban_list))
|
||||
.wrap(BannedCidrFilter::new(cidr_ban_set))
|
||||
.wrap(Logger::new(&log_format)
|
||||
|
||||
Reference in new issue
Block a user