7
0

Compare commits

..

No commits in common. "c2428de6358b4892d1ec7e1c1c0c0e7a143ae34a" and "f038071d289c0d3a9e76976c6b5adb7014f40df3" have entirely different histories.

9 changed files with 14 additions and 87 deletions

View File

@ -1,15 +0,0 @@
package credentials
type StdTokenCredential struct {
AccessKeyId string
AccessKeySecret string
AccessKeyFrom string
}
func NewStsTokenCredential(accessKeyId, accessKeySecret, accessFrom string) *StdTokenCredential {
return &StdTokenCredential{
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
AccessKeyFrom: accessFrom,
}
}

View File

@ -26,9 +26,6 @@ func signRpcRequest(request requests.AcsRequest, signer Signer) (err error) {
request.SetStringToSign(stringToSign)
signature := signer.Sign(stringToSign, "&")
request.GetQueryParams()["sign"] = signature
debug("GrSdk sign: %s", signature)
debug("GrSdk sign string: %s", stringToSign)
debug("GrSdk sign: \r\n")
return
}
@ -109,7 +106,7 @@ func unsignRpcRequest(request *http.Request, signer Signer) (err error) {
stringToSign = strings.Replace(stringToSign, "%7E", "~", -1)
stringToSign = url.QueryEscape(stringToSign)
stringToSign = request.Method + "&%2F&" + stringToSign
debug("GrSdk sign: %s", stringToSign)
debug("grsdk singstring %s", stringToSign)
if timestamp, err := strconv.ParseInt(signParams["access_time"], 10, 64); err != nil {
return err

View File

@ -22,8 +22,6 @@ func NewSignerWithCredential(credential Credential, commonApi func(request *requ
signer = signers.NewAccessKeySigner(instance)
case *credentials.BaseCredential:
signer = signers.NewAccessKeySigner(instance.ToAccessKeyCredential())
case *credentials.StdTokenCredential:
signer = signers.NewStsTokenSigner(instance)
default:
err = errors.New("UnsupportedCredentialErrorCode = SDK.UnsupportedCredential")
}

View File

@ -1,41 +0,0 @@
package signers
import (
"crypto/md5"
"fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/credentials"
)
type StsTokenSigner struct {
credential *credentials.StdTokenCredential
}
func (signer *StsTokenSigner) GetAccessKeyId() (string, error) {
return signer.credential.AccessKeyId, nil
}
func (signer *StsTokenSigner) GetAccessKeyFrom() (string, error) {
return signer.credential.AccessKeyFrom, nil
}
func (*StsTokenSigner) GetName() string {
return "MD5"
}
func (signer *StsTokenSigner) Sign(stringToSign, secretSuffix string) string {
secret := signer.credential.AccessKeySecret + secretSuffix
return Md5(stringToSign, secret)
}
func NewStsTokenSigner(credential *credentials.StdTokenCredential) *StsTokenSigner {
return &StsTokenSigner{
credential: credential,
}
}
func Md5(source, secret string) string {
data := []byte(fmt.Sprintf("%s##%s", secret, source))
has := md5.Sum(data)
md5str := fmt.Sprintf("%x", has)
return md5str
}

View File

@ -1,7 +1,6 @@
package sdk
import (
"bytes"
"context"
"crypto/tls"
"fmt"
@ -12,7 +11,6 @@ import (
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils"
"net"
"net/http"
"net/http/httputil"
"net/url"
"os"
"regexp"
@ -93,16 +91,6 @@ func (client *Client) InitWithAccessKey(accessKeyId, accessKeySecret, accessKeyF
return client.InitWithOptions(config, credential)
}
func (client *Client) InitWithStsToken(accessKeyId, accessKeySecret, accessKeyFrom string) (err error) {
config := client.InitWithConfig()
credential := &credentials.StdTokenCredential{
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
AccessKeyFrom: accessKeyFrom,
}
return client.InitWithOptions(config, credential)
}
func (client *Client) InitWithOptions(config *Config, credential auth.Credential) (err error) {
client.httpClient = &http.Client{}
client.config = config
@ -239,10 +227,8 @@ func (client *Client) DoActionWithSigner(request requests.AcsRequest, response r
client.httpClient.Transport = trans
}
dump, err := httputil.DumpRequest(httpRequest, true)
debug("client %s", bytes.NewBuffer(dump).String())
var httpResponse *http.Response
httpResponse, err = hookDo(client.httpClient.Do)(httpRequest)
if err != nil {
return
@ -299,6 +285,8 @@ func (client *Client) buildRequestWithSigner(request requests.AcsRequest, signer
userAgent := DefaultUserAgent
httpRequest.Header.Set("User-Agent", userAgent)
debug("%s", request.GetStringToSign())
debug("%s", httpRequest.Method)
return
}

View File

@ -202,8 +202,8 @@ func defaultBaseRequest() (request *baseRequest) {
Method: GET,
QueryParams: make(map[string]string),
Headers: map[string]string{
"Gr-Sdk-Client": "golang/1.14",
"Gr-Sdk-Invoke-Type": "normal",
"gr-sdk-client": "golang/1.14",
"gr-sdk-invoke-type": "normal",
"Accept-Encoding": Json,
},
FormParams: make(map[string]string),

View File

@ -10,6 +10,7 @@ type SendSmsRequest struct {
User string `position:"Query" field:"user" default:"" `
Code string `position:"Query" field:"code" default:"" `
Params string `position:"Query" field:"params" default:"" `
TestBody string `position:"Body" field:"test_body" default:"2121" `
}
type SendSmsResponseData struct {

View File

@ -10,13 +10,12 @@ type DemoTestRequest struct {
Param1 string `position:"Query" field:"param_1" default:"" `
Param2 int `position:"Query" field:"param_2" default:"10086" `
Param3 bool `position:"Query" field:"param_3" default:"false" `
ParamBody string `position:"Body" field:"param_body" default:"foobar" `
}
func CreateDemoTestRequest() (req *DemoTestRequest) {
req = &DemoTestRequest{RpcRequest: &requests.RpcRequest{}}
req.InitWithApiInfo(HOST, VERSION, "/api/sms/Index")
req.Method = requests.POST
req.Method = requests.GET
return
}