@@ -47,7 +47,7 @@ const (
47
47
KSYUN_DEFAULT_API_VERSION = "2016-03-04"
48
48
KSYUN_RDS_API_VERSION = "2016-07-01"
49
49
KSYUN_SKS_API_VERSION = "2015-11-01"
50
- KSYUN_MONITOR_API_VERSION = "2023-07-12 "
50
+ KSYUN_MONITOR_API_VERSION = "2018-11-14 "
51
51
)
52
52
53
53
type KsyunClientConfig struct {
@@ -137,7 +137,7 @@ func (cli *SKsyunClient) getUrl(service, regionId string) (string, error) {
137
137
case "kec" , "tag" , "krds" :
138
138
return fmt .Sprintf ("https://%s.%s.api.ksyun.com" , service , regionId ), nil
139
139
case "monitor" :
140
- return fmt .Sprintf ("https://%s.api.ksyun.com/v4/ " , service ), nil
140
+ return fmt .Sprintf ("https://%s.api.ksyun.com" , service ), nil
141
141
}
142
142
return "" , errors .Wrapf (cloudprovider .ErrNotSupported , "service %s" , service )
143
143
}
@@ -233,21 +233,27 @@ func (cli *SKsyunClient) Do(req *http.Request) (*http.Response, error) {
233
233
client := cli .getDefaultClient ()
234
234
req .Header .Set ("Accept" , "application/json" )
235
235
236
- if req .Method == "POST" {
236
+ if req .Method == "POST" || req . Method == "PUT" || req . Method == "DELETE" && req . Body != nil {
237
237
cred := credentials .NewStaticCredentials (cli .accessKeyId , cli .accessKeySecret , "" )
238
238
sig := v4 .NewSigner (cred )
239
- sig .DisableRequestBodyOverwrite = false
240
239
var body io.ReadSeeker = nil
241
- if req . Body != nil {
242
- bodyBytes , err := io . ReadAll ( req . Body )
243
- if err != nil {
244
- return nil , errors . Wrapf ( err , "ReadAll" )
245
- }
246
- req . Header . Set ( "Content-Length" , fmt . Sprintf ( "%d" , len ( bodyBytes )))
247
- req . ContentLength = int64 ( len ( bodyBytes ) )
248
- req . Body = io . NopCloser ( bytes . NewReader ( bodyBytes ))
249
- body = bytes . NewReader ( bodyBytes )
240
+ bodyBytes , err := io . ReadAll ( req . Body )
241
+ if err != nil {
242
+ return nil , errors . Wrapf ( err , "ReadAll" )
243
+ }
244
+ body = bytes . NewReader ( bodyBytes )
245
+
246
+ v4Req , err := http . NewRequestWithContext ( cli . ctx , req . Method , req . URL . String (), body )
247
+ if err != nil {
248
+ return nil , errors . Wrapf ( err , "NewRequestWithContext" )
250
249
}
250
+ v4Req .Header .Set ("Accept" , "application/json" )
251
+ v4Req .Header .Set ("X-Amz-Date" , time .Now ().UTC ().Format ("20060102T150405Z" ))
252
+ v4Req .Header .Set ("Content-Type" , req .Header .Get ("Content-Type" ))
253
+ v4Req .Header .Set ("Host" , req .URL .Host )
254
+ v4Req .Header .Set ("User-Agent" , req .Header .Get ("User-Agent" ))
255
+ v4Req .ContentLength = int64 (len (bodyBytes ))
256
+
251
257
service , regionId := "" , KSYUN_DEFAULT_REGION
252
258
urlInfo := strings .Split (req .URL .Host , "." )
253
259
if len (urlInfo ) < 2 {
@@ -257,11 +263,11 @@ func (cli *SKsyunClient) Do(req *http.Request) (*http.Response, error) {
257
263
if urlInfo [1 ] != "api" {
258
264
regionId = urlInfo [1 ]
259
265
}
260
- _ , err : = sig .Sign (req , body , service , regionId , time .Now ())
266
+ _ , err = sig .Sign (v4Req , body , service , regionId , time .Now ())
261
267
if err != nil {
262
268
return nil , errors .Wrapf (err , "sign" )
263
269
}
264
- return client .Do (req )
270
+ return client .Do (v4Req )
265
271
}
266
272
267
273
signature , err := cli .sign (req )
@@ -324,14 +330,16 @@ func (cli *SKsyunClient) request(service, regionId, apiName, apiVersion string,
324
330
values := url.Values {}
325
331
values .Set ("Action" , apiName )
326
332
values .Set ("Version" , apiVersion )
333
+ values .Set ("Service" , service )
327
334
328
335
method := httputils .GET
329
- if service == "monitor " {
336
+ if apiName == "GetMetricStatisticsBatch " {
330
337
method = httputils .POST
331
- } else {
338
+ }
339
+
340
+ if method == httputils .GET {
332
341
values .Set ("Accesskey" , cli .accessKeyId )
333
342
values .Set ("SignatureMethod" , "HMAC-SHA256" )
334
- values .Set ("Service" , service )
335
343
values .Set ("Format" , "json" )
336
344
values .Set ("SignatureVersion" , "1.0" )
337
345
values .Set ("Timestamp" , time .Now ().UTC ().Format ("2006-01-02T15:04:05Z" ))
0 commit comments