Skip to content

Commit 2a7c4ca

Browse files
committed
Implement snapshot bucket configuration
1 parent c786ab9 commit 2a7c4ca

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

mithril-aggregator/src/command_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl ServeCommand {
297297
debug!("SERVE command"; "config" => format!("{:?}", config));
298298
// Init dependencies
299299
let snapshot_store = config.build_snapshot_store()?;
300-
let snapshot_uploader = config.build_snapshot_uploader();
300+
let snapshot_uploader = config.build_snapshot_uploader()?;
301301

302302
let sqlite_db_path = Some(config.get_sqlite_file());
303303

mithril-aggregator/src/configuration.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ pub struct Configuration {
4949
/// Type of snapshot uploader to use
5050
pub snapshot_uploader_type: SnapshotUploaderType,
5151

52+
/// Bucket name where the snapshots are stored if snapshot_uploader_type is Gcp
53+
pub snapshot_bucket_name: Option<String>,
54+
5255
/// Server listening IP
5356
pub server_ip: String,
5457

@@ -109,7 +112,11 @@ impl Configuration {
109112
pub fn build_snapshot_store(&self) -> Result<Arc<dyn SnapshotStore>, Box<dyn Error>> {
110113
match self.snapshot_store_type {
111114
SnapshotStoreType::Gcp => Ok(Arc::new(RemoteSnapshotStore::new(
112-
Box::new(GcpFileUploader::default()),
115+
Box::new(GcpFileUploader::new(
116+
self.snapshot_bucket_name.to_owned().ok_or_else(|| {
117+
ConfigError::Message("missing snapshot bucket name".to_string())
118+
})?,
119+
)),
113120
self.url_snapshot_manifest.clone(),
114121
))),
115122
SnapshotStoreType::Local => Ok(Arc::new(LocalSnapshotStore::new(
@@ -123,15 +130,17 @@ impl Configuration {
123130
}
124131

125132
/// Create a snapshot uploader from configuration settings.
126-
pub fn build_snapshot_uploader(&self) -> Arc<dyn SnapshotUploader> {
133+
pub fn build_snapshot_uploader(&self) -> Result<Arc<dyn SnapshotUploader>, Box<dyn Error>> {
127134
match self.snapshot_uploader_type {
128-
SnapshotUploaderType::Gcp => Arc::new(RemoteSnapshotUploader::new(Box::new(
129-
GcpFileUploader::default(),
130-
))),
131-
SnapshotUploaderType::Local => Arc::new(LocalSnapshotUploader::new(
135+
SnapshotUploaderType::Gcp => Ok(Arc::new(RemoteSnapshotUploader::new(Box::new(
136+
GcpFileUploader::new(self.snapshot_bucket_name.to_owned().ok_or_else(|| {
137+
ConfigError::Message("missing snapshot bucket name".to_string())
138+
})?),
139+
)))),
140+
SnapshotUploaderType::Local => Ok(Arc::new(LocalSnapshotUploader::new(
132141
self.get_server_url(),
133142
&self.snapshot_directory,
134-
)),
143+
))),
135144
}
136145
}
137146

mithril-aggregator/src/dependency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ pub mod tests {
193193
.to_string(),
194194
snapshot_store_type: SnapshotStoreType::Local,
195195
snapshot_uploader_type: SnapshotUploaderType::Local,
196+
snapshot_bucket_name: None,
196197
server_ip: "0.0.0.0".to_string(),
197198
server_port: 8000,
198199
run_interval: 5000,

mithril-aggregator/tests/test_extensions/dependency.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub async fn initialize_dependencies(
3737
.to_string(),
3838
snapshot_store_type: SnapshotStoreType::Local,
3939
snapshot_uploader_type: SnapshotUploaderType::Local,
40+
snapshot_bucket_name: None,
4041
server_ip: "0.0.0.0".to_string(),
4142
server_port: 8000,
4243
run_interval: 5000,

0 commit comments

Comments
 (0)