From ca9c46de0dc387fb4ed0a21c74177c81c1e07060 Mon Sep 17 00:00:00 2001 From: Leon Verschuren Date: Tue, 4 Jan 2022 18:09:20 +0100 Subject: [PATCH] Option to override serviceUrl --- .../S3FileSystem.cs | 17 +++++++++++++---- .../S3FileSystemOptions.cs | 8 ++++++++ .../S3FileSystemProvider.cs | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystem.cs b/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystem.cs index d164328d..3e310aaa 100644 --- a/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystem.cs +++ b/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystem.cs @@ -34,10 +34,19 @@ public sealed class S3FileSystem : IUnixFileSystem public S3FileSystem(S3FileSystemOptions options, string rootDirectory) { _options = options; - _client = new AmazonS3Client( - options.AwsAccessKeyId, - options.AwsSecretAccessKey, - RegionEndpoint.GetBySystemName(options.BucketRegion)); + + var config = new AmazonS3Config(); + + if (!string.IsNullOrEmpty(options.ServiceUrl)) + { + config.ServiceURL = options.ServiceUrl; + } + else + { + config.RegionEndpoint = RegionEndpoint.GetBySystemName(options.BucketRegion); + } + + _client = new AmazonS3Client(options.AwsAccessKeyId, options.AwsSecretAccessKey, config); Root = new S3DirectoryEntry(rootDirectory, true); _transferUtility = new TransferUtility(_client); } diff --git a/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystemOptions.cs b/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystemOptions.cs index 5825b5bd..8fd14b1e 100644 --- a/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystemOptions.cs +++ b/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystemOptions.cs @@ -32,6 +32,14 @@ public class S3FileSystemOptions /// public string? BucketRegion { get; set; } + /// + /// Gets or sets the S3 service URL. + /// + /// + /// Takes precedence over BucketRegion. + /// + public string? ServiceUrl { get; set; } + /// /// Gets or sets the S3 bucket name. /// diff --git a/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystemProvider.cs b/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystemProvider.cs index 8f31534d..39f68991 100644 --- a/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystemProvider.cs +++ b/src/FubarDev.FtpServer.FileSystem.S3/S3FileSystemProvider.cs @@ -31,7 +31,7 @@ public S3FileSystemProvider(IOptions options, IAccountDirec if (string.IsNullOrEmpty(_options.AwsAccessKeyId) || string.IsNullOrEmpty(_options.AwsSecretAccessKey) || string.IsNullOrEmpty(_options.BucketName) - || string.IsNullOrEmpty(_options.BucketRegion)) + || (string.IsNullOrEmpty(_options.BucketRegion) && string.IsNullOrEmpty(_options.ServiceUrl))) { throw new ArgumentException("S3 Credentials have not been set correctly"); }