1 Star 0 Fork 0

litian/machine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sign3.go 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
// Thanks to Michael Vierling for contributing sign3.go
package awsauth
import (
"encoding/base64"
"net/http"
"time"
)
func stringToSignV3(req *http.Request) string {
// TASK 1. http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/RESTAuthentication.html#StringToSign
return req.Header.Get("Date") + req.Header.Get("x-amz-nonce")
}
func signatureV3(stringToSign string, keys Credentials) string {
// TASK 2. http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/RESTAuthentication.html#Signature
hash := hmacSHA256([]byte(keys.SecretAccessKey), stringToSign)
return base64.StdEncoding.EncodeToString(hash)
}
func buildAuthHeaderV3(signature string, keys Credentials) string {
// TASK 3. http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/RESTAuthentication.html#AuthorizationHeader
return "AWS3-HTTPS AWSAccessKeyId=" + keys.AccessKeyID +
", Algorithm=HmacSHA256" +
", Signature=" + signature
}
func prepareRequestV3(req *http.Request) *http.Request {
ts := timestampV3()
necessaryDefaults := map[string]string{
"Content-Type": "application/x-www-form-urlencoded; charset=utf-8",
"x-amz-date": ts,
"Date": ts,
"x-amz-nonce": "",
}
for header, value := range necessaryDefaults {
if req.Header.Get(header) == "" {
req.Header.Set(header, value)
}
}
if req.URL.Path == "" {
req.URL.Path += "/"
}
return req
}
func timestampV3() string {
return now().Format(timeFormatV3)
}
const timeFormatV3 = time.RFC1123
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/litian33/machine.git
git@gitee.com:litian33/machine.git
litian33
machine
machine
v0.1.0-rc4

搜索帮助