zerops

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 24 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, start, stop, restart, reload and size of a service, processes, service envs.

Index

Constants

View Source
const (
	CpuShared    = "SHARED"
	CpuDedicated = "DEDICATED"
)

The cpu modes of a workspace VM, as the import and the autoscaling endpoint spell them.

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

View Source
var ErrCreateProjects = errors.New("the account is not allowed to create projects")

ErrCreateProjects is the refusal of ProjectOrganization when the role does not allow a new project.

Functions

func Applied added in v0.5.0

func Applied(stack output.ServiceStack, r Resize) bool

Applied says whether the service already has the cpu mode and every resource r names, each pinned as min and max. The stored custom autoscaling counts too, since it keeps a size above the account's limit that the current one is trimmed from.

func AutoscalingBody added in v0.5.0

func AutoscalingBody(stack output.ServiceStack, r Resize) (body.Autoscaling, error)

AutoscalingBody is the body of `PUT /service-stack/{id}/autoscaling` that applies r to the service. The endpoint replaces the stored custom autoscaling with the one in the body, so the body carries the stored one with only what r names changed. The autoscaling profile is sent back as it is, because the endpoint drops a profile that the body leaves out.

func CheckSize added in v0.5.0

func CheckSize(cpu, ram, disk int) error

CheckSize refuses a workspace size under the driver floor of 2 cpu, 2 GiB RAM and 10 GiB disk. A zero resource is not given and passes, the message names only the ones given.

func DiskFloor added in v0.5.0

func DiskFloor(stack output.ServiceStack) float64

DiskFloor is the disk a resize cannot go under: the larger of the current and the custom max disk. The platform compares a new disk with the custom one, which stays above the current one when the size is trimmed.

func IsCode

func IsCode(err error, code string) bool

IsCode matches an error the public API named.

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
	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. 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) Autoscale added in v0.5.0

func (c *Client) Autoscale(ctx context.Context, serviceId string, in body.Autoscaling) (*output.Process, error)

Autoscale sends `PUT /service-stack/{id}/autoscaling`. The answer carries no process when the service has nothing deployed to apply it to.

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) ProcessOutput added in v0.5.0

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

ProcessOutput is the process as `GET /process/{id}` answers it.

func (*Client) Project

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

func (*Client) ReloadServiceStack added in v0.5.0

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

ReloadServiceStack answers the Zerops process that reloads the service, `PUT /service-stack/{id}/reload`.

func (*Client) RestartServiceStack added in v0.5.0

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

RestartServiceStack answers the Zerops process that restarts the service, `PUT /service-stack/{id}/restart`.

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) StartServiceStack added in v0.5.0

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

StartServiceStack answers the Zerops process that starts the service, `PUT /service-stack/{id}/start`.

func (*Client) StopServiceStack added in v0.5.0

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

StopServiceStack answers the Zerops process that stops the service, `PUT /service-stack/{id}/stop`.

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 reads the organisations of the user.

func (*Client) WaitProcesses

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

WaitProcesses polls the given processes and reports every status change through onChange. It returns an error when any process ends in a state other than FINISHED, when the API refuses a read or answers the process is gone, and when maxPollFailures reads of one process in a row fail.

func (*Client) Workspaces

func (c *Client) Workspaces(ctx context.Context, orgs []Organization) (stacks []WorkspaceStack, skipped []Organization, err error)

Workspaces lists the workspace services of the organisations: every project of each, then the services of every project, kept when their type is the Box Workspace. The `recipeSource` marker is sent on import but the lists do not filter on it, the type does. An organisation that answers forbidden or not-found is left out and returned in skipped, a project that does is left out silently. The project list returns every project of the organisation, also those that the user has no role in.

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 AsError added in v0.5.0

func AsError(err error) (Error, bool)

AsError reads the answer of the public API out of err, from the SDK or from a call made outside it.

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: cpu cores, 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
	// CpuMode is SHARED or DEDICATED, empty leaves the platform's default, SHARED.
	CpuMode string
	// 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 Organization added in v0.5.0

type Organization struct {
	Id                string
	Name              string
	CanCreateProjects bool
}

Organization is one Zerops organisation (a client) the user is an active member of.

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 Resize added in v0.5.0

type Resize struct {
	CpuMode string
	Cpu     int
	Ram     int
	Disk    int
}

Resize is what `zbox workspace resize` changes. A zero resource and an empty CpuMode keep what the service has.

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 Size added in v0.5.0

type Size struct {
	CpuMode string  `json:"cpuMode,omitempty"`
	Cpu     int     `json:"cpu"`
	Ram     float64 `json:"ramGiB"`
	Disk    float64 `json:"diskGiB"`
}

Size is the vertical autoscaling of a workspace VM, read from the maximum since a workspace pins min equal to max. Ram and Disk are GiB. CpuMode is DEDICATED or SHARED, empty when the service names none.

func StackSize added in v0.5.0

func StackSize(stack output.ServiceStack) Size

StackSize is the size the platform applies to the service, its currentAutoscaling. The custom autoscaling stands in when the service has no current one.

func (Size) Known added in v0.5.0

func (s Size) Known() bool

Known says whether the service names any resource at all.

type User

type User struct {
	Email    string
	FullName string
	// ClientId and Account are the first organisation the user may create projects in, empty when there is none.
	ClientId string
	Account  string
	// Organizations are the active memberships, in the order the API lists them.
	Organizations []Organization
}

func (User) ProjectOrganization added in v0.5.0

func (u User) ProjectOrganization(ref string) (Organization, error)

ProjectOrganization is the organisation a new project is created in: the one ref names by id or name, the first that allows it when ref is empty.

type WorkspaceStack

type WorkspaceStack struct {
	ServiceId        string `json:"serviceId"`
	Hostname         string `json:"hostname"`
	ProjectId        string `json:"projectId"`
	ProjectName      string `json:"projectName"`
	OrganizationId   string `json:"organizationId"`
	OrganizationName string `json:"organizationName"`
	Status           string `json:"status"`
}

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