mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
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"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
@ -33,9 +34,14 @@ func s3Factory(conf map[string]string) (Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
serverSideEncryption := false
|
serverSideEncryption := false
|
||||||
_, ok = conf["encrypt"]
|
if raw, ok := conf["encrypt"]; ok {
|
||||||
if ok {
|
v, err := strconv.ParseBool(raw)
|
||||||
serverSideEncryption = true
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf(
|
||||||
|
"'encrypt' field couldn't be parsed as bool: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
serverSideEncryption = v
|
||||||
}
|
}
|
||||||
|
|
||||||
accessKeyId := conf["access_key"]
|
accessKeyId := conf["access_key"]
|
||||||
@ -130,13 +136,10 @@ func (c *S3Client) Put(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.serverSideEncryption {
|
if c.serverSideEncryption {
|
||||||
e := "AES256"
|
i.ServerSideEncryption = aws.String("AES256")
|
||||||
i.ServerSideEncryption = &e
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := c.nativeClient.PutObject(i)
|
if _, err := c.nativeClient.PutObject(i); err == nil {
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
return fmt.Errorf("Failed to upload state: %v", err)
|
return fmt.Errorf("Failed to upload state: %v", err)
|
||||||
|
@ -29,6 +29,7 @@ func TestS3Factory(t *testing.T) {
|
|||||||
config["bucket"] = "foo"
|
config["bucket"] = "foo"
|
||||||
config["key"] = "bar"
|
config["key"] = "bar"
|
||||||
config["encrypt"] = "1"
|
config["encrypt"] = "1"
|
||||||
|
|
||||||
// For this test we'll provide the credentials as config. The
|
// For this test we'll provide the credentials as config. The
|
||||||
// acceptance tests implicitly test passing credentials as
|
// acceptance tests implicitly test passing credentials as
|
||||||
// environment variables.
|
// environment variables.
|
||||||
|
Loading…
Reference in New Issue
Block a user