From c9e7329590891b6436b995b1ecc90e4aab435935 Mon Sep 17 00:00:00 2001 From: Francisco Facioni Date: Tue, 9 Jul 2024 18:05:57 +0200 Subject: [PATCH] add s3 prefix support --- src/Velopack.Deployment/S3Repository.cs | 23 +++++++++++++++---- .../Commands/Deployment/S3BaseCommand.cs | 6 +++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Velopack.Deployment/S3Repository.cs b/src/Velopack.Deployment/S3Repository.cs index ef5a611d..7e584ca9 100644 --- a/src/Velopack.Deployment/S3Repository.cs +++ b/src/Velopack.Deployment/S3Repository.cs @@ -18,6 +18,8 @@ public class S3DownloadOptions : RepositoryOptions, IObjectDownloadOptions public string Endpoint { get; set; } public string Bucket { get; set; } + + public string Prefix { get; set; } } public class S3UploadOptions : S3DownloadOptions, IObjectUploadOptions @@ -30,18 +32,20 @@ public class S3BucketClient public AmazonS3Client Amazon { get; } public string Bucket { get; } + public string Prefix { get; } - public S3BucketClient(AmazonS3Client client, string bucket) + public S3BucketClient(AmazonS3Client client, string bucket, string prefix) { Amazon = client; Bucket = bucket; + Prefix = prefix; } public virtual Task DeleteObjectAsync(string key, CancellationToken cancellationToken = default) { var request = new DeleteObjectRequest(); request.BucketName = Bucket; - request.Key = key; + request.Key = Prefix + key; return Amazon.DeleteObjectAsync(request, cancellationToken); } @@ -49,7 +53,7 @@ public class S3BucketClient { var request = new GetObjectRequest(); request.BucketName = Bucket; - request.Key = key; + request.Key = Prefix + key; return Amazon.GetObjectAsync(request, cancellationToken); } @@ -57,7 +61,7 @@ public class S3BucketClient { var request = new GetObjectMetadataRequest(); request.BucketName = Bucket; - request.Key = key; + request.Key = Prefix + key; return Amazon.GetObjectMetadataAsync(request, cancellationToken); } } @@ -87,7 +91,16 @@ public class S3Repository : ObjectRepository((v) => Prefix = v, "--prefix") + .SetDescription("Prefix to the S3 url.") + .SetArgumentHelpName("PREFIX"); } private static void MustBeValidAwsRegion(OptionResult result)