-
Notifications
You must be signed in to change notification settings - Fork 342
/
extract_sse.go
84 lines (78 loc) · 3.05 KB
/
extract_sse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package s3
import (
"net/http"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
// extractSSHeaderUploadPart extracts the x-amz-server-side-* headers from the given
// UploadPartOutput response.
func extractSSHeaderUploadPart(resp *s3.UploadPartOutput) http.Header {
// x-amz-server-side-* headers
headers := make(http.Header)
if resp.SSECustomerAlgorithm != nil {
headers.Set("X-Amz-Server-Side-Encryption-Customer-Algorithm", *resp.SSECustomerAlgorithm)
}
if resp.SSECustomerKeyMD5 != nil {
headers.Set("X-Amz-Server-Side-Encryption-Customer-Key-Md5", *resp.SSECustomerKeyMD5)
}
if resp.SSEKMSKeyId != nil {
headers.Set("X-Amz-Server-Side-Encryption-Aws-Kms-Key-Id", *resp.SSEKMSKeyId)
}
if resp.ServerSideEncryption != "" {
headers.Set("X-Amz-Server-Side-Encryption", string(resp.ServerSideEncryption))
}
return headers
}
// extractSSHeaderUploadPartCopy extracts the x-amz-server-side-* headers from the given
// UploadPartCopyOutput response.
func extractSSHeaderUploadPartCopy(resp *s3.UploadPartCopyOutput) http.Header {
// x-amz-server-side-* headers
headers := make(http.Header)
if resp.SSECustomerAlgorithm != nil {
headers.Set("X-Amz-Server-Side-Encryption-Customer-Algorithm", *resp.SSECustomerAlgorithm)
}
if resp.SSECustomerKeyMD5 != nil {
headers.Set("X-Amz-Server-Side-Encryption-Customer-Key-Md5", *resp.SSECustomerKeyMD5)
}
if resp.SSEKMSKeyId != nil {
headers.Set("X-Amz-Server-Side-Encryption-Aws-Kms-Key-Id", *resp.SSEKMSKeyId)
}
if resp.ServerSideEncryption != "" {
headers.Set("X-Amz-Server-Side-Encryption", string(resp.ServerSideEncryption))
}
return headers
}
// extractSSHeaderCreateMultipartUpload extracts the x-amz-server-side-* headers from the given
// CreateMultipartUploadOutput response.
func extractSSHeaderCreateMultipartUpload(resp *s3.CreateMultipartUploadOutput) http.Header {
// x-amz-server-side-* headers
headers := make(http.Header)
if resp.SSECustomerAlgorithm != nil {
headers.Set("X-Amz-Server-Side-Encryption-Customer-Algorithm", *resp.SSECustomerAlgorithm)
}
if resp.SSECustomerKeyMD5 != nil {
headers.Set("X-Amz-Server-Side-Encryption-Customer-Key-Md5", *resp.SSECustomerKeyMD5)
}
if resp.SSEKMSKeyId != nil {
headers.Set("X-Amz-Server-Side-Encryption-Aws-Kms-Key-Id", *resp.SSEKMSKeyId)
}
if resp.ServerSideEncryption != "" {
headers.Set("X-Amz-Server-Side-Encryption", string(resp.ServerSideEncryption))
}
if resp.SSEKMSEncryptionContext != nil {
headers.Set("X-Amz-Server-Side-Encryption-Context", *resp.SSEKMSEncryptionContext)
}
return headers
}
// extractSSHeaderCompleteMultipartUpload extracts the x-amz-server-side-* headers from the given
// CompleteMultipartUploadOutput response.
func extractSSHeaderCompleteMultipartUpload(resp *s3.CompleteMultipartUploadOutput) http.Header {
// x-amz-server-side-* headers
headers := make(http.Header)
if resp.SSEKMSKeyId != nil {
headers.Set("X-Amz-Server-Side-Encryption-Aws-Kms-Key-Id", *resp.SSEKMSKeyId)
}
if resp.ServerSideEncryption != "" {
headers.Set("X-Amz-Server-Side-Encryption", string(resp.ServerSideEncryption))
}
return headers
}