Skip to content

Commit

Permalink
refactor: make configuration automatically compute if directory servi…
Browse files Browse the repository at this point in the history
…ng is enabled in the HTTP server
  • Loading branch information
jpraynaud committed Dec 20, 2024
1 parent 6971f6c commit 92470a7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
35 changes: 26 additions & 9 deletions mithril-aggregator/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@ pub struct Configuration {

/// Time interval at which usage metrics are persisted in event database (in seconds).
pub persist_usage_report_interval_in_seconds: u64,

/// If set to true, the HTTP server can serve static directories.
pub allow_http_serve_directory: bool,
}

/// Uploader needed to copy the snapshot once computed.
Expand Down Expand Up @@ -273,7 +270,6 @@ impl Configuration {
metrics_server_ip: "0.0.0.0".to_string(),
metrics_server_port: 9090,
persist_usage_report_interval_in_seconds: 10,
allow_http_serve_directory: false,
}
}

Expand Down Expand Up @@ -336,6 +332,15 @@ impl Configuration {

Ok(allowed_discriminants)
}

/// Check if the HTTP server can serve static directories.
// TODO: This function should be completed when the configuration of the uploaders for the Cardano database is done.
pub fn allow_http_serve_directory(&self) -> bool {
match self.snapshot_uploader_type {
SnapshotUploaderType::Local => true,
SnapshotUploaderType::Gcp => false,
}
}
}

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

/// Time interval at which metrics are persisted in event database (in seconds).
pub persist_usage_report_interval_in_seconds: u64,

/// If set to true, the HTTP server can serve static directories.
pub allow_http_serve_directory: bool,
}

impl Default for DefaultConfiguration {
Expand Down Expand Up @@ -450,7 +452,6 @@ impl Default for DefaultConfiguration {
metrics_server_ip: "0.0.0.0".to_string(),
metrics_server_port: 9090,
persist_usage_report_interval_in_seconds: 10,
allow_http_serve_directory: false,
}
}
}
Expand Down Expand Up @@ -538,7 +539,6 @@ impl Source for DefaultConfiguration {
),
])),
);
insert_default_configuration!(result, myself.allow_http_serve_directory);
Ok(result)
}
}
Expand Down Expand Up @@ -608,4 +608,21 @@ mod test {
BTreeSet::from(SignedEntityConfig::DEFAULT_ALLOWED_DISCRIMINANTS)
);
}

#[test]
fn allow_http_serve_directory() {
let config = Configuration {
snapshot_uploader_type: SnapshotUploaderType::Local,
..Configuration::new_sample()
};

assert!(config.allow_http_serve_directory());

let config = Configuration {
snapshot_uploader_type: SnapshotUploaderType::Gcp,
..Configuration::new_sample()
};

assert!(!config.allow_http_serve_directory());
}
}
2 changes: 1 addition & 1 deletion mithril-aggregator/src/dependency_injection/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ impl DependenciesBuilder {
.clone(),
snapshot_directory: self.configuration.get_snapshot_dir()?,
cardano_node_version: self.configuration.cardano_node_version.clone(),
allow_http_serve_directory: self.configuration.allow_http_serve_directory,
allow_http_serve_directory: self.configuration.allow_http_serve_directory(),
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ mod handlers {
}

/// Download a file if it's a Cardano_database artifact file
// TODO: this function should probable be unit tested once the file naming convention is defined
pub async fn ensure_downloaded_file_is_a_cardano_database_artifact(
reply: warp::fs::File,
logger: Logger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ impl Aggregator {
),
("CARDANO_TRANSACTIONS_SIGNING_CONFIG__STEP", "15"),
("PERSIST_USAGE_REPORT_INTERVAL_IN_SECONDS", "3"),
("ALLOW_HTTP_SERVE_DIRECTORY", "true"),
]);
let args = vec![
"--db-directory",
Expand Down

0 comments on commit 92470a7

Please sign in to comment.