Return an error when conflicting etag & kms_key_id parameters are provided and now with ServerSideEncryption we can go back to the higher level PutObject.

This commit is contained in:
Kraig Amador 2016-03-04 09:22:43 -08:00
parent db91aebd8e
commit 74de6531fe
1 changed files with 8 additions and 6 deletions

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io" "io"
"log" "log"
"net/http"
"os" "os"
"strings" "strings"
@ -103,7 +102,6 @@ func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) erro
bucket := d.Get("bucket").(string) bucket := d.Get("bucket").(string)
key := d.Get("key").(string) key := d.Get("key").(string)
var body io.ReadSeeker var body io.ReadSeeker
headers := make(http.Header)
if v, ok := d.GetOk("source"); ok { if v, ok := d.GetOk("source"); ok {
source := v.(string) source := v.(string)
@ -124,6 +122,12 @@ func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) erro
return fmt.Errorf("Must specify \"source\" or \"content\" field") return fmt.Errorf("Must specify \"source\" or \"content\" field")
} }
if _, ok := d.GetOk("kms_key_id"); ok {
if _, ok := d.GetOk("etag"); ok {
return fmt.Errorf("Unable to specify kms_key_id and etag on the same object")
}
}
putInput := &s3.PutObjectInput{ putInput := &s3.PutObjectInput{
Bucket: aws.String(bucket), Bucket: aws.String(bucket),
Key: aws.String(key), Key: aws.String(key),
@ -152,12 +156,10 @@ func resourceAwsS3BucketObjectPut(d *schema.ResourceData, meta interface{}) erro
if v, ok := d.GetOk("kms_key_id"); ok { if v, ok := d.GetOk("kms_key_id"); ok {
putInput.SSEKMSKeyId = aws.String(v.(string)) putInput.SSEKMSKeyId = aws.String(v.(string))
headers.Add("x-amz-server-side-encryption", "aws:kms") putInput.ServerSideEncryption = aws.String("aws:kms")
} }
req, resp := s3conn.PutObjectRequest(putInput) resp, err := s3conn.PutObject(putInput)
req.HTTPRequest.Header = headers
err := req.Send()
if err != nil { if err != nil {
return fmt.Errorf("Error putting object in S3 bucket (%s): %s", bucket, err) return fmt.Errorf("Error putting object in S3 bucket (%s): %s", bucket, err)
} }