config

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const DefaultAPIURL = "https://api.outplane.com/api"

DefaultAPIURL is where the CLI talks unless told otherwise.

View Source
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.

View Source
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

func Dir() (string, error)

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

func ExpiryOf(token string) (expiresAt string, daysLeft int)

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

func ForgetCredential(slug string) error

ForgetCredential removes one team's token. An empty slug removes all of them, which is what `outplane logout --all` does.

func RemoveLink(path string) error

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 Save

func Save(f File) error

Save writes the preferences file atomically.

func SaveLink(dir string, l Link) (string, error)

SaveLink writes .outplane/link.json in dir.

func SetActiveTeam

func SetActiveTeam(slug string) error

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.

func Load

func Load() (File, error)

Load reads the preferences file, returning defaults when it does not exist. A first run is not an error.

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.

func FindLink(dir string) (*Link, error)

FindLink walks up from dir looking for .outplane/link.json.

Walking upward is what lets a monorepo subdirectory inherit its repository's link, so that `cd services/api && outplane deploy create` works.

func (Link) Path

func (l Link) Path() string

Path reports the file this link was read from.

type LinkUnreadableError

type LinkUnreadableError struct {
	Path string
	Err  error
}

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 OutputPrefs struct {
	Color  string `json:"color,omitempty"`  // auto | always | never
	Format string `json:"format,omitempty"` // auto | text | json
}

type Overrides

type Overrides struct {
	APIURL string
	Token  string
	Team   string
	App    string
}

Overrides are the values a flag supplied. Empty means "not given".

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".

func Resolve

func Resolve(ov Overrides) (Resolved, error)

Resolve works out the effective settings.

It never fails on a missing credential: whether one is required is a per-command decision, and a command that does not need auth should not be blocked by its absence.

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

type TeamTokenConflictError struct {
	RequestedTeam string
	TokenTeamID   string
	TokenTeamSlug string
}

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

func InspectToken(token string) (TokenInfo, error)

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"`
}

type Value

type Value struct {
	Value  string
	Source Source
}

Value is a resolved setting together with its origin.

func (Value) IsSet

func (v Value) IsSet() bool

func (Value) String

func (v Value) String() string

Jump to

Keyboard shortcuts

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