userconfig

package
v0.0.0-...-1bdfbe6 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HetznerAPITokenEnvVar represents the environment variable name
	// that the resolver will look for when resolving the Hetzner API token.
	HetznerAPITokenEnvVar = "HCLOUD_TOKEN"

	// HetznerRegionEnvVar represents the environment variable name
	// that the resolver will look for when resolving the Hetzner region.
	HetznerRegionEnvVar = "HCLOUD_REGION"
)

Variables

View Source
var (
	// ErrMissingConfig represents the error
	// returned when a resolver cannot resolve config.
	ErrMissingConfig = errors.New("ErrMissingConfig")

	// ErrMissingRegion represents the error
	// returned when a resolver cannot resolve region.
	ErrMissingRegion = errors.New("ErrMissingRegion")
)
View Source
var DefaultConfigFilePath string
View Source
var (
	// ErrMissingRegionInEnv represents the error
	// returned when API token is set but a region was not
	// passed as an option nor set as a environment variable.
	ErrMissingRegionInEnv = errors.New("ErrMissingRegionInEnv")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// Credentials represents the resolved credentials (API token).
	Credentials Credentials

	// ElevenConfigDir represents the path to the directory where the Eleven's configuration is stored.
	ElevenConfigDir string

	// Region represents the resolved region.
	Region string
}

Config represents the resolved user config.

func NewConfig

func NewConfig(
	apiToken string,
	region string,
) *Config

NewConfig constructs a new resolved user config.

type ContextLoader

type ContextLoader interface {
	Load(
		context string,
		configFilePath string,
	) (*Config, error)
}

ContextLoader represents the interface used to load configuration context from files.

type Credentials

type Credentials struct {
	// APIToken represents the API token.
	APIToken string
}

Credentials represents the Hetzner credentials resolved from user config.

func (Credentials) HasKeys

func (c 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 Hetzner 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 Hetzner account configuration from environment variables.

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

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 sandbox if not set.
	Region string
}

EnvVarsResolverOpts represents the options used to configure the EnvVarsResolver.

type FilesResolver

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

FilesResolver retrieves the Hetzner account configuration from config files.

func NewFilesResolver

func NewFilesResolver(
	contextLoader ContextLoader,
	opts FilesResolverOpts,
	envVars EnvVarsGetter,
) FilesResolver

NewFilesResolver constructs the FilesResolver struct.

func (FilesResolver) Resolve

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

Resolve retrieves the Hetzner account configuration from config files.

The ConfigFilePath option is used to locate the config file.

The Context option specifies which configuration context will be loaded.

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

Config file is loaded via the ContextLoader interface passed as constructor argument.

type FilesResolverOpts

type FilesResolverOpts struct {
	// Context specifies which configuration context will be loaded.
	Context 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
}

FilesResolverOpts represents the options used to configure the FilesResolver.

Jump to

Keyboard shortcuts

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