Documentation
¶
Index ¶
- func AWSProfileFields(name string) (map[string]string, error)
- func Clear(scope string) *shellcfg.Script
- func DeleteAWSProfile(name string) error
- func DeleteGCPConfig(name string) error
- func GCPConfigFields(name string) (map[string]string, error)
- func HasDanger(alerts []Alert) bool
- func LoadGCP() ([]Target, GCPState, error)
- func ProbeADC(ctx context.Context, a *ADC)
- func ProbeAWS(ctx context.Context, targets []Target, concurrency int)
- func ProbeGCP(ctx context.Context, targets []Target, concurrency int)
- func ShortWarnings(gcp []Target, state GCPState, adc ADC) []string
- func SwitchAWS(profile string) *shellcfg.Script
- func SwitchGCP(config string) *shellcfg.Script
- func ValidateName(name string) error
- func WriteAWSSSO(s AWSSSOSpec) error
- func WriteAWSStatic(s AWSStaticSpec) error
- func WriteGCPConfig(s GCPConfigSpec) error
- type ADC
- type AWSSSOSpec
- type AWSStaticSpec
- type Action
- type ActiveSource
- type Alert
- type CredKind
- type GCPConfigSpec
- type GCPState
- type Health
- type Severity
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AWSProfileFields ¶
AWSProfileFields returns a profile's stored settings, merged across both files, for pre-filling an edit form.
func Clear ¶
Clear removes cx's overrides for one provider or all of them. Afterwards the shell falls back to whatever the machine-wide defaults are, which for gcloud means the shared active_config file again.
func DeleteAWSProfile ¶
DeleteAWSProfile removes a profile from both AWS files.
It deliberately does not touch any sso-session block the profile referred to: those are shared, and removing one would break every other profile using it.
func DeleteGCPConfig ¶
DeleteGCPConfig removes a gcloud configuration.
func GCPConfigFields ¶
GCPConfigFields returns a gcloud configuration's properties, flattened to the names the forms use.
func HasDanger ¶
HasDanger reports whether any alert describes state that can misdirect a command. Callers use it to decide an exit code.
func LoadGCP ¶
LoadGCP reads gcloud configurations straight from disk. It deliberately does not invoke the gcloud CLI: gcloud is a Python program that takes on the order of a second to start, which makes a per-configuration shell loop painfully slow, and its config files are a stable documented format.
func ProbeADC ¶
ProbeADC resolves who ADC actually authenticates as. For a user credential the file holds only a refresh token, so the identity can be discovered only by minting an access token and asking Google who it belongs to.
func ProbeAWS ¶
ProbeAWS resolves each profile's real identity by calling STS, concurrently and with a hard timeout. Probing serially -- as a shell loop must -- costs seconds per profile on a slow link, which is the main reason this tool is not a shell script.
It shells out to the AWS CLI rather than using the SDK so that SSO token caches, credential_process helpers, and every other resolution mechanism the user has already configured work identically here and in their terminal.
func ProbeGCP ¶
ProbeGCP checks whether each configuration's account still holds a usable refresh token, concurrently.
func ShortWarnings ¶
ShortWarnings returns terse codes for hazards worth putting in a shell prompt. It is deliberately narrow: a prompt has room for a nudge, not an explanation, and `cx status` is where the full reasoning lives.
Only locally-determinable hazards appear here. Anything needing a network round trip is excluded, because this runs before every prompt.
func SwitchGCP ¶
SwitchGCP builds the environment changes that point a shell at a gcloud configuration.
It deliberately does not run `gcloud config configurations activate`. That command writes a file shared by every shell on the machine, so it would retarget terminals the user is not looking at. Setting the environment variable affects this shell and only this shell.
func ValidateName ¶
ValidateName reports why a name is unusable, or nil if it is fine.
func WriteAWSSSO ¶
func WriteAWSSSO(s AWSSSOSpec) error
WriteAWSSSO creates or updates an SSO profile plus the sso-session block it refers to. This is the credential kind worth steering people towards: the CLI refreshes its tokens, so the profile does not silently go stale.
func WriteAWSStatic ¶
func WriteAWSStatic(s AWSStaticSpec) error
WriteAWSStatic creates or updates a key-based profile. Keys go to the credentials file and settings to the config file, matching where the AWS CLI itself puts them.
func WriteGCPConfig ¶
func WriteGCPConfig(s GCPConfigSpec) error
WriteGCPConfig creates or updates a gcloud configuration by writing its file directly.
gcloud stores configurations as plain INI files, and shelling out to `gcloud config configurations create` would cost about a second per call for something that is three lines of text.
Types ¶
type ADC ¶
type ADC struct {
// Present reports whether an ADC file exists.
Present bool
// Path is where it was found.
Path string
// Kind is the credential type recorded in the file.
Kind CredKind
// QuotaProject is the project billed for API calls made with ADC. When it
// disagrees with the active gcloud project, that is worth flagging.
QuotaProject string
// Identity is the resolved principal.
Identity string
// Health is the probe result.
Health Health
// Detail explains a non-Valid health.
Detail string
}
ADC describes Application Default Credentials: the credential set used by Terraform, the Google client libraries, and essentially everything that is not the gcloud binary itself.
ADC is entirely independent of the active gcloud configuration. A shell can have `gcloud config` pointing at a staging project while ADC authenticates as a different principal entirely, and nothing in the standard tooling shows both at once.
Note what ADC does and does not decide. It supplies the identity Terraform and the client libraries authenticate as. Its quota project decides who is billed for API calls made by the client libraries -- but not by Terraform, whose google provider has its own billing_project and does not read the ADC file's quota project at all.
type AWSSSOSpec ¶
type AWSSSOSpec struct {
Name string
SessionName string
StartURL string
SSORegion string
AccountID string
RoleName string
Region string
}
AWSSSOSpec describes a profile authenticated through IAM Identity Center.
type AWSStaticSpec ¶
type AWSStaticSpec struct {
Name string
Region string
AccessKeyID string
SecretAccessKey string
// SessionToken is optional, and when set makes the profile one that expires.
SessionToken string
}
AWSStaticSpec describes a profile authenticated with long-lived or pasted keys.
type Action ¶
type Action struct {
// Label is what the menu shows.
Label string
// Key is the single keystroke that selects it.
Key string
// Cmd and Args are the command to run.
Cmd string
Args []string
// Hint explains what the flow does, for the menu.
Hint string
}
Action is an external command cx runs on the user's behalf, by suspending the dashboard and handing the terminal over. cx never reimplements these flows: they are interactive, they change over time, and the vendor CLIs already do them correctly.
func LoginAction ¶
LoginAction returns the command that re-authenticates an AWS profile.
The right command depends on how the profile gets its credentials: an SSO profile needs a new SSO session, while a static profile has no login flow at all and can only be re-entered by hand.
func LoginActionGCP ¶
LoginActionGCP returns the command that re-authenticates a gcloud configuration's account.
type ActiveSource ¶
type ActiveSource int
ActiveSource records how the current gcloud configuration was selected. The distinction is the whole reason this tool exists: an env-var selection is private to one shell, while the on-disk selection is shared by every shell on the machine and changes under you when another terminal switches.
const ( // SourceNone means no configuration is selected at all. SourceNone ActiveSource = iota // SourceShell means CLOUDSDK_ACTIVE_CONFIG_NAME is set: safe, shell-local. SourceShell // SourceGlobal means the selection comes from ~/.config/gcloud/active_config, // which is machine-wide mutable state. SourceGlobal )
func (ActiveSource) String ¶
func (s ActiveSource) String() string
type Alert ¶
type Alert struct {
Severity Severity
// Title states what is wrong.
Title string
// Fix states what to do about it.
Fix string
}
Alert is a hazard that spans more than one target, and so cannot be expressed by any single row of the dashboard.
func Audit ¶
Audit inspects the whole resolved picture for the ways a shell can end up pointed somewhere other than where its operator believes.
This lives in the domain layer rather than the UI because both the dashboard and the scriptable --plain mode need it, and because a non-zero exit from the latter is the thing that can gate a `terraform apply`.
type CredKind ¶
type CredKind string
CredKind describes how a target obtains credentials. This matters more than it looks: static long-lived keys and hand-pasted session tokens rot, while SSO and credential_process refresh themselves. Surfacing the distinction is the point of the dashboard.
const ( KindStatic CredKind = "static" // access key + secret, long-lived KindStaticTemp CredKind = "static+token" // access key + secret + pasted session token KindSSO CredKind = "sso" // legacy inline sso_* keys KindSSOSession CredKind = "sso-session" // modern sso_session reference KindAssumeRole CredKind = "assume-role" // role_arn + source_profile KindProcess CredKind = "process" // credential_process KindUser CredKind = "user" // GCP: an authorized user account KindServiceAcc CredKind = "service-account" // GCP: a service account key KindNone CredKind = "none" // nothing configured )
type GCPConfigSpec ¶
GCPConfigSpec describes a gcloud configuration.
type GCPState ¶
type GCPState struct {
// Active is the configuration name in effect for this shell.
Active string
// Source is how Active was chosen.
Source ActiveSource
// Global is the machine-wide selection from the active_config file.
Global string
// GlobalMissing reports that active_config names a configuration that does
// not exist, which makes gcloud silently fall back to built-in defaults.
GlobalMissing bool
// ProjectOverride and AccountOverride hold CLOUDSDK_CORE_* values, which
// beat the configuration's own properties and are easy to forget about.
ProjectOverride string
AccountOverride string
}
GCPState describes how the current shell resolves gcloud configuration, and where that resolution disagrees with the machine-wide default.
type Health ¶
type Health int
Health is the result of probing a target's credentials.
const ( // Unknown means the target has not been probed yet this refresh. Unknown Health = iota // Probing means a probe is currently in flight. Probing // Valid means the credentials resolved to a real identity. Valid // Expired means credentials exist but the provider rejected them. For AWS // this is the common case for a hand-pasted session token; for GCP it means // no unexpired refresh token for the account. Expired // Missing means the target names credentials that are not present at all. Missing )
type Target ¶
type Target struct {
// Name is the identifier the user switches to.
Name string
// Kind is how credentials are obtained.
Kind CredKind
// Account is the human-facing owner: an AWS account ID, or a GCP account
// email. Populated by a probe where it is not known statically.
Account string
// Scope is the blast radius: an AWS region, or a GCP project. For the
// active GCP target it is the effective value, with any environment
// override already applied.
Scope string
// ConfiguredScope is what the configuration file itself says, before any
// environment override. Scope carries the effective value, so once an
// override is in force the original is gone -- and comparing the two is
// exactly what the audit needs in order to tell a silent retarget from an
// override that merely restates the configuration.
ConfiguredScope string
// Identity is the resolved principal (an AWS ARN, a GCP email).
Identity string
// Active reports whether this target applies to the current shell.
Active bool
// Health is the probe result.
Health Health
// Detail carries a short explanation for a non-Valid health, shown inline.
Detail string
// Sensitive marks a target the user has flagged as production.
Sensitive bool
// ProbedAt records when Health was last established.
ProbedAt time.Time
}
Target is one switchable destination: an AWS profile, a GCP configuration, or the ADC slot. The zero value is not useful; construct via the provider loaders.