client

package
v0.6.56 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const EnvToken = "DPLOYR_TOKEN"

EnvToken is the environment variable checked before config for CI usage.

Variables

This section is empty.

Functions

func ReleaseAssetURL added in v0.6.53

func ReleaseAssetURL(tag, goos, goarch string) (archiveURL, binaryInArchive string, err error)

ReleaseAssetURL constructs the GitHub release asset URL for the given version, OS, and architecture, matching the GoReleaser archive naming convention: dployr-{OS}-{arch}.tar.gz (or .zip on Windows)

Types

type ApiToken

type ApiToken struct {
	ID         string    `json:"id"`
	Name       string    `json:"name"`
	Scopes     []string  `json:"scopes"`
	CreatedAt  UnixTime  `json:"createdAt"`
	ExpiresAt  *UnixTime `json:"expiresAt,omitempty"`
	LastUsedAt *UnixTime `json:"lastUsedAt,omitempty"`
}

ApiToken is a scoped personal access token (dpat_).

type Client

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

Client is a typed HTTP client for the dployr-base API.

func New

func New(cfg *config.Config) *Client

func (*Client) AcceptInvite

func (c *Client) AcceptInvite(ctx context.Context, clusterName string) error

AcceptInvite accepts a cluster invite identified by cluster name.

func (*Client) AddClusterUsers

func (c *Client) AddClusterUsers(ctx context.Context, clusterName string, emails []string, role string) error

AddClusterUsers invites users to a cluster with a given role.

func (*Client) AddInstanceDomain

func (c *Client) AddInstanceDomain(ctx context.Context, name, domain string) error

AddInstanceDomain configures a custom domain on an instance.

func (*Client) Cluster

func (c *Client) Cluster() string

Cluster returns the active cluster name for this client.

func (*Client) CreateDeployment

func (c *Client) CreateDeployment(ctx context.Context, req CreateDeploymentRequest) (CreateDeploymentResult, error)

CreateDeployment submits a new deployment and returns the task ID.

func (*Client) CreateToken

func (c *Client) CreateToken(ctx context.Context, name string, scopes []string, expiresIn *int) (CreatedApiToken, error)

CreateToken creates a new scoped personal access token. The returned CreatedApiToken includes the plaintext — it is shown only once.

func (*Client) DeclineInvite

func (c *Client) DeclineInvite(ctx context.Context, clusterName string) error

DeclineInvite declines a cluster invite identified by cluster name.

func (*Client) DeleteDeployment

func (c *Client) DeleteDeployment(ctx context.Context, id string) error

DeleteDeployment removes a deployment by ID.

func (*Client) DeleteInstance

func (c *Client) DeleteInstance(ctx context.Context, id string) error

DeleteInstance removes an instance.

func (*Client) DeleteService

func (c *Client) DeleteService(ctx context.Context, id string) error

DeleteService deletes a service and its associated resources.

func (*Client) ExchangeOIDCToken

func (c *Client) ExchangeOIDCToken(ctx context.Context, token string) (string, error)

ExchangeOIDCToken exchanges a CI-issued OIDC token for a dployr session ID. Corresponds to POST /v1/auth/oidc/exchange.

func (*Client) Get2FAStatus added in v0.6.54

func (c *Client) Get2FAStatus(ctx context.Context) (TwoFAStatus, error)

Get2FAStatus returns the current user's 2FA configuration.

func (*Client) GetCluster

func (c *Client) GetCluster(ctx context.Context, name string) (Cluster, error)

GetCluster returns a cluster by name by scanning the user's cluster list. There is no dedicated GET /:id endpoint — name lookup is done client-side.

func (*Client) GetDeployment

func (c *Client) GetDeployment(ctx context.Context, id string) (Deployment, error)

GetDeployment returns a single deployment by ID.

func (*Client) GetInstance

func (c *Client) GetInstance(ctx context.Context, id string) (Instance, error)

GetInstance returns a single instance by ID. The server returns { "success": true, "data": <instance> } with the instance directly as the data value (no intermediate field name).

func (*Client) GetLatestVersion added in v0.6.53

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

GetLatestVersion fetches the latest CLI version from /v1/runtime/versions.

func (*Client) GetLogs

func (c *Client) GetLogs(ctx context.Context, q LogQuery) ([]LogChunk, error)

GetLogs fetches historical log entries for a service.

