config

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 9 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 persists the CLI state: the Zerops token and API URL, the workspace in use (its Zerops ids when the account knows it, the zproxy access minted for it, or the API URL and key of one pointed at by hand) and the other known workspaces `zbox workspace switch` moves between.

Index

Constants

View Source
const (
	// DefaultApiUrl is the Zerops public API the CLI works against. A stored apiUrl wins, `zbox login --public-api-url` moves a config over to another environment.
	DefaultApiUrl = "https://api.app-prg1.zerops.io"
	// DefaultBaseImage is the image registered as the first base of a new workspace: the saved default sandbox image (ubuntu 26.04 with claude, gh, codex, python3, node 24 and cron) served through the Zerops CDN, which the orchestrator pulls and flattens from the tarball URL. A plain registry reference works as well.
	DefaultBaseImage = "https://storage.cdn.zerops.app/4ga3k-boxstorage/zbox/zbox-base.tar.gz"

	EnvConfigPath   = "ZBOX_CONFIG"
	EnvToken        = "ZBOX_TOKEN"
	EnvWorkspaceUrl = "ZBOX_WORKSPACE_URL"
	EnvWorkspaceKey = "ZBOX_API_KEY"
	// EnvWorkspace names a known workspace for one run, the env form of --workspace. Unlike the URL and key pair it carries no secret, the access is the stored one.
	EnvWorkspace = "ZBOX_WORKSPACE"
)

Variables

This section is empty.

Functions

func DefaultName

func DefaultName(workspaceUrl string) string

DefaultName names a workspace assigned without a name after the first label of its API host, `zbox-c-8080` for `https://zbox-c-8080.app-prg1.zerops.io`.

func HalfEnvPair

func HalfEnvPair() (set, missing string)

HalfEnvPair names the one of ZBOX_WORKSPACE_URL and ZBOX_API_KEY that is set without the other, empty when both or neither are. The pair only stands as a whole.

func Path

func Path() (string, error)

Types

type Access

type Access struct {
	Url   string `json:"url"`
	Token string `json:"token"`
}

Access is the zproxy access of a workspace: the base URL the orchestrator API is reached under and the access token sent as the bearer, which zproxy swaps for the workspace key. Minted with `POST /service-stack/{id}/ui-access` of the public API, it lives an hour past its last use and is minted again when zproxy refuses it.

type Config

type Config struct {
	ApiUrl string `json:"apiUrl"`
	// GuiUrl is a Zerops GUI origin that stands in for the one the API names in the consent page URL of a browser login, for the GUI dev server. Empty keeps the API's; a `zbox login --gui-url` saves the flag here with the login.
	GuiUrl string `json:"guiUrl,omitempty"`
	// Session is the login of `zbox login` and `zbox register`, refreshed by the CLI. Token is a personal access token given to `zbox login --token`, stored as is; a login sets one of the two.
	Session     *Session `json:"session,omitempty"`
	Token       string   `json:"token,omitempty"`
	ClientId    string   `json:"clientId,omitempty"`
	ProjectId   string   `json:"projectId,omitempty"`
	ProjectName string   `json:"projectName,omitempty"`
	// ServiceId keeps its spelling from before the workspace rename so an existing assignment survives it.
	ServiceId string `json:"serviceId,omitempty"`
	// WorkspaceUrl is the API host of the workspace, the first of the two subdomains the service publishes, empty on a workspace without subdomain access. The ingress host comes from GET /workspace.
	WorkspaceUrl string `json:"workspaceUrl,omitempty"`
	// ApiKey is the bearer of a workspace pointed at by hand (`zbox workspace use --api-key`): the workspace API key, the generated sensitive env of the service and the whole authority on the orchestrator API, or a scoped token. A workspace of the account carries none here, zproxy holds the key.
	ApiKey string `json:"apiKey,omitempty"`
	// Access is the zproxy access of the workspace in use, see Workspace.Access.
	Access *Access `json:"access,omitempty"`
	// Workspaces are the known workspaces, the current one included. The flat fields above stay the current one so every reader is unchanged; `zbox workspace switch` copies another entry into them.
	Workspaces []Workspace `json:"workspaces,omitempty"`
	// contains filtered or unexported fields
}

func Load

func Load() (Config, error)

func (*Config) AdoptOverrides

func (c *Config) AdoptOverrides()

AdoptOverrides makes the overridden URLs the ones Save writes, for the login that moves a config between environments.

func (*Config) Assign

func (c *Config) Assign(w Workspace) error

Assign remembers w and makes it the current workspace.

func (Config) Current

func (c Config) Current() (Workspace, bool)

Current is the workspace in use, as an entry of the list.

func (Config) EffectiveGuiUrl

func (c Config) EffectiveGuiUrl() string

EffectiveGuiUrl is the stored GUI origin without its trailing slash, empty when the API's consent page URL is to be used as it is.

