|
|
@@ -1,7 +1,6 @@ |
|
|
package cdsapi |
|
|
package cdsapi |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
|
|
|
"crypto/sha256" |
|
|
"crypto/sha256" |
|
|
"encoding/hex" |
|
|
"encoding/hex" |
|
|
"fmt" |
|
|
"fmt" |
|
|
@@ -11,10 +10,7 @@ import ( |
|
|
ul "net/url" |
|
|
ul "net/url" |
|
|
"path/filepath" |
|
|
"path/filepath" |
|
|
"strings" |
|
|
"strings" |
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
v4 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" |
|
|
|
|
|
"github.com/aws/aws-sdk-go-v2/credentials" |
|
|
|
|
|
"github.com/google/go-querystring/query" |
|
|
"github.com/google/go-querystring/query" |
|
|
"gitlink.org.cn/cloudream/common/pkgs/iterator" |
|
|
"gitlink.org.cn/cloudream/common/pkgs/iterator" |
|
|
"gitlink.org.cn/cloudream/common/sdks" |
|
|
"gitlink.org.cn/cloudream/common/sdks" |
|
|
@@ -59,14 +55,7 @@ func JSONAPI[Resp sdks.APIResponse, Req sdks.APIRequest](cfg *Config, cli *http. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if cfg.AccessKey != "" && cfg.SecretKey != "" { |
|
|
if cfg.AccessKey != "" && cfg.SecretKey != "" { |
|
|
prod := credentials.NewStaticCredentialsProvider(cfg.AccessKey, cfg.SecretKey, "") |
|
|
|
|
|
cred, err := prod.Retrieve(context.TODO()) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return re, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
signer := v4.NewSigner() |
|
|
|
|
|
err = signer.SignHTTP(context.Background(), cred, httpReq, calcSha256(param.Body), AuthService, AuthRegion, time.Now()) |
|
|
|
|
|
|
|
|
err = SignWithPayloadHash(httpReq, cfg.AccessKey, cfg.SecretKey, calcSha256(param.Body)) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return re, err |
|
|
return re, err |
|
|
} |
|
|
} |
|
|
@@ -90,14 +79,7 @@ func JSONAPINoData[Resp sdks.APIResponse, Req sdks.APIRequest](cfg *Config, cli |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if cfg.AccessKey != "" && cfg.SecretKey != "" { |
|
|
if cfg.AccessKey != "" && cfg.SecretKey != "" { |
|
|
prod := credentials.NewStaticCredentialsProvider(cfg.AccessKey, cfg.SecretKey, "") |
|
|
|
|
|
cred, err := prod.Retrieve(context.TODO()) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
signer := v4.NewSigner() |
|
|
|
|
|
err = signer.SignHTTP(context.Background(), cred, httpReq, calcSha256(param.Body), AuthService, AuthRegion, time.Now()) |
|
|
|
|
|
|
|
|
err = SignWithPayloadHash(httpReq, cfg.AccessKey, cfg.SecretKey, calcSha256(param.Body)) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
@@ -115,10 +97,12 @@ func calcSha256(body sdks.RequestBody) string { |
|
|
hasher := sha256.New() |
|
|
hasher := sha256.New() |
|
|
switch body := body.(type) { |
|
|
switch body := body.(type) { |
|
|
case *sdks.StringBody: |
|
|
case *sdks.StringBody: |
|
|
return hex.EncodeToString(hasher.Sum([]byte(body.Value))) |
|
|
|
|
|
|
|
|
hasher.Write([]byte(body.Value)) |
|
|
|
|
|
return hex.EncodeToString(hasher.Sum(nil)) |
|
|
|
|
|
|
|
|
case *sdks.BytesBody: |
|
|
case *sdks.BytesBody: |
|
|
return hex.EncodeToString(hasher.Sum(body.Value)) |
|
|
|
|
|
|
|
|
hasher.Write(body.Value) |
|
|
|
|
|
return hex.EncodeToString(hasher.Sum(nil)) |
|
|
|
|
|
|
|
|
default: |
|
|
default: |
|
|
return "" |
|
|
return "" |
|
|
@@ -179,14 +163,7 @@ func PostMultiPart(cfg *Config, url string, info any, files http2.MultiPartFileI |
|
|
req.Body = pr |
|
|
req.Body = pr |
|
|
|
|
|
|
|
|
if cfg.AccessKey != "" && cfg.SecretKey != "" { |
|
|
if cfg.AccessKey != "" && cfg.SecretKey != "" { |
|
|
prod := credentials.NewStaticCredentialsProvider(cfg.AccessKey, cfg.SecretKey, "") |
|
|
|
|
|
cred, err := prod.Retrieve(context.TODO()) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return nil, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
signer := v4.NewSigner() |
|
|
|
|
|
err = signer.SignHTTP(context.Background(), cred, req, "", AuthService, AuthRegion, time.Now()) |
|
|
|
|
|
|
|
|
err = SignWithoutBody(req, cfg.AccessKey, cfg.SecretKey) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return nil, err |
|
|
return nil, err |
|
|
} |
|
|
} |
|
|
|