assumeroler.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright © The ESO Authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. // Package fake implements mocks for AWS auth service clients.
  14. package fake
  15. import (
  16. "context"
  17. "github.com/aws/aws-sdk-go-v2/aws"
  18. "github.com/aws/aws-sdk-go-v2/service/sts"
  19. )
  20. type stsAPI interface {
  21. AssumeRole(ctx context.Context, params *sts.AssumeRoleInput, optFns ...func(*sts.Options)) (*sts.AssumeRoleOutput, error)
  22. AssumeRoleWithSAML(ctx context.Context, params *sts.AssumeRoleWithSAMLInput, optFns ...func(*sts.Options)) (*sts.AssumeRoleWithSAMLOutput, error)
  23. AssumeRoleWithWebIdentity(ctx context.Context, params *sts.AssumeRoleWithWebIdentityInput, optFns ...func(*sts.Options)) (*sts.AssumeRoleWithWebIdentityOutput, error)
  24. AssumeRoot(ctx context.Context, params *sts.AssumeRootInput, optFns ...func(*sts.Options)) (*sts.AssumeRootOutput, error)
  25. DecodeAuthorizationMessage(ctx context.Context, params *sts.DecodeAuthorizationMessageInput, optFns ...func(*sts.Options)) (*sts.DecodeAuthorizationMessageOutput, error)
  26. }
  27. // AssumeRoler is a mock implementation of the AWS STS AssumeRole API.
  28. type AssumeRoler struct {
  29. stsAPI
  30. AssumeRoleFunc func(input *sts.AssumeRoleInput) (*sts.AssumeRoleOutput, error)
  31. }
  32. // AssumeRole mocks the AWS STS AssumeRole API.
  33. func (f *AssumeRoler) AssumeRole(_ context.Context, params *sts.AssumeRoleInput, _ ...func(*sts.Options)) (*sts.AssumeRoleOutput, error) {
  34. return f.AssumeRoleFunc(params)
  35. }
  36. // CredentialsProvider is a mock implementation of the AWS credentials provider.
  37. type CredentialsProvider struct {
  38. RetrieveFunc func() (aws.Credentials, error)
  39. }
  40. // Retrieve mocks the AWS credentials provider Retrieve method.
  41. func (t CredentialsProvider) Retrieve(_ context.Context) (aws.Credentials, error) {
  42. return t.RetrieveFunc()
  43. }