Documentation ¶
Index ¶
- Constants
- Variables
- func GetShell() (string, error)
- type ARN
- type Config
- func (c *Config) AddRole(r IRole) error
- func (c *Config) ExecRole(alias string, sessionDuration int32, command string, arguments []string) error
- func (c *Config) GetFormat() ConfigFormat
- func (c *Config) GetPath() string
- func (c *Config) GetRoleByAlias(alias string) (IRole, error)
- func (c *Config) GetRoles() []IRole
- func (c *Config) RemoveRoleByAlias(alias string) error
- func (c *Config) Save() error
- func (c *Config) SetFormat(format ConfigFormat)
- func (c *Config) SetPath(p string)
- func (c *Config) UpdateRoleByAlias(alias string, r IRole) error
- type ConfigFormat
- type EnvMap
- type IConfig
- type IEnvMap
- type IRole
- type NewConfigOpts
- type Role
Constants ¶
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
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
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 ¶
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 ¶
Types ¶
type ARN ¶
ARN is a wrapper around github.com/aws/aws-sdk-go-v2/aws/arn.ARN to allow custom serdes
func (*ARN) MarshalJSON ¶
MarshalJSON serializes to JSON by stringifying the ARN
func (*ARN) MarshalYAML ¶
MarshalYAML seriaalizes to YAML by stringifying the ARN
func (*ARN) UnmarshalJSON ¶
UnmarshalJSON deserializes the ARN from JSON by parsing it
func (*ARN) UnmarshalYAML ¶
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) 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) GetRoleByAlias ¶
GetRoleByAlias returns a Role by its configured alias
func (*Config) RemoveRoleByAlias ¶
RemoveRoleByAlias removes a specified Role by its configured alias
func (*Config) SetFormat ¶
func (c *Config) SetFormat(format ConfigFormat)
SetFormat sets the configuraion format
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 (*EnvMap) StringSlice ¶
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 ¶
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) GetSessionName ¶
GetSessionName gets the Role's STS Session Name
func (*Role) SetSessionName ¶
SetSessionName sets the Role's STS Session Name