Skip to content

Commit 92470a7

Browse files
committed
refactor: make configuration automatically compute if directory serving is enabled in the HTTP server
1 parent 6971f6c commit 92470a7

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

mithril-aggregator/src/configuration.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,6 @@ pub struct Configuration {
186186

187187
/// Time interval at which usage metrics are persisted in event database (in seconds).
188188
pub persist_usage_report_interval_in_seconds: u64,
189-
190-
/// If set to true, the HTTP server can serve static directories.
191-
pub allow_http_serve_directory: bool,
192189
}
193190

194191
/// Uploader needed to copy the snapshot once computed.
@@ -273,7 +270,6 @@ impl Configuration {
273270
metrics_server_ip: "0.0.0.0".to_string(),
274271
metrics_server_port: 9090,
275272
persist_usage_report_interval_in_seconds: 10,
276-
allow_http_serve_directory: false,
277273
}
278274
}
279275

@@ -336,6 +332,15 @@ impl Configuration {
336332

337333
Ok(allowed_discriminants)
338334
}
335+
336+
/// Check if the HTTP server can serve static directories.
337+
// TODO: This function should be completed when the configuration of the uploaders for the Cardano database is done.
338+
pub fn allow_http_serve_directory(&self) -> bool {
339+
match self.snapshot_uploader_type {
340+
SnapshotUploaderType::Local => true,
341+
SnapshotUploaderType::Gcp => false,
342+
}
343+
}
339344
}
340345

341346
/// Default configuration with all the default values for configurations.
@@ -415,9 +420,6 @@ pub struct DefaultConfiguration {
415420

416421
/// Time interval at which metrics are persisted in event database (in seconds).
417422
pub persist_usage_report_interval_in_seconds: u64,
418-
419-
/// If set to true, the HTTP server can serve static directories.
420-
pub allow_http_serve_directory: bool,
421423
}
422424

423425
impl Default for DefaultConfiguration {
@@ -450,7 +452,6 @@ impl Default for DefaultConfiguration {
450452
metrics_server_ip: "0.0.0.0".to_string(),
451453
metrics_server_port: 9090,
452454
persist_usage_report_interval_in_seconds: 10,
453-
allow_http_serve_directory: false,
454455
}
455456
}
456457
}
@@ -538,7 +539,6 @@ impl Source for DefaultConfiguration {
538539
),
539540
])),
540541
);
541-
insert_default_configuration!(result, myself.allow_http_serve_directory);
542542
Ok(result)
543543
}
544544
}
@@ -608,4 +608,21 @@ mod test {
608608
BTreeSet::from(SignedEntityConfig::DEFAULT_ALLOWED_DISCRIMINANTS)
609609
);
610610
}
611+
612+
#[test]
613+
fn allow_http_serve_directory() {
614+
let config = Configuration {
615+
snapshot_uploader_type: SnapshotUploaderType::Local,
616+
..Configuration::new_sample()
617+
};
618+
619+
assert!(config.allow_http_serve_directory());
620+
621+
let config = Configuration {
622+
snapshot_uploader_type: SnapshotUploaderType::Gcp,
623+
..Configuration::new_sample()
624+
};
625+
626+
assert!(!config.allow_http_serve_directory());
627+
}
611628
}

mithril-aggregator/src/dependency_injection/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ impl DependenciesBuilder {
15561556
.clone(),
15571557
snapshot_directory: self.configuration.get_snapshot_dir()?,
15581558
cardano_node_version: self.configuration.cardano_node_version.clone(),
1559-
allow_http_serve_directory: self.configuration.allow_http_serve_directory,
1559+
allow_http_serve_directory: self.configuration.allow_http_serve_directory(),
15601560
},
15611561
);
15621562

mithril-aggregator/src/http_server/routes/artifact_routes/cardano_database.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ mod handlers {
103103
}
104104

105105
/// Download a file if it's a Cardano_database artifact file
106+
// TODO: this function should probable be unit tested once the file naming convention is defined
106107
pub async fn ensure_downloaded_file_is_a_cardano_database_artifact(
107108
reply: warp::fs::File,
108109
logger: Logger,

mithril-test-lab/mithril-end-to-end/src/mithril/aggregator.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ impl Aggregator {
9999
),
100100
("CARDANO_TRANSACTIONS_SIGNING_CONFIG__STEP", "15"),
101101
("PERSIST_USAGE_REPORT_INTERVAL_IN_SECONDS", "3"),
102-
("ALLOW_HTTP_SERVE_DIRECTORY", "true"),
103102
]);
104103
let args = vec![
105104
"--db-directory",

0 commit comments

Comments
 (0)