func (Config) EffectiveToken

func (c Config) EffectiveToken() string

EffectiveToken is the bearer of the public API calls: ZBOX_TOKEN overrides the stored login, which keeps CI and scripts stateless.

func (Config) EffectiveWorkspace

func (c Config) EffectiveWorkspace() Workspace

EffectiveWorkspace is the workspace one run works on: the current (or pinned) one, or the direct URL and key pair the environment names, for scripts and for sandboxes that hold the key of their own workspace. A pinned workspace is the more specific word and is not overridden. The environment pair stands on its own: it never mixes with the current workspace, whose stored key may be the stale one of an account workspace from before zproxy (HalfEnvPair refuses half a pair before any reader gets here).

func (*Config) ForgetWorkspace

func (c *Config) ForgetWorkspace() error

ForgetWorkspace drops the current workspace from the list and leaves none in use, `zbox workspace switch` picks the next one. A pinned workspace is dropped the same way and the stored selection stays, unless it was that very workspace.

func (Config) HasWorkspace

func (c Config) HasWorkspace() bool

HasWorkspace says whether an orchestrator can be called at all.

func (Config) HasZeropsWorkspace

func (c Config) HasZeropsWorkspace() bool

HasZeropsWorkspace says whether the workspace is a service of the account, which is what teardown and status need.

func (Config) IsCurrent

func (c Config) IsCurrent(w Workspace) bool

IsCurrent says whether w is the workspace the flat fields show.

func (Config) Lookup

func (c Config) Lookup(ref string) (Workspace, error)

Lookup resolves what the user typed: a name, an API URL or host, a service id, a project name or id, or a prefix of the name or host when nothing matches whole. A ref that fits several workspaces is refused with the candidates, never settled by the order of the list.

func (Config) Others

func (c Config) Others() []string

Others lists the known workspaces that are not the current one, for the hint after a teardown or forget.

func (*Config) Override

func (c *Config) Override(apiUrl string, guiUrl *string)

Override replaces the API and GUI URLs for this run only (a nil guiUrl leaves it), Save keeps writing the stored ones.

func (Config) Pin

func (c Config) Pin(ref string) (Config, error)

Pin answers the config with the workspace named by ref in place of the current one, for one run: every reader of the flat fields works on it, and Save still writes the selection that was stored.

func (Config) Pinned

func (c Config) Pinned() bool

Pinned says whether the flat fields show a workspace named for this run rather than the stored selection.

func (*Config) Remember

func (c *Config) Remember(w Workspace) error

Remember stores w in the list without switching to it, unless nothing is current yet. A name already used by another workspace is refused rather than silently reassigned.

func (Config) Save

func (c Config) Save() error

func (*Config) SaveAccess

func (c *Config) SaveAccess(w Workspace, a Access) error

SaveAccess stores a freshly minted zproxy access of w: in its list entry, in the flat fields when w is the one in use, and in the stored selection when that is w too. Nothing else about the selection changes.

type Session

type Session struct {
	AccessToken  string    `json:"accessToken"`
	ExpiresAt    time.Time `json:"expiresAt"`
	RefreshToken string    `json:"refreshToken"`
}

Session is the Zerops login: the access token every public API call sends, when it runs out, and the refresh token that gets the next pair.

type Workspace

type Workspace struct {
	Name         string  `json:"name"`
	ProjectId    string  `json:"projectId,omitempty"`
	ProjectName  string  `json:"projectName,omitempty"`
	ServiceId    string  `json:"serviceId,omitempty"`
	WorkspaceUrl string  `json:"workspaceUrl,omitempty"`
	ApiKey       string  `json:"apiKey,omitempty"`
	Access       *Access `json:"access,omitempty"`
}

Workspace is one saved assignment, addressed by its name in `zbox workspace switch`. A workspace of the account has a ServiceId and is reached through zproxy with an access minted from the Zerops token; one pointed at by hand has the API URL and the key.

func (Workspace) Direct

func (w Workspace) Direct() bool

Direct says whether the workspace is reached at its own API host with the key, the way `zbox workspace use --api-key` stores one, rather than through zproxy with the account.

func (Workspace) Host

func (w Workspace) Host() string

Host is the API host without the scheme, what the table shows and what `zbox workspace switch` matches on. Empty on a workspace without subdomain access.

func (Workspace) Label

func (w Workspace) Label() string

Label is the workspace in a sentence: the API host when it has one, the service id otherwise.

func (Workspace) Same

func (w Workspace) Same(o Workspace) bool

Same says whether two entries are the same workspace.

func (Workspace) Usable

func (w Workspace) Usable() bool

Usable says whether the orchestrator of the workspace can be called at all: a workspace of the account (zproxy mints the access), or a URL and key pair.

Jump to

Keyboard shortcuts

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