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
- func BoxOrigin(raw string) (string, error)
- func DefaultName(workspaceUrl string) string
- func HalfEnvPair() (set, missing string)
- func Path() (string, error)
- type Access
- type Config
- func (c *Config) AdoptOverrides()
- func (c *Config) Assign(w Workspace) error
- func (c Config) Current() (Workspace, bool)
- func (c Config) EffectiveBoxUrl() (string, error)
- func (c Config) EffectiveGuiUrl() string
- func (c Config) EffectiveToken() string
- func (c Config) EffectiveWorkspace() Workspace
- func (c *Config) ForgetWorkspace() error
- func (c Config) HasWorkspace() bool
- func (c Config) HasZeropsWorkspace() bool
- func (c Config) IsCurrent(w Workspace) bool
- func (c Config) Lookup(ref string) (Workspace, error)
- func (c Config) Others() []string
- func (c *Config) Override(apiUrl string, guiUrl, boxUrl *string)
- func (c Config) Pin(ref string) (Config, error)
- func (c Config) Pinned() bool
- func (c Config) PinsAnother() bool
- func (c *Config) Remember(w Workspace) error
- func (c Config) Save() error
- func (c *Config) SaveAccess(w Workspace, a Access) error
- type Session
- type Workspace
Constants ¶
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" // DefaultBoxUrl is Zerops Box, the web app that serves the console of every workspace of the account. A stored boxUrl wins, for a dev environment. DefaultBoxUrl = "https://box.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 BoxOrigin ¶ added in v0.5.0
BoxOrigin reads a Zerops Box URL as an origin without a trailing slash. A value without a scheme is taken as https. Anything that is not an http or https origin is refused, so the console never opens a file path or a page under another path.
func DefaultName ¶
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.
Types ¶
type Access ¶
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"`
// BoxUrl is a Zerops Box origin that stands in for DefaultBoxUrl, for a dev environment. Empty keeps the default; a `zbox login --box-url` saves the flag here with the login.
BoxUrl string `json:"boxUrl,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 (*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) EffectiveBoxUrl ¶ added in v0.5.0
EffectiveBoxUrl is the Zerops Box origin, see BoxOrigin: the stored one, DefaultBoxUrl when none is.
func (Config) EffectiveGuiUrl ¶
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 ¶
EffectiveToken is the bearer of the public API calls: ZBOX_TOKEN overrides the stored login, which keeps CI and scripts stateless.
func (Config) EffectiveWorkspace ¶
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 ¶
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 ¶
HasWorkspace says whether an orchestrator can be called at all.
func (Config) HasZeropsWorkspace ¶
HasZeropsWorkspace says whether the workspace is a service of the account, which is what teardown and status need.
func (Config) Lookup ¶
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 ¶
Others lists the known workspaces that are not the current one, for the hint after a teardown or forget.
func (*Config) Override ¶
Override replaces the API, GUI and Box URLs for this run only (a nil guiUrl or boxUrl leaves it), Save keeps writing the stored ones.
func (Config) Pin ¶
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 ¶
Pinned says whether the flat fields show a workspace named for this run rather than the stored selection.
func (Config) PinsAnother ¶ added in v0.5.0
PinsAnother says whether the workspace named for this run is another one than the stored selection.
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 ¶
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 ¶
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 ¶
Label is the workspace in a sentence: the API host when it has one, the service id otherwise.
func (Workspace) Usable ¶
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.
func (Workspace) WithoutSecrets ¶ added in v0.5.0
WithoutSecrets is the entry as listings print it under --json: the API key and the zproxy access are left out, `zbox workspace key` prints the key.