fix(region): avoid ctyun signature verification failed (#18301)

This commit is contained in:
屈轩
2023-10-12 19:05:59 +08:00
committed by GitHub
parent 478df09d11
commit 6dcf4c7faa
4 changed files with 13 additions and 14 deletions
+1 -1
View File
@@ -83,7 +83,7 @@ require (
k8s.io/client-go v0.19.3
k8s.io/cluster-bootstrap v0.19.3
moul.io/http2curl/v2 v2.3.0
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231012092902-f5b98c301971
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231012110302-e5895789bde1
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32
yunion.io/x/jsonutils v1.0.1-0.20230613121553-0f3b41e2ef19
yunion.io/x/log v1.0.1-0.20230411060016-feb3f46ab361
+2 -2
View File
@@ -1174,8 +1174,8 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.1/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231012092902-f5b98c301971 h1:QmALtZI/hajZWEoxWcy8Fzu7JY/DULHV6bl09dYrQE4=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231012092902-f5b98c301971/go.mod h1:2sgCN7nRPQL3woLfdgqLDd92vwAHqtlz3KKiHxC5BAw=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231012110302-e5895789bde1 h1:Hn3EQcCwnKddW4jSWo87mQujLjLyDFBA1E/z17eoyM8=
yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231012110302-e5895789bde1/go.mod h1:2sgCN7nRPQL3woLfdgqLDd92vwAHqtlz3KKiHxC5BAw=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32 h1:v7POYkQwo1XzOxBoIoRVr/k0V9Y5JyjpshlIFa9raug=
yunion.io/x/executor v0.0.0-20230705125604-c5ac3141db32/go.mod h1:Uxuou9WQIeJXNpy7t2fPLL0BYLvLiMvGQwY7Qc6aSws=
yunion.io/x/jsonutils v0.0.0-20190625054549-a964e1e8a051/go.mod h1:4N0/RVzsYL3kH3WE/H1BjUQdFiWu50JGCFQuuy+Z634=
+1 -1
View File
@@ -1432,7 +1432,7 @@ sigs.k8s.io/structured-merge-diff/v4/value
# sigs.k8s.io/yaml v1.2.0
## explicit; go 1.12
sigs.k8s.io/yaml
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231012092902-f5b98c301971
# yunion.io/x/cloudmux v0.3.10-0-alpha.1.0.20231012110302-e5895789bde1
## explicit; go 1.18
yunion.io/x/cloudmux/pkg/apis
yunion.io/x/cloudmux/pkg/apis/billing
+9 -10
View File
@@ -120,13 +120,11 @@ func (self *SCtyunClient) getUrl(service, resource string) (string, error) {
}
type sCtyunError struct {
StatusCode int `json:"StatusCode"`
RequestId string `json:"RequestId"`
ErrorMsg struct {
Code string `json:"Code"`
Message string `json:"Message"`
Type string `json:"Type"`
} `json:"Error"`
StatusCode string
Code string
EopErrCode string
RequestId string
Message string
}
func (self *sCtyunError) Error() string {
@@ -137,7 +135,6 @@ func (self *sCtyunError) ParseErrorFromJsonResponse(statusCode int, status strin
if body != nil {
body.Unmarshal(self)
}
self.StatusCode = statusCode
return self
}
@@ -211,7 +208,8 @@ func (self *SCtyunClient) sign(req *http.Request) (string, error) {
kTime := hmacSha256([]byte(self.accessSecret), []byte(eopDate))
kAk := hmacSha256(kTime, []byte(self.accessKey))
kDate := hmacSha256(kAk, []byte(time.Now().Format("20060102")))
t := strings.Split(eopDate, "T")[0]
kDate := hmacSha256(kAk, []byte(t))
signBase64 := base64.StdEncoding.EncodeToString(hmacSha256(kDate, []byte(signStr)))
return fmt.Sprintf("%s Headers=ctyun-eop-request-id;eop-date Signature=%s", self.accessKey, signBase64), nil
@@ -222,7 +220,8 @@ func (self *SCtyunClient) Do(req *http.Request) (*http.Response, error) {
req.Header.Set("Content-Type", "application/json")
req.Header.Set("ctyun-eop-request-id", utils.GenRequestId(20))
req.Header.Set("eop-date", time.Now().Format("20060102T150405Z"))
sh, _ := time.LoadLocation("Asia/Shanghai")
req.Header.Set("eop-date", time.Now().In(sh).Format("20060102T150405Z"))
signature, err := self.sign(req)
if err != nil {