7
0

Compare commits

..

No commits in common. "b688b909e879c8ab89403ef0adfb5367897f0b94" and "a7992dd1312f02e673a6c6ed2a942109195a8b26" have entirely different histories.

8 changed files with 16 additions and 164 deletions

View File

@ -7,26 +7,7 @@ import (
"strings" "strings"
) )
func signHttpRequest(request requests.AcsRequest, signer Signer) (err error) { func buildRpcStringToSign(request requests.AcsRequest) (stringToSign string) {
err = completeHttpSignParams(request, signer)
if err != nil {
return
}
if _, isContainsSign := request.GetQueryParams()["Sign"]; isContainsSign {
delete(request.GetQueryParams(), "Sign")
}
stringToSign := buildHttpStringToSign(request)
request.SetStringToSign(stringToSign)
signature := signer.Sign(stringToSign, "&")
request.GetQueryParams()["Sign"] = signature
return
}
func completeHttpSignParams(requests requests.AcsRequest, signer Signer) (err error) {
return
}
func buildHttpStringToSign(request requests.AcsRequest) (stringToSign string) {
signParams := make(map[string]string) signParams := make(map[string]string)
for key, value := range request.GetQueryParams() { for key, value := range request.GetQueryParams() {
signParams[key] = value signParams[key] = value
@ -43,3 +24,5 @@ func buildHttpStringToSign(request requests.AcsRequest) (stringToSign string) {
stringToSign = request.GetMethod() + "&%2F&" + stringToSign stringToSign = request.GetMethod() + "&%2F&" + stringToSign
return return
} }

View File

@ -13,6 +13,7 @@ type Signer interface {
Sign(stringToSign, secretSuffix string) string Sign(stringToSign, secretSuffix string) string
} }
func NewSignerWithCredential(credential Credential, commonApi func(request *requests.CommonRequest, signer interface{}) (response *responses.CommonResponse, err error)) (signer Signer, err error) { func NewSignerWithCredential(credential Credential, commonApi func(request *requests.CommonRequest, signer interface{}) (response *responses.CommonResponse, err error)) (signer Signer, err error) {
switch instance := credential.(type) { switch instance := credential.(type) {
case *credentials.AccessKeyCredential: case *credentials.AccessKeyCredential:
@ -23,8 +24,9 @@ func NewSignerWithCredential(credential Credential, commonApi func(request *requ
return return
} }
func Sign(request requests.AcsRequest, signer Signer) (err error) {
//TODO 根据rpc和roa两种风格签名自行选择
err = signHttpRequest(request, signer) func Sign(request requests.AcsRequest, signer Signer, regionId string) (err error) {
return
} }

View File

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth" "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/credentials"
"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" "net"
@ -29,20 +28,7 @@ type Client struct {
config *Config config *Config
} }
func (client *Client) InitClientConfig() (config *Config) { func (client *Client) InitWithOptions(host string, config *Config, creditial auth.Credential) (err error) {
}
func (client *Client) InitWithAccessKey(accessKeyId, accessKeySecret, source string) (err error) {
config := client.InitWithConfig()
credential := &credentials.BaseCredential{
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
}
return client.InitWithOptions("", config, credential)
}
func (client *Client) InitWithOptions(host string, config *Config, credential auth.Credential) (err error) {
client.httpClient = &http.Client{} client.httpClient = &http.Client{}
if config.Transport != nil { if config.Transport != nil {
@ -55,6 +41,7 @@ func (client *Client) InitWithOptions(host string, config *Config, credential au
client.httpClient.Timeout = config.Timeout client.httpClient.Timeout = config.Timeout
} }
client.signer, err = auth.NewSignerWithCredential(credential, client.ProcessCommonRequestWithSigner) client.signer, err = auth.NewSignerWithCredential(credential, client.ProcessCommonRequestWithSigner)
return nil return nil
@ -68,6 +55,7 @@ func (client *Client) InitWithConfig() (config *Config) {
} }
} }
func (client *Client) ProcessCommonRequestWithSigner(request *requests.CommonRequest, signerInterface interface{}) (response *responses.CommonResponse, err error) { func (client *Client) ProcessCommonRequestWithSigner(request *requests.CommonRequest, signerInterface interface{}) (response *responses.CommonResponse, err error) {
if signer, isSigner := signerInterface.(auth.Signer); isSigner { if signer, isSigner := signerInterface.(auth.Signer); isSigner {
response = responses.NewCommonResponse() response = responses.NewCommonResponse()
@ -126,5 +114,5 @@ func (client *Client) DoAction(request requests.AcsRequest, response responses.A
} }
func (client *Client) DoActionWithSigner(request requests.AcsRequest, response responses.AcsResponse, signer auth.Signer) (err error) { func (client *Client) DoActionWithSigner(request requests.AcsRequest, response responses.AcsResponse, signer auth.Signer) (err error) {
return nil
} }

View File

@ -2,21 +2,4 @@ package requests
type CommonRequest struct { type CommonRequest struct {
*baseRequest *baseRequest
Product string
Ontology AcsRequest
}
func (request *CommonRequest) TransToAscRequest() {
httpReqeust := &HttpRequest{}
httpReqeust.baseRequest = request.baseRequest
httpReqeust.product = request.Product
request.Ontology = httpReqeust
}
func (request *CommonRequest) BuildUrl() string {
return request.Ontology.BuildUrl()
}
func (request *CommonRequest) BuildQueries() string {
return request.Ontology.BuildQueries()
} }

View File

@ -3,27 +3,3 @@ package requests
type HttpRequest struct { type HttpRequest struct {
*baseRequest *baseRequest
} }
func (request *HttpRequest) init() {
request.baseRequest = defaultBaseRequest()
request.Method = POST
}
func (request *HttpRequest) BuildUrl() string {
return ""
}
func (request *HttpRequest) BuildQueries() string {
return ""
}
func (request *HttpRequest) GetActionName() string {
return request.actionName
}
func (request *HttpRequest) InitWithApiInfo(product, version, action string) {
request.init()
request.product = product
request.version = version
request.actionName = action
}

View File

@ -44,15 +44,6 @@ type AcsRequest interface {
GetQueryParams() map[string]string GetQueryParams() map[string]string
GetFormParams() map[string]string GetFormParams() map[string]string
GetMethod() string GetMethod() string
GetScheme() string
GetDomain() string
GetActionName() string
BuildUrl() string
BuildQueries() string
SetScheme(scheme string)
SetDomain(host string)
SetStringToSign(stringToSign string) SetStringToSign(stringToSign string)
} }
@ -60,7 +51,6 @@ type baseRequest struct {
Scheme string Scheme string
Method string Method string
Host string Host string
Port string
Domain string Domain string
From string From string
ReadTimeout time.Duration ReadTimeout time.Duration
@ -68,7 +58,6 @@ type baseRequest struct {
isInsecure *bool isInsecure *bool
AcceptFormat string AcceptFormat string
actionName string
userAgent map[string]string userAgent map[string]string
product string product string
@ -83,26 +72,6 @@ type baseRequest struct {
stringToSign string stringToSign string
} }
func (request *baseRequest) GetActionName() string {
return request.actionName
}
func (request *baseRequest) SetScheme(scheme string) {
request.Scheme = scheme
}
func (request *baseRequest) SetDomain(host string) {
request.Domain = host
}
func (request *baseRequest) GetScheme() string {
return request.Scheme
}
func (request *baseRequest) GetDomain() string {
return request.Domain
}
func (request *baseRequest) GetMethod() string { func (request *baseRequest) GetMethod() string {
return request.Method return request.Method
} }
@ -158,7 +127,3 @@ func defaultBaseRequest() (request *baseRequest) {
} }
return return
} }
func InitParam(request AcsRequest) (err error) {
return nil
}

View File

@ -2,23 +2,10 @@ package jedi
import "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk" import "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
const (
PRODUCT = "jedi"
VERSION = "2020-08-04"
)
type Client struct { type Client struct {
sdk.Client sdk.Client
} }
func (c *Client) SendSms(req *SendSmsRequest) (response *SendSmsResponse, err error) { func NewClientWithAccessKey(accesskey, secrect string) *Client {
response = CreateSendSmsResponse() return nil
err = c.DoAction(req, response)
return
}
func NewClientWithAccessKey(accesskey, secrect, source string) (client *Client, err error) {
client = &Client{}
err = client.InitWithOptions("", nil, "")
return
} }

View File

@ -1,33 +1 @@
package jedi package jedi
import (
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests"
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses"
)
type SendSmsRequest struct {
*requests.HttpRequest
User string `position:"Query" name:"User" default:""`
Code string `position:"Query" name:"Code" default:"-"`
Prams string `position:"Query" name:"Prams" default:"-"`
}
type SendSmsResponse struct {
*responses.BaseResponse
BizId string `json:"BizId"`
}
func CreateSendSmsRequest() (req *SendSmsRequest) {
req = &SendSmsRequest{
HttpRequest: &requests.HttpRequest{},
}
req.InitWithApiInfo(PRODUCT, VERSION, "/api/sms/send")
return
}
func CreateSendSmsResponse() (response *SendSmsResponse) {
response = &SendSmsResponse{
BaseResponse: &responses.BaseResponse{},
}
return
}