From 268c39ea8c2bf178ff84caaaf2a7048bc09a4557 Mon Sep 17 00:00:00 2001 From: boxjan Date: Thu, 1 Sep 2022 23:26:39 +0800 Subject: [PATCH] add forceVirtualHostedStyle for stores which only support virtual hosted style --- context/context.go | 2 +- man/aptly.1 | 5 +++++ man/aptly.1.ronn.tmpl | 4 ++++ s3/public.go | 10 +++++++--- s3/public_test.go | 6 +++--- utils/config.go | 29 +++++++++++++++-------------- utils/config_test.go | 1 + 7 files changed, 36 insertions(+), 21 deletions(-) diff --git a/context/context.go b/context/context.go index 8ee3ebf92b..d80528a544 100644 --- a/context/context.go +++ b/context/context.go @@ -393,7 +393,7 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto params.AccessKeyID, params.SecretAccessKey, params.SessionToken, params.Region, params.Endpoint, params.Bucket, params.ACL, params.Prefix, params.StorageClass, params.EncryptionMethod, params.PlusWorkaround, params.DisableMultiDel, - params.ForceSigV2, params.Debug) + params.ForceSigV2, params.ForceVirtualHostedStyle, params.Debug) if err != nil { Fatal(err) } diff --git a/man/aptly.1 b/man/aptly.1 index 03c8e8a112..fe986f0ff9 100644 --- a/man/aptly.1 +++ b/man/aptly.1 @@ -84,6 +84,7 @@ Configuration file is stored in JSON format (default values shown below): "plusWorkaround": false, "disableMultiDel": false, "forceSigV2": false, + "forceVirtualHostedStyle": false, "debug": false } }, @@ -265,6 +266,10 @@ bucket name (optional) disable Signature V4 support, useful with non\-AWS S3\-compatible object stores which do not support SigV4, shouldn\(cqt be enabled for AWS . .TP +\fBforceVirtualHostedStyle\fR +(optional) disable path style visit, useful with non\-AWS S3\-compatible object stores which only support virtual hosted style +. +.TP \fBdebug\fR (optional) enables detailed request/response dump for each S3 operation . diff --git a/man/aptly.1.ronn.tmpl b/man/aptly.1.ronn.tmpl index 82cc1dfc5c..df49404a4a 100644 --- a/man/aptly.1.ronn.tmpl +++ b/man/aptly.1.ronn.tmpl @@ -76,6 +76,7 @@ Configuration file is stored in JSON format (default values shown below): "plusWorkaround": false, "disableMultiDel": false, "forceSigV2": false, + "forceVirtualHostedStyle": true, "debug": false } }, @@ -251,6 +252,9 @@ and associated settings: * `forceSigV2`: (optional) disable Signature V4 support, useful with non-AWS S3-compatible object stores which do not support SigV4, shouldn't be enabled for AWS + * `forceVirtualHostedStyle`: + (optional) disable path style visit, useful with non-AWS S3-compatible object stores + which only support virtual hosted style * `debug`: (optional) enables detailed request/response dump for each S3 operation diff --git a/s3/public.go b/s3/public.go index b44c7fe682..0b60612828 100644 --- a/s3/public.go +++ b/s3/public.go @@ -79,15 +79,19 @@ func NewPublishedStorageRaw( // NewPublishedStorage creates new instance of PublishedStorage with specified S3 access // keys, region and bucket name -func NewPublishedStorage(accessKey, secretKey, sessionToken, region, endpoint, bucket, defaultACL, prefix, - storageClass, encryptionMethod string, plusWorkaround, disableMultiDel, forceSigV2, debug bool) (*PublishedStorage, error) { +func NewPublishedStorage( + accessKey, secretKey, sessionToken, region, endpoint, bucket, defaultACL, prefix, storageClass, encryptionMethod string, + plusWorkaround, disableMultiDel, forceSigV2, forceVirtualHostedStyle, debug bool) (*PublishedStorage, error) { config := &aws.Config{ Region: aws.String(region), } if endpoint != "" { - config = config.WithEndpoint(endpoint).WithS3ForcePathStyle(true) + config = config.WithEndpoint(endpoint) + if !forceVirtualHostedStyle { + config = config.WithS3ForcePathStyle(true) + } } if accessKey != "" { diff --git a/s3/public_test.go b/s3/public_test.go index 72fe21acfb..5a216a01e3 100644 --- a/s3/public_test.go +++ b/s3/public_test.go @@ -29,11 +29,11 @@ func (s *PublishedStorageSuite) SetUpTest(c *C) { c.Assert(err, IsNil) c.Assert(s.srv, NotNil) - s.storage, err = NewPublishedStorage("aa", "bb", "", "test-1", s.srv.URL(), "test", "", "", "", "", false, true, false, false) + s.storage, err = NewPublishedStorage("aa", "bb", "", "test-1", s.srv.URL(), "test", "", "", "", "", false, true, false, false, false) c.Assert(err, IsNil) - s.prefixedStorage, err = NewPublishedStorage("aa", "bb", "", "test-1", s.srv.URL(), "test", "", "lala", "", "", false, true, false, false) + s.prefixedStorage, err = NewPublishedStorage("aa", "bb", "", "test-1", s.srv.URL(), "test", "", "lala", "", "", false, true, false, false, false) c.Assert(err, IsNil) - s.noSuchBucketStorage, err = NewPublishedStorage("aa", "bb", "", "test-1", s.srv.URL(), "no-bucket", "", "", "", "", false, true, false, false) + s.noSuchBucketStorage, err = NewPublishedStorage("aa", "bb", "", "test-1", s.srv.URL(), "no-bucket", "", "", "", "", false, true, false, false, false) c.Assert(err, IsNil) _, err = s.storage.s3.CreateBucket(&s3.CreateBucketInput{Bucket: aws.String("test")}) diff --git a/utils/config.go b/utils/config.go index 2b60d6c6d1..e2d2d93edb 100644 --- a/utils/config.go +++ b/utils/config.go @@ -46,20 +46,21 @@ type FileSystemPublishRoot struct { // S3PublishRoot describes single S3 publishing entry point type S3PublishRoot struct { - Region string `json:"region"` - Bucket string `json:"bucket"` - Endpoint string `json:"endpoint"` - AccessKeyID string `json:"awsAccessKeyID"` - SecretAccessKey string `json:"awsSecretAccessKey"` - SessionToken string `json:"awsSessionToken"` - Prefix string `json:"prefix"` - ACL string `json:"acl"` - StorageClass string `json:"storageClass"` - EncryptionMethod string `json:"encryptionMethod"` - PlusWorkaround bool `json:"plusWorkaround"` - DisableMultiDel bool `json:"disableMultiDel"` - ForceSigV2 bool `json:"forceSigV2"` - Debug bool `json:"debug"` + Region string `json:"region"` + Bucket string `json:"bucket"` + Endpoint string `json:"endpoint"` + AccessKeyID string `json:"awsAccessKeyID"` + SecretAccessKey string `json:"awsSecretAccessKey"` + SessionToken string `json:"awsSessionToken"` + Prefix string `json:"prefix"` + ACL string `json:"acl"` + StorageClass string `json:"storageClass"` + EncryptionMethod string `json:"encryptionMethod"` + PlusWorkaround bool `json:"plusWorkaround"` + DisableMultiDel bool `json:"disableMultiDel"` + ForceSigV2 bool `json:"forceSigV2"` + ForceVirtualHostedStyle bool `json:"forceVirtualHostedStyle"` + Debug bool `json:"debug"` } // SwiftPublishRoot describes single OpenStack Swift publishing entry point diff --git a/utils/config_test.go b/utils/config_test.go index 3dc523c443..4e10fab785 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -102,6 +102,7 @@ func (s *ConfigSuite) TestSaveConfig(c *C) { " \"plusWorkaround\": false,\n"+ " \"disableMultiDel\": false,\n"+ " \"forceSigV2\": false,\n"+ + " \"forceVirtualHostedStyle\": false,\n"+ " \"debug\": false\n"+ " }\n"+ " },\n"+