7
0

Compare commits

..

No commits in common. "9c2898517e663c9aec63e68ee65d989d770f0aef" and "0feabe2c1f9e8e1aec87595e6452109adec7f364" have entirely different histories.

8 changed files with 13 additions and 142 deletions

View File

@ -2,13 +2,10 @@ package auth
import (
"bytes"
"errors"
"fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils"
"net/http"
"net/url"
"strconv"
"strings"
"time"
)
@ -57,11 +54,8 @@ func buildRpcStringToSign(request requests.AcsRequest) (stringToSign string) {
for key, value := range request.GetQueryParams() {
signParams[key] = value
}
if strings.ToUpper(request.GetMethod()) == requests.POST {
for key, value := range request.GetFormParams() {
signParams[key] = value
}
for key, value := range request.GetFormParams() {
signParams[key] = value
}
stringToSign = utils.GetUrlFormedMap(signParams)
@ -72,41 +66,3 @@ func buildRpcStringToSign(request requests.AcsRequest) (stringToSign string) {
stringToSign = request.GetMethod() + "&%2F&" + stringToSign
return
}
func unsignRpcRequest(request *http.Request, signer Signer) (err error) {
signParams := make(map[string]string)
for key, value := range request.URL.Query() {
signParams[key] = value[0]
}
if strings.ToUpper(request.Method) == requests.POST {
for key, value := range request.Form {
signParams[key] = value[0]
}
}
signValue, ok := signParams["sign"]
if !ok {
return errors.New("sign value is not exists")
}
stringToSign := utils.GetUrlFormedMap(signParams)
stringToSign = strings.Replace(stringToSign, "+", "%20", -1)
stringToSign = strings.Replace(stringToSign, "*", "%2A", -1)
stringToSign = strings.Replace(stringToSign, "%7E", "~", -1)
stringToSign = url.QueryEscape(stringToSign)
stringToSign = request.Method + "&%2F&" + stringToSign
if timestamp, err := strconv.ParseInt(signParams["access_time"], 10, 64); err != nil {
return err
} else {
if time.Unix(timestamp, 0).Before(time.Now().Add(-5 * time.Minute)) {
err = errors.New("sign timeout 5 minute")
}
}
if signer.Sign(stringToSign, "&") != signValue {
return errors.New("sign string is not correct")
}
return
}

View File

@ -6,7 +6,6 @@ import (
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/signers"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
"net/http"
)
type Signer interface {
@ -33,9 +32,3 @@ func Sign(request requests.AcsRequest, signer Signer) (err error) {
err = signRpcRequest(request, signer)
return
}
func UnSign(request *http.Request, signer Signer) (err error) {
//TODO 根据rpc和roa两种风格签名自行选择
err = unsignRpcRequest(request, signer)
return
}

View File

@ -25,12 +25,6 @@ var defaultReadTimeout = 10 * time.Second
var defaultDomain = ".gaore.com"
var DefaultUserAgent = fmt.Sprintf("GaoreGoSdk (%s;%s) Golang/%s Core/%s", runtime.GOOS, runtime.GOARCH, strings.Trim(runtime.Version(), "go"), Version)
var debug utils.Debug
func init() {
debug = utils.Init("sdk")
}
type Client struct {
Host string
httpClient *http.Client
@ -42,6 +36,7 @@ type Client struct {
httpProxy string
httpsProxy string
noProxy string
debug utils.Debug
}
func (client *Client) GetNoProxy() string {
@ -94,6 +89,7 @@ func (client *Client) InitWithAccessKey(accessKeyId, accessKeySecret, accessKeyF
func (client *Client) InitWithOptions(config *Config, credential auth.Credential) (err error) {
client.httpClient = &http.Client{}
client.config = config
client.debug = utils.Init("sdk", true)
if config.Transport != nil {
client.httpClient.Transport = config.Transport
@ -285,8 +281,7 @@ func (client *Client) buildRequestWithSigner(request requests.AcsRequest, signer
userAgent := DefaultUserAgent
httpRequest.Header.Set("User-Agent", userAgent)
debug("%s", request.GetStringToSign())
debug("%s", httpRequest.Method)
client.debug("%s", request.GetStringToSign())
return
}

View File

@ -3,7 +3,6 @@ package requests
import (
"errors"
"fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils"
"io"
"math/cmplx"
"reflect"
@ -44,12 +43,6 @@ const (
HeaderSeparator = "\n"
)
var debug utils.Debug
func init() {
debug = utils.Init("request")
}
type AcsRequest interface {
GetReadTimeout() time.Duration
GetConnectTimeout() time.Duration
@ -229,7 +222,6 @@ func flatRepeatedList(reflectValue reflect.Value, request AcsRequest, position s
}
fieldDefault, _ := field.Tag.Lookup("default")
debug("%s %s %s", name, fieldPosition, fieldDefault)
if isContiansNameTag {
var value string
switch field.Type.Kind() {
@ -251,10 +243,6 @@ func flatRepeatedList(reflectValue reflect.Value, request AcsRequest, position s
value = fieldDefault
}
if value == "0" && fieldDefault != "" && fieldDefault != "0" {
value = fieldDefault
}
err = addParam(request, fieldPosition, name, value)
}
}

View File

@ -1,10 +1,6 @@
package utils
import (
"fmt"
"os"
"strings"
)
import "fmt"
type Debug func(format string, v ...interface{})
@ -12,21 +8,7 @@ var hookPrint = func(input string) {
fmt.Println(input)
}
var hookGetEnv = func() string {
return os.Getenv("DEBUG")
}
func Init(flag string) Debug {
enable := false
env := hookGetEnv()
parts := strings.Split(env, ",")
for _, part := range parts {
if part == flag {
enable = true
break
}
}
func Init(flag string, enable bool) Debug {
return func(format string, v ...interface{}) {
if enable {

View File

@ -3,7 +3,7 @@ package jedi
import "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
const (
HOST = "jedi"
HOST = "jedi.gaore.com"
VERSION = "2020-08-04"
)
@ -17,12 +17,6 @@ func (c *Client) SendSms(req *SendSmsRequest) (response *SendSmsResponse, err er
return
}
func (c *Client) Test(req *DemoTestRequest) (response *DemoTestResponse, err error) {
response = CreateDemoTestResponse()
err = c.DoAction(req, response)
return
}
func NewClientWithAccessKey(accesskey, secrect, source string) (client *Client, err error) {
client = &Client{}
err = client.InitWithAccessKey(accesskey, secrect, source)

View File

@ -7,15 +7,14 @@ import (
type SendSmsRequest struct {
*requests.RpcRequest
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" `
User string `position:"Query" field:"user" default:"" `
Code string `position:"Query" field:"code" default:"" `
Params string `position:"Query" field:"params" default:"" `
}
type SendSmsResponseData struct {
Account string `json:"account"`
Total int `json:"total"`
Account string `json:"account"`
Createtime int64 `json:"createtime"`
}
type SendSmsResponse struct {

View File

@ -1,36 +0,0 @@
package jedi
import (
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
)
type DemoTestRequest struct {
*requests.RpcRequest
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" `
}
func CreateDemoTestRequest() (req *DemoTestRequest) {
req = &DemoTestRequest{RpcRequest: &requests.RpcRequest{}}
req.InitWithApiInfo(HOST, VERSION, "/api/sms/Index")
req.Method = requests.GET
return
}
type DemoTestResponse struct {
*responses.BaseResponse
Data DemoTestResponseData `json:"data"`
}
type DemoTestResponseData struct {
Account string `json:"account"`
Total int `json:"total"`
}
func CreateDemoTestResponse() *DemoTestResponse {
return &DemoTestResponse{
BaseResponse: &responses.BaseResponse{},
}
}