Support SigV2 and S3 debug for publishing.

This commit is contained in:
Andrey Smirnov
2016-03-20 20:11:19 +03:00
parent 76edf9649b
commit 75b860e0b1
8 changed files with 38 additions and 9 deletions

View File

@@ -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'

View File

@@ -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)
}

View File

@@ -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": {

View File

@@ -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": {

View File

@@ -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

View File

@@ -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")})

View File

@@ -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

View File

@@ -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"+