credentials

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvCredentialsToken specifies the name of the environment variable points
	// to the Spot Token.
	EnvCredentialsToken = credentials.EnvCredentialsVarToken

	// EnvCredentialsAccount specifies the name of the environment variable points
	// to the Spot account ID.
	EnvCredentialsAccount = credentials.EnvCredentialsVarAccount
)

Variables

View Source
var ErrEnvCredentialsNotFound = fmt.Errorf("credentials: %s and %s not found "+
	"in environment", EnvCredentialsToken, EnvCredentialsAccount)

ErrEnvCredentialsNotFound is returned when no credentials can be found in the process's environment.

View Source
var ErrNoValidProvidersFoundInChain = errors.New("credentials: no valid " +
	"credentials providers in chain")

ErrNoValidProvidersFoundInChain Is returned when there are no valid credentials providers in the ChainProvider.

View Source
var ErrSecretCredentialsNotFound = fmt.Errorf("credentials: %s and %s not found "+
	"in Secret", EnvCredentialsToken, EnvCredentialsAccount)

ErrSecretCredentialsNotFound is returned when no credentials can be found in Secret.

Functions

This section is empty.

Types

type ChainProvider

type ChainProvider struct {
	Providers []Provider
}

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, Retrieve() will return the error ErrNoValidProvidersFoundInChain.

If a Provider is found which returns valid credentials, ChainProvider will cache that Provider for all calls until Retrieve is called again.

func (*ChainProvider) Retrieve

func (x *ChainProvider) Retrieve(ctx context.Context) (*Value, error)

Retrieve retrieves and returns the credentials, or error in case of failure.

func (*ChainProvider) String

func (x *ChainProvider) String() string

String returns the string representation of the Chain provider.

type Credentials

type Credentials struct {
	// contains filtered or unexported fields
}

Credentials provides synchronous safe retrieval of credentials.

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. All calls to Get() after that will return the cached credentials.

func NewChainProvider

func NewChainProvider(providers ...Provider) *Credentials

NewChainProvider returns a new Credentials object wrapping a chain of providers.

func NewCredentials

func NewCredentials(provider Provider) *Credentials

NewCredentials returns a new Credentials with the provider set.

func NewEnvProvider

func NewEnvProvider() *Credentials

NewEnvProvider returns a new Credentials object wrapping the Env provider.

func NewSecretProvider

func NewSecretProvider(client client.Client, name, namespace string) *Credentials

NewSecretProvider returns a new Credentials object wrapping the Secret provider.

func (*Credentials) Get

func (x *Credentials) Get(ctx context.Context) (*Value, error)

Get returns the credentials, or error if the credentials failed to be retrieved. Will return the cached credentials. If the credentials are empty the Provider's Retrieve() will be called to refresh the credentials.

func (*Credentials) Refresh

func (x *Credentials) Refresh() *Credentials

Refresh refreshes the credentials and forces it to be retrieved on the next call to Get().

type EnvProvider

type EnvProvider struct{}

EnvProvider retrieves credentials from the environment variables of the process.

func (*EnvProvider) Retrieve

func (x *EnvProvider) Retrieve(ctx context.Context) (*Value, error)

Retrieve retrieves and returns the credentials, or error in case of failure.

func (*EnvProvider) String

func (x *EnvProvider) String() string

String returns the string representation of the Env provider.

type Provider

type Provider interface {
	fmt.Stringer

	// Retrieve retrieves and returns the credentials, or error in case of failure.
	Retrieve(ctx context.Context) (*Value, error)
}

Provider defines the interface for any component which will provide credentials. The Provider should not need to implement its own mutexes, because that will be managed by Config.

type SecretProvider

type SecretProvider struct {
	Client          client.Client
	Name, Namespace string
}

SecretProvider retrieves credentials from a Secret.

func (*SecretProvider) Retrieve

func (x *SecretProvider) Retrieve(ctx context.Context) (*Value, error)

Retrieve retrieves and returns the credentials, or error in case of failure.

func (*SecretProvider) String

func (x *SecretProvider) String() string

String returns the string representation of the Secret provider.

type Value

type Value struct {
	Token   string `json:"token,omitempty"   yaml:"token,omitempty"`
	Account string `json:"account,omitempty" yaml:"account,omitempty"`
}

Value represents the operator credentials.

func (*Value) IsComplete

func (v *Value) IsComplete() bool

IsComplete if all fields of a Value are set.

func (*Value) IsEmpty

func (v *Value) IsEmpty() bool

IsEmpty if all fields of a Value are empty.

func (*Value) Merge

func (v *Value) Merge(v2 *Value) *Value

Merge merges the passed in Value into the existing Value object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL