static_provider.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package credentials
  2. import (
  3. "github.com/ks3sdklib/aws-sdk-go/internal/apierr"
  4. )
  5. var (
  6. // ErrStaticCredentialsEmpty is emitted when static credentials are empty.
  7. ErrStaticCredentialsEmpty = apierr.New("EmptyStaticCreds", "static credentials are empty", nil)
  8. )
  9. // A StaticProvider is a set of credentials which are set pragmatically,
  10. // and will never expire.
  11. type StaticProvider struct {
  12. Value
  13. }
  14. // NewStaticCredentials returns a pointer to a new Credentials object
  15. // wrapping a static credentials value provider.
  16. func NewStaticCredentials(id, secret, token string) *Credentials {
  17. return NewCredentials(&StaticProvider{Value: Value{
  18. AccessKeyID: id,
  19. SecretAccessKey: secret,
  20. SessionToken: token,
  21. }})
  22. }
  23. // Retrieve returns the credentials or error if the credentials are invalid.
  24. func (s *StaticProvider) Retrieve() (Value, error) {
  25. if s.AccessKeyID == "" || s.SecretAccessKey == "" {
  26. return Value{}, ErrStaticCredentialsEmpty
  27. }
  28. return s.Value, nil
  29. }
  30. // IsExpired returns if the credentials are expired.
  31. //
  32. // For StaticProvider, the credentials never expired.
  33. func (s *StaticProvider) IsExpired() bool {
  34. return false
  35. }