TODO: Wire to GET /v1/services/:id/logs once the centralized log API is finalized. Expected query params: source, since (RFC3339), limit.

func (*Client) GetService

func (c *Client) GetService(ctx context.Context, id string) (Service, error)

GetService returns a service by ID.

func (*Client) ListClusterUsers

func (c *Client) ListClusterUsers(ctx context.Context, clusterName string) ([]ClusterUser, error)

ListClusterUsers returns all users in a cluster identified by name.

func (*Client) ListClusters

func (c *Client) ListClusters(ctx context.Context) ([]Cluster, error)

ListClusters returns all clusters the authenticated user belongs to.

func (*Client) ListDeployments

func (c *Client) ListDeployments(ctx context.Context, limit int) ([]Deployment, error)

ListDeployments returns deployments in the active cluster.

func (*Client) ListInstances

func (c *Client) ListInstances(ctx context.Context, limit int) ([]Instance, error)

ListInstances returns instances visible to the authenticated user.

func (*Client) ListInvites

func (c *Client) ListInvites(ctx context.Context) ([]PendingInvite, error)

ListInvites returns pending cluster invites for the authenticated user.

func (*Client) ListServices

func (c *Client) ListServices(ctx context.Context, limit int) ([]Service, error)

ListServices returns services in the active cluster.

func (*Client) ListTokens

func (c *Client) ListTokens(ctx context.Context) ([]ApiToken, error)

ListTokens returns all personal access tokens for the authenticated user.

func (*Client) Logout

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

Logout invalidates the current session. Corresponds to GET /v1/auth/logout.

func (*Client) Me

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

Me returns the current authenticated user's profile. Corresponds to GET /v1/users/me.

func (*Client) PingInstance

func (c *Client) PingInstance(ctx context.Context, name string) error

PingInstance sends a health ping to the instance daemon.

func (*Client) RawResponse

func (c *Client) RawResponse(ctx context.Context, method, path string, query url.Values, body any) (*http.Response, error)

RawResponse returns the raw *http.Response for callers that need to handle streaming or custom decoding (e.g. WebSocket upgrade).

func (*Client) RemoveClusterUsers

func (c *Client) RemoveClusterUsers(ctx context.Context, clusterName string, userIDs []string) error

RemoveClusterUsers removes users from a cluster.

func (*Client) RequestEmailOTP

func (c *Client) RequestEmailOTP(ctx context.Context, email string) (requireTotp bool, err error)

RequestEmailOTP sends an OTP to the given email address and returns whether the account requires TOTP instead of an email code. Corresponds to POST /v1/auth/login/email.

func (*Client) RevokeToken

func (c *Client) RevokeToken(ctx context.Context, id string) error

RevokeToken deletes a token by ID.

func (*Client) RotateInstanceToken

func (c *Client) RotateInstanceToken(ctx context.Context, instanceID string) error

RotateInstanceToken rotates the access token for an instance.

func (*Client) StartService

func (c *Client) StartService(ctx context.Context, id string) error

StartService wakes a sleeping service.

func (*Client) StopService

func (c *Client) StopService(ctx context.Context, id string) error

StopService stops (sleeps) a service.

func (*Client) StreamLogs

func (c *Client) StreamLogs(ctx context.Context, serviceID, source string, onChunk func(LogChunk)) error

StreamLogs opens a server-sent events (or newline-delimited JSON) stream for real-time log output from both build and instance nodes.

TODO: The streaming endpoint and wire format will be confirmed once the centralized logging implementation in dployr-base is finalized. Candidate endpoints:

  • GET /v1/services/:id/logs?follow=true (SSE / ndjson)
  • WS /v1/ws/logs/:serviceId (WebSocket, LogSubscribeRequest protocol)

onChunk is called for each received LogChunk. The stream ends when ctx is cancelled or the server closes the connection.

func (*Client) SystemReboot

func (c *Client) SystemReboot(ctx context.Context, instanceID string, force bool) error

SystemReboot reboots the underlying machine.

func (*Client) SystemRestart

func (c *Client) SystemRestart(ctx context.Context, instanceID string, force bool) error

SystemRestart restarts the dployrd daemon on the instance.

func (*Client) UpdateCluster

func (c *Client) UpdateCluster(ctx context.Context, name, newName string) (Cluster, error)

UpdateCluster renames a cluster. Resolves the cluster name to its ID first since the rename endpoint requires the cluster UUID.

func (*Client) Verify2FA added in v0.6.54

