api

package
v0.16.521 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 99 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 api assembles the hub: it builds every service from one configuration and one database, routes the requests among them, and runs the background work (the local machine's code, the sweeping of what expired).

Index

Constants

This section is empty.

Variables

View Source
var AppsView func(st *storehub.Store, dataDir string, log *slog.Logger) storehub.AppsViewer

AppsView serves the apps from the store (appsview.Hub): guest links, and a space's apps to its members with every machine off; the hub's main sets it, as DesignView. Nil: an app opens only on a machine.

View Source
var DesignView func(st *storehub.Store, db *store.DB, derived bool, dataDir string, app fs.FS, log *slog.Logger) designaccess.Viewer

DesignView makes the store's view of design projects (designview.Hub): guest links and the team's reads and edits through the hub with no machine. The hub's main sets it; this package does not import the view, whose design code imports the agent, whose tests import this package. Nil: projects are read from the machines only.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	Handler http.Handler
	// Internal serves what the hub's replicas say to one another (HUB_REPLICAS); nil without them. It gets a listener
	// of its own (HUB_REPLICA_LISTEN) and is never mounted on Handler.
	Internal http.Handler
	// Metrics serves the hub's numbers at /metrics in the Prometheus text format, unauthenticated. It gets a listener
	// of its own (HUB_METRICS_LISTEN) and is never mounted on Handler.
	Metrics http.Handler

	// Rollout says whether a rollout is under way and takes the pipeline's word about it.
	Rollout   *rollout.Service
	Auth      *auth.Service
	Spaces    *spaces.Service
	Orgs      *orgs.Service
	Analytics *analytics.Service
	// Env is the environment and the catalog of the organizations; its endpoints answer 404 while the features are off.
	Env *env.Service
	// Features are the organizations' flags.
	Features *features.Store
	// Switches are the rollout switches by person and machine.
	Switches *switches.Store
	Machines *machines.Service
	// Ingest pulls the machines' spend facts; nil unless HUB_USAGE_INGEST=on.
	Ingest *ingest.Service
	// History keeps the people's chats (HUB_HISTORY); nil when it is off.
	History *history.Service

	// Limits sends the machines their limit lists; nil while HUB_LIMITS_ENFORCE=off.
	Limits *limits.Pusher
	// EnvPush sends the machines their environment lists; nil without a feature on.
	EnvPush *env.Pusher
	Relay   *relay.Service
	Proxy   *proxy.Service
	// Docs is the documents and boards of the installation (HUB_DOCS).
	Docs *docs.Service
	// Efficiency serves the figures of the «Эффективность» screen behind the organization flag.
	Efficiency *efficiency.Service
	// Automations is the rules and runs of the installation (HUB_AUTOMATIONS).
	Automations *automations.Service
	// Bus is the journal of events and its subscriptions (HUB_EVENT_BUS, docs/hub/event-bus.md); nil when off.
	Bus *eventbus.Bus
	// Sources keeps the managed connections and binds them to machines; nil without the event bus.
	Sources *sources.Service
	// OrgTriggers keeps the trigger templates of organizations and teams and rolls them out; nil without the
	// event bus.
	OrgTriggers *orgtriggers.Service

	// Design is who may see and change a machine's designs, and the guest links to them.
	Design *designaccess.Service
	// Render is the queue of the design pictures the hub's render worker draws; nil without HUB_RENDER_TOKEN.
	Render *designrender.Service
	// Notices keeps the person's notices in the hub's database, behind the switch hub-notices.
	Notices *noticehub.Service
	// TbotJoin gives the machines the join tokens of their Teleport identities once the person approved.
	TbotJoin *tbotjoin.Service
	Dist     *dist.Handler
	SSH      *sshinstall.Service
	Dialer   *link.Dialer
	Registry *link.Registry
	// Jobs is the pool of builders and the queue of heavy jobs; nil with HUB_BUILDERS=off.
	Jobs   *jobs.Service
	Events *events.Broker
	// OrgEvents is the bus of the organizations' live stream (GET /api/orgs/{org}/events).
	OrgEvents *events.MemoryBus
	// Fleet is the bus of the workspace page's live channel (GET /api/v2/machines/events).
	Fleet   *events.FleetBus
	Tickets *ticket.Store
	// Sites is the published-sites module; nil when HARNESSLY_SITES is off.
	Sites *sites.Service
	// Ext is the registry of the extension adapters (docs/hub/extensions.md); nil unless HUB_EXTENSIONS=on.
	Ext *ext.Registry
	// Safe keeps the machines' safes on the hub's server; nil when HUB_SECRETS_VAULT_ADDR is not set.
	Safe *hubsafe.Broker

	// Store keeps the spaces' collections the machines sync with (docs/hub/store.md); nil only in tests that build the API without one.
	Store *storehub.Store
	// Migration is the journal of the move of the machines' data into the store (docs/migrations); nil with
	// the store off.
	Migration *migration.Service
	// contains filtered or unexported fields
}

