@@ -2,6 +2,7 @@ package s3
2
2
3
3
import (
4
4
"context"
5
+ "encoding/json"
5
6
"fmt"
6
7
"io"
7
8
"log"
@@ -29,6 +30,11 @@ type container struct {
29
30
extraArgs string
30
31
}
31
32
33
+ type S3ExtraArgs struct {
34
+ ServerSideEncryption string
35
+ SSEKMSKeyId string
36
+ }
37
+
32
38
func (c * container ) PreSignRequest (ctx context.Context , clientMethod stow.ClientMethod , id string ,
33
39
params stow.PresignRequestParams ) (url string , err error ) {
34
40
@@ -52,19 +58,28 @@ func (c *container) PreSignRequest(ctx context.Context, clientMethod stow.Client
52
58
}
53
59
log .Printf ("bucket: %s // %s" , c .name , id )
54
60
log .Printf ("extra args: %s" , c .extraArgs )
55
- if bucketEncrypted , sseAlgortihm , encryptionKey := getKmsMasterKeyId (c .client , c .name ); bucketEncrypted {
56
- log .Printf ("sse: %s // %s" , sseAlgortihm , encryptionKey )
57
- // switch sseAlgortihm {
58
- // case s3.ServerSideEncryptionAes256:
59
- // params.ServerSideEncryption = aws.String(sseAlgortihm)
60
- // case s3.ServerSideEncryptionAwsKms:
61
- // params.ServerSideEncryption = aws.String(sseAlgortihm)
62
- // if encryptionKey != "" {
63
- // params.SSEKMSKeyId = aws.String(encryptionKey)
64
- // }
65
- // }
66
- params .ServerSideEncryption = aws .String ("aws:kms" )
67
- params .SSEKMSKeyId = aws .String ("kmsId" ) // placeholder - i think the presigned-url setup means this dummy value is sufficient
61
+
62
+ // First, try to set SSE using stow.config
63
+ var extraArgs S3ExtraArgs
64
+ json .Unmarshal ([]byte (c .extraArgs ), & extraArgs )
65
+ log .Printf ("extra args: %s // %s" , extraArgs .ServerSideEncryption , extraArgs .SSEKMSKeyId )
66
+
67
+ if extraArgs .ServerSideEncryption == "" {
68
+ // As backup, try to set SSE using s3.GetBucketEncryption
69
+ if bucketEncrypted , sseAlgortihm , encryptionKey := getKmsMasterKeyId (c .client , c .name ); bucketEncrypted {
70
+ log .Printf ("sse: %s // %s" , sseAlgortihm , encryptionKey )
71
+ extraArgs .ServerSideEncryption , extraArgs .SSEKMSKeyId = sseAlgortihm , encryptionKey
72
+ }
73
+ }
74
+
75
+ switch extraArgs .ServerSideEncryption {
76
+ case s3 .ServerSideEncryptionAes256 :
77
+ params .ServerSideEncryption = aws .String (extraArgs .ServerSideEncryption )
78
+ case s3 .ServerSideEncryptionAwsKms :
79
+ params .ServerSideEncryption = aws .String (extraArgs .ServerSideEncryption )
80
+ if extraArgs .SSEKMSKeyId != "" {
81
+ params .SSEKMSKeyId = aws .String (extraArgs .SSEKMSKeyId )
82
+ }
68
83
}
69
84
70
85
req , _ = c .client .PutObjectRequest (params )
0 commit comments