Documentation
¶
Overview ¶
Package config resolves everything the CLI needs to know before it can make a request: which API to talk to, which credential to use, and which team and application are in play.
Three things, three jobs, and they are kept apart on purpose:
config.json preferences. Never contains a secret.
the credential store the tokens. The OS keychain where there is one, and
a file with owner-only permissions where there is
not. See store.go; OUTPLANE_TOKEN skips both.
.outplane/link.json which app this directory belongs to. Per-project.
Resolution order is fixed and identical for every setting: an explicit flag, then an environment variable, then the project link, then the config file, then a built-in default. `outplane config list` prints each value together with where it came from, so that "why is it using that team" is answerable in one command instead of by guesswork.
Index ¶
- Constants
- func ActiveTeamSlug() string
- func CredentialStore() string
- func Dir() (string, error)
- func ExpiryOf(token string) (expiresAt string, daysLeft int)
- func ForgetCredential(slug string) error
- func RemoveLink(path string) error
- func Save(f File) error
- func SaveLink(dir string, l Link) (string, error)
- func SetActiveTeam(slug string) error
- func StoreCredential(c Credential) error
- type Credential
- type File
- type Link
- type LinkUnreadableError
- type OutputPrefs
- type Overrides
- type Profile
- type Resolved
- type Source
- type TeamNotSignedInError
- type TeamTokenConflictError
- type TokenInfo
- type UpdatePrefs
- type Value
Constants ¶
const DefaultAPIURL = "https://api.outplane.com/api"
DefaultAPIURL is where the CLI talks unless told otherwise.
const DefaultLogURL = "https://loki.outplane.com"
DefaultLogURL is the gateway that serves an application's own output.
A second host, not a path on the API: logs are read straight from the log store's query interface, with the same bearer token and team header. Nothing else in the CLI talks to it.
const DefaultMetricsURL = "https://metrics.outplane.com"
DefaultMetricsURL is the gateway that serves resource usage.
A third host, reached exactly like the log gateway: same bearer token, same team header, its own query language. Only `metrics` talks to it.
Variables ¶
This section is empty.
Functions ¶
func ActiveTeamSlug ¶
func ActiveTeamSlug() string
ActiveTeamSlug returns the team used when nothing more specific is given.
When exactly one credential is stored it is the active one whether or not anything was ever set: a single-team user should never have to run `team use`.
func CredentialStore ¶
func CredentialStore() string
CredentialStore names where this machine's tokens are kept, for `status` to report. A reader deciding whether a token is safe on this machine needs to know which of the two answered.
func Dir ¶
Dir is where preferences live. XDG on Unix from the very first release: adding it later would be a migration, and honouring it costs one function.
func ExpiryOf ¶
ExpiryOf reports when a token expires, reading the token itself.
The token is the authority on its own lifetime. A stored credential keeps a copy of the expiry so that listing teams does not have to decode anything, but a token supplied through OUTPLANE_TOKEN has no stored copy at all, and answering "never expires" for one that expires next week is precisely the wrong answer to give somebody deciding whether to rotate it.
daysLeft is -1 when the token carries no expiry, matching DaysLeft. A token that cannot be decoded reports the same, because a caller that reached this point holds a token every other command is about to fail on regardless.
func ForgetCredential ¶
ForgetCredential removes one team's token. An empty slug removes all of them, which is what `outplane logout --all` does.
func RemoveLink ¶
RemoveLink deletes a link file and, if it leaves the .outplane directory empty, that directory too.
Tidying up the directory matters more than it sounds: a stray empty .outplane/ left in a repository is the kind of thing that gets committed by somebody running `git add .`, and then puzzled over months later.
An already-absent file is not an error. Unlinking twice should be quiet, so a teardown script can run unconditionally.
func SetActiveTeam ¶
SetActiveTeam changes which stored credential is used by default.
func StoreCredential ¶
func StoreCredential(c Credential) error
StoreCredential saves a team's token and makes it active.
Signing in to a second team ADDS a credential rather than replacing the first. A user who runs `outplane login --team beta` has not stopped working on acme, and silently discarding that token would be a surprise they only discover on their next deploy.
Types ¶
type Credential ¶
type Credential struct {
Token string `json:"token"`
TeamID string `json:"teamId"`
TeamSlug string `json:"teamSlug"`
// Name is the label shown in the console's token list, so that a user
// looking at three tokens can tell which machine each belongs to.
Name string `json:"name,omitempty"`
// ExpiresAt is RFC 3339, or empty for a token that never expires. Stored
// so `status` can warn before a CI pipeline stops working one morning.
ExpiresAt string `json:"expiresAt,omitempty"`
// AddedAt records when this CLI stored the credential.
AddedAt string `json:"addedAt,omitempty"`
}
Credential is one team's stored token plus what can be known about it without asking the server.
func FindCredential ¶
func FindCredential(teamRef string) (Credential, bool)
FindCredential returns the credential for a team, looked up by slug or id.
Both are accepted because a person types the slug and a script is more likely to hold the id, and forcing either to convert would mean a network call before the CLI even knows which token to authenticate with.
func SignedInTeams ¶
func SignedInTeams() []Credential
SignedInTeams lists every team the CLI holds a credential for, sorted by slug so that output is stable between runs.
func (Credential) DaysLeft ¶
func (c Credential) DaysLeft() int
DaysLeft returns whole days until expiry, or -1 when it never expires.
func (Credential) Expired ¶
func (c Credential) Expired() bool
Expired reports whether the stored expiry has passed.
This is a local hint, not authorisation: the server decides. It exists so the CLI can say "the token for acme expired last Tuesday" instead of relaying an opaque 403.
type File ¶
type File struct {
Version int `json:"version"`
ActiveProfile string `json:"activeProfile"`
Profiles map[string]Profile `json:"profiles"`
Output OutputPrefs `json:"output,omitempty"`
Update UpdatePrefs `json:"update,omitempty"`
}
File is the on-disk preferences file. It never holds a secret; tokens live in the credential store, so that a stray `cat` of the config, or a screen share, cannot leak one.
Profiles is a map even though the CLI currently exposes only one. Shaping it this way costs nothing today and is the difference between adding multi-account support later as a feature or as a migration.
type Link ¶
type Link struct {
APIURL string `json:"apiUrl,omitempty"`
TeamID string `json:"teamId,omitempty"`
TeamSlug string `json:"teamSlug,omitempty"`
AppID string `json:"appId,omitempty"`
AppName string `json:"appName,omitempty"`
// contains filtered or unexported fields
}
Link ties a directory to an application. It is written by `outplane link` and read by walking up from the working directory, so that subdirectories of a repository inherit it.
It is gitignored rather than committed: teamId is per-user in a multi-team organisation, and committing it means a colleague's CLI silently targets someone else's team.
type LinkUnreadableError ¶
LinkUnreadableError is a link file that exists but cannot be parsed.
It is a distinct type so that the two commands which must keep working despite it can: `outplane unlink` deletes the file it names, and `outplane status` reports it instead of dying on it.
func (*LinkUnreadableError) Error ¶
func (e *LinkUnreadableError) Error() string
func (*LinkUnreadableError) Unwrap ¶
func (e *LinkUnreadableError) Unwrap() error
type OutputPrefs ¶
type Profile ¶
type Profile struct {
APIURL string `json:"apiUrl,omitempty"`
TeamID string `json:"teamId,omitempty"`
TeamSlug string `json:"teamSlug,omitempty"`
}
Profile is one account context.
type Resolved ¶
type Resolved struct {
APIURL Value
LogURL Value
MetricsURL Value
Token Value
TeamID Value
TeamSlug Value
AppID Value
// TeamError explains why no team could be resolved, when none could. It is
// carried rather than returned so that commands which need no credential
// still run: `schema`, `version` and `help` must work on a machine that has
// never been logged in.
TeamError error
// File and Link are the underlying sources, exposed so that `status` and
// `config list` can report detail without re-reading anything.
File File
Link *Link
// LinkError is a link file that exists but could not be parsed. Carried,
// not returned, so that the commands which diagnose and repair it still
// run. See Resolve.
LinkError error
}
Resolved is the complete answer to "what should this invocation do".
type Source ¶
type Source string
Source says where a resolved value came from. It exists so that every setting can explain itself, which turns a class of confusing support questions into a single command.
const ( SourceFlag Source = "flag" SourceEnv Source = "environment" SourceLink Source = "link file" SourceFile Source = "config file" // SourceKeychain and SourceCredentialFile are where a stored token came // from. They are separate because the answer changes what a reader should // do: a token in the keychain is encrypted at rest, and one in a file is a // plaintext copy that a stray `cat` or a synced dotfiles directory can // leak. SourceKeychain Source = "keychain" SourceCredentialFile Source = "credential file" SourceToken Source = "token claim" SourceDefault Source = "default" SourceUnset Source = "unset" )
type TeamNotSignedInError ¶
type TeamNotSignedInError struct {
Requested string
Available []Credential
}
TeamNotSignedInError says a team was named that the CLI holds no credential for. It carries the list of teams that ARE available so the message can show them, which is the difference between an error a user can act on and one that sends them to the documentation.
func (*TeamNotSignedInError) AvailableSlugs ¶
func (e *TeamNotSignedInError) AvailableSlugs() []string
AvailableSlugs lists the teams a credential exists for.
func (*TeamNotSignedInError) Error ¶
func (e *TeamNotSignedInError) Error() string
type TeamTokenConflictError ¶
TeamTokenConflictError is raised when an explicit token and an explicit --team name different teams.
It exists as its own type so the message can show both sides. "team mismatch" would leave the caller guessing which of their two inputs was wrong.
func (*TeamTokenConflictError) Error ¶
func (e *TeamTokenConflictError) Error() string
type TokenInfo ¶
type TokenInfo struct {
TeamID string
// TeamSlug is the team's name as people type it. It is a claim rather than
// something the CLI asks the server for, which is what makes signing in
// work with no network at all.
//
// Embedding it is safe because a slug is written once, when a team is
// created, and nothing ever changes it: renaming a team edits its Name and
// leaves the Slug alone. The team's Name is deliberately NOT a claim, for
// the mirror-image reason: it is editable, and a token outlives a rename by
// up to 180 days.
TeamSlug string
TokenID string
ExpiresAt time.Time
IsAPIToken bool
}
TokenInfo is what can be learned from a token without asking the server.
func InspectToken ¶
InspectToken decodes a token's claims locally.
This is how the CLI knows which team a freshly pasted token belongs to, before it has made a single request. It is what makes a first run work with nothing but a paste.
The signature is NOT verified, and does not need to be. That is usually a bug, so it is worth being explicit: nothing here is a trust decision. The server verifies the token on every request. All we are doing is reading which team a credential the user just handed us belongs to, so that we address the right one. A forged token buys nothing, because the server would reject it.
type UpdatePrefs ¶
type UpdatePrefs struct {
AutoCheck bool `json:"autoCheck"`
}