forked from aws/aws-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customizations.go
58 lines (47 loc) · 1.25 KB
/
customizations.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
package glacier
import (
"encoding/hex"
"reflect"
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/aws/service"
)
var (
defaultAccountID = "-"
)
func init() {
initRequest = func(r *service.Request) {
r.Handlers.Validate.PushFront(addAccountID)
r.Handlers.Validate.PushFront(copyParams) // this happens first
r.Handlers.Build.PushBack(addChecksum)
r.Handlers.Build.PushBack(addAPIVersion)
}
}
func copyParams(r *service.Request) {
r.Params = awsutil.CopyOf(r.Params)
}
func addAccountID(r *service.Request) {
if !r.ParamsFilled() {
return
}
v := reflect.Indirect(reflect.ValueOf(r.Params))
if f := v.FieldByName("AccountID"); f.IsNil() {
f.Set(reflect.ValueOf(&defaultAccountID))
}
}
func addChecksum(r *service.Request) {
if r.Body == nil {
return
}
h := ComputeHashes(r.Body)
if r.HTTPRequest.Header.Get("X-Amz-Content-Sha256") == "" {
hstr := hex.EncodeToString(h.LinearHash)
r.HTTPRequest.Header.Set("X-Amz-Content-Sha256", hstr)
}
if r.HTTPRequest.Header.Get("X-Amz-Sha256-Tree-Hash") == "" {
hstr := hex.EncodeToString(h.TreeHash)
r.HTTPRequest.Header.Set("X-Amz-Sha256-Tree-Hash", hstr)
}
}
func addAPIVersion(r *service.Request) {
r.HTTPRequest.Header.Set("X-Amz-Glacier-Version", r.Service.APIVersion)
}