signer_ecs_instance.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 SignerEcsInstance struct {
  19. credential *credentials.EcsInstanceCredential
  20. }
  21. func NewSignerEcsInstance(credential *credentials.EcsInstanceCredential) *SignerEcsInstance {
  22. return &SignerEcsInstance{
  23. credential: credential,
  24. }
  25. }
  26. func (*SignerEcsInstance) GetName() string {
  27. return "HMAC-SHA1"
  28. }
  29. func (*SignerEcsInstance) GetType() string {
  30. return ""
  31. }
  32. func (*SignerEcsInstance) GetVersion() string {
  33. return "1.0"
  34. }
  35. func (signer *SignerEcsInstance) GetAccessKeyId() string {
  36. return signer.credential.RoleName
  37. }
  38. func (signer *SignerEcsInstance) GetExtraParam() map[string]string {
  39. return map[string]string{"SecurityToken": signer.credential.RoleName}
  40. }
  41. func (signer *SignerEcsInstance) Sign(stringToSign, secretSuffix string) string {
  42. secret := signer.credential.RoleName + secretSuffix
  43. return ShaHmac1(stringToSign, secret)
  44. }
  45. func (signer *SignerEcsInstance) Shutdown() {
  46. }