42 lines
1.3 KiB
Go
42 lines
1.3 KiB
Go
package auth
|
||
|
||
import (
|
||
"errors"
|
||
"golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/auth/credentials"
|
||
"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 {
|
||
GetName() string
|
||
GetAccessKeyId() (string, error)
|
||
GetAccessKeyFrom() (string, error)
|
||
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:
|
||
signer = signers.NewAccessKeySigner(instance)
|
||
case *credentials.BaseCredential:
|
||
signer = signers.NewAccessKeySigner(instance.ToAccessKeyCredential())
|
||
default:
|
||
err = errors.New("UnsupportedCredentialErrorCode = SDK.UnsupportedCredential")
|
||
}
|
||
return
|
||
}
|
||
|
||
func Sign(request requests.AcsRequest, signer Signer) (err error) {
|
||
//TODO 根据rpc和roa两种风格签名,自行选择
|
||
err = signRpcRequest(request, signer)
|
||
return
|
||
}
|
||
|
||
func UnSign(request *http.Request, signer Signer) (err error) {
|
||
//TODO 根据rpc和roa两种风格签名,自行选择
|
||
err = unsignRpcRequest(request, signer)
|
||
return
|
||
}
|