Documentation
¶
Index ¶
Constants ¶
const ( // EnvCredentialsProviderName specifies the name of the 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 specifies the name of the 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 specifies the name of the Static provider.
Variables ¶
var ( // ErrFileCredentialsLoadFailed is returned when the provider is unable to load // credentials from the credentials file. ErrFileCredentialsLoadFailed = errors.New("spotinst: failed to load credentials file") // ErrFileCredentialsNotFound is returned when the loaded credentials // are empty. ErrFileCredentialsNotFound = errors.New("spotinst: credentials file or profile is empty") )
var ErrEnvCredentialsNotFound = fmt.Errorf("spotinst: %s and %s not found "+ "in environment", EnvCredentialsVarToken, EnvCredentialsVarAccount)
ErrEnvCredentialsNotFound is returned when no credentials can 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 ErrNoValidTokenFound = errors.New("spotinst: no valid token found")
ErrNoValidTokenFound is returned when there is no valid token.
var ErrStaticCredentialsEmpty = errors.New("spotinst: static credentials are empty")
ErrStaticCredentialsEmpty is returned 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
}
A ChainProvider will search for a provider which returns credentials.
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.
func (*ChainProvider) String ¶
func (c *ChainProvider) String() string
String returns the string representation of the provider.
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
String returns the string representation of the provider.
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
String returns the string representation of the provider.
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
String returns the string representation of the provider.
type Value ¶
type Value struct { // Spotinst API token. Token string `ini:"token" json:"token"` // Spotinst account ID. Account string `ini:"account" json:"account"` // Provider used to get credentials. ProviderName string `ini:"-" json:"-"` }
A Value is the Spotinst credentials value for individual credential fields.
func (*Value) IsComplete ¶ added in v1.52.0
IsComplete if all fields of a Value are set.