From c279c32a0970626a7f5f54bc2a6f7438b3590b93 Mon Sep 17 00:00:00 2001 From: Dennis Glindhart Date: Wed, 15 Jul 2020 13:02:53 +0200 Subject: [PATCH 1/2] Usable with Minio --- README.md | 13 +++++++++++++ .../BucketMediaFileSystemComposer.cs | 13 ++++++++++++- .../Umbraco.Storage.S3/BucketFileSystemConfig.cs | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3089813..b2d61c2 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,19 @@ Replace config file located `~/config/imageprocessor/security.config` ``` +## Using Minio + +It is possible to use the provider with a (self-hosted) Minio (https://min.io). Minio requires that ForcePathStyle config settings is true and there needs to be specified a custom URL for the Minio/S3 instance. + +Add the following extra settings for Minio to work + +```xml + + +``` + +Note: Minio uses `us-east-1` as the default region. + ## Future work on this project Due to not having access to the original Umbraco.Storage.S3 package name I've released the NuGet package under `Our.Umbraco.FileSystemProviders.S3...`. Add in the Web.config keys and we have 3 different naming conventions. I intend to resolve this at some point in the future. If the Web.config keys are changed then I will ensure the new names are optional and the old keys will continue to work. diff --git a/Umbraco.Storage.S3/Umbraco.Storage.S3.Media/BucketMediaFileSystemComposer.cs b/Umbraco.Storage.S3/Umbraco.Storage.S3.Media/BucketMediaFileSystemComposer.cs index 1885b8f..dcf9873 100644 --- a/Umbraco.Storage.S3/Umbraco.Storage.S3.Media/BucketMediaFileSystemComposer.cs +++ b/Umbraco.Storage.S3/Umbraco.Storage.S3.Media/BucketMediaFileSystemComposer.cs @@ -25,12 +25,19 @@ public void Compose(Composition composition) composition.RegisterUnique(config); composition.Register(new DefaultMimeTypeResolver()); + var s3config = new AmazonS3Config() + { + RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(config.Region), + ForcePathStyle = config.ForcePathStyle, + ServiceURL = config.ServiceUrl + }; + composition.SetMediaFileSystem((f) => new BucketFileSystem( config: config, mimeTypeResolver: f.GetInstance(), fileCacheProvider: null, logger: f.GetInstance(), - s3Client: new AmazonS3Client(Amazon.RegionEndpoint.GetBySystemName(config.Region)) + s3Client: new AmazonS3Client(s3config) )); composition.Components().Append(); @@ -43,6 +50,8 @@ private BucketFileSystemConfig CreateConfiguration() { var bucketName = ConfigurationManager.AppSettings[$"{AppSettingsKey}:BucketName"]; var bucketHostName = ConfigurationManager.AppSettings[$"{AppSettingsKey}:BucketHostname"]; + var serviceUrl = ConfigurationManager.AppSettings[$"{AppSettingsKey}:ServiceUrl"]; + bool.TryParse(ConfigurationManager.AppSettings[$"{AppSettingsKey}:ForcePathStyle"], out var forcepathstyle); var bucketPrefix = ConfigurationManager.AppSettings[$"{AppSettingsKey}:MediaPrefix"]; var region = ConfigurationManager.AppSettings[$"{AppSettingsKey}:Region"]; bool.TryParse(ConfigurationManager.AppSettings[$"{AppSettingsKey}:DisableVirtualPathProvider"], out var disableVirtualPathProvider); @@ -63,6 +72,8 @@ private BucketFileSystemConfig CreateConfiguration() { BucketName = bucketName, BucketHostName = bucketHostName, + ServiceUrl = serviceUrl, + ForcePathStyle = forcepathstyle, BucketPrefix = bucketPrefix.Trim(Delimiters), Region = region, CannedACL = new S3CannedACL("public-read"), diff --git a/Umbraco.Storage.S3/Umbraco.Storage.S3/BucketFileSystemConfig.cs b/Umbraco.Storage.S3/Umbraco.Storage.S3/BucketFileSystemConfig.cs index a4fc655..9cd6f35 100644 --- a/Umbraco.Storage.S3/Umbraco.Storage.S3/BucketFileSystemConfig.cs +++ b/Umbraco.Storage.S3/Umbraco.Storage.S3/BucketFileSystemConfig.cs @@ -7,6 +7,8 @@ public class BucketFileSystemConfig public string BucketName { get; set; } public string BucketHostName { get; set; } + public string ServiceUrl { get; set; } + public bool ForcePathStyle { get; set; } public string BucketPrefix { get; set; } From 8c0967d6f8487118ab66cf4a6ff056519d9e8639 Mon Sep 17 00:00:00 2001 From: Dennis Glindhart Date: Wed, 15 Jul 2020 13:12:11 +0200 Subject: [PATCH 2/2] Add Minio/Forcestylepath/serviceurl to Forms project too --- .../BucketFormsFileSystemComposer.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Umbraco.Storage.S3/Umbraco.Storage.S3.Forms/BucketFormsFileSystemComposer.cs b/Umbraco.Storage.S3/Umbraco.Storage.S3.Forms/BucketFormsFileSystemComposer.cs index e75b494..f0a8a2f 100644 --- a/Umbraco.Storage.S3/Umbraco.Storage.S3.Forms/BucketFormsFileSystemComposer.cs +++ b/Umbraco.Storage.S3/Umbraco.Storage.S3.Forms/BucketFormsFileSystemComposer.cs @@ -30,12 +30,19 @@ public void Compose(Composition composition) composition.RegisterUnique(config); composition.Register(new DefaultMimeTypeResolver()); + var s3config = new AmazonS3Config() + { + RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(config.Region), + ForcePathStyle = config.ForcePathStyle, + ServiceURL = config.ServiceUrl + }; + composition.RegisterUniqueFor(f => new BucketFileSystem( config: config, mimeTypeResolver: f.GetInstance(), fileCacheProvider: null, logger: f.GetInstance(), - s3Client: new AmazonS3Client(Amazon.RegionEndpoint.GetBySystemName(config.Region)) + s3Client: new AmazonS3Client(s3config) )); } @@ -46,6 +53,8 @@ private BucketFileSystemConfig CreateConfiguration() var bucketName = ConfigurationManager.AppSettings[$"{AppSettingsKey}:BucketName"]; var bucketHostName = ConfigurationManager.AppSettings[$"{AppSettingsKey}:BucketHostname"]; var bucketPrefix = ConfigurationManager.AppSettings[$"{AppSettingsKey}:FormsPrefix"]; + var serviceUrl = ConfigurationManager.AppSettings[$"{AppSettingsKey}:ServiceUrl"]; + bool.TryParse(ConfigurationManager.AppSettings[$"{AppSettingsKey}:ForcePathStyle"], out var forcepathstyle); var region = ConfigurationManager.AppSettings[$"{AppSettingsKey}:Region"]; bool.TryParse(ConfigurationManager.AppSettings[$"{AppSettingsKey}:DisableVirtualPathProvider"], out var disableVirtualPathProvider); @@ -65,6 +74,8 @@ private BucketFileSystemConfig CreateConfiguration() { BucketName = bucketName, BucketHostName = bucketHostName, + ServiceUrl = serviceUrl, + ForcePathStyle = forcepathstyle, BucketPrefix = bucketPrefix.Trim(Delimiters), Region = region, CannedACL = new S3CannedACL("public-read"),