1
0
Fork 0
mirror of https://github.com/Luzifer/share.git synced 2024-12-21 02:51:17 +00:00
share/vendor/github.com/aws/aws-sdk-go/service/glacier/customizations.go
Knut Ahlers 8f80d158ca
Move CLI util
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2017-12-02 19:12:46 +01:00

54 lines
1.2 KiB
Go

package glacier
import (
"encoding/hex"
"reflect"
"github.com/aws/aws-sdk-go/aws/awsutil"
"github.com/aws/aws-sdk-go/aws/request"
)
var (
defaultAccountID = "-"
)
func init() {
initRequest = func(r *request.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 *request.Request) {
r.Params = awsutil.CopyOf(r.Params)
}
func addAccountID(r *request.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 *request.Request) {
if r.Body == nil || r.HTTPRequest.Header.Get("X-Amz-Sha256-Tree-Hash") != "" {
return
}
h := ComputeHashes(r.Body)
hstr := hex.EncodeToString(h.TreeHash)
r.HTTPRequest.Header.Set("X-Amz-Sha256-Tree-Hash", hstr)
hLstr := hex.EncodeToString(h.LinearHash)
r.HTTPRequest.Header.Set("X-Amz-Content-Sha256", hLstr)
}
func addAPIVersion(r *request.Request) {
r.HTTPRequest.Header.Set("X-Amz-Glacier-Version", r.ClientInfo.APIVersion)
}