zerops

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: 22 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 zerops wraps the public Zerops SDK for the handful of calls the CLI makes: login check, import, processes, service envs.

Index

Constants

View Source
const ProxyApiPrefix = "/service-api"

ProxyApiPrefix is where zproxy serves the header-authenticated form of a service's web UI and API, see Access.

View Source
const RecipeSource = "zeropsio/zbox"

RecipeSource marks the imported service as a zbox workspace. It rides in the request body, not the YAML, and the public API returns it on every service stack, which is how the Zerops GUI lists workspaces (`zeropsSetup` is not returned).

Variables

This section is empty.

Functions

func IsCode

func IsCode(err error, code string) bool

IsCode matches an error the public API named, from the SDK or from a call made outside it.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound recognises the answer the public API gives for a project or service that is gone, which for the CLI means a workspace deleted outside of it. The match is on the error code because the API answers these with HTTP 400 today, even though the ACL middleware that raises them was meant to answer 404. The status is checked too, so a fix on the API side keeps working.

func IsTerminal

func IsTerminal(status string) bool

func RenderImport

func RenderImport(p ImportParams) (string, error)

func SubdomainHosts

func SubdomainHosts(value string) (apiHost, ingressHost string)

SubdomainHosts takes the hosts out of the service env zeropsSubdomain: the platform writes one URL per published port, API first, ingress second (zbox design §6.1), so a service without subdomain access has none.

Types

type Access

type Access struct {
	Token      string
	Expiration string
	UrlUi      string
	UrlApi     string
}

Access is the zproxy access of a workspace, the answer of POST /service-stack/{id}/ui-access: the orchestrator API is reached at UrlApi (`https://proxy.<domain>/service-api`) with Token as the bearer, which zproxy swaps for the workspace key; UrlUi is the browser form of the same access, the console. The token lives an hour past its last use. Minting needs BasicUser or above on the stack.

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(apiUrl, token string) *Client

func (*Client) DeleteProject

func (c *Client) DeleteProject(ctx context.Context, projectId string) (string, error)

func (*Client) DeleteServiceStack

func (c *Client) DeleteServiceStack(ctx context.Context, serviceId string) (string, error)

DeleteServiceStack deletes one service and answers the id of the Zerops process doing it. The project around it stays.

func (*Client) ImportProject

func (c *Client) ImportProject(ctx context.Context, clientId, yaml string) (ImportResult, error)

func (*Client) ImportServiceStack

func (c *Client) ImportServiceStack(ctx context.Context, projectId, yaml string) (ImportResult, error)

ImportServiceStack adds one service to an existing project, which is how a workspace is created next to whatever else the project already runs.

func (*Client) InSudo

func (c *Client) InSudo(ctx context.Context) (bool, error)

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) error

Logout ends the session on the API, so the stored refresh token cannot be used after `zbox logout`.

func (*Client) Process

func (c *Client) Process(ctx context.Context, processId string) (ProcessState, error)

func (*Client) Project

func (c *Client) Project(ctx context.Context, projectId string) (output.Project, error)

func (*Client) ServiceEnv

func (c *Client) ServiceEnv(ctx context.Context, serviceId, key string) (string, bool, error)

ServiceEnv returns the value of one generated service variable, for example zeropsSubdomain.

func (*Client) ServiceStack

func (c *Client) ServiceStack(ctx context.Context, serviceId string) (output.ServiceStack, error)

func (*Client) Sudo

func (c *Client) Sudo(ctx context.Context, guiUrl string, print func(string)) error

Sudo puts the session into sudo mode, which reading a secret of the account needs, through the same consent page as the login. The API refuses it for a personal access token.

func (*Client) UiAccess

func (c *Client) UiAccess(ctx context.Context, serviceId string) (Access, error)

UiAccess mints a zproxy access for the workspace service. The route is not in the released SDK yet, so it is posted by hand. A `urlApi` missing from the answer (an older public API) is derived from `urlUi`, the proxy host with the API prefix.

func (*Client) UserInfo

func (c *Client) UserInfo(ctx context.Context) (User, error)

UserInfo validates the token and picks the first organisation the user may create projects in.

func (*Client) WaitProcesses

func (c *Client) WaitProcesses(ctx context.Context, ids []string, onChange func(ProcessState)) error

WaitProcesses polls the given processes every two seconds and reports every status change through onChange. It returns an error when any process ends in a state other than FINISHED.

func (*Client) Workspaces

func (c *Client) Workspaces(ctx context.Context, clientId string) ([]WorkspaceStack, error)

Workspaces lists the workspace services of the organisation. The `recipeSource` marker is sent on import but the search index does not carry it, so it is not filtered on.

type Error

type Error struct {
	Status  int
	Code    string
	Message string
}

Error is an answer of the public API to a call made outside the SDK, the `{"error": {code, message}}` envelope decoded.

func (Error) Error

func (e Error) Error() string

type ImportParams

type ImportParams struct {
	ProjectName string
	Hostname    string
	// Cpu, Ram and Disk size the one container: dedicated cpus, GiB of RAM, GiB of disk, each pinned as min and max. Zero leaves the resource to the
	// platform's default for the type, the driver floor is 2 cpu, 2 GiB, 10 GiB.
	Cpu  int
	Ram  int
	Disk int
	// NoSubdomain leaves subdomain access off: no API host and no ingress host, so sandbox ports get no public URL until a domain is added. The API is reached through zproxy either way.
	NoSubdomain bool
}

func (ImportParams) Sized

func (p ImportParams) Sized() bool

Sized tells whether any resource is pinned, so the template leaves the autoscaling block out otherwise.

type ImportResult

type ImportResult struct {
	ProjectId   string
	ProjectName string
	ServiceId   string
	Processes   []string
}

type ProcessState

type ProcessState struct {
	Id     string
	Action string
	Status string
	Error  string
}

type Registration

type Registration struct {
	Email       string
	Password    string
	Name        string
	AccountName string
}

type Session

type Session struct {
	AccessToken  string
	ExpiresAt    time.Time
	RefreshToken string
}

Session is what a login answers and the CLI stores: the access token every public API call sends, when it runs out, and the refresh token that gets the next pair. The CLI mints no personal access token.

func DeviceLogin

func DeviceLogin(ctx context.Context, apiUrl, guiUrl string, print func(string)) (Session, error)

DeviceLogin is the browser login: the API opens a login request for zbox, the user approves it on the consent page of the Zerops GUI (signing in or registering there first) and the CLI, which polls the request, receives the session. Nothing listens on this machine. guiUrl replaces the origin of the consent page the API names, for a GUI other than the environment's deployed one; empty keeps the API's.

func Login

func Login(ctx context.Context, apiUrl, email, password string) (Session, error)

Login opens a session with email and password. An account with two-factor authentication turned on cannot finish here, the CLI has no second factor: the browser login is the way in for it.

func Refresh

func Refresh(ctx context.Context, apiUrl, refreshToken string) (Session, error)

Refresh trades the refresh token for a new pair. The old pair is dead afterwards, so the caller stores the answer at once.

func Register

func Register(ctx context.Context, apiUrl string, r Registration) (Session, error)

Register creates the account and its organisation and opens the session of the new user.

type User

type User struct {
	Email    string
	FullName string
	ClientId string
	Account  string
}

type WorkspaceStack

type WorkspaceStack struct {
	ServiceId   string
	Hostname    string
	ProjectId   string
	ProjectName string
	Status      string
}

WorkspaceStack is a workspace service of the account, a Box Workspace service (zbox@1).

Jump to

Keyboard shortcuts

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