static.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * MinIO Go Library for Amazon S3 Compatible Cloud Storage
  3. * Copyright 2017 MinIO, Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package credentials
  18. // A Static is a set of credentials which are set programmatically,
  19. // and will never expire.
  20. type Static struct {
  21. Value
  22. }
  23. // NewStaticV2 returns a pointer to a new Credentials object
  24. // wrapping a static credentials value provider, signature is
  25. // set to v2. If access and secret are not specified then
  26. // regardless of signature type set it Value will return
  27. // as anonymous.
  28. func NewStaticV2(id, secret, token string) *Credentials {
  29. return NewStatic(id, secret, token, SignatureV2)
  30. }
  31. // NewStaticV4 is similar to NewStaticV2 with similar considerations.
  32. func NewStaticV4(id, secret, token string) *Credentials {
  33. return NewStatic(id, secret, token, SignatureV4)
  34. }
  35. // NewStatic returns a pointer to a new Credentials object
  36. // wrapping a static credentials value provider.
  37. func NewStatic(id, secret, token string, signerType SignatureType) *Credentials {
  38. return New(&Static{
  39. Value: Value{
  40. AccessKeyID: id,
  41. SecretAccessKey: secret,
  42. SessionToken: token,
  43. SignerType: signerType,
  44. },
  45. })
  46. }
  47. // Retrieve returns the static credentials.
  48. func (s *Static) Retrieve() (Value, error) {
  49. if s.AccessKeyID == "" || s.SecretAccessKey == "" {
  50. // Anonymous is not an error
  51. return Value{SignerType: SignatureAnonymous}, nil
  52. }
  53. return s.Value, nil
  54. }
  55. // IsExpired returns if the credentials are expired.
  56. //
  57. // For Static, the credentials never expired.
  58. func (s *Static) IsExpired() bool {
  59. return false
  60. }