client

package
v1.0.0-beta.37 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 26 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 talks to the hub API for the CLI and the TUI.

Index

Constants

View Source
const DefaultURL = "https://moin.run"

DefaultURL is the hosted hub.

View Source
const FromDirectory = "the directory name"

FromDirectory says an app name came from the name of the directory.

View Source
const MovedHeader = "X-Hub-URL"

MovedHeader names the hub's address in an answer to a request that came on an old one.

Variables

View Source
var ErrLoginEnded = errors.New("your login ended: run `" + build.Name + " login` again")

ErrLoginEnded is a connection the hub ended: removed in Settings, unused for 90 days, or its refresh token used twice.

View Source
var ErrNotLoggedIn = errors.New("not logged in: run `" + build.Name + " login`")

ErrNotLoggedIn means there is no token in the environment or config file.

View Source
var TokenVariable = strings.ToUpper(build.Name) + "_TOKEN"

TokenVariable overrides the saved token, for CI.

Functions

func AppName

func AppName(flagValue, dir string) string

AppName picks the app: the flag, or the name of the directory.

func CheckURL

func CheckURL(raw string) error

CheckURL refuses a hub URL the token would cross the internet in plain text to. http is fine on this machine and on a tailnet, which Tailscale already encrypts; everywhere else it must be https.

func IsClientOutdated

func IsClientOutdated(err error) bool

IsClientOutdated reports whether the hub refused this moin as too old. The message says how to update.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether err is a not_found answer.

func IsReadOnlyQuery

func IsReadOnlyQuery(err error) bool

IsReadOnlyQuery reports whether a read query was refused because it changes data.

func Logout

func Logout(ctx context.Context, config Config) error

Logout ends the connection of config at the hub, so its tokens stop working, before the config is forgotten. A CI token stays: it belongs to Settings.

func OriginRepo

func OriginRepo(dir string) string

OriginRepo is owner/name of the GitHub repo of dir's remote origin, "" when it has none.

func Percent

func Percent(value *float64) string

Percent is an uptime for people: "99.95%", or "-" without a visit.

func PickApp

func PickApp(flagValue, dir string) (name, from string)

PickApp is AppName that also says where the name came from: "--app" or FromDirectory.

func PushedCommit

func PushedCommit(dir string) (repo, commit string, err error)

PushedCommit is what `moin deploy` deploys from dir: the GitHub repo of its remote origin, as owner/name, and the commit HEAD is at. The server builds that commit from GitHub, so it fails, saying what to do, unless dir is the top folder of a GitHub repo with every change committed and pushed.

func RemoveConfig

func RemoveConfig() error

RemoveConfig deletes the config file.

func SaveConfig

func SaveConfig(config Config) error

SaveConfig writes the config file, readable only by the user.

func Share

func Share(used, total float64) string

Share is used of total in percent, like 42%; "-" without a total.

func Sparkline

func Sparkline(values []float64, width int) string

Sparkline draws values as a line of block characters from the lowest to the highest, at most width of them: more values average into width.

func ViaLabel

func ViaLabel(via, token string) string

ViaLabel names how a change came in, with the connection or CI token it came with: "CLI, token ci". The web shows the same label as the CLI.

Types

type Account

type Account struct {
	Email string `json:"email"`
	Name  string `json:"name"`
	// EmailAlerts mails the user when a site or a server goes down or
	// comes back, or a deploy fails.
	EmailAlerts bool `json:"email_alerts"`
}

Account is the signed-in user.

type ActivityPage

type ActivityPage struct {
	Items []Event
	Next  string
}

ActivityPage is a page of the activity, newest first. Next continues with older events and is empty on the last page.

type ActivityQuery

type ActivityQuery struct {
	App, Server, User, Cursor string
	Limit                     int
}

ActivityQuery picks a page of the activity: up to Limit events, after the cursor of the page before, of one app, server or member (an email).

type AlertDestination

type AlertDestination struct {
	ID           string     `json:"id"`
	Name         string     `json:"name"`
	Kind         string     `json:"kind"`
	Hint         string     `json:"hint"`
	ChatID       string     `json:"chat_id"`
	Events       []string   `json:"events"`
	Failing      bool       `json:"failing"`
	FailingSince *time.Time `json:"failing_since"`
	LastError    string     `json:"last_error"`
	LastSentAt   *time.Time `json:"last_sent_at"`
	CreatedAt    time.Time  `json:"created_at"`
	// SigningSecret comes only with a new webhook.
	SigningSecret string `json:"signing_secret,omitempty"`
}

AlertDestination is where the alerts of the workspace go besides email: Slack, Discord, Telegram or a webhook. Hint shows its host and last characters, never the URL or token.

type App

type App struct {
	ID           string   `json:"id"`
	Name         string   `json:"name"`
	ServerID     string   `json:"server_id"`
	ServerName   string   `json:"server_name"`
	LatestNumber int      `json:"latest_number"`
	LatestStatus string   `json:"latest_status"`
	LiveNumber   int      `json:"live_number"`
	Domains      []string `json:"domains"`
	Canonical    string   `json:"canonical"`
	// Password says the app's password is on: its domains and its
	// instant address ask for it.
	Password bool `json:"password"`
	// ServiceDomains are the domains of the app's other services.
	ServiceDomains map[string][]string `json:"service_domains"`
	// Instant is the instant address, "" when the app has none. The
	// app's password guards it like the app's domains.
	Instant         string `json:"instant"`
	InstantProvider string `json:"instant_provider"`
	Stopped         bool   `json:"stopped"`
	// ChangesWaiting counts the changes saved since the live deploy
	// started; a restart applies them. Only App fills it.
	ChangesWaiting int `json:"changes_waiting"`
	// Repo and Branch are the GitHub repo the app follows, if any.
	Repo       string `json:"repo"`
	Branch     string `json:"branch"`
	AutoDeploy bool   `json:"auto_deploy"`
	Pinned     bool   `json:"pinned"`
	// Hook says the app has a deploy hook URL.
	Hook bool `json:"hook"`
	// DeployFrom is ci or github, where new versions come from; empty
	// while neither is set up.
	DeployFrom string `json:"deploy_from"`
	// HookImage is the image the hook deploys new tags of, the one running
	// now; empty while the app runs from its repo.
	HookImage string `json:"hook_image"`
	// Bucket is the bucket the app backs up to; empty follows
	// the workspace's default.
	Bucket string `json:"bucket"`
	// Catalog is the catalog entry the app was installed from; empty for
	// an app of your own.
	Catalog   string    `json:"catalog"`
	CreatedAt time.Time `json:"created_at"`
}

App is a compose project on a server, as the API answers it.

func (App) Status

func (a App) Status() string

Status is "live v3", "deploying v4", "failed v4 · v3 live" or "new".

type AppBackups

type AppBackups struct {
	Bucket string `json:"bucket"`
	BackupSchedule
	Databases []DatabaseBackups `json:"databases"`
}

AppBackups are the backups of an app's databases: the bucket the copies go to, the user's own, the schedule and each database.

type AppDetail

type AppDetail struct {
	App     App      `json:"app"`
	Deploys []Deploy `json:"deploys"`
}

AppDetail is an app with its newest deploys.

type AppMetrics

type AppMetrics struct {
	App          string         `json:"app"`
	Server       string         `json:"server"`
	ServerOnline bool           `json:"server_online"`
	Range        string         `json:"range"`
	StepSeconds  int            `json:"step_seconds"`
	Now          *AppMetricsNow `json:"now"`
	Points       []MetricsPoint `json:"points"`
	Deploys      []DeployMark   `json:"deploys"`
}

AppMetrics are the metrics of an app: now, over a range, and the deploys that went live in it.

type AppMetricsNow

type AppMetricsNow struct {
	At          time.Time `json:"at"`
	CPU         float64   `json:"cpu"`
	MemoryUsed  uint64    `json:"memory_used"`
	MemoryLimit uint64    `json:"memory_limit"`
	NetRx       float64   `json:"net_rx"`
	NetTx       float64   `json:"net_tx"`
	Containers  int       `json:"containers"`
}

AppMetricsNow is the newest sample of an app; a MemoryLimit of 0 is none.

type BackupSchedule

type BackupSchedule struct {
	EveryMinutes int `json:"every_minutes"`
	KeepDays     int `json:"keep_days"`
}

BackupSchedule is how an app is backed up: a copy every EveryMinutes, each kept KeepDays.

type Bucket

type Bucket struct {
	Name         string     `json:"name"`
	Default      bool       `json:"default"`
	Endpoint     string     `json:"endpoint"`
	Region       string     `json:"region"`
	Bucket       string     `json:"bucket"`
	Path         string     `json:"path"`
	Folder       string     `json:"folder,omitempty"`
	AccessKey    string     `json:"access_key"`
	Apps         []string   `json:"apps,omitempty"`
	OlderBackups []string   `json:"older_backups,omitempty"`
	CreatedAt    time.Time  `json:"created_at"`
	Servers      []SecretOn `json:"servers,omitempty"`
	MissingOn    []string   `json:"missing_on,omitempty"`
}

Bucket is one bucket of the workspace, without its secret key, which only the servers keep: Servers say which, MissingOn which do not. Apps use it now; OlderBackups moved away and keep older backups there.

func (Bucket) Input

func (b Bucket) Input() BucketInput

Input is the bucket as it is, to change some of it.

type BucketInput

type BucketInput struct {
	Server    string `json:"server,omitempty"`
	Name      string `json:"name"`
	Endpoint  string `json:"endpoint"`
	Region    string `json:"region"`
	Bucket    string `json:"bucket"`
	Path      string `json:"path"`
	AccessKey string `json:"access_key"`
	SecretKey string `json:"secret_key"`
	Default   bool   `json:"default"`
}

BucketInput adds or changes a bucket. Server tests it and keeps the secret key, empty for the workspace's only server. On a change an empty Name keeps the name and an empty SecretKey the key the server keeps.

type CIToken

type CIToken struct {
	ID         string     `json:"id"`
	Name       string     `json:"name"`
	Prefix     string     `json:"prefix"`
	Rights     []string   `json:"rights"`
	App        *string    `json:"app"`
	CreatedBy  string     `json:"created_by"`
	LastUsedAt *time.Time `json:"last_used_at"`
	ExpiresAt  *time.Time `json:"expires_at"`
	Expired    bool       `json:"expired"`
}

CIToken is a token made by hand for CI, as the API answers it.

type CatalogDeploy

type CatalogDeploy struct {
	App    App    `json:"app"`
	Deploy Deploy `json:"deploy"`
	// Login, only from an install, holds the secrets the first sign-in
	// needs, such as ADMIN_PASSWORD: the one time they are shown.
	Login map[string]string `json:"login"`
	// Password, only from an install, is the app's password, user moin,
	// which its domains and its instant address ask for: the one time
	// moin shows it.
	Password string `json:"password"`
}

CatalogDeploy is an installed or updated app and its started deploy.

type CatalogEntry

type CatalogEntry struct {
	Slug     string `json:"slug"`
	Name     string `json:"name"`
	Pitch    string `json:"pitch"`
	Category string `json:"category"`
	Website  string `json:"website"`
	Source   string `json:"source"`
	License  string `json:"license"`
	Image    string `json:"image"`
	Database string `json:"database"`
	// DatabaseNote says when moin does not back up the app's database.
	DatabaseNote string `json:"database_note"`
	Login        string `json:"login"`
	// NeedsDomain says the install needs --domain.
	NeedsDomain bool             `json:"needs_domain"`
	Secrets     []string         `json:"secrets"`
	Latest      *CatalogVersion  `json:"latest"`
	Versions    []CatalogVersion `json:"versions"`
}

CatalogEntry is an open source app moin installs in one click. Versions is only set by CatalogApp.

type CatalogInstall

type CatalogInstall struct {
	Server  string `json:"server"`
	Version string `json:"version,omitempty"`
	Name    string `json:"name,omitempty"`
	Domain  string `json:"domain,omitempty"`
}

CatalogInstall installs a catalog app; the empty fields take the newest release, the slug and no domain.

type CatalogVersion

type CatalogVersion struct {
	Tag  string     `json:"tag"`
	Date *time.Time `json:"date"`
}

CatalogVersion is a release of a catalog app; Date is nil when the registry does not say.

type Change

type Change struct {
	App App `json:"app"`
	// Unchanged is set when the app had it so already; nothing restarts.
	Unchanged bool `json:"unchanged"`
}

Change is the app after a change of its settings. Saving never restarts it: the next restart, start or deploy applies the change.

type Client

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

Client calls the hub as a connection or with a CI token.

func New

func New(config Config) (*Client, error)

New returns a client for the config, or ErrNotLoggedIn.

func (*Client) Account

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

Account returns the user the token belongs to.

func (*Client) Activity

func (c *Client) Activity(ctx context.Context, query ActivityQuery) (ActivityPage, error)

Activity returns a page of the token's workspace activity, newest first.

func (*Client) AddAlertDestination

func (c *Client) AddAlertDestination(ctx context.Context, destination NewAlertDestination) (AlertDestination, error)

AddAlertDestination adds an alert destination; a webhook comes back with its signing secret.

func (*Client) AddApp

func (c *Client) AddApp(ctx context.Context, name, server string) (CreatedApp, error)

AddApp creates an app on a server.

func (*Client) AddBucket

func (c *Client) AddBucket(ctx context.Context, input BucketInput) (Bucket, error)

AddBucket checks and stores a new bucket.

func (*Client) AddServer

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

AddServer creates a server and the install token for its daemon.

func (*Client) AlertDestinations

func (c *Client) AlertDestinations(ctx context.Context) ([]AlertDestination, error)

AlertDestinations lists the alert destinations of the workspace.

func (*Client) App

func (c *Client) App(ctx context.Context, app string) (AppDetail, error)

App returns an app with its newest deploys.

func (*Client) AppMetrics

func (c *Client) AppMetrics(ctx context.Context, app, rangeName string) (AppMetrics, error)

AppMetrics returns the metrics of an app over a range: 1h, 24h, 7d or 30d, "" for 1h.

func (*Client) Apps

func (c *Client) Apps(ctx context.Context) ([]App, error)

Apps lists the apps of the account.

func (*Client) Backups

func (c *Client) Backups(ctx context.Context, app string) (AppBackups, error)

Backups lists the backups of an app with the moments to go back to.

func (*Client) Bucket

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

Bucket returns one bucket by name.

func (*Client) Buckets

func (c *Client) Buckets(ctx context.Context) ([]Bucket, error)

Buckets lists the workspace's buckets, the default first.

func (*Client) CITokens

func (c *Client) CITokens(ctx context.Context) ([]CIToken, error)

CITokens lists the CI tokens of the workspace you see.

func (*Client) Catalog

func (c *Client) Catalog(ctx context.Context) ([]CatalogEntry, error)

Catalog lists the catalog with each app's newest release.

func (*Client) CatalogApp

func (c *Client) CatalogApp(ctx context.Context, slug string) (CatalogEntry, error)

CatalogApp returns a catalog app with every release, newest first.

func (*Client) CheckDomains

func (c *Client) CheckDomains(ctx context.Context, app string) ([]DomainCheck, error)

CheckDomains looks up every domain of an app.

func (*Client) ComposeFile

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

ComposeFile answers the compose file of the app's live deploy.

func (*Client) Connections

func (c *Client) Connections(ctx context.Context) ([]Connection, error)

Connections lists the connections of the workspace this login is in, this one marked Current.

func (*Client) DaemonUpdates

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

DaemonUpdates reports whether the daemons of the workspace update to the hub's version by themselves.

func (*Client) DeployImage

func (c *Client) DeployImage(ctx context.Context, app, image, ref string) (Deploy, error)

DeployImage deploys an image built elsewhere as the app's main service. An app that follows a GitHub repo takes the compose file of ref there; an empty ref is the linked branch.

func (*Client) DeployRef

func (c *Client) DeployRef(ctx context.Context, app, ref string) (Deploy, error)

DeployRef deploys a branch, tag or commit of the app's GitHub repo; an empty ref deploys the linked branch.

func (*Client) Download

func (c *Client) Download(ctx context.Context, app, database, moment string) (Download, error)

Download signs a link to a copy of a database: the newest, or the one moment names.

func (*Client) EditBucket

func (c *Client) EditBucket(ctx context.Context, name string, input BucketInput) (Bucket, error)

EditBucket changes a bucket.

func (*Client) Env

func (c *Client) Env(ctx context.Context, app string) ([]EnvVar, error)

Env lists the env vars of an app, by key.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, app, service string, argv []string, line string, timeout int, output func(string)) (ExecResult, error)

Exec runs a command in a container of an app and hands what it writes to output as it comes. argv is the command as words; line, used when argv is empty, is one line the hub splits like a shell quotes it.

func (*Client) FetchCopy

func (c *Client) FetchCopy(ctx context.Context, link string, out io.Writer) error

FetchCopy writes the copy a download link points to, in the user's own bucket, to out. It goes straight to the bucket, not to the hub.

func (*Client) FollowDeploy

func (c *Client) FollowDeploy(ctx context.Context, app string, number int, line func(string)) (Deploy, error)

FollowDeploy calls line for every log line of a deploy and returns the deploy once it ended.

func (*Client) GetDeploy

func (c *Client) GetDeploy(ctx context.Context, app string, number int) (Deploy, error)

GetDeploy returns one deploy with its whole log.

func (*Client) GitHub

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

GitHub returns the installations and the install link.

func (*Client) GitHubBranches

func (c *Client) GitHubBranches(ctx context.Context, repo string) ([]string, error)

GitHubBranches lists the branches of a repo, owner/name, the default branch first.

func (*Client) GitHubRepos

func (c *Client) GitHubRepos(ctx context.Context) ([]GitHubRepo, error)

GitHubRepos lists the repos moin may read.

func (*Client) InstallCatalogApp

func (c *Client) InstallCatalogApp(ctx context.Context, slug string, install CatalogInstall) (CatalogDeploy, error)

InstallCatalogApp creates the app from the catalog and deploys it.

func (*Client) Instant

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

Instant reports the app's instant address.

func (*Client) Integrations

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

Integrations says which keys are stored.

func (*Client) Invite

func (c *Client) Invite(ctx context.Context, email, role string) error

Invite emails an invitation to the token's workspace. role is member or admin.

func (*Client) LinkRepo

func (c *Client) LinkRepo(ctx context.Context, app, repo, branch string, autoDeploy bool) (App, error)

LinkRepo makes an app follow a repo and branch.

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, app string, tail int) ([]string, error)

Logs returns the last lines of an app's containers.

func (*Client) Meta

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

Meta returns the hub's name and version.

func (*Client) NewInstallCommand

func (c *Client) NewInstallCommand(ctx context.Context, idOrName string) (NewServer, error)

NewInstallCommand makes a new one-time install command for a server; the old one stops working.

func (*Client) Query

func (c *Client) Query(ctx context.Context, app, database, sql string, write bool, limit int) (protocol.DBResult, error)

Query runs SQL on an app's database. Without write it cannot change anything.

func (*Client) Redeploy

func (c *Client) Redeploy(ctx context.Context, app string) (Deploy, error)

Redeploy builds the newest source again with the env as it is now.

func (*Client) Registries

func (c *Client) Registries(ctx context.Context) ([]Registry, error)

Registries lists the workspace's registry logins.

func (*Client) RemoveAlertDestination

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

RemoveAlertDestination removes an alert destination by name or ID.

func (*Client) RemoveApp

func (c *Client) RemoveApp(ctx context.Context, app, confirm string) error

RemoveApp stops an app and removes it. Its data stays on the server. confirm is the app's name, typed out; the hub checks it.

func (*Client) RemoveBucket

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

RemoveBucket forgets a bucket nothing uses; what is in it stays. confirm is the bucket's name, typed out; the hub checks it.

func (*Client) RemoveCIToken

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

RemoveCIToken deletes a CI token.

func (*Client) RemoveConnection

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

RemoveConnection ends a connection and its tokens.

func (*Client) RemoveDeployHook

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

RemoveDeployHook turns the deploy hook off; its URL stops working.

func (*Client) RemovePassword

func (c *Client) RemovePassword(ctx context.Context, app string) (Change, error)

RemovePassword turns the app's password off.

func (*Client) RemoveRegistry

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

RemoveRegistry deletes the login for a registry host.

func (*Client) RemoveServer

func (c *Client) RemoveServer(ctx context.Context, idOrName, confirm string) (RemovedServer, error)

RemoveServer deletes a server by ID or name. Its daemon is disconnected and stays installed. An offline server goes with its apps. confirm is the server's name, typed out; the hub checks it.

func (*Client) RenameApp

func (c *Client) RenameApp(ctx context.Context, app, name string) (App, error)

RenameApp gives an app a new name. app is its name, ID or link.

func (*Client) RenameServer

func (c *Client) RenameServer(ctx context.Context, idOrName, name string) (Server, error)

RenameServer gives a server a new name and returns it.

func (*Client) RenameWorkspace

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

RenameWorkspace gives the workspace a new name.

func (*Client) ReplaceEnv

func (c *Client) ReplaceEnv(ctx context.Context, app string, env map[string]string) (dotenv.Change, error)

ReplaceEnv makes env every env var of the app, like one .env file: keys not in env are removed. It answers what changed, by key. The next deploy gets them.

func (*Client) ResendInvitation

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

ResendInvitation emails an open invitation again.

func (*Client) Restart

func (c *Client) Restart(ctx context.Context, app string) (Deploy, error)

Restart starts the live deploy again with the env and domains as they are now.

func (*Client) Restore

func (c *Client) Restore(ctx context.Context, app, database, moment string, at *time.Time, confirm string) error

Restore puts a database back to a moment from Backups, by its ID or label, or to a time: the newest copy at or before it. It waits until the daemon is done: a restore runs on its own on the hub, as a big database takes a while. confirm is the app's name as the user typed it; the hub refuses a restore without it.

func (*Client) RevokeInvitation

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

RevokeInvitation takes an open invitation back.

func (*Client) Rollback

func (c *Client) Rollback(ctx context.Context, app string, number int) (Deploy, error)

Rollback starts an earlier successful release again. Number 0 is the one before the live deploy.

func (*Client) RotateDeployHook

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

RotateDeployHook gives the app a new deploy hook URL; the old one stops working.

func (*Client) Rows

func (c *Client) Rows(ctx context.Context, app, database, table string, offset, limit int) (TableRows, error)

Rows returns one page of a table, newest first.

func (*Client) ServerMetrics

func (c *Client) ServerMetrics(ctx context.Context, server, rangeName string) (ServerMetrics, error)

ServerMetrics returns the metrics of a server over a range.

func (*Client) Servers

func (c *Client) Servers(ctx context.Context) ([]Server, error)

Servers lists the servers of the account.

func (*Client) SetAppBucket

func (c *Client) SetAppBucket(ctx context.Context, app, bucket string) (App, error)

SetAppBucket moves an app's new backups to a bucket; empty follows the workspace's default.

func (*Client) SetBackupSchedule

func (c *Client) SetBackupSchedule(ctx context.Context, app string, schedule BackupSchedule) (BackupSchedule, error)

SetBackupSchedule sets how often an app is copied and how long each copy stays.

func (*Client) SetBucketKey

func (c *Client) SetBucketKey(ctx context.Context, name, server, secretKey string) (Bucket, error)

