From 75b860e0b1cf66c137495b775b10b59f8c2cae92 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Sun, 20 Mar 2016 20:11:19 +0300 Subject: [PATCH] Support SigV2 and S3 debug for publishing. --- Gomfile | 1 + context/context.go | 3 ++- man/aptly.1 | 6 ++++-- man/aptly.1.ronn.tmpl | 4 +++- s3/public.go | 23 +++++++++++++++++++++-- s3/public_test.go | 4 ++-- utils/config.go | 2 ++ utils/config_test.go | 4 +++- 8 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Gomfile b/Gomfile index ab737a0e..f5b55ed5 100644 --- a/Gomfile +++ b/Gomfile @@ -12,6 +12,7 @@ gom 'github.com/mattn/go-shellwords', :commit => 'c7ca6f94add751566a61cf2199e1de gom 'github.com/mkrautz/goar', :commit => '282caa8bd9daba480b51f1d5a988714913b97aad' gom 'github.com/mxk/go-flowrate/flowrate', :commit => 'cca7078d478f8520f85629ad7c68962d31ed7682' gom 'github.com/ncw/swift', :commit => '384ef27c70645e285f8bb9d02276bf654d06027e' +gom 'github.com/smira/go-aws-auth', :commit => '0070896e9d7f4f9f2d558532b2d896ce2239992a' gom 'github.com/smira/go-xz', :commit => '0c531f070014e218b21f3cfca801cc992d52726d' gom 'github.com/smira/commander', :commit => 'f408b00e68d5d6e21b9f18bd310978dafc604e47' gom 'github.com/smira/flag', :commit => '357ed3e599ffcbd4aeaa828e1d10da2df3ea5107' diff --git a/context/context.go b/context/context.go index 75b7a7c4..b4c76877 100644 --- a/context/context.go +++ b/context/context.go @@ -324,7 +324,8 @@ func (context *AptlyContext) GetPublishedStorage(name string) aptly.PublishedSto publishedStorage, err = s3.NewPublishedStorage( 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.EncryptionMethod, params.PlusWorkaround, params.DisableMultiDel, + params.ForceSigV2, params.Debug) if err != nil { Fatal(err) } diff --git a/man/aptly.1 b/man/aptly.1 index 8a18f1f0..7eff094e 100644 --- a/man/aptly.1 +++ b/man/aptly.1 @@ -1,7 +1,7 @@ .\" generated with Ronn/v0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3 . -.TH "APTLY" "1" "February 2016" "" "" +.TH "APTLY" "1" "March 2016" "" "" . .SH "NAME" \fBaptly\fR \- Debian repository management tool @@ -61,7 +61,9 @@ Configuration file is stored in JSON format (default values shown below): "storageClass": "", "encryptionMethod": "", "plusWorkaround": false, - "disableMultiDel": false + "disableMultiDel": false, + "forceSigV2": false, + "debug": false } }, "SwiftPublishEndpoints": { diff --git a/man/aptly.1.ronn.tmpl b/man/aptly.1.ronn.tmpl index 596e5d41..a4fe1f54 100644 --- a/man/aptly.1.ronn.tmpl +++ b/man/aptly.1.ronn.tmpl @@ -53,7 +53,9 @@ Configuration file is stored in JSON format (default values shown below): "storageClass": "", "encryptionMethod": "", "plusWorkaround": false, - "disableMultiDel": false + "disableMultiDel": false, + "forceSigV2": false, + "debug": false } }, "SwiftPublishEndpoints": { diff --git a/s3/public.go b/s3/public.go index d998f66a..5ea42a88 100644 --- a/s3/public.go +++ b/s3/public.go @@ -3,11 +3,14 @@ package s3 import ( "fmt" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/corehandlers" "github.com/aws/aws-sdk-go/aws/credentials" + "github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" "github.com/smira/aptly/aptly" "github.com/smira/aptly/files" + "github.com/smira/go-aws-auth" "os" "path/filepath" "strings" @@ -63,10 +66,14 @@ func NewPublishedStorageRaw( return result, nil } +func signV2(req *request.Request) { + awsauth.SignS3(req.HTTPRequest) +} + // 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 bool) (*PublishedStorage, error) { + storageClass, encryptionMethod string, plusWorkaround, disableMultiDel, forceSigV2, debug bool) (*PublishedStorage, error) { config := &aws.Config{ Region: aws.String(region), @@ -80,8 +87,20 @@ func NewPublishedStorage(accessKey, secretKey, sessionToken, region, endpoint, b config.Credentials = credentials.NewStaticCredentials(accessKey, secretKey, sessionToken) } - return NewPublishedStorageRaw(bucket, defaultACL, prefix, storageClass, + if debug { + config = config.WithLogLevel(aws.LogDebug) + } + + result, err := NewPublishedStorageRaw(bucket, defaultACL, prefix, storageClass, encryptionMethod, plusWorkaround, disableMultiDel, config) + + if err == nil && forceSigV2 { + result.s3.Handlers.Sign.Clear() + result.s3.Handlers.Sign.PushBackNamed(corehandlers.BuildContentLengthHandler) + result.s3.Handlers.Sign.PushBack(signV2) + } + + return result, err } // String diff --git a/s3/public_test.go b/s3/public_test.go index 1a234768..e0c270f4 100644 --- a/s3/public_test.go +++ b/s3/public_test.go @@ -27,9 +27,9 @@ 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) + s.storage, err = NewPublishedStorage("aa", "bb", "", "test-1", s.srv.URL(), "test", "", "", "", "", false, true, false, false) c.Assert(err, IsNil) - s.prefixedStorage, err = NewPublishedStorage("aa", "bb", "", "test-1", s.srv.URL(), "test", "", "lala", "", "", false, true) + s.prefixedStorage, err = NewPublishedStorage("aa", "bb", "", "test-1", s.srv.URL(), "test", "", "lala", "", "", false, true, 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 5ec86dd1..c05edbc6 100644 --- a/utils/config.go +++ b/utils/config.go @@ -40,6 +40,8 @@ type S3PublishRoot struct { EncryptionMethod string `json:"encryptionMethod"` PlusWorkaround bool `json:"plusWorkaround"` DisableMultiDel bool `json:"disableMultiDel"` + ForceSigV2 bool `json:"forceSigV2"` + 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 8bcfc0cd..229eba7e 100644 --- a/utils/config_test.go +++ b/utils/config_test.go @@ -76,7 +76,9 @@ func (s *ConfigSuite) TestSaveConfig(c *C) { " \"storageClass\": \"\",\n"+ " \"encryptionMethod\": \"\",\n"+ " \"plusWorkaround\": false,\n"+ - " \"disableMultiDel\": false\n"+ + " \"disableMultiDel\": false,\n"+ + " \"forceSigV2\": false,\n"+ + " \"debug\": false\n"+ " }\n"+ " },\n"+ " \"SwiftPublishEndpoints\": {\n"+