credentials

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package credentials provides ...

Index

Constants

View Source
const (
	// EnvironmentProviderName is the name of this provider
	EnvironmentProviderName = "EnvironmentProvider"

	// CredAPIKeyEnvStr - environment variable for the Pureport API Key
	CredAPIKeyEnvStr = "PUREPORT_API_KEY"

	// CredAPISecretEnvStr - environment variable for the Pureport API Secret
	CredAPISecretEnvStr = "PUREPORT_API_SECRET"
)
View Source
const (
	// FileProviderName the name of this provider
	FileProviderName = "FileProvider"

	// CredConfigFileEnvStr - environment variable for the path to the file
	// containing credentials information.
	CredConfigFileEnvStr = "PUREPORT_CREDENTIALS_FILE"

	// CredConfigProfileEnvStr - environment variable for the credentials
	// profile to use.
	CredConfigProfileEnvStr = "PUREPORT_PROFILE"

	// CredConfigAPIKeyStr - INI key for the API Key Value
	CredConfigAPIKeyStr = "api_key"

	// CredConfigAPISecretStr - INI key for the API Secret Value
	CredConfigAPISecretStr = "api_secret"
)
View Source
const (
	// StaticProviderName the name of this provider
	StaticProviderName = "StaticProvider"
)
View Source
const (
	// ViperProviderName is the name of this provider
	ViperProviderName = "ViperProvider"
)

Variables

View Source
var (
	// ErrorEnvironmentAPIKeyNotFound for the when the APIKey isn't found in the environment
	ErrorEnvironmentAPIKeyNotFound = errors.New("PUREPORT_API_KEY not found in environment")

	// ErrorEnvironmentAPISecretNotFound for the when the API Secret isn't found in the environment
	ErrorEnvironmentAPISecretNotFound = errors.New("PUREPORT_API_SECRET not found in environment")
)
View Source
var (

	// ErrorFileAPIKeyNotFound is returned when the API Key can not be found in the configuration file
	ErrorFileAPIKeyNotFound = errors.New("api_key not found in configuration file")

	// ErrorFileAPISecretNotFound is returned when the API Secret can not be found in the configuration file
	ErrorFileAPISecretNotFound = errors.New("api_secret not found in configuration file")

	// ErrorFileConfigurationFileNotFound is return when the specified configuration file
	// can't be found.
	ErrorFileConfigurationFileNotFound = errors.New("No available credentials file found")

	// ErrorFileHomeDirectoryNotFound is returned when the users home directory can't be found.
	ErrorFileHomeDirectoryNotFound = errors.New("No available home directory found for current user")
)
View Source
var (

	// ErrorStaticAPIKeyNotFound is returned when the API Key can not be found in the configuration file
	ErrorStaticAPIKeyNotFound = errors.New("api_key not found in configuration file")

	// ErrorStaticAPISecretNotFound is returned when the API Secret can not be found in the configuration file
	ErrorStaticAPISecretNotFound = errors.New("api_secret not found in configuration file")
)

Functions

This section is empty.

Types

type ChainProvider

type ChainProvider struct {
	Providers []Provider
	// contains filtered or unexported fields
}

ChainProvider provides chaining of multiple providers so we can gracefully go through the provider list until we find one that works.

func (*ChainProvider) IsExpired

func (c *ChainProvider) IsExpired() bool

IsExpired - see Provider.IsExpired()

func (*ChainProvider) Retrieve

func (c *ChainProvider) Retrieve() (Value, error)

Retrieve - see Provider.Retrieve()

type Credentials

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

The Credentials object provides threadsafe access to credentials provided by the Pureport API. It takes care of caching credentials and requesting new access tokens when they expire.

func NewChainCredentials

func NewChainCredentials(providers []Provider) *Credentials

NewChainCredentials creates a new credential using the chaining provider

func NewCredentials

func NewCredentials(provider Provider) *Credentials

NewCredentials creates new credentials information for the specified provider

func NewEnvironmentCredentials

func NewEnvironmentCredentials() *Credentials

NewEnvironmentCredentials creates a new Credentials using the EnvironmentProvider

func NewFileCredentials

func NewFileCredentials(filename string, profile string) *Credentials

NewFileCredentials constructs a Credentials object for the specified file and profile

func NewStaticCredentials added in v0.2.0

func NewStaticCredentials(key string, secret string) *Credentials

NewStaticCredentials create a new credential using static API information

func NewViperCredentials