func (c *Client) Verify2FA(ctx context.Context, code string) error

Verify2FA submits a TOTP code (or backup code) and marks the session as 2FA-verified. Corresponds to POST /v1/auth/2fa/verify.

func (*Client) VerifyEmailOTP

func (c *Client) VerifyEmailOTP(ctx context.Context, email, code string) (string, error)

VerifyEmailOTP submits the OTP code and returns the session cookie on success. Corresponds to POST /v1/auth/login/email/verify.

func (*Client) WithCluster

func (c *Client) WithCluster(name string) *Client

WithCluster returns a copy of the client scoped to a specific cluster name.

type Cluster

type Cluster struct {
	ID        string   `json:"id"`
	Name      string   `json:"name"`
	Owner     string   `json:"owner,omitempty"`
	Role      string   `json:"role,omitempty"` // owner | admin | developer | viewer
	CreatedAt UnixTime `json:"createdAt"`
	UpdatedAt UnixTime `json:"updatedAt"`
}

type ClusterUser

type ClusterUser struct {
	ID    string `json:"id"`
	Email string `json:"email"`
	Name  string `json:"name"`
	Role  string `json:"role"` // owner | admin | developer | viewer
}

type CreateDeploymentRequest

type CreateDeploymentRequest struct {
	Name             string            `json:"name"`
	Description      string            `json:"description,omitempty"`
	Source           string            `json:"source"` // remote | image
	Type             string            `json:"type,omitempty"`
	RuntimeType      string            `json:"runtimeType"`
	RuntimeVersion   string            `json:"runtimeVersion,omitempty"`
	RunCmd           string            `json:"runCmd,omitempty"`
	BuildCmd         string            `json:"buildCmd,omitempty"`
	Port             int               `json:"port,omitempty"`
	WorkingDir       string            `json:"workingDir,omitempty"`
	StaticDir        string            `json:"staticDir,omitempty"`
	HealthCheck      string            `json:"healthCheck,omitempty"`
	Image            string            `json:"image,omitempty"`
	Domain           string            `json:"domain,omitempty"`
	RemoteURL        string            `json:"remoteUrl,omitempty"`
	RemoteBranch     string            `json:"remoteBranch,omitempty"`
	RemoteCommitHash string            `json:"remoteCommitHash,omitempty"`
	EnvVars          map[string]string `json:"envVars,omitempty"`
	Secrets          map[string]string `json:"secrets,omitempty"`
	ForceRebuild     bool              `json:"forceRebuild,omitempty"`
}

type CreateDeploymentResult

type CreateDeploymentResult struct {
	TaskID string `json:"taskId"`
	Cached bool   `json:"cached,omitempty"`
}

type CreatedApiToken

type CreatedApiToken struct {
	ApiToken
	Token string `json:"token"`
}

CreatedApiToken is returned once on token creation — includes the plaintext.

type Deployment

type Deployment struct {
	ID               string    `json:"id"`
	ClusterID        string    `json:"clusterId"`
	ServiceID        string    `json:"serviceId"`
	UserID           string    `json:"userId"`
	Name             string    `json:"name"`
	Type             string    `json:"type"`
	Source           string    `json:"source"` // remote | image
	Status           string    `json:"status"` // pending | running | success | failed
	Description      string    `json:"description"`
	RunCmd           string    `json:"runCmd"`
	BuildCmd         string    `json:"buildCmd"`
	Port             int       `json:"port"`
	WorkingDir       string    `json:"workingDir"`
	StaticDir        string    `json:"staticDir"`
	Image            string    `json:"image"`
	Domain           string    `json:"domain"`
	RuntimeType      string    `json:"runtimeType"`
	RuntimeVersion   string    `json:"runtimeVersion"`
	RemoteURL        string    `json:"remoteUrl"`
	RemoteBranch     string    `json:"remoteBranch"`
	RemoteCommitHash string    `json:"remoteCommitHash"`
	CreatedAt        UnixTime  `json:"createdAt"`
	UpdatedAt        UnixTime  `json:"updatedAt"`
	FinishedAt       *UnixTime `json:"finishedAt,omitempty"`
}

type ErrTwoFARequired added in v0.6.54

type ErrTwoFARequired struct{}

ErrTwoFARequired is returned when the server responds with auth.two_fa_required (HTTP 403). Callers can detect this with errors.Is to prompt the user for a TOTP code and retry.

