state/remote: clean up the encryption flag stuff
/cc @hobbeswalsh
This commit is contained in:
parent
a5af429457
commit
e135ff546a
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
|
@ -33,9 +34,14 @@ func s3Factory(conf map[string]string) (Client, error) {
|
|||
}
|
||||
|
||||
serverSideEncryption := false
|
||||
_, ok = conf["encrypt"]
|
||||
if ok {
|
||||
serverSideEncryption = true
|
||||
if raw, ok := conf["encrypt"]; ok {
|
||||
v, err := strconv.ParseBool(raw)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"'encrypt' field couldn't be parsed as bool: %s", err)
|
||||
}
|
||||
|
||||
serverSideEncryption = v
|
||||
}
|
||||
|
||||
accessKeyId := conf["access_key"]
|
||||
|
@ -130,13 +136,10 @@ func (c *S3Client) Put(data []byte) error {
|
|||
}
|
||||
|
||||
if c.serverSideEncryption {
|
||||
e := "AES256"
|
||||
i.ServerSideEncryption = &e
|
||||
i.ServerSideEncryption = aws.String("AES256")
|
||||
}
|
||||
|
||||
_, err := c.nativeClient.PutObject(i)
|
||||
|
||||
if err == nil {
|
||||
if _, err := c.nativeClient.PutObject(i); err == nil {
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("Failed to upload state: %v", err)
|
||||
|
|
|
@ -29,6 +29,7 @@ func TestS3Factory(t *testing.T) {
|
|||
config["bucket"] = "foo"
|
||||
config["key"] = "bar"
|
||||
config["encrypt"] = "1"
|
||||
|
||||
// For this test we'll provide the credentials as config. The
|
||||
// acceptance tests implicitly test passing credentials as
|
||||
// environment variables.
|
||||
|
|
Loading…
Reference in New Issue