Hub is the assembled hub.

func New

func New(o Options) (*Hub, error)

New builds the hub.

func (*Hub) BeginDrain

func (h *Hub) BeginDrain()

BeginDrain takes the hub out of rotation without stopping it: /readyz answers 503 (and /healthz stays 200, so the process is not restarted), and a machine that dials is turned away to dial again. Requests and the links already taken go on.

func (h *Hub) DrainLinks(ctx context.Context, window time.Duration) int

DrainLinks asks the machines linked to this process to dial again, one at a time over window, and returns how many it asked.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context)

Run does the hub's background work until ctx ends: the local machine's registration code, and the sweeping of what expired (sessions, challenges, tickets, remembered nonces).

func (*Hub) Shutdown

func (h *Hub) Shutdown()

Shutdown ends the open event streams, agent links and SSH installs, which would otherwise hold the server from stopping.

type Options

type Options struct {
	Config *config.Config
	DB     *store.DB
	Mailer mail.Mailer
	Log    *slog.Logger
	// Now is the clock; nil means time.Now.
	Now     func() time.Time
	Limiter *ratelimit.Limiter
	// HTTPClient and Endpoints are for the calls to sign-in providers; tests move them.
	HTTPClient *http.Client
	Endpoints  auth.Endpoints
	// UI is the built hub page (index.html and assets/); nil serves a note instead. Config.WebDir, when set, wins.
	UI fs.FS
	// Workspace is the runtime's built page (web/dist): the fleet's workspace at /agents/ (internal/hub/proxy/workspace.go).
	// nil leaves /agents/ to the hub's page.
	Workspace fs.FS
	// SourcesManual keeps the rebinder of managed connections from running by itself: a test ticks it.
	SourcesManual bool
	// OAuthRootCAs are the authorities the hub's own requests to OAuth providers trust (nil: the system's); a test sets
	// its provider's.
	OAuthRootCAs *x509.CertPool
	// SSHDial opens the connections of the SSH install way; nil uses the network. Tests move it.
	SSHDial sshinstall.Dialer
	// SSHOnlineWait shortens the last step of an SSH install (tests).
	SSHOnlineWait time.Duration
	// SiteBlobs replaces the store of the sites' files (tests); nil: the configured folder or bucket.
	SiteBlobs sites.Blobs
	// AgentTimeout shortens every wait for an agent's answer in the owner endpoints (tests).
	AgentTimeout time.Duration
	// EnvFeatures says which parts of the environment section are on for an organization; nil: the ones HUB_ENV_FEATURES
	// names, for every organization.
	EnvFeatures env.FeatureGate
	// Provider replaces the machines' provider that the settings (HUB_PROVIDER*) name (tests).
	Provider provider.Provider
	// Features says whether an organization has a feature on; nil: the resources, load and operations of machines are
	// on for every organization when HUB_MACHINE_RESOURCES=on, else dark (docs/hub/machines-resources.md).
	Features machines.FeatureGate
	// Ext replaces the registry the settings (HUB_EXTENSIONS*) name (tests).
	Ext *ext.Registry
	// Publisher carries the machines' live events to the organization's channel; nil: the space's own stream.
	Publisher machines.Publisher
	// SafeKV replaces the server of the machines' safes that HUB_SECRETS_VAULT_* name (tests).
	SafeKV secrets.KV
	// StoreMeta and StoreBlobs replace the store's configured drivers (tests); the hub does not close them.
	StoreMeta  filestore.MetaStore
	StoreBlobs filestore.BlobStore
}

Options are what the hub is built from. Only Config, DB and Mailer are required.

Jump to

Keyboard shortcuts

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