Documentation ¶
Index ¶
Constants ¶
const ( // EnvCredentialsProviderName provides a name of Env provider. EnvCredentialsProviderName = "EnvCredentialsProvider" // EnvCredentialsVarToken specifies the name of the environment variable // points to the Spotinst Token. EnvCredentialsVarToken = "SPOTINST_TOKEN" // EnvCredentialsVarAccount specifies the name of the environment variable // points to the Spotinst account ID. EnvCredentialsVarAccount = "SPOTINST_ACCOUNT" )
const ( // FileCredentialsProviderName provides a name of File provider. FileCredentialsProviderName = "FileCredentialsProvider" // FileCredentialsEnvVarFile specifies the name of the environment variable // points to the location of the credentials file. FileCredentialsEnvVarFile = "SPOTINST_CREDENTIALS_FILE" // FileCredentialsEnvVarProfile specifies the name of the environment variable // points to a profile name to use when loading credentials. FileCredentialsEnvVarProfile = "SPOTINST_CREDENTIALS_PROFILE" )
const StaticCredentialsProviderName = "StaticCredentialsProvider"
StaticCredentialsProviderName provides a name of Static provider.
Variables ¶
var ( // ErrFileCredentialsLoadFailed is emitted when the provider is unable to load // credentials from the credentials file. ErrFileCredentialsLoadFailed = errors.New("spotinst: failed to load credentials file") // ErrFileCredentialsTokenNotFound is emitted when the loaded credentials // do not contain a valid token. ErrFileCredentialsTokenNotFound = errors.New("spotinst: credentials do not contain token") )
var ErrEnvCredentialsTokenNotFound = fmt.Errorf("spotinst: %s not found in environment", EnvCredentialsVarToken)
ErrEnvCredentialsTokenNotFound is returned when the Spotinst Token can't be found in the process's environment.
var ErrNoValidProvidersFoundInChain = errors.New("spotinst: no valid credentials providers in chain")
ErrNoValidProvidersFoundInChain Is returned when there are no valid credentials providers in the ChainProvider.
var ErrStaticCredentialsEmpty = errors.New("spotinst: static credentials are empty")
ErrStaticCredentialsEmpty is emitted when static credentials are empty.
Functions ¶
func DefaultFilename ¶
func DefaultFilename() string
DefaultFilename returns the SDK's default file path for the credentials file.
Builds the config file path based on the OS's platform.
- Linux/Unix : $HOME/.spotinst/credentials
- Windows : %USERPROFILE%\.spotinst\credentials
func DefaultProfile ¶
func DefaultProfile() string
DefaultProfile returns the SDK's default profile name to use when loading credentials.
Types ¶
type ChainProvider ¶
type ChainProvider struct { Providers []Provider // contains filtered or unexported fields }
A ChainProvider will search for a provider which returns credentials and cache that provider until Retrieve is called again.
The ChainProvider provides a way of chaining multiple providers together which will pick the first available using priority order of the Providers in the list.
If none of the Providers retrieve valid credentials Value, ChainProvider's Retrieve() will return the error ErrNoValidProvidersFoundInChain.
If a Provider is found which returns valid credentials Value ChainProvider will cache that Provider for all calls until Retrieve is called again.
Example of ChainProvider to be used with an EnvCredentialsProvider and FileCredentialsProvider. In this example EnvProvider will first check if any credentials are available via the environment variables. If there are none ChainProvider will check the next Provider in the list, FileProvider in this case. If FileCredentialsProvider does not return any credentials ChainProvider will return the error ErrNoValidProvidersFoundInChain.
creds := credentials.NewChainCredentials( new(credentials.EnvProvider), new(credentials.FileProvider), )
func (*ChainProvider) Retrieve ¶
func (c *ChainProvider) Retrieve() (Value, error)
Retrieve returns the credentials value or error if no provider returned without error. If a provider is found it will be cached.
func (*ChainProvider) String ¶
func (c *ChainProvider) String() string
type Credentials ¶
type Credentials struct {
// contains filtered or unexported fields
}
A Credentials provides synchronous safe retrieval of Spotinst credentials. Credentials will cache the credentials value.
Credentials is safe to use across multiple goroutines and will manage the synchronous state so the Providers do not need to implement their own synchronization.
The first Credentials.Get() will always call Provider.Retrieve() to get the first instance of the credentials Value. All calls to Get() after that will return the cached credentials Value.
func NewChainCredentials ¶
func NewChainCredentials(providers ...Provider) *Credentials
NewChainCredentials returns a pointer to a new Credentials object wrapping a chain of providers.
func NewCredentials ¶
func NewCredentials(provider Provider) *Credentials
NewCredentials returns a pointer to a new Credentials with the provider set.
func NewEnvCredentials ¶
func NewEnvCredentials() *Credentials
NewEnvCredentials returns a pointer to a new Credentials object wrapping the environment variable provider.
func NewFileCredentials ¶
func NewFileCredentials(profile, filename string) *Credentials
NewFileCredentials returns a pointer to a new Credentials object wrapping the file provider.
func NewStaticCredentials ¶
func NewStaticCredentials(token, account string) *Credentials
NewStaticCredentials returns a pointer to a new Credentials object wrapping a static credentials value provider.
func (*Credentials) Get ¶
func (c *Credentials) Get() (Value, error)
Get returns the credentials value, or error if the credentials Value failed to be retrieved.
Will return the cached credentials Value. If the credentials Value is empty the Provider's Retrieve() will be called to refresh the credentials.
func (*Credentials) Refresh ¶
func (c *Credentials) Refresh()
Refresh refreshes the credentials and forces them to be retrieved on the next call to Get().
type EnvProvider ¶
type EnvProvider struct{}
A EnvProvider retrieves credentials from the environment variables of the running process.
Environment variables used: * Token : SPOTINST_TOKEN * Account : SPOTINST_ACCOUNT
func (*EnvProvider) Retrieve ¶
func (e *EnvProvider) Retrieve() (Value, error)
Retrieve retrieves the keys from the environment.
func (*EnvProvider) String ¶
func (e *EnvProvider) String() string
type FileProvider ¶
type FileProvider struct { // Profile to load. Profile string // Path to the credentials file. // // If empty will look for FileCredentialsEnvVarFile env variable. If the // env value is empty will default to current user's home directory. // - Linux/Unix : $HOME/.spotinst/credentials // - Windows : %USERPROFILE%\.spotinst\credentials Filename string // contains filtered or unexported fields }
A FileProvider retrieves credentials from the current user's home directory.
func (*FileProvider) Retrieve ¶
func (p *FileProvider) Retrieve() (Value, error)
Retrieve reads and extracts the shared credentials from the current users home directory.
func (*FileProvider) String ¶
func (p *FileProvider) String() string
type Provider ¶
type Provider interface { fmt.Stringer // Refresh returns nil if it successfully retrieved the value. Error is // returned if the value were not obtainable, or empty. Retrieve() (Value, error) }
A Provider is the interface for any component which will provide credentials Value.
The Provider should not need to implement its own mutexes, because that will be managed by Credentials.
type StaticProvider ¶
type StaticProvider struct {
Value
}
A StaticProvider is a set of credentials which are set programmatically.
func (*StaticProvider) Retrieve ¶
func (s *StaticProvider) Retrieve() (Value, error)
Retrieve returns the credentials or error if the credentials are invalid.
func (*StaticProvider) String ¶
func (s *StaticProvider) String() string