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
+21 -2
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