func NewViperCredentials(profile string) *Credentials

NewViperCredentials creates a new credentials provider using Viper

func (*Credentials) Expire

func (c *Credentials) Expire()

Expire force refresh of the credentials even if they haven't expired

func (*Credentials) Get

func (c *Credentials) Get() (Value, error)

Get the current value of the credentials

func (*Credentials) IsExpired

func (c *Credentials) IsExpired() bool

IsExpired whether the current credentials are expired

type EnvironmentProvider

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

An EnvironmentProvider retrieves the base credentials from the current execution environment of the running process. Environment credentials never expire.

func (*EnvironmentProvider) IsExpired

func (e *EnvironmentProvider) IsExpired() bool

IsExpired see Provider.IsExpired()

func (*EnvironmentProvider) Retrieve

func (e *EnvironmentProvider) Retrieve() (Value, error)

Retrieve see Provider.Retrieve()

type ErrorProvider

type ErrorProvider struct {

	// The error to return from Provider.Retrieve()
	Err error

	// The name to set on the Provider.Retrieve()
	ProviderName string
}

ErrorProvider is a stub credentials provider that will always return an error. This provider is returned when the requested provider creation failed due to errors.

func (ErrorProvider) IsExpired

func (p ErrorProvider) IsExpired() bool

IsExpired see Provider.IsExpired()

func (ErrorProvider) Retrieve

func (p ErrorProvider) Retrieve() (Value, error)

Retrieve see Provider.Retrieve()

type Expiry

type Expiry struct {

	// Function to use to get the current time
	// This can be changed by unit tests.
	CurrentTime func() time.Time
	// contains filtered or unexported fields
}

Expiry stores the expiration data use by credentials providers

func (*Expiry) ExpiresAt

func (e *Expiry) ExpiresAt() time.Time

ExpiresAt returns the expiration time

func (*Expiry) IsExpired

func (e *Expiry) IsExpired() bool

IsExpired return if the current Expiry time has be reached

func (*Expiry) SetExpiration

func (e *Expiry) SetExpiration(expiration time.Time, window time.Duration)

SetExpiration set the time of expiration that is used by Provider.IsExpired()

Specifying a value for window will cause the expiration to occur prior to the actual expiration time. This will allow a new token to be requested before the existing token has reach is expiration time.

type FileProvider

type FileProvider struct {

	// The location of the configuration file
	// Linux/OSX "$HOME/.pureport/credentials"
	Filename string

	// The Profile for the credentials that we want to use
	Profile string
	// contains filtered or unexported fields
}

FileProvider holds information for fetch credentials information from configurations files.

func (*FileProvider) IsExpired

func (p *FileProvider) IsExpired() bool

IsExpired Provider.IsExpired()

func (*FileProvider) Retrieve

func (p *FileProvider) Retrieve() (Value, error)

Retrieve Provider.Retrieve()

type Provider

type Provider interface {
	Retrieve() (Value, error)
	IsExpired() bool
}

The Provider interface defines a component who is capable of requesting credentials for a session and managing credential expiration.

The Provider instance does not need to handle locking of resources. This will be managed by the Credentials object.

type StaticProvider added in v0.2.0

type StaticProvider struct {
	APIKey    string
	APISecret string
}

StaticProvider provides credentials that are allocated at startup only.

func (*StaticProvider) IsExpired added in v0.2.0

func (p *StaticProvider) IsExpired() bool

IsExpired Provider.IsExpired()

func (*StaticProvider) Retrieve added in v0.2.0

func (p *StaticProvider) Retrieve() (Value, error)

Retrieve Provider.Retrieve()

type Value

type Value struct {

	// Pureport API Key
	APIKey string

	// Pureport Secret Access Key
	Secret string

	// Pureport Session Token
	SessionToken string

	// Pureport Refresh Token
	RefreshToken string

	// Provider used to get credentials
	ProviderName string
}

Value is the gathered credentials information

type ViperProvider

type ViperProvider struct {

	// Filename - path to the configuration file (Optional)
	Filename string

	// Profile - the profile to use from the configuration file (Optional)
	Profile string
	// contains filtered or unexported fields
}

ViperProvider is a credentials provider using Viper as the configuration source.

func (*ViperProvider) IsExpired

func (p *ViperProvider) IsExpired() bool

IsExpired Provider.IsExpired()

func (*ViperProvider) Retrieve

func (p *ViperProvider) Retrieve() (Value, error)

Retrieve Provider.Retrieve()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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