internal

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ShellEnvVar        = "SHELL"
	DefaultShell       = "/bin/bash"
	SubShellVar        = "WHOIAM_SUBSHELL"
	SubShellVarEnabled = "WHOIAM_SUBSHELL=1"
)
View Source
const AwsProfileEnvVar = "AWS_PROFILE"
View Source
const ExpectedEnvVar = "WHOIAM_EXPECTED_ENV"

Variables

This section is empty.

Functions

func AssertAccountAsExpected

func AssertAccountAsExpected(identity *sts.GetCallerIdentityOutput, expectedAccount string) error

func ClearCurrentEnv

func ClearCurrentEnv() error

ClearCurrentEnv removes .whoiam/expected-env if it exists.

func ClearGlobalCurrentEnv

func ClearGlobalCurrentEnv() error

ClearGlobalCurrentEnv removes ~/.whoiam/expected-env if it exists.

func FindLocalDir

func FindLocalDir() (string, error)

FindLocalDir walks up from CWD looking for a .whoiam/ directory. Returns "" (no error) if none is found. Stops before reaching the home directory to avoid treating ~/.whoiam/ as local.

func GetIsWhoIAmSubShell

func GetIsWhoIAmSubShell() bool

func GetShell

func GetShell() string

func NewSubShell

func NewSubShell(args ...string) (*exec.Cmd, error)

func PrintCallerIdentityTable

func PrintCallerIdentityTable(identity *sts.GetCallerIdentityOutput, name string)

func ReadCurrentEnv

func ReadCurrentEnv() (string, error)

ReadCurrentEnv reads the account name from .whoiam/expected-env. Checks local first, then falls back to global. Returns "" if neither is set.

func ReadCurrentEnvForConfig

func ReadCurrentEnvForConfig(cfg *Config) (string, string, error)

ReadCurrentEnvForConfig resolves the expected environment using the full priority chain, including AWS_PROFILE if the profile name matches an account defined in cfg. Priority: --env flag (caller) > WHOIAM_EXPECTED_ENV > AWS_PROFILE (if matched) > local file > global file.

func ReadCurrentEnvWithSource

func ReadCurrentEnvWithSource() (string, string, error)

ReadCurrentEnvWithSource is like ReadCurrentEnv but also returns the source: "env" (WHOIAM_EXPECTED_ENV), "local" (.whoiam/expected-env), "global" (~/.whoiam/expected-env), or "" if not set. Does not check AWS_PROFILE; use ReadCurrentEnvForConfig when a config is available.

func ReadGlobalCurrentEnv

func ReadGlobalCurrentEnv() (string, error)

ReadGlobalCurrentEnv reads the account name from ~/.whoiam/expected-env.

func ValidateAccountNumber

func ValidateAccountNumber(number string) error

func WriteCurrentEnv

func WriteCurrentEnv(name string) error

WriteCurrentEnv writes the account name to .whoiam/expected-env. Requires a .whoiam/ directory to already exist (created by whoiam init).

func WriteGlobalCurrentEnv

func WriteGlobalCurrentEnv(name string) error

WriteGlobalCurrentEnv writes the account name to ~/.whoiam/expected-env.

Types

type CallerIdentityClient added in v0.6.0

type CallerIdentityClient interface {
	GetCallerIdentity() (*sts.GetCallerIdentityOutput, error)
}

CallerIdentityClient is the interface used by commands to look up AWS identity.

type Config

type Config struct {
	Accounts map[string]string `yaml:"accounts"`
}

func LoadEffectiveConfig

func LoadEffectiveConfig() (*Config, error)

LoadEffectiveConfig loads the global config and merges any project-local config on top. Local account definitions take precedence over global ones on conflict.

func LoadEffectiveConfigWithSources

func LoadEffectiveConfigWithSources() (*Config, map[string]string, error)

LoadEffectiveConfigWithSources is like LoadEffectiveConfig but also returns a map of account name -> source ("global" or "local") for each entry.

func NewTemplateConfig

func NewTemplateConfig() (*Config, error)

func (*Config) AccountExists

func (c *Config) AccountExists(name string) bool

func (*Config) AddAccount

func (c *Config) AddAccount(name, number string) error

func (*Config) DeleteAccount

func (c *Config) DeleteAccount(name string)

func (*Config) GetAccountByNumber

func (c *Config) GetAccountByNumber(number string) string

func (*Config) PrintConfigTable

func (c *Config) PrintConfigTable(w io.Writer)

func (*Config) PrintConfigTableWithSource

func (c *Config) PrintConfigTableWithSource(w io.Writer, sources map[string]string)

type ConfigPath

type ConfigPath struct {
	Path string
	File string
}

func FindLocalConfigPath

func FindLocalConfigPath() (*ConfigPath, error)

FindLocalConfigPath walks up the directory tree from CWD looking for a .whoiam/whoiam.yaml. Returns nil (no error) if no local config is found. Stops before reaching the home directory to avoid treating ~/.whoiam/whoiam.yaml as local.

func NewConfigPath

func NewConfigPath() (*ConfigPath, error)

func NewProjectConfigPath

func NewProjectConfigPath() (*ConfigPath, error)

NewProjectConfigPath returns a ConfigPath rooted at .whoiam/ in the current directory. Used by whoiam init to create a project-local config.

func (*ConfigPath) ConfigFileExists

func (c *ConfigPath) ConfigFileExists() bool

func (*ConfigPath) Create

func (c *ConfigPath) Create() error

func (*ConfigPath) Exists

func (c *ConfigPath) Exists() bool

func (*ConfigPath) FullPath

func (c *ConfigPath) FullPath() string

func (*ConfigPath) LoadConfig

func (c *ConfigPath) LoadConfig() (*Config, error)

func (*ConfigPath) SaveConfig

func (c *ConfigPath) SaveConfig(config *Config) error

type StsClient

type StsClient struct {
	Client *sts.Client
}

func NewStsClient

func NewStsClient() (*StsClient, error)

func (*StsClient) GetCallerIdentity

func (s *StsClient) GetCallerIdentity() (*sts.GetCallerIdentityOutput, error)

type SubShell

type SubShell struct {
	CommandArgs []string
}

Jump to

Keyboard shortcuts

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