func (ErrTwoFARequired) Error added in v0.6.54

func (ErrTwoFARequired) Error() string

type Instance

type Instance struct {
	ID        string   `json:"id"`
	Kind      string   `json:"kind"` // dedicated | pool
	ClusterID *string  `json:"clusterId,omitempty"`
	Address   string   `json:"address"`
	Tag       string   `json:"tag"`
	Status    string   `json:"status"` // healthy | degraded | offline | unreachable | maintenance | provisioning
	Role      string   `json:"role"`   // instance | build
	Managed   bool     `json:"managed"`
	Region    string   `json:"region,omitempty"`
	CreatedAt UnixTime `json:"createdAt"`
	UpdatedAt UnixTime `json:"updatedAt"`
}

type LogChunk

type LogChunk struct {
	Timestamp UnixTime `json:"timestamp"`
	Source    string   `json:"source"` // build | runtime
	Level     string   `json:"level"`  // info | warn | error
	Message   string   `json:"message"`
}

LogChunk is a single log entry returned from the log API.

type LogQuery

type LogQuery struct {
	ServiceID string
	Source    string    // build | runtime | all (default: all)
	Since     time.Time // zero means no filter
	Limit     int       // 0 means server default
}

LogQuery parameters for historical log retrieval. The API endpoint and exact field names will be confirmed once the centralized logging implementation in dployr-base is finalized.

type LogSubscribeRequest

type LogSubscribeRequest struct {
	Kind      string `json:"kind"` // "log_subscribe"
	ServiceID string `json:"serviceId"`
	Source    string `json:"source"` // build | runtime | all
}

LogSubscribeRequest is sent over WebSocket to subscribe to a service log stream.

type LoginEmailRequest

type LoginEmailRequest struct {
	Email string `json:"email"`
}

LoginEmailRequest is the body for POST /v1/auth/login/email.

type Me

type Me struct {
	ID       string `json:"id"`
	Email    string `json:"email"`
	Name     string `json:"name"`
	Picture  string `json:"picture,omitempty"`
	Provider string `json:"provider"`
}

type PendingInvite

type PendingInvite struct {
	ClusterID   string `json:"clusterId"`
	ClusterName string `json:"clusterName"`
	OwnerName   string `json:"ownerName"`
}

PendingInvite is returned by GET /v1/clusters/users/invites.

type Service

type Service struct {
	ID             string    `json:"id"`
	ClusterID      string    `json:"clusterId"`
	Name           string    `json:"name"`
	Label          string    `json:"label"`
	Type           string    `json:"type"` // static | web | worker | job
	DeploymentID   *string   `json:"deploymentId,omitempty"`
	DeploymentName *string   `json:"deploymentName,omitempty"`
	IcedAt         *UnixTime `json:"icedAt,omitempty"`
	CreatedAt      UnixTime  `json:"createdAt"`
	UpdatedAt      UnixTime  `json:"updatedAt"`
}

type TwoFAStatus added in v0.6.54

type TwoFAStatus struct {
	Method               string `json:"method"`
	TotpEnabled          bool   `json:"totpEnabled"`
	BackupCodesRemaining int    `json:"backupCodesRemaining"`
}

TwoFAStatus mirrors GET /v1/auth/2fa/status.

type UnixTime

type UnixTime time.Time

UnixTime is a time.Time that unmarshals from either a Unix timestamp (ms or s) or an RFC3339 string, matching the server's D1/SQLite storage format.

func (UnixTime) IsZero

func (t UnixTime) IsZero() bool

func (UnixTime) MarshalJSON

func (t UnixTime) MarshalJSON() ([]byte, error)

func (UnixTime) Time

func (t UnixTime) Time() time.Time

func (*UnixTime) UnmarshalJSON

func (t *UnixTime) UnmarshalJSON(data []byte) error

type VerifyEmailRequest

type VerifyEmailRequest struct {
	Email string `json:"email"`
	Code  string `json:"code"`
}

VerifyEmailRequest is the body for POST /v1/auth/login/email/verify.

type VersionsResponse added in v0.6.53

type VersionsResponse struct {
	Latest                 string   `json:"latest"`
	OldestSupportedVersion string   `json:"oldestSupportedVersion"`
	Versions               []string `json:"versions"`
	IncludePreReleases     bool     `json:"includePreReleases"`
}

VersionsResponse mirrors the /runtime/versions response data.

Jump to

Keyboard shortcuts

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