SetBucketKey hands one more server the secret key of a bucket; it tests the bucket with it first.

func (*Client) SetDaemonUpdates

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

SetDaemonUpdates turns automatic daemon updates on or off.

func (*Client) SetDomains

func (c *Client) SetDomains(ctx context.Context, app string, domains []string, canonical string) (Change, error)

SetDomains replaces the domains and the canonical one ("" for none).

func (*Client) SetEmailAlerts

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

SetEmailAlerts turns the email alerts of the signed-in user on or off.

func (*Client) SetEnv

func (c *Client) SetEnv(ctx context.Context, app string, set map[string]string, unset []string) ([]EnvVar, error)

SetEnv sets and removes env vars and answers them all, by key. The next deploy gets them.

func (*Client) SetInstant

func (c *Client) SetInstant(ctx context.Context, app, provider string) (Change, error)

SetInstant picks the provider of the instant address, or off.

func (*Client) SetIntegrations

func (c *Client) SetIntegrations(ctx context.Context, cloudflareToken, tailscaleKey *string, server string) (Integrations, error)

SetIntegrations stores keys; a nil one stays, an empty one is removed. The Tailscale key goes to server, which keeps it; empty is the workspace's only server.

func (*Client) SetPassword

func (c *Client) SetPassword(ctx context.Context, app, username, password string) (NewPassword, error)

SetPassword turns the app's password on for its domains and its instant address. An empty password lets moin make one.

func (*Client) SetPinned

func (c *Client) SetPinned(ctx context.Context, app string, pinned bool) (App, error)

SetPinned pins an app, or unpins it, and returns it.

func (*Client) SetRegistry

func (c *Client) SetRegistry(ctx context.Context, host, username, password, server string) error

SetRegistry hands the login for a registry host to a server, which keeps it; an empty server is the workspace's only one.

func (*Client) SetSecurity

func (c *Client) SetSecurity(ctx context.Context, server string, security Security) (Server, error)

SetSecurity applies the settings and returns the server with what its daemon set up.

func (*Client) SetServiceDomains

func (c *Client) SetServiceDomains(ctx context.Context, app, service string, domains []string) (Change, error)

SetServiceDomains replaces the domains of another service of the app.

func (*Client) SetUptime

func (c *Client) SetUptime(ctx context.Context, app, domain string, path *string, paused *bool) (UptimeDomain, error)

SetUptime changes the path of a domain's visit, nil keeps it and "" goes back to /, and pauses or resumes it, nil keeps it.

func (*Client) Start

func (c *Client) Start(ctx context.Context, app string) (Deploy, error)

Start runs a stopped app again.

func (*Client) Status

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

Status asks whether everything is OK.

func (*Client) Stop

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

Stop takes the app offline until it starts again. Its data stays.

func (*Client) Tables

func (c *Client) Tables(ctx context.Context, app, database string) (protocol.DBTables, error)

Tables lists the tables of an app's database; "" is the first one.

func (*Client) Team

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

Team returns the workspace the token belongs to.

func (*Client) TestAlertDestination

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

TestAlertDestination sends a test alert to a destination.

func (*Client) URL

func (c *Client) URL() string

URL is the hub this client talks to, without a slash at the end.

func (*Client) UnlinkRepo

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

UnlinkRepo stops an app from following its repo.

func (*Client) UpdateApp

func (c *Client) UpdateApp(ctx context.Context, app, version string) (CatalogDeploy, error)

UpdateApp sets a catalog app to version, the newest when empty, and deploys it.

func (*Client) UpdateDaemon

func (c *Client) UpdateDaemon(ctx context.Context, idOrName string) (Server, error)

UpdateDaemon has the daemon of a server download the hub's moin binary, swap it in and restart. It returns the server once the new daemon is back.

func (*Client) Uptime

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

Uptime returns the uptime of every domain of an app.

func (*Client) UseSurface

func (c *Client) UseSurface(surface string)

UseSurface names the program that sends the requests: "cli" or "tui".

func (*Client) Version

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

Version returns the hub's version and the newest release.

func (*Client) WatchApps

func (c *Client) WatchApps(ctx context.Context, fn func([]App)) error

WatchApps calls fn with the full app list on connect and on every change.

func (*Client) WatchServers

func (c *Client) WatchServers(ctx context.Context, fn func([]Server)) error

WatchServers calls fn with the full server list on connect and on every change, until ctx ends or the stream breaks.

type ComposeFile

type ComposeFile struct {
	Number int    `json:"number"`
	Text   string `json:"compose_file"`
}

ComposeFile is the compose file of an app's live deploy, YAML: everything moin runs for it, without a secret value.

type Config

type Config struct {
	URL   string `json:"url"`
	Token string `json:"token"`
	// RefreshToken gets the next pair once ExpiresAt comes.
	RefreshToken string     `json:"refresh_token,omitempty"`
	ExpiresAt    *time.Time `json:"expires_at,omitempty"`
	// Connection is the ID of the connection the login made.
	Connection string `json:"connection,omitempty"`
	// TokenFromEnv is true when the token came from MOIN_TOKEN.
	TokenFromEnv bool `json:"-"`
	// contains filtered or unexported fields
}

Config is what `moin login` saves. A login in the browser keeps the access token of its connection in Token, the refresh token and when the access token ends; the client refreshes them by itself. A CI token has only Token.

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig reads the config file. MOIN_URL and MOIN_TOKEN override it.

func LoadSaved

func LoadSaved() (Config, error)

LoadSaved reads the saved config alone, without the environment.

func LoginInBrowser

func LoginInBrowser(ctx context.Context, baseURL, surface string, show func(DeviceLogin)) (Config, error)

LoginInBrowser logs this computer in through the browser, the device flow of RFC 8628: it starts a login on the hub at baseURL, calls show with the code and the page to open, and polls until the user approved or denied it there, or it expired. surface is "cli" or "tui". The config it returns has the tokens of the new connection; the caller saves it with SaveConfig.

