Compare commits
No commits in common. "9c2898517e663c9aec63e68ee65d989d770f0aef" and "0feabe2c1f9e8e1aec87595e6452109adec7f364" have entirely different histories.
9c2898517e
...
0feabe2c1f
@ -2,13 +2,10 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils"
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils"
|
||||||
"net/http"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -57,11 +54,8 @@ func buildRpcStringToSign(request requests.AcsRequest) (stringToSign string) {
|
|||||||
for key, value := range request.GetQueryParams() {
|
for key, value := range request.GetQueryParams() {
|
||||||
signParams[key] = value
|
signParams[key] = value
|
||||||
}
|
}
|
||||||
|
for key, value := range request.GetFormParams() {
|
||||||
if strings.ToUpper(request.GetMethod()) == requests.POST {
|
signParams[key] = value
|
||||||
for key, value := range request.GetFormParams() {
|
|
||||||
signParams[key] = value
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stringToSign = utils.GetUrlFormedMap(signParams)
|
stringToSign = utils.GetUrlFormedMap(signParams)
|
||||||
@ -72,41 +66,3 @@ func buildRpcStringToSign(request requests.AcsRequest) (stringToSign string) {
|
|||||||
stringToSign = request.GetMethod() + "&%2F&" + stringToSign
|
stringToSign = request.GetMethod() + "&%2F&" + stringToSign
|
||||||
return
|
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
|
|
||||||
}
|
|
||||||
|
@ -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/auth/signers"
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Signer interface {
|
type Signer interface {
|
||||||
@ -33,9 +32,3 @@ func Sign(request requests.AcsRequest, signer Signer) (err error) {
|
|||||||
err = signRpcRequest(request, signer)
|
err = signRpcRequest(request, signer)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnSign(request *http.Request, signer Signer) (err error) {
|
|
||||||
//TODO 根据rpc和roa两种风格签名,自行选择
|
|
||||||
err = unsignRpcRequest(request, signer)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
@ -25,12 +25,6 @@ var defaultReadTimeout = 10 * time.Second
|
|||||||
var defaultDomain = ".gaore.com"
|
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 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 {
|
type Client struct {
|
||||||
Host string
|
Host string
|
||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
@ -42,6 +36,7 @@ type Client struct {
|
|||||||
httpProxy string
|
httpProxy string
|
||||||
httpsProxy string
|
httpsProxy string
|
||||||
noProxy string
|
noProxy string
|
||||||
|
debug utils.Debug
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) GetNoProxy() string {
|
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) {
|
func (client *Client) InitWithOptions(config *Config, credential auth.Credential) (err error) {
|
||||||
client.httpClient = &http.Client{}
|
client.httpClient = &http.Client{}
|
||||||
client.config = config
|
client.config = config
|
||||||
|
client.debug = utils.Init("sdk", true)
|
||||||
|
|
||||||
if config.Transport != nil {
|
if config.Transport != nil {
|
||||||
client.httpClient.Transport = config.Transport
|
client.httpClient.Transport = config.Transport
|
||||||
@ -285,8 +281,7 @@ func (client *Client) buildRequestWithSigner(request requests.AcsRequest, signer
|
|||||||
userAgent := DefaultUserAgent
|
userAgent := DefaultUserAgent
|
||||||
httpRequest.Header.Set("User-Agent", userAgent)
|
httpRequest.Header.Set("User-Agent", userAgent)
|
||||||
|
|
||||||
debug("%s", request.GetStringToSign())
|
client.debug("%s", request.GetStringToSign())
|
||||||
debug("%s", httpRequest.Method)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package requests
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/utils"
|
|
||||||
"io"
|
"io"
|
||||||
"math/cmplx"
|
"math/cmplx"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -44,12 +43,6 @@ const (
|
|||||||
HeaderSeparator = "\n"
|
HeaderSeparator = "\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
var debug utils.Debug
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
debug = utils.Init("request")
|
|
||||||
}
|
|
||||||
|
|
||||||
type AcsRequest interface {
|
type AcsRequest interface {
|
||||||
GetReadTimeout() time.Duration
|
GetReadTimeout() time.Duration
|
||||||
GetConnectTimeout() time.Duration
|
GetConnectTimeout() time.Duration
|
||||||
@ -229,7 +222,6 @@ func flatRepeatedList(reflectValue reflect.Value, request AcsRequest, position s
|
|||||||
}
|
}
|
||||||
|
|
||||||
fieldDefault, _ := field.Tag.Lookup("default")
|
fieldDefault, _ := field.Tag.Lookup("default")
|
||||||
debug("%s %s %s", name, fieldPosition, fieldDefault)
|
|
||||||
if isContiansNameTag {
|
if isContiansNameTag {
|
||||||
var value string
|
var value string
|
||||||
switch field.Type.Kind() {
|
switch field.Type.Kind() {
|
||||||
@ -251,10 +243,6 @@ func flatRepeatedList(reflectValue reflect.Value, request AcsRequest, position s
|
|||||||
value = fieldDefault
|
value = fieldDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
if value == "0" && fieldDefault != "" && fieldDefault != "0" {
|
|
||||||
value = fieldDefault
|
|
||||||
}
|
|
||||||
|
|
||||||
err = addParam(request, fieldPosition, name, value)
|
err = addParam(request, fieldPosition, name, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Debug func(format string, v ...interface{})
|
type Debug func(format string, v ...interface{})
|
||||||
|
|
||||||
@ -12,21 +8,7 @@ var hookPrint = func(input string) {
|
|||||||
fmt.Println(input)
|
fmt.Println(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
var hookGetEnv = func() string {
|
func Init(flag string, enable bool) Debug {
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return func(format string, v ...interface{}) {
|
return func(format string, v ...interface{}) {
|
||||||
if enable {
|
if enable {
|
||||||
|
@ -3,7 +3,7 @@ package jedi
|
|||||||
import "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
|
import "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HOST = "jedi"
|
HOST = "jedi.gaore.com"
|
||||||
VERSION = "2020-08-04"
|
VERSION = "2020-08-04"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -17,12 +17,6 @@ func (c *Client) SendSms(req *SendSmsRequest) (response *SendSmsResponse, err er
|
|||||||
return
|
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) {
|
func NewClientWithAccessKey(accesskey, secrect, source string) (client *Client, err error) {
|
||||||
client = &Client{}
|
client = &Client{}
|
||||||
err = client.InitWithAccessKey(accesskey, secrect, source)
|
err = client.InitWithAccessKey(accesskey, secrect, source)
|
||||||
|
@ -7,15 +7,14 @@ import (
|
|||||||
|
|
||||||
type SendSmsRequest struct {
|
type SendSmsRequest struct {
|
||||||
*requests.RpcRequest
|
*requests.RpcRequest
|
||||||
User string `position:"Query" field:"user" default:"" `
|
User string `position:"Query" field:"user" default:"" `
|
||||||
Code string `position:"Query" field:"code" default:"" `
|
Code string `position:"Query" field:"code" default:"" `
|
||||||
Params string `position:"Query" field:"params" default:"" `
|
Params string `position:"Query" field:"params" default:"" `
|
||||||
TestBody string `position:"Body" field:"test_body" default:"2121" `
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendSmsResponseData struct {
|
type SendSmsResponseData struct {
|
||||||
Account string `json:"account"`
|
Account string `json:"account"`
|
||||||
Total int `json:"total"`
|
Createtime int64 `json:"createtime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendSmsResponse struct {
|
type SendSmsResponse struct {
|
||||||
|
@ -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{},
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user