command

package
v0.0.0-...-5575e35 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTTL for requested credentials in hours
	DefaultTTL uint = 1
	// DefaultTimeRemaining for new key requests in minutes
	DefaultTimeRemaining uint = 5
)
View Source
const (
	ExitCodeTokensExpiredOrAbsent int = 0x1
	ExitCodeUndisclosedOktaError  int = 0x2
	ExitCodeAuthenticationError   int = 0x3
	ExitCodeConnectivityError     int = 0x4
	ExitCodeValueError            int = 0x5
	ExitCodeAWSError              int = 0x6
	ExitCodeUnknownError          int = 0x7D
)
View Source
const CredentialProcessVersion = 1

CredentialProcessVersion is the schema version required by the AWS SDKs' credential_process protocol. It must always be 1. See https://docs.aws.amazon.com/sdkref/latest/guide/feature-process-credentials.html

Variables

View Source
var (
	FlagNoRefresh     = "no-refresh"
	FlagServerAddress = "server-address"

	ErrSessionExpired = errors.New("session expired")
)
View Source
var (
	ClientID       string
	OIDCDomain     string
	ServerAddress  string
	Version        = "TBD"
	BuildTimestamp = "BuildTimestamp is not set"
	// CallbackPorts is a list of ports that will be attempted in no particular order for hosting an Oauth2 callback web server.
	// This cannot be set using -ldflags='-X ..' because -X requires that this be a string literal or uninitialized.
	//
	// These ports are chosen somewhat arbitrarily
	CallbackPorts = []string{"57468", "47512", "57123", "61232", "48231", "49757", "59834", "54293"}
)

Vars for build time

View Source
var (
	FlagRegion        = "region"
	FlagRoleName      = "role"
	FlagTimeRemaining = "time-remaining"
	FlagTimeToLive    = "ttl"
	FlagBypassCache   = "bypass-cache"
	FlagLogin         = "login"
	FlagProfileName   = "profile"
)
View Source
var (
	FlagURLOnly   = "url-only"
	FlagNoBrowser = "no-browser"
)
View Source
var (
	FlagOIDCDomain = "oidc-domain"
	FlagClientID   = "client-id"
	FlagQuiet      = "quiet"
	FlagTimeout    = "timeout"
)
View Source
var (
	FlagRoleSessionName = "role-session-name"
	FlagOutputType      = "output"
	FlagShellType       = "shell"
	FlagAWSCLIPath      = "awscli"
)
View Source
var (
	ErrTokensExpiredOrAbsent = UsageError{
		ExitCode:     ExitCodeTokensExpiredOrAbsent,
		DebugMessage: "tokens expired or absent",
		Description:  "Your session has expired. Please login again.",
	}
)

Functions

func ConfigContext

func ConfigContext(ctx context.Context, config *Config) context.Context

func Execute

func Execute(ctx context.Context, args []string) error

func FindOktaHeaders

func FindOktaHeaders(r *http.Response) []slog.Attr

func GetExitCode

func GetExitCode(err error) (int, bool)

func ResolveAWSCredentialsPath

func ResolveAWSCredentialsPath(rootPath string) string

func SaveCloudCredentialInCLI

func SaveCloudCredentialInCLI(cloudCliPath string, entry CloudCliEntry) error

func ShouldUseMachineOutput

func ShouldUseMachineOutput(flags flagSet) bool

ShouldUseMachineOutput indicates whether or not we should write to standard output as if the user is a machine.

What this means is implementation specific, but this usually indicates the user is trying to use this program in a script and we should avoid user-friendly output messages associated with values a user might find useful.

func TouchFile

func TouchFile(path string) (*os.File, error)

func UnknownAccountError

func UnknownAccountError(accountID, bypassCacheFlag string) error

func UnknownRoleError

func UnknownRoleError(role, applicationID string) error

Types

type AWSError

type AWSError struct {
	InnerError error
	Message    string
}

func (AWSError) Code

func (o AWSError) Code() int

func (AWSError) Error

func (o AWSError) Error() string

func (AWSError) Unwrap

func (o AWSError) Unwrap() error

type Account

type Account struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	Alias          string `json:"alias"`
	MostRecentRole string `json:"most_recent_role"`
}

func (*Account) IsNameMatch

func (a *Account) IsNameMatch(name string) bool

func (*Account) NormalizeName

func (a *Account) NormalizeName() string

type CloudCliEntry

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

func NewCloudCliEntry

func NewCloudCliEntry(c CloudCredentials, a Account, profileName string) CloudCliEntry

type CloudCredentials

type CloudCredentials struct {
	Version         int    `json:"Version"`
	AccountID       string `json:"AccountId"`
	AccessKeyID     string `json:"AccessKeyId"`
	SecretAccessKey string `json:"SecretAccessKey"`
	SessionToken    string `json:"SessionToken"`
	Expiration      string `json:"Expiration"`
}