func (Config) Login

func (c Config) Login() string

Login names the login for the TUI's cache: the connection, or a CI token itself.

type Connection

type Connection struct {
	ID           string     `json:"id"`
	ClientName   string     `json:"client_name"`
	RedirectHost string     `json:"redirect_host"`
	WorkspaceID  string     `json:"workspace_id"`
	Rights       []string   `json:"rights"`
	Current      bool       `json:"current"`
	LastUsedAt   *time.Time `json:"last_used_at"`
	CreatedAt    time.Time  `json:"created_at"`
}

Connection is a client let in from the browser, as the API answers it.

type CreatedApp

type CreatedApp struct {
	App      App    `json:"app"`
	Password string `json:"password"`
}

CreatedApp is the answer of AddApp: the app and its password, user moin, the one time moin shows it.

type DatabaseBackup

type DatabaseBackup struct {
	Database   string          `json:"database"`
	Kind       string          `json:"kind,omitempty"`
	CopiedAt   *time.Time      `json:"copied_at,omitempty"`
	CheckedAt  *time.Time      `json:"checked_at,omitempty"`
	CheckError string          `json:"check_error,omitempty"`
	Copies     []protocol.Copy `json:"copies"`
	Undos      []protocol.Copy `json:"undos"`
	Error      string          `json:"error,omitempty"`
}

DatabaseBackup is how one database is backed up, as the daemon reports it: protocol.DatabaseBackup under the API's own names.

type DatabaseBackups

type DatabaseBackups struct {
	DatabaseBackup
	Problem string   `json:"problem,omitempty"`
	Moments []Moment `json:"moments"`
}

DatabaseBackups is the backup of one database: how it stands, Problem in one sentence when it does not work, and the moments a restore can go back to.

type Deploy

type Deploy struct {
	Number     int    `json:"number"`
	Status     string `json:"status"`
	FromNumber int    `json:"from_number"`
	Image      string `json:"image"`
	// Ref and Commit name the GitHub commit the deploy came from.
	Ref           string             `json:"ref"`
	Commit        string             `json:"commit"`
	CommitMessage string             `json:"commit_message"`
	Error         string             `json:"error"`
	Detected      *protocol.Detected `json:"detected"`
	CreatedAt     time.Time          `json:"created_at"`
	FinishedAt    *time.Time         `json:"finished_at"`
	Log           []string           `json:"log"`
}

Deploy is one version of an app, v12.

type DeployMark

type DeployMark struct {
	Number int       `json:"number"`
	At     time.Time `json:"at"`
}

DeployMark is a deploy that went live.

type DeviceLogin

type DeviceLogin struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
}

DeviceLogin is a login in the browser that waits for the user: the code to check and the page to approve it on.

type DomainCheck

type DomainCheck struct {
	Domain    string   `json:"domain"`
	Canonical bool     `json:"canonical"`
	Address   string   `json:"address"`
	IPv4      string   `json:"ipv4"`
	IPv6      string   `json:"ipv6"`
	Advice    string   `json:"advice"`
	Found     []string `json:"found"`
	Points    bool     `json:"points"`
	// Service is the service of compose.yml the domain reaches, empty for
	// the main one.
	Service string `json:"service"`
}

DomainCheck says whether a domain points at the app's server.

type Download

type Download struct {
	App      string    `json:"app"`
	Database string    `json:"database"`
	Copy     string    `json:"copy"`
	Label    string    `json:"label"`
	At       time.Time `json:"at"`
	Size     int64     `json:"size"`
	Link     string    `json:"link"`
}

Download is a copy of a database in the app's bucket; Link is a link to it there, signed by the app's server, valid 15 minutes.

type EnvVar

type EnvVar struct {
	Key       string    `json:"key"`
	UpdatedAt time.Time `json:"updated_at"`
}

EnvVar is an env var of an app: its key and when it changed. Values are write-only: the hub never answers one.

type Error

type Error struct {
	Status  int
	Code    string
	Message string
}

Error is an error answer of the API.

func (*Error) Error

func (e *Error) Error() string

type Event

type Event struct {
	ID        string    `json:"id"`
	Action    string    `json:"action"`
	Actor     string    `json:"actor"`
	Summary   string    `json:"summary"`
	Via       string    `json:"via"`
	Token     string    `json:"token"`
	App       string    `json:"app"`
	Server    string    `json:"server"`
	IP        string    `json:"ip"`
	UserAgent string    `json:"user_agent"`
	Metadata  string    `json:"metadata"`
	CreatedAt time.Time `json:"created_at"`
}

Event is one thing that happened in the workspace. Actor and Summary read as a sentence: "Ada Lovelace deployed blog v12". Via is web, cli, tui, api, mcp, hook, github or system, Token the connection or CI token by name. IP and UserAgent are there for admins only.

type ExecResult

type ExecResult struct {
	Service   string `json:"service"`
	ExitCode  int    `json:"exit_code"`
	Truncated bool   `json:"truncated"`
	TimedOut  bool   `json:"timed_out"`
}

ExecResult is how a command ended.

type GitHub

type GitHub struct {
	Enabled       bool   `json:"enabled"`
	ConnectURL    string `json:"connect_url"`
	InstallURL    string `json:"install_url"`
	Installations []struct {
		ID          int64  `json:"id"`
		Account     string `json:"account"`
		SettingsURL string `json:"settings_url"`
	} `json:"installations"`
}

GitHub is where the moin GitHub App is installed.

type GitHubRepo

type GitHubRepo struct {
	FullName      string `json:"full_name"`
	DefaultBranch string `json:"default_branch"`
	Private       bool   `json:"private"`
	Account       string `json:"account"`
}

GitHubRepo is a repo moin may read.

type HubBackup

type HubBackup struct {
	State    string     `json:"state"`
	Bucket   string     `json:"bucket"`
	LastCopy *time.Time `json:"last_copy"`
}

HubBackup is how the backup of the hub's own database stands: State is on, off or late.

