awssume

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrCheckFileExists is returned when error is encountered while checking
	// for the existence of the specified format configuration file on the
	// filesystem
	ErrCheckFileExists string = "error occurred while checking for %s configuration file existence: %w"

	// ErrCreatingFile is returned when an error is encountered while creating
	// the specified file
	ErrCreatingFile string = "error creating file: %w"

	// ErrExecCmd is returned when an error is encountered while executing a
	// passed command
	ErrExecCmd string = "error executing command %s (args %s): %w"

	// ErrExeNotFound is returned when the specified command executable cannot
	// be located in $PATH
	ErrExeNotFound string = "executable %s not found: %w"

	// ErrGetRoleByAlias is returned when the Role cannot be retrieved given its
	// alias
	ErrGetRoleByAlias string = "error getting Role for alias %s: %w"

	// ErrLoadAWSConfig is returned when AWS configuration cannot be loaded
	ErrLoadAWSConfig string = "error loading AWS config: %w"

	// ErrMarshal is returned when an error is encountered during serialization
	ErrMarshal string = "error serializing: %w"

	// ErrNewConfig is returned when a new aws.Config struct cannot be created
	ErrNewConfig string = "error creating config: %w"

	// ErrReadingFile is returned when an error reading a specified file is
	// encountered
	ErrReadingFile string = "error reading file %s: %w"

	// ErrReadingFromByteBuf is returned when an error is encountered reading
	// from a byte buffer
	ErrReadingFromByteBuf string = "error reading from byte buffer: %w"

	// ErrRoleExists is returned when a specified Role already exists in the
	// configuration
	ErrRoleExists string = "role %s already exists: %w"

	// ErrRoleNotFound is returned when the specified file cannot be found
	ErrRoleNotFound string = "no role with alias %s found"

	// ErrSTSAssumeRole is returned when an error is encountered while
	// performing the sts:AssumeRole operation
	ErrSTSAssumeRole string = "error assuming Role %s: %w"

	// ErrUnmarshal is returned when an error is encountered during
	// deserialization
	ErrUnmarshal string = "error deserializing: %w"

	// ErrUnmarshalARN is returned when an error is encountered during
	// deserialization of an ARN
	ErrUnmarshalARN string = "error deserializing ARN: %w"

	// ErrWritingToFile is returned when an error is encountered while writing
	// to a file
	ErrWritingToFile string = "error writing to file %s: %w"
)

errors

View Source
const (
	// AWS Access Key ID environment variable name
	AWSAccessKeyIDEnvVar string = "AWS_ACCESS_KEY_ID"

	// AWS Secret Access Key environment variable name
	AWSSecreteAccessKeyEnvVar string = "AWS_SECRET_ACCESS_KEY"

	// AWS Security Token (otherwise known as Session Token) environment
	// variable name
	AWSSecurityTokenEnvVar string = "AWS_SECURITY_TOKEN"

	// AWS Session Token is the STS Session Token received as part of an
	// sts:AssumeRole API call
	AWSSessionTokenEnvVar string = "AWS_SESSION_TOKEN"
)

SDK defaults

View Source
const (
	// DefaultConfigFilePath is the default filesystem path where the configuration
	// file is located
	DefaultConfigFilePath string = ".config/awssume"

	// DefaultIndent is the default indentation to use when serializing into
	// various formats
	DefaultIndent int = 2
)

Variables

View Source
var (
	// ErrCommandMissing is returned when there is no command passed
	ErrCommandMissing error = errors.New("command was not passed")

	// ErrNoArgs is returned when there are no arguments passed to the command
	ErrNoArgs error = errors.New("no arguments passed")

	// ErrNoShell is returned when a shell cannot be found
	ErrNoShell error = errors.New("no shell found")

	// ErrUnsupportedConfigFormat is returned when an unsupported configuration
	// file format is specified
	ErrUnsupportedConfigFormat error = errors.New("unsupported config file format")

	// ErrMultipleConfigs is returns when multiple configuration fils are
	// detected
	ErrMultipleConfigs error = errors.New("multiple configuration files detected")

	// ErrUnexpected is returned when an unexpected error occurs
	ErrUnexpected error = errors.New("unexpected error occurred")
)

Functions

func GetShell

func GetShell() (string, error)

GetShell tries to return a shell to use, starting with a configured one and falling back to defaults, erroring out if nothing is found

Types

type ARN

type ARN struct{ *arn.ARN }

ARN is a wrapper around github.com/aws/aws-sdk-go-v2/aws/arn.ARN to allow custom serdes

func ParseARN

func ParseARN(s string) (ARN, error)

ParseARN ...

func (*ARN) MarshalJSON

func (a *ARN) MarshalJSON() ([]byte, error)

MarshalJSON serializes to JSON by stringifying the ARN

func (*ARN) MarshalYAML

func (a *ARN) MarshalYAML() (interface{}, error)

MarshalYAML seriaalizes to YAML by stringifying the ARN

func (*ARN) String

func (a *ARN) String() string

func (*ARN) UnmarshalJSON

func (a *ARN) UnmarshalJSON(bs []byte) error

UnmarshalJSON deserializes the ARN from JSON by parsing it

func (*ARN) UnmarshalYAML

func (a *ARN) UnmarshalYAML(n *yaml.Node) error

UnmarshalYAML deserializes the ARN from JSON by parsing it

type Config

type Config struct {
	// Path represents the filesystem path where the configuration is located
	Path string `json:"-" toml:"-" yaml:"-"`

	// Format describes the current configuration format
	Format ConfigFormat `json:"-" toml:"-" yaml:"-"`

	// Roles holds all of the configured Roles
	Roles []*Role `json:"roles" toml:"roles" yaml:"roles"`
	// contains filtered or unexported fields
}

Config represents the configured Roles

