userconfig

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AWSAccessKeyIDEnvVar represents the environment variable name
	// that the resolver will look for when resolving the AWS access key id.
	AWSAccessKeyIDEnvVar = "AWS_ACCESS_KEY_ID"

	// AWSSecretAccessKeyEnvVar represents the environment variable name
	// that the resolver will look for when resolving the AWS secret access key.
	AWSSecretAccessKeyEnvVar = "AWS_SECRET_ACCESS_KEY"

	// AWSRegionEnvVar represents the environment variable name
	// that the resolver will look for when resolving the AWS region.
	AWSRegionEnvVar = "AWS_REGION"
)
View Source
const (
	// AWSConfigFileDefaultProfile represents the configuration profile
	// that will be loaded by default if the Profile option is not set.
	AWSConfigFileDefaultProfile = "default"
)

Variables

View Source
var (
	// ErrMissingAccessKeyInEnv represents the error
	// returned when a secret is set but an access key cannot be found.
	ErrMissingAccessKeyInEnv = errors.New("ErrMissingAccessKeyInEnv")

	// ErrMissingSecretInEnv represents the error
	// returned when access key is set but a secret cannot be found.
	ErrMissingSecretInEnv = errors.New("ErrMissingSecretInEnv")

	// ErrMissingRegionInEnv represents the error
	// returned when access key and secret are set but a region was not
	// passed as an option nor set as an environment variable.
	ErrMissingRegionInEnv = errors.New("ErrMissingRegionInEnv")
)
View Source
var (
	// ErrMissingConfig represents the error
	// returned when a resolver cannot resolve config.
	ErrMissingConfig = errors.New("ErrMissingConfig")
)
View Source
var (
	// ErrMissingRegionInFiles represents the error
	// returned when no region is found in config files and
	// the Region option is not set.
	ErrMissingRegionInFiles = errors.New("ErrMissingRegionInFiles")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Credentials represents the resolved credentials (access key + secret).
	Credentials Credentials

	// Region represents the resolved region.
	Region string
}

Config represents the resolved user config.

func NewConfig

func NewConfig(
	accessKeyID string,
	secretAccessKey string,
	region string,
) *Config

NewConfig constructs a new resolved user config.

type Credentials

type Credentials struct {
	// AccessKeyID represents the access key.
	AccessKeyID string

	// SecretAccessKey represents the secret associated with the access key.
	SecretAccessKey string

	// SessionToken represents an AWS session token that
	// could replace the access key + secret set.
	// Currently not supported.
	SessionToken string
}

Credentials represents the AWS credentials resolved from user config.

func (Credentials) HasKeys

func (u Credentials) HasKeys() bool

HasKeys is an helper method used to check that the credentials in the Credentials struct are not empty.

type EnvVarsGetter

type EnvVarsGetter interface {
	Get(string) string
}

EnvVarsGetter represents the interface used to access environment variables.

type EnvVarsResolver

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

EnvVarsResolver retrieves the AWS account configuration from environment variables.

func NewEnvVarsResolver

func NewEnvVarsResolver(
	envVars EnvVarsGetter,
	opts EnvVarsResolverOpts,
) EnvVarsResolver

NewFilesResolver constructs the EnvVarsResolver struct.

func (EnvVarsResolver) Resolve

func (e EnvVarsResolver) Resolve() (*Config, error)

Resolve retrieves the AWS account configuration from environment variables.

The Region option takes precedence over the one found in environment.

Partial configurations return an adequate errror.

Env vars are retrieved via the EnvVarsGetter interface passed as constructor argument.

type EnvVarsResolverOpts

type EnvVarsResolverOpts struct {
	// Region specifies which region will be used in the resulting config.
	// Default to the one found in environment if not set.
	Region string
}

EnvVarsResolverOpts represents the options used to configure the EnvVarsResolver.

type ErrProfileNotFound

type ErrProfileNotFound struct {
	Profile             string
	CredentialsFilePath string
	ConfigFilePath      string
}

ErrProfileNotFound represents the error returned when the Profile passed in option was not found.

func (ErrProfileNotFound) Error

func (ErrProfileNotFound) Error() string

type FilesResolver

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

FilesResolver retrieves the AWS account configuration from config files.

func NewFilesResolver

func NewFilesResolver(
	profileLoader ProfileLoader,
	opts FilesResolverOpts,
) FilesResolver

NewFilesResolver constructs the FilesResolver struct.

func (FilesResolver) Resolve

func (f FilesResolver) Resolve() (*Config, error)

Resolve retrieves the AWS account configuration from config files.

The CredentialsFilePath and ConfigFilePath options are used to locate the credentials and config files.

The Profile option specifies which configuration profile will be loaded (the function fallback to AWSConfigFileDefaultProfile if not set).

The Region option takes precedence over the region found in config files.

Config files are loaded via the ProfileLoader interface passed as constructor argument.

type FilesResolverOpts

type FilesResolverOpts struct {
	// Profile specifies which configuration profile will be loaded.
	// Default to AWSConfigFileDefaultProfile if not set.
	Profile string

	// Region specifies which region will be used in the resulting config.
	// Default to the one found in config files if not set.
	Region string

	// CredentialsFilePath specifies the file path of the credentials file.
	CredentialsFilePath string

	// ConfigFilePath specifies the file path of the config file.
	ConfigFilePath string
}

FilesResolverOpts represents the options used to configure the FilesResolver.

type ProfileLoader

type ProfileLoader interface {
	Load(
		profile string,
		credentialsFilePath string,
		configFilePath string,
	) (config.SharedConfig, error)
}

ProfileLoader represents the interface used to load configuration profile from files

Jump to

Keyboard shortcuts

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