Skip to content

Commit

Permalink
add forceVirtualHostedStyle for stores which only support virtual hos…
Browse files Browse the repository at this point in the history
…ted style
  • Loading branch information
boxjan authored and randombenj committed Sep 9, 2022
1 parent b3d9055 commit 268c39e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 21 deletions.
2 changes: 1 addition & 1 deletion context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions man/aptly.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down Expand Up @@ -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
.
Expand Down
4 changes: 4 additions & 0 deletions man/aptly.1.ronn.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand Down Expand Up @@ -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

Expand Down
10 changes: 7 additions & 3 deletions s3/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
6 changes: 3 additions & 3 deletions s3/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")})
Expand Down
29 changes: 15 additions & 14 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions utils/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"+
Expand Down

0 comments on commit 268c39e

Please sign in to comment.