mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-07 19:22:14 +09:00
refactor(api): emit moderation events and apply account actions (#3031)
This commit is contained in:
@@ -9,10 +9,8 @@ pub enum GeoipSourceConfig {
|
||||
},
|
||||
S3 {
|
||||
maxmind_db_path: String,
|
||||
maxmind_asn_db_path: Option<String>,
|
||||
s3_bucket: String,
|
||||
s3_key: String,
|
||||
s3_asn_key: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -82,33 +80,10 @@ fn parse_geoip_s3_source_config(raw_value: &str, service_name: &str) -> GeoipSou
|
||||
}
|
||||
let maxmind_db_path =
|
||||
geoip_runtime_path(&resolve_geoip_download_path(&url, raw_value), service_name);
|
||||
let s3_asn_key = url
|
||||
.query_pairs()
|
||||
.find(|(key, _)| key == "asn_key")
|
||||
.map(|(_, value)| value.into_owned());
|
||||
let maxmind_asn_db_path = s3_asn_key.as_ref().map(|asn_key| {
|
||||
let configured_path = url
|
||||
.query_pairs()
|
||||
.find(|(key, _)| key == "asn_download_path")
|
||||
.map(|(_, value)| require_absolute_path(value.as_ref(), "asn_download_path", raw_value))
|
||||
.unwrap_or_else(|| {
|
||||
let directory = Path::new(&maxmind_db_path)
|
||||
.parent()
|
||||
.map(Path::to_path_buf)
|
||||
.unwrap_or_default();
|
||||
directory
|
||||
.join(Path::new(asn_key).file_name().unwrap_or_default())
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
});
|
||||
geoip_runtime_path(&configured_path, service_name)
|
||||
});
|
||||
GeoipSourceConfig::S3 {
|
||||
maxmind_db_path,
|
||||
maxmind_asn_db_path,
|
||||
s3_bucket,
|
||||
s3_key,
|
||||
s3_asn_key,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -357,19 +332,15 @@ mod tests {
|
||||
#[test]
|
||||
fn parses_s3_geoip_source() {
|
||||
let source = parse_geoip_source_config(
|
||||
"s3://geoip/GeoLite2-City.mmdb?download_path=/tmp/city.mmdb&asn_key=GeoLite2-ASN.mmdb",
|
||||
"s3://geoip/GeoLite2-City.mmdb?download_path=/tmp/city.mmdb",
|
||||
"test_svc",
|
||||
);
|
||||
assert_eq!(
|
||||
source,
|
||||
GeoipSourceConfig::S3 {
|
||||
maxmind_db_path: "/tmp/fluxer/geoip/test_svc/city.mmdb".to_owned(),
|
||||
maxmind_asn_db_path: Some(
|
||||
"/tmp/fluxer/geoip/test_svc/GeoLite2-ASN.mmdb".to_owned()
|
||||
),
|
||||
s3_bucket: "geoip".to_owned(),
|
||||
s3_key: "GeoLite2-City.mmdb".to_owned(),
|
||||
s3_asn_key: Some("GeoLite2-ASN.mmdb".to_owned()),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -181,19 +181,14 @@ fn prepare_geoip_database(
|
||||
GeoipSourceConfig::Filesystem { maxmind_db_path } => Ok(maxmind_db_path.clone()),
|
||||
GeoipSourceConfig::S3 {
|
||||
maxmind_db_path,
|
||||
maxmind_asn_db_path,
|
||||
s3_bucket,
|
||||
s3_key,
|
||||
s3_asn_key,
|
||||
} => {
|
||||
let s3 = s3_config.ok_or_else(|| {
|
||||
anyhow::anyhow!("GeoIP is configured for S3 mode, but S3 configuration is missing")
|
||||
})?;
|
||||
require_s3_config(s3)?;
|
||||
download_s3_object(s3, s3_bucket, s3_key, Path::new(maxmind_db_path))?;
|
||||
if let (Some(asn_key), Some(asn_path)) = (s3_asn_key, maxmind_asn_db_path) {
|
||||
download_s3_object(s3, s3_bucket, asn_key, Path::new(asn_path))?;
|
||||
}
|
||||
tracing::info!(
|
||||
maxmind_db_path,
|
||||
s3_bucket,
|
||||
|
||||
Reference in New Issue
Block a user