doc.go 2.3 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 provides credential retrieval and management
  18. // for S3 compatible object storage.
  19. //
  20. // By default the Credentials.Get() will cache the successful result of a
  21. // Provider's Retrieve() until Provider.IsExpired() returns true. At which
  22. // point Credentials will call Provider's Retrieve() to get new credential Value.
  23. //
  24. // The Provider is responsible for determining when credentials have expired.
  25. // It is also important to note that Credentials will always call Retrieve the
  26. // first time Credentials.Get() is called.
  27. //
  28. // Example of using the environment variable credentials.
  29. //
  30. // creds := NewFromEnv()
  31. // // Retrieve the credentials value
  32. // credValue, err := creds.Get()
  33. // if err != nil {
  34. // // handle error
  35. // }
  36. //
  37. // Example of forcing credentials to expire and be refreshed on the next Get().
  38. // This may be helpful to proactively expire credentials and refresh them sooner
  39. // than they would naturally expire on their own.
  40. //
  41. // creds := NewFromIAM("")
  42. // creds.Expire()
  43. // credsValue, err := creds.Get()
  44. // // New credentials will be retrieved instead of from cache.
  45. //
  46. //
  47. // Custom Provider
  48. //
  49. // Each Provider built into this package also provides a helper method to generate
  50. // a Credentials pointer setup with the provider. To use a custom Provider just
  51. // create a type which satisfies the Provider interface and pass it to the
  52. // NewCredentials method.
  53. //
  54. // type MyProvider struct{}
  55. // func (m *MyProvider) Retrieve() (Value, error) {...}
  56. // func (m *MyProvider) IsExpired() bool {...}
  57. //
  58. // creds := NewCredentials(&MyProvider{})
  59. // credValue, err := creds.Get()
  60. //
  61. package credentials