func LoadAWSCredentialsFromEnvironment

func LoadAWSCredentialsFromEnvironment() CloudCredentials

func (*CloudCredentials) ValidUntil

func (c *CloudCredentials) ValidUntil(account Account, dur time.Duration) bool

func (CloudCredentials) WriteFormat

func (c CloudCredentials) WriteFormat(w io.Writer, format ShellType) (int, error)

type Config

type Config struct {
	Accounts        *accountSet `json:"accounts"`
	TTL             uint        `json:"ttl"`
	TimeRemaining   uint        `json:"time_remaining"`
	LastUsedAccount *string     `json:"last_used_account"`
}

Config stores all information related to the user

func ConfigFromContext

func ConfigFromContext(ctx context.Context) *Config

func (*Config) AddAccount

func (c *Config) AddAccount(id string, account Account)

func (*Config) Alias

func (c *Config) Alias(id, name string)

func (*Config) Decode

func (c *Config) Decode(reader io.Reader) error

Decode populates all member values of config using default values where needed

func (*Config) DumpAccounts

func (c *Config) DumpAccounts(w io.Writer, withHeaders bool)

func (*Config) Encode

func (c *Config) Encode(w io.Writer) error

Encode writes the config to the file provided overwriting the file if it exists

func (*Config) FindAccount

func (c *Config) FindAccount(name string) (Account, bool)

func (*Config) Unalias

func (c *Config) Unalias(name string)

func (*Config) UpdateAccounts

func (c *Config) UpdateAccounts(entries []Account)

type ErrKeychainLocked

type ErrKeychainLocked struct{}

ErrKeychainLocked indicates that the operating system keychain is locked and needs to be unlocked.

This usually only occurs on Darwin systems.

func (ErrKeychainLocked) Error

func (e ErrKeychainLocked) Error() string

func (ErrKeychainLocked) ExitCode

func (e ErrKeychainLocked) ExitCode() int

type ErrNoPortsAvailable

type ErrNoPortsAvailable struct{}

func (ErrNoPortsAvailable) Error

func (e ErrNoPortsAvailable) Error() string

func (ErrNoPortsAvailable) ExitCode

func (e ErrNoPortsAvailable) ExitCode() int

type GetCommand

type GetCommand struct {
	AccountIDOrName                                                                        string
	TimeToLive                                                                             uint
	TimeRemaining                                                                          uint
	OutputType, ShellType, RoleName, AWSCLIPath, OIDCDomain, ClientID, Region, ProfileName string
	Login, URLOnly, NoBrowser, BypassCache, MachineOutput                                  bool
}

func (GetCommand) Execute

func (g GetCommand) Execute(ctx context.Context, config *Config) error

func (*GetCommand) Parse

func (g *GetCommand) Parse(flags flagSet) error

type LogRoundTripper

type LogRoundTripper struct {
	RoundTripper http.RoundTripper
}

func (LogRoundTripper) RoundTrip

func (t LogRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

type LoginCommand

type LoginCommand struct {
	OIDCDomain    string
	ClientID      string
	MachineOutput bool
	NoBrowser     bool
}

func (LoginCommand) Execute

func (c LoginCommand) Execute(ctx context.Context, config *Config) error

func (*LoginCommand) Parse

func (c *LoginCommand) Parse(flags flagSet, args []string) error

type OktaError

type OktaError struct {
	InnerError error
	Message    string
}

func (OktaError) Code

func (o OktaError) Code() int

func (OktaError) Error

func (o OktaError) Error() string

func (OktaError) Unwrap

func (o OktaError) Unwrap() error

type ShellType

type ShellType = string

type SwitchCommand

type SwitchCommand struct {
	OutputType      string
	ShellType       string
	AWSCLIPath      string
	RoleSessionName string
	AccountID       string
}

func (SwitchCommand) Execute

func (s SwitchCommand) Execute(ctx context.Context) error

func (*SwitchCommand) Parse

func (s *SwitchCommand) Parse(flags flagSet) error

type TimeToLiveError

type TimeToLiveError struct {
	MaxDuration       time.Duration
	RequestedDuration time.Duration
}

func (TimeToLiveError) Code

func (o TimeToLiveError) Code() int

func (TimeToLiveError) Error

func (o TimeToLiveError) Error() string

type UsageError

type UsageError struct {
	ExitCode     int
	Description  string
	DebugMessage string
}

UsageError indicates that the user used the program incorrectly

func (UsageError) Code

func (u UsageError) Code() int

func (UsageError) Error

func (u UsageError) Error() string

type ValueError

type ValueError struct {
	Value       string
	ValidValues []string
}

func (ValueError) Code

func (v ValueError) Code() int

func (ValueError) Error

func (v ValueError) Error() string

Jump to

Keyboard shortcuts

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