signer_sts_token.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Licensed under the Apache License, Version 2.0 (the "License");
  3. * you may not use this file except in compliance with the License.
  4. * You may obtain a copy of the License at
  5. *
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. */
  14. package signers
  15. import (
  16. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  17. )
  18. type StsTokenSigner struct {
  19. credential *credentials.StsTokenCredential
  20. }
  21. func NewStsTokenSigner(credential *credentials.StsTokenCredential) *StsTokenSigner {
  22. return &StsTokenSigner{
  23. credential: credential,
  24. }
  25. }
  26. func (*StsTokenSigner) GetName() string {
  27. return "HMAC-SHA1"
  28. }
  29. func (*StsTokenSigner) GetType() string {
  30. return ""
  31. }
  32. func (*StsTokenSigner) GetVersion() string {
  33. return "1.0"
  34. }
  35. func (signer *StsTokenSigner) GetAccessKeyId() (accessKeyId string, err error) {
  36. return signer.credential.AccessKeyId, nil
  37. }
  38. func (signer *StsTokenSigner) GetExtraParam() map[string]string {
  39. return map[string]string{"SecurityToken": signer.credential.AccessKeyStsToken}
  40. }
  41. func (signer *StsTokenSigner) Sign(stringToSign, secretSuffix string) string {
  42. secret := signer.credential.AccessKeySecret + secretSuffix
  43. return ShaHmac1(stringToSign, secret)
  44. }