Skip to content

Commit

Permalink
fix: use or create bucket or cancel if s3 is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
Kek5chen committed Jun 10, 2024
1 parent c12324f commit b3ed28a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions vicky/src/bin/vicky/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::time::Duration;
use aws_config::BehaviorVersion;

use aws_sdk_s3::config::{Credentials, Region};
use aws_sdk_s3::error::SdkError;
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use jwtk::jwk::RemoteJwksVerifier;
use rocket::{Build, Rocket, routes};
Expand Down Expand Up @@ -155,6 +156,43 @@ async fn main() -> anyhow::Result<()> {
.await;

let s3_client = aws_sdk_s3::Client::new(&aws_conf);

match s3_client
.create_bucket()
.bucket(aws_cfg.log_bucket.clone())
.send()
.await
{
Ok(b) => {
log::info!(
"Bucket \"{}\" was successfully created on the log drain.",
b.location().unwrap_or_default()
);
}
Err(e) => match &e {
SdkError::ServiceError(c) if c.err().is_bucket_already_exists() => {
log::info!(
"Bucket \"{}\" is already present on the log drain.",
&aws_cfg.log_bucket
);
}
SdkError::DispatchFailure(_) => {
log::error!(
"Failed to communicate with Log Drain / S3 Bucket Connector (is the bucket running and available?): {:?}",
e
);
return Err(e.into());
}
_ => {
log::error!(
"Log Drain / S3 Bucket Connector ran into an irrecoverable error: {:?}",
e
);
return Err(e.into());
}
},
};

let s3_ext_client_drain = S3Client::new(s3_client.clone(), aws_cfg.log_bucket.clone());
let s3_ext_client = S3Client::new(s3_client, aws_cfg.log_bucket.clone());

Expand Down

0 comments on commit b3ed28a

Please sign in to comment.