client

package
v0.1.45 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 10 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 client builds an authenticated Hostim API client from resolved config and maps API error responses (including 429 rate limiting) into Go errors.

Index

Constants

View Source
const ProjectIDPrefix = "hpr-"

ProjectIDPrefix is the prefix of the system-generated project identifiers used as the {projectName} path parameter by the API. Friendly project names are resolved to an ID before nested calls.

Variables

View Source
var ErrBuildFailed = errors.New("build failed")

ErrBuildFailed is returned by PollBuild when the build reaches "failed".

View Source
var ErrDeployFailed = errors.New("deploy failed")

ErrDeployFailed is returned by PollBuild when the new rollout cannot become healthy: the image can't be pulled, or the app keeps crashing.

View Source
var ErrEmptyResponse = errors.New("the API returned an empty response; retry, and report it if it keeps happening")

ErrEmptyResponse covers a 2xx answer with no payload: nothing the caller did causes it and no command can continue past it.

View Source
var UserAgent = "hostim-cli/dev"

UserAgent is sent on every request so CLI traffic can be told apart from the console in the backend access logs. cmd sets it to the build version.

Functions

func Check

func Check(status int, body []byte) error

Check returns an *APIError if the response status is >= 400, else nil. Generated response structs expose StatusCode() and a Body []byte field, so callers use client.Check(resp.StatusCode(), resp.Body).

func MergeVars added in v0.1.22

func MergeVars(base, updates []api.EnvVar) []api.EnvVar

MergeVars overlays updates onto base, replacing by name and appending new keys. The result is never nil, since the API rejects a null env array.

func New

New returns a ClientWithResponses that injects the Bearer token and transparently retries on 429 responses, honouring Retry-After.

func NewAnonymous added in v0.1.20

func NewAnonymous(apiURL string) (*api.ClientWithResponses, error)

NewAnonymous returns a client for the endpoints that take no token (the device-login flow), with the same 429 retry behaviour as New. Without it a single rate-limited poll would end a login that is otherwise fine.

func NormalizeApp added in v0.1.22

func NormalizeApp(app *api.App)

NormalizeApp replaces nil required-array fields with empty slices so they serialize as [] rather than null, which the API schema rejects.

func ResolveProjectID added in v0.1.22

func ResolveProjectID(ctx context.Context, cl *api.ClientWithResponses, ref string) (string, error)

ResolveProjectID maps a project reference (friendly name or ID) to the ID the API expects in the {projectName} path parameter. An ID (hpr-…) is returned as-is; a name is looked up via GetProjects. Callers pass whatever the user typed, so both work everywhere a project is referenced.

Types

type APIError

type APIError struct {
	Status  int
	Code    string // GenericMessage.error, when present
	Message string // GenericMessage.message, when present
}

APIError is a structured error built from a non-2xx API response.

func (*APIError) Error

func (e *APIError) Error() string

type Baseline added in v0.1.41

type Baseline struct {
	BuildStatus    api.AppStatusBuildStatus
	LastBuiltAt    *time.Time
	LastDeployedAt *time.Time
	// contains filtered or unexported fields
}

Baseline is an existing app's state captured before a deploy changes it. The operator acts on a rebuild request asynchronously, so for a few seconds after the request the status still describes the previous build and rollout. The baseline tells those stale values apart from the ones this deploy produces.

func NewBaseline added in v0.1.41

func NewBaseline(ctx context.Context, c *api.ClientWithResponses, project, app string) (*Baseline, error)

NewBaseline reads app's current status (and, after a failed build, its BuildFailed events) for PollBuild.

type BuildResult

type BuildResult struct {
	BuildStatus   api.AppStatusBuildStatus
	RuntimeStatus api.AppStatusRuntimeStatus
	Status        *api.AppStatus
}

BuildResult is the terminal outcome of a deploy poll.

func PollBuild

func PollBuild(
	ctx context.Context,
	c *api.ClientWithResponses,
	project, app string,
	interval time.Duration,
	expectBuild bool,
	since *Baseline,
	onTick func(*api.AppStatus),
) (BuildResult, error)

PollBuild polls an app's status until the deploy reaches a terminal state or the context is cancelled. onTick, if non-nil, is called with each observed status so callers can render progress.

A git source (expectBuild) first waits for its build: succeeded moves on to the rollout, failed returns ErrBuildFailed. Then every deploy waits for the new rollout: running is success, imagePullBackoff is a definitive failure, and a crash seen on 3 consecutive polls is treated as one too; both return ErrDeployFailed. Other transient states (pending) keep polling.

since is the app's state before an update (nil for a create, which has no previous build or rollout to mistake for this one). With it set, a succeeded build counts only once lastBuiltAt moves past since, a failed one only once it is shown to be new, and the runtime status only once lastDeployedAt moves past since. lastDeployedAt is the creation time of the Deployment's newest ReplicaSet; the operator stamps hostim.dev/restarted-at into the pod template on every rebuild, so every deploy creates a new one.

type VolumeMount added in v0.1.22

type VolumeMount = struct {
	MountPath *string `json:"mountPath,omitempty"`
	Name      *string `json:"name,omitempty"`
}

VolumeMount matches the anonymous struct type of App.VolumeMounts, so it can be assigned directly.

func ParseVolumeMounts added in v0.1.22

func ParseVolumeMounts(specs []string) ([]VolumeMount, error)

ParseVolumeMounts turns "name:/mount/path" values into app volume mounts.

Jump to

Keyboard shortcuts

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