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
- func IsCode(err error, code string) bool
- func IsNotFound(err error) bool
- func IsTerminal(status string) bool
- func RenderImport(p ImportParams) (string, error)
- func SubdomainHosts(value string) (apiHost, ingressHost string)
- type Access
- type Client
- func (c *Client) DeleteProject(ctx context.Context, projectId string) (string, error)
- func (c *Client) DeleteServiceStack(ctx context.Context, serviceId string) (string, error)
- func (c *Client) ImportProject(ctx context.Context, clientId, yaml string) (ImportResult, error)
- func (c *Client) ImportServiceStack(ctx context.Context, projectId, yaml string) (ImportResult, error)
- func (c *Client) InSudo(ctx context.Context) (bool, error)
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) Process(ctx context.Context, processId string) (ProcessState, error)
- func (c *Client) Project(ctx context.Context, projectId string) (output.Project, error)
- func (c *Client) ServiceEnv(ctx context.Context, serviceId, key string) (string, bool, error)
- func (c *Client) ServiceStack(ctx context.Context, serviceId string) (output.ServiceStack, error)
- func (c *Client) Sudo(ctx context.Context, guiUrl string, print func(string)) error
- func (c *Client) UiAccess(ctx context.Context, serviceId string) (Access, error)
- func (c *Client) UserInfo(ctx context.Context) (User, error)
- func (c *Client) WaitProcesses(ctx context.Context, ids []string, onChange func(ProcessState)) error
- func (c *Client) Workspaces(ctx context.Context, clientId string) ([]WorkspaceStack, error)
- type Error
- type ImportParams
- type ImportResult
- type ProcessState
- type Registration
- type Session
- func DeviceLogin(ctx context.Context, apiUrl, guiUrl string, print func(string)) (Session, error)
- func Login(ctx context.Context, apiUrl, email, password string) (Session, error)
- func Refresh(ctx context.Context, apiUrl, refreshToken string) (Session, error)
- func Register(ctx context.Context, apiUrl string, r Registration) (Session, error)
- type User
- type WorkspaceStack
Constants ¶
const ProxyApiPrefix = "/service-api"
ProxyApiPrefix is where zproxy serves the header-authenticated form of a service's web UI and API, see Access.
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 ¶
IsCode matches an error the public API named, from the SDK or from a call made outside it.
func IsNotFound ¶
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 RenderImport ¶
func RenderImport(p ImportParams) (string, error)
func SubdomainHosts ¶
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 ¶
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 (*Client) DeleteProject ¶
func (*Client) DeleteServiceStack ¶
DeleteServiceStack deletes one service and answers the id of the Zerops process doing it. The project around it stays.
func (*Client) ImportProject ¶
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) Logout ¶
Logout ends the session on the API, so the stored refresh token cannot be used after `zbox logout`.
func (*Client) ServiceEnv ¶
ServiceEnv returns the value of one generated service variable, for example zeropsSubdomain.
func (*Client) ServiceStack ¶
func (*Client) Sudo ¶
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 ¶
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 ¶
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 ¶
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 ¶
Error is an answer of the public API to a call made outside the SDK, the `{"error": {code, message}}` envelope decoded.
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 Registration ¶
type Session ¶
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 ¶
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 ¶
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.