type Instant

type Instant struct {
	URL      string `json:"url"`
	Provider string `json:"provider"`
	Reason   string `json:"reason"`
}

Instant is the app's instant address, or why it has none.

type Integrations

type Integrations struct {
	Cloudflare        bool          `json:"cloudflare"`
	CloudflareAccount string        `json:"cloudflare_account"`
	Tailscale         SecretServers `json:"tailscale"`
}

Integrations says which keys there are: the Cloudflare API token the hub keeps, and the servers that keep a Tailscale key.

type Invitation

type Invitation struct {
	ID        string    `json:"id"`
	Email     string    `json:"email"`
	Role      string    `json:"role"`
	ExpiresAt time.Time `json:"expires_at"`
}

Invitation is an open invitation to the workspace.

type Meta

type Meta struct {
	Name string `json:"name"`
	// Version is the version of the hub and of the moin binary
	// it serves; "dev" for a build without one.
	Version string `json:"version"`
}

Meta is what the hub says about itself.

type MetricsPoint

type MetricsPoint struct {
	At     time.Time `json:"at"`
	CPU    float64   `json:"cpu"`
	Memory uint64    `json:"memory"`
	Disk   uint64    `json:"disk"`
	NetRx  float64   `json:"net_rx"`
	NetTx  float64   `json:"net_tx"`
	Load   float64   `json:"load"`
}

MetricsPoint is a server or an app at one point; apps have no disk and no load.

type Moment

type Moment struct {
	ID    string    `json:"id"`
	Label string    `json:"label"`
	At    time.Time `json:"at"`
	Kind  string    `json:"kind"`
}

Moment is one moment to go back to; Restore takes its ID or label.

type NewAlertDestination

type NewAlertDestination struct {
	Kind     string   `json:"kind"`
	Name     string   `json:"name"`
	URL      string   `json:"url,omitempty"`
	BotToken string   `json:"bot_token,omitempty"`
	ChatID   string   `json:"chat_id,omitempty"`
	Events   []string `json:"events,omitempty"`
}

NewAlertDestination is a destination to add. URL is for Slack, Discord and webhooks; BotToken and ChatID for Telegram. No events means all.

type NewPassword

type NewPassword struct {
	Change
	Password string `json:"password"`
}

NewPassword is the answer of SetPassword: the change, and the password moin made when none was given, the one time it shows it.

type NewServer

type NewServer struct {
	Server         Server    `json:"server"`
	InstallToken   string    `json:"install_token"`
	InstallCommand string    `json:"install_command"`
	ExpiresAt      time.Time `json:"expires_at"`
}

NewServer is a server that waits for its daemon.

type Outage

type Outage struct {
	StartedAt time.Time  `json:"started_at"`
	EndedAt   *time.Time `json:"ended_at"`
	Reason    string     `json:"reason"`
}

Outage is a time a domain was down; EndedAt is nil while it lasts.

type Registry

type Registry struct {
	Host      string     `json:"host"`
	Username  string     `json:"username"`
	CreatedAt time.Time  `json:"created_at"`
	Servers   []SecretOn `json:"servers"`
	MissingOn []string   `json:"missing_on"`
}

Registry is a registry login without its password, which only the servers keep: Servers say which, MissingOn which do not.

type RemovedServer

type RemovedServer struct {
	UninstallCommand string
	Apps             []string
}

RemovedServer is a server just removed: the command that removes its daemon on the machine, empty when no daemon ever connected there, and the apps that went with it because it was offline.

type Restore

type Restore struct {
	ID       string `json:"id"`
	Database string `json:"database"`
	To       string `json:"to"`
	State    string `json:"state"`
	Error    string `json:"error"`
}

Restore is a restore the daemon runs: running, then done or failed.

type SecretOn

type SecretOn struct {
	Server    string    `json:"server"`
	UpdatedAt time.Time `json:"updated_at"`
}

SecretOn is a server that keeps a secret, and since when.

type SecretServers

type SecretServers struct {
	Servers   []SecretOn `json:"servers"`
	MissingOn []string   `json:"missing_on"`
}

SecretServers says which servers keep a secret and which do not.

type Security

type Security struct {
	Tunnel   bool   `json:"tunnel"`
	SSH      string `json:"ssh"`
	Firewall bool   `json:"firewall"`
}

Security is how a server should be reached and locked down. SSH is tailscale, everyone or off.

type SecurityLine

type SecurityLine struct {
	Name, Is, Set string
}

SecurityLine is one line of how a server is reached: what is on the server (Is) and what is set (Set), the lines of its Security page.

type Server

type Server struct {
	ID            string     `json:"id"`
	Name          string     `json:"name"`
	Online        bool       `json:"online"`
	Hostname      string     `json:"hostname"`
	OS            string     `json:"os"`
	Arch          string     `json:"arch"`
	DaemonVersion string     `json:"daemon_version"`
	LastSeenAt    *time.Time `json:"last_seen_at"`
	// Tunnel, SSH and Firewall say how the server should be reached and
	// locked down; SSH is tailscale, everyone or off. Security is what its
	// daemon last saw on it.
	Tunnel   bool                         `json:"tunnel"`
	SSH      string                       `json:"ssh"`
	Firewall bool                         `json:"firewall"`
	Security *protocol.ServerConfigResult `json:"security"`
	// Rules are what the owner allows moin to do on the server, from
	// /etc/moin/rules there. Nil without rules.
	Rules     *protocol.Rules `json:"rules"`
	CreatedAt time.Time       `json:"created_at"`
}

Server is a server with a daemon, as the API answers it.

func (Server) Access

func (s Server) Access() string

Access says in a few words how the server is reached.

func (Server) LastSeen

func (s Server) LastSeen(now time.Time) string

LastSeen is "now" for online servers and a rough age for the others.

func (Server) Outdated

func (s Server) Outdated(version string) bool

Outdated reports whether the server's daemon runs another version than the hub. Development builds never count.

func (Server) RulesText

