init project
This commit is contained in:
parent
a7992dd131
commit
cd5642dbb7
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
}
|
@ -28,7 +28,7 @@ type Client struct {
|
||||
config *Config
|
||||
}
|
||||
|
||||
func (client *Client) InitWithOptions(host string, config *Config, creditial auth.Credential) (err error) {
|
||||
func (client *Client) InitWithOptions(host string, config *Config, credential auth.Credential) (err error) {
|
||||
client.httpClient = &http.Client{}
|
||||
|
||||
if config.Transport != nil {
|
||||
@ -41,7 +41,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 +54,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 +112,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
|
||||
|
||||
}
|
||||
|
@ -3,3 +3,11 @@ package requests
|
||||
type HttpRequest struct {
|
||||
*baseRequest
|
||||
}
|
||||
|
||||
func (request *HttpRequest) BuildUrl() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (request *HttpRequest) BuildQueries() string {
|
||||
return ""
|
||||
}
|
||||
|
@ -44,6 +44,14 @@ type AcsRequest interface {
|
||||
GetQueryParams() map[string]string
|
||||
GetFormParams() map[string]string
|
||||
GetMethod() string
|
||||
GetScheme() string
|
||||
GetDomain() string
|
||||
|
||||
BuildUrl() string
|
||||
BuildQueries() string
|
||||
|
||||
SetScheme(scheme string)
|
||||
SetDomain(host string)
|
||||
SetStringToSign(stringToSign string)
|
||||
}
|
||||
|
||||
@ -51,6 +59,7 @@ type baseRequest struct {
|
||||
Scheme string
|
||||
Method string
|
||||
Host string
|
||||
Port string
|
||||
Domain string
|
||||
From string
|
||||
ReadTimeout time.Duration
|
||||
@ -72,6 +81,22 @@ type baseRequest struct {
|
||||
stringToSign string
|
||||
}
|
||||
|
||||
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 +152,7 @@ func defaultBaseRequest() (request *baseRequest) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func InitParam(request AcsRequest) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user