7
0

Compare commits

...

2 Commits

Author SHA1 Message Date
liangzy
b688b909e8 init project 2020-08-04 12:23:34 +08:00
liangzy
cd5642dbb7 init project 2020-08-04 11:22:37 +08:00
8 changed files with 164 additions and 16 deletions

View File

@ -7,7 +7,26 @@ import (
"strings"
)
func buildRpcStringToSign(request requests.AcsRequest) (stringToSign string) {
func signHttpRequest(request requests.AcsRequest, signer Signer) (err error) {
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)
for key, value := range request.GetQueryParams() {
signParams[key] = value
@ -24,5 +43,3 @@ func buildRpcStringToSign(request requests.AcsRequest) (stringToSign string) {
stringToSign = request.GetMethod() + "&%2F&" + stringToSign
return
}

View File

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

View File

@ -4,6 +4,7 @@ import (
"context"
"fmt"
"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/responses"
"net"
@ -28,7 +29,20 @@ type Client struct {
config *Config
}
func (client *Client) InitWithOptions(host string, config *Config, creditial auth.Credential) (err error) {
func (client *Client) InitClientConfig() (config *Config) {
}
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{}
if config.Transport != nil {
@ -41,7 +55,6 @@ func (client *Client) InitWithOptions(host string, config *Config, creditial aut
client.httpClient.Timeout = config.Timeout
}
client.signer, err = auth.NewSignerWithCredential(credential, client.ProcessCommonRequestWithSigner)
return nil
@ -55,7 +68,6 @@ func (client *Client) InitWithConfig() (config *Config) {
}
}
func (client *Client) ProcessCommonRequestWithSigner(request *requests.CommonRequest, signerInterface interface{}) (response *responses.CommonResponse, err error) {
if signer, isSigner := signerInterface.(auth.Signer); isSigner {
response = responses.NewCommonResponse()
@ -114,5 +126,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) {
return nil
}

View File

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

View File

@ -2,10 +2,23 @@ package jedi
import "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk"
const (
PRODUCT = "jedi"
VERSION = "2020-08-04"
)
type Client struct {
sdk.Client
}
func NewClientWithAccessKey(accesskey, secrect string) *Client {
return nil
func (c *Client) SendSms(req *SendSmsRequest) (response *SendSmsResponse, err error) {
response = CreateSendSmsResponse()
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 +1,33 @@
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
}