func (s Server) RulesText() string

RulesText names the server's rules in a few words, or "-" without.

func (Server) SecurityLines

func (s Server) SecurityLines() []SecurityLine

SecurityLines are web, SSH and the firewall, the lines of the Security page in the same words, once the daemon reported; nil before.

func (Server) Status

func (s Server) Status() string

Status is "online", "offline" or "waiting" for a server whose daemon never connected.

func (Server) System

func (s Server) System() string

System is "linux/amd64", or a dash before the daemon registered.

type ServerAppMetrics

type ServerAppMetrics struct {
	App string         `json:"app"`
	Now *AppMetricsNow `json:"now"`
}

ServerAppMetrics is an app on a server and its newest sample, nil when it does not run.

type ServerMetrics

type ServerMetrics struct {
	Server      string             `json:"server"`
	Online      bool               `json:"online"`
	Range       string             `json:"range"`
	StepSeconds int                `json:"step_seconds"`
	Now         *ServerMetricsNow  `json:"now"`
	Points      []MetricsPoint     `json:"points"`
	Apps        []ServerAppMetrics `json:"apps"`
}

ServerMetrics are the metrics of a server: now, over a range, and its apps now, the one with the most memory first.

type ServerMetricsNow

type ServerMetricsNow struct {
	At          time.Time `json:"at"`
	CPU         float64   `json:"cpu"`
	Cores       int       `json:"cores"`
	MemoryUsed  uint64    `json:"memory_used"`
	MemoryTotal uint64    `json:"memory_total"`
	DiskUsed    uint64    `json:"disk_used"`
	DiskTotal   uint64    `json:"disk_total"`
	NetRx       float64   `json:"net_rx"`
	NetTx       float64   `json:"net_tx"`
	Load        float64   `json:"load"`
}

ServerMetricsNow is the newest sample of a server.

type Status

type Status struct {
	OK      bool           `json:"ok"`
	Issues  []StatusIssue  `json:"issues"`
	Updates []StatusUpdate `json:"updates"`
	Counts  StatusCounts   `json:"counts"`
}

Status says whether everything is OK in the workspace.

type StatusCounts

type StatusCounts struct {
	Apps           int `json:"apps"`
	AppsLive       int `json:"apps_live"`
	Servers        int `json:"servers"`
	ServersOnline  int `json:"servers_online"`
	Databases      int `json:"databases"`
	BackupsChecked int `json:"backups_checked"`
}

StatusCounts is what runs well.

type StatusIssue

type StatusIssue struct {
	Kind   string     `json:"kind"`
	Target string     `json:"target"`
	Detail string     `json:"detail"`
	Path   string     `json:"path"`
	Since  *time.Time `json:"since"`
}

StatusIssue is one thing that needs you, with the web page to fix it, under the workspace.

type StatusUpdate

type StatusUpdate struct {
	App     string `json:"app"`
	Name    string `json:"name"`
	Version string `json:"version"`
	Latest  string `json:"latest"`
}

StatusUpdate is a catalog app with a newer release.

type TableRows

type TableRows struct {
	Database  string           `json:"database"`
	Table     protocol.DBTable `json:"table"`
	Columns   []string         `json:"columns"`
	Rows      [][]any          `json:"rows"`
	Offset    int              `json:"offset"`
	Limit     int              `json:"limit"`
	Truncated bool             `json:"truncated"`
}

TableRows is one page of a table. When the table has a rowid, it is the first column.

type Team

type Team struct {
	Workspace struct {
		ID   string `json:"id"`
		Name string `json:"name"`
		Slug string `json:"slug"`
	} `json:"workspace"`
	Role        string `json:"role"`
	Permissions struct {
		ManageWorkspace bool `json:"manage_workspace"`
		ManageMembers   bool `json:"manage_members"`
	} `json:"permissions"`
	Members []struct {
		ID    string `json:"id"`
		Name  string `json:"name"`
		Email string `json:"email"`
		Role  string `json:"role"`
	} `json:"members"`
	Invitations []Invitation `json:"invitations"`
}

Team is the workspace of the token with its members and the invitations still open.

type Uptime

type Uptime struct {
	App          string         `json:"app"`
	State        string         `json:"state"`
	Server       string         `json:"server"`
	ServerOnline bool           `json:"server_online"`
	Domains      []UptimeDomain `json:"domains"`
}

Uptime is the uptime of an app: one state for all its domains, its server, and each domain.

type UptimeDomain

type UptimeDomain struct {
	Domain        string     `json:"domain"`
	Path          string     `json:"path"`
	CustomPath    bool       `json:"custom_path"`
	Paused        bool       `json:"paused"`
	State         string     `json:"state"`
	Since         *time.Time `json:"since"`
	VisitedAt     *time.Time `json:"visited_at"`
	StatusCode    int        `json:"status_code"`
	ResponseMS    int        `json:"response_ms"`
	Error         string     `json:"error"`
	CertExpiresAt *time.Time `json:"cert_expires_at"`
	Uptime24h     *float64   `json:"uptime_24h"`
	Uptime7d      *float64   `json:"uptime_7d"`
	Uptime30d     *float64   `json:"uptime_30d"`
	AverageMS     int        `json:"average_ms"`
	Outages       []Outage   `json:"outages"`
}

UptimeDomain is the uptime of one domain.

type Version

type Version struct {
	Version         string     `json:"version"`
	SelfHosted      bool       `json:"self_hosted"`
	Latest          string     `json:"latest"`
	UpdateAvailable bool       `json:"update_available"`
	PublishedAt     *time.Time `json:"published_at"`
	NotesURL        string     `json:"notes_url"`
	Summary         string     `json:"summary"`
	ReadFirst       string     `json:"read_first"`
	// HubBackup is how the backup of the hub's own database stands; only
	// the admins of the hub get it.
	HubBackup *HubBackup `json:"hub_backup"`
}

Version is the hub's version and, on a self-hosted one, the newest release.

Jump to

Keyboard shortcuts

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