func NewConfig

func NewConfig(opts *NewConfigOpts) (*Config, error)

NewConfig parses a config object from a specified path

func (*Config) AddRole

func (c *Config) AddRole(r IRole) error

AddRole configures a specified Role

func (*Config) ExecRole

func (c *Config) ExecRole(
	alias string,
	sessionDuration int32,
	command string,
	arguments []string,
) error

ExecRole allows executing subprocesses by assuming the target Role through STS and providing the resulting credentials as environment variables

func (*Config) GetFormat

func (c *Config) GetFormat() ConfigFormat

GetFormat returns the configuration format

func (*Config) GetPath

func (c *Config) GetPath() string

GetPath returns the configuration filesystem path

func (*Config) GetRoleByAlias

func (c *Config) GetRoleByAlias(alias string) (IRole, error)

GetRoleByAlias returns a Role by its configured alias

func (*Config) GetRoles

func (c *Config) GetRoles() []IRole

GetRoles returns a list of all configured Roles

func (*Config) RemoveRoleByAlias

func (c *Config) RemoveRoleByAlias(alias string) error

RemoveRoleByAlias removes a specified Role by its configured alias

func (*Config) Save

func (c *Config) Save() error

Save serializes the configuration to the filesystem

func (*Config) SetFormat

func (c *Config) SetFormat(format ConfigFormat)

SetFormat sets the configuraion format

func (*Config) SetPath

func (c *Config) SetPath(p string)

SetPath sets the configuration filesystem path

func (*Config) UpdateRoleByAlias

func (c *Config) UpdateRoleByAlias(alias string, r IRole) error

UpdateRoleByAlias updates the specified Role by its alias and the updated Role

type ConfigFormat

type ConfigFormat int

ConfigFormat describes the various supported configuration file formats

const (
	// JSON //
	JSON ConfigFormat = iota

	// TOML //
	TOML

	// YAML //
	YAML

	// Unknown //
	Unknown
)

func (*ConfigFormat) FromExt

func (cf *ConfigFormat) FromExt(ext string)

FromExt creates a ConfigFormat from its associated well-known extension

func (ConfigFormat) String

func (cf ConfigFormat) String() string

String returns the string file extension for the config format

type EnvMap

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

EnvMap implements IEnvMap

func NewEnvMap

func NewEnvMap(m map[string]string) *EnvMap

NewEnvMap creates a new EnvMap from a passed map

func (*EnvMap) StringSlice

func (e *EnvMap) StringSlice() []string

StringSlice returns the string slice representation of the environment variable map

type IConfig

type IConfig interface {
	// GetPath returns the configuration filesystem path.
	GetPath() string

	// SetPath sets the configuration filesystem path.
	SetPath(string)

	// GetFormat returns the configuration format
	GetFormat() ConfigFormat

	// SetFormat sets the configuraion format
	SetFormat(ConfigFormat)

	// Save serializes the configuration to the filesystem
	Save() error

	// ListRoles returns a list of all configured Roles
	GetRoles() []IRole

	// GetRoleByAlias returns a Role by its configured alias
	GetRoleByAlias(string) (IRole, error)

	// RemoveRoleByAlias removes a specified Role by its configured alias
	RemoveRoleByAlias(string) error

	// AddRole configures a specified Role
	AddRole(IRole) error

	// UpdateRoleByAlias updates the specified Role by its alias and the updated Role
	UpdateRoleByAlias(string, IRole) error

	// ExecRole allows executing subprocesses by assuming the target Role
	// through STS and providing the resulting credentials as environment
	// variables
	ExecRole(alias string, sessionDuration int32, command string, args []string) error
}

IConfig interface describes operations against configuration source(s) for Role(s).

type IEnvMap

type IEnvMap interface {
	StringSlice() []string
}

IEnvMap describes a map of environment variables that can be transformed to a string slice

type IRole

type IRole interface {
	// GetAlias gets the Role's human friendly name
	GetAlias() string

	// SetAlias sets the Role's human friendly name
	SetAlias(string)

	// GetARN retrieves the Role's ARN (Amazon Resource Name)
	GetARN() *ARN

	// SetARN sets the Role's ARN (Amazon Resource Name)
	SetARN(*ARN)

	// GetSessionName gets the Role's Session name
	GetSessionName() string

	// SetRoleSessionName sets the Role's session name
	SetSessionName(string)
}

IRole interface describes operations against IAM Roles

type NewConfigOpts

type NewConfigOpts struct {
	Fs   afero.Fs
	Path string
}

NewConfigOpts is an option set passed to the config constructors

type Role

type Role struct {
	// alias refers to a human-friendly Role identifier
	Alias string `json:"alias" toml:"alias" yaml:"alias"`

	// rn is the Amazon Resource Name
	ARN *ARN `json:"arn" toml:"arn" yaml:"arn"`

	// sessionName is the the string to use for the STS Session when assuming
	// the target Role
	SessionName string `json:"session_name" toml:"session_name" yaml:"session_name"`
}

Role struct implements the Role interface

func (*Role) GetARN

func (r *Role) GetARN() *ARN

GetARN returns the Role's Amazon Resource Name

func (*Role) GetAlias

func (r *Role) GetAlias() string

GetAlias returns the Role's alias

func (*Role) GetSessionName

func (r *Role) GetSessionName() string

GetSessionName gets the Role's STS Session Name

func (*Role) SetARN

func (r *Role) SetARN(a *ARN)

SetARN sets the Role's Amazon Resource Name

func (*Role) SetAlias

func (r *Role) SetAlias(alias string)

SetAlias sets the Role's alias

func (*Role) SetSessionName

func (r *Role) SetSessionName(sname string)

SetSessionName sets the Role's STS Session Name

Jump to

Keyboard shortcuts

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