env_minio.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. import "os"
  19. // A EnvMinio retrieves credentials from the environment variables of the
  20. // running process. EnvMinioironment credentials never expire.
  21. //
  22. // EnvMinioironment variables used:
  23. //
  24. // * Access Key ID: MINIO_ACCESS_KEY.
  25. // * Secret Access Key: MINIO_SECRET_KEY.
  26. type EnvMinio struct {
  27. retrieved bool
  28. }
  29. // NewEnvMinio returns a pointer to a new Credentials object
  30. // wrapping the environment variable provider.
  31. func NewEnvMinio() *Credentials {
  32. return New(&EnvMinio{})
  33. }
  34. // Retrieve retrieves the keys from the environment.
  35. func (e *EnvMinio) Retrieve() (Value, error) {
  36. e.retrieved = false
  37. id := os.Getenv("MINIO_ACCESS_KEY")
  38. secret := os.Getenv("MINIO_SECRET_KEY")
  39. signerType := SignatureV4
  40. if id == "" || secret == "" {
  41. signerType = SignatureAnonymous
  42. }
  43. e.retrieved = true
  44. return Value{
  45. AccessKeyID: id,
  46. SecretAccessKey: secret,
  47. SignerType: signerType,
  48. }, nil
  49. }
  50. // IsExpired returns if the credentials have been retrieved.
  51. func (e *EnvMinio) IsExpired() bool {
  52. return !e.retrieved
  53. }