Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove bucket creation in s3 persister #557

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions server/src/persistence/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,6 @@ impl From<SdkError<PutObjectError>> for EdgeError {
}
}

impl S3Persister {
async fn create_bucket_if_not_exists(&self) -> EdgeResult<()> {
match self
.client
.create_bucket()
.bucket(&self.bucket)
.send()
.await
{
Ok(_) => Ok(()),
Err(err) => {
if err.to_string().contains("BucketAlreadyOwnedByYou")
|| err.to_string().contains("BucketAlreadyExists")
{
Ok(())
} else {
Err(EdgeError::PersistenceError(format!(
"Failed to create bucket: {}",
err
)))
}
}
}
}
}

#[async_trait]
impl EdgePersistence for S3Persister {
async fn load_tokens(&self) -> EdgeResult<Vec<EdgeToken>> {
Expand All @@ -96,7 +70,6 @@ impl EdgePersistence for S3Persister {
}

async fn save_tokens(&self, tokens: Vec<EdgeToken>) -> EdgeResult<()> {
self.create_bucket_if_not_exists().await?;
let body_data = serde_json::to_vec(&tokens)
.map_err(|_| EdgeError::PersistenceError("Failed to serialize tokens".to_string()))
.map(SdkBody::from)?;
Expand Down Expand Up @@ -144,7 +117,6 @@ impl EdgePersistence for S3Persister {
}

async fn save_features(&self, features: Vec<(String, ClientFeatures)>) -> EdgeResult<()> {
self.create_bucket_if_not_exists().await?;
let body_data = serde_json::to_vec(&features)
.map_err(|_| EdgeError::PersistenceError("Failed to serialize features".to_string()))?;
let byte_stream = ByteStream::new(SdkBody::from(body_data));
Expand Down
8 changes: 8 additions & 0 deletions server/tests/s3_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ mod s3_tests {
.force_path_style(true)
.build();

let client = s3::Client::from_conf(config.clone());
client
.create_bucket()
.bucket(bucket_name)
.send()
.await
.expect("Failed to setup S3 bucket pre test run");

//hopefully we don't care, this should just work with localstack
let persister = S3Persister::new_with_config(bucket_name, config);

Expand Down