Skip to content

Commit

Permalink
feat(s3storage): bucket deletion should be optional
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicGD committed Feb 9, 2024
1 parent 29909a9 commit cba18f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Sitko.Core.Storage.S3/S3Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,23 @@ protected override async Task DoDeleteAllAsync(CancellationToken cancellationTok
if (string.IsNullOrEmpty(Options.Prefix))
{
using var s3Client = s3ClientProvider.S3Client;
try
if (Options.DeleteBucketOnCleanup)
{
await AmazonS3Util.DeleteS3BucketWithObjectsAsync(s3Client, Options.Bucket,
cancellationToken);
try
{
await AmazonS3Util.DeleteS3BucketWithObjectsAsync(s3Client, Options.Bucket,
cancellationToken);
}
catch (AmazonS3Exception ex) when (ex.Message.Contains(
"A header you provided implies functionality that is not implemented"))
{
await DeleteAllObjectsInBucket(cancellationToken);
await s3Client.DeleteBucketAsync(Options.Bucket, cancellationToken);
}
}
catch (AmazonS3Exception ex) when (ex.Message.Contains(
"A header you provided implies functionality that is not implemented"))
else
{
await DeleteAllObjectsInBucket(cancellationToken);
await s3Client.DeleteBucketAsync(Options.Bucket, cancellationToken);
}
}
else
Expand Down Expand Up @@ -273,4 +280,3 @@ protected override async Task<IEnumerable<StorageItemInfo>> GetAllItemsAsync(str
return items;
}
}

1 change: 1 addition & 0 deletions src/Sitko.Core.Storage.S3/S3StorageModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class S3StorageOptions : StorageOptions, IModuleOptionsWithValidation
public bool GeneratePreSignedUrls { get; set; }
public int PreSignedUrlsExpirationInHours { get; set; } = 1;
public Policy? BucketPolicy { get; set; }
public bool DeleteBucketOnCleanup { get; set; }

public Policy AnonymousReadPolicy => new()
{
Expand Down

0 comments on commit cba18f7

Please sign in to comment.