api

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 39 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 implements the REST API defined in api/openapi.yaml on top of the generated strict server (ADR 0003).

Index

Constants

View Source
const BaseURL = "/api/v1"

BaseURL is the path prefix of all REST endpoints.

Variables

View Source
var ErrNotImplemented = errors.New("not implemented")

ErrNotImplemented marks operations that exist in the contract but not yet in code.

Functions

func Register

func Register(mux *http.ServeMux, cfg config.Config, log *slog.Logger, deps Deps)

Register mounts all API operations on mux under BaseURL. It panics if the embedded OpenAPI spec cannot be read, which is a build defect.

func WriteProblem

func WriteProblem(w http.ResponseWriter, status int, title, detail string)

WriteProblem writes an RFC 9457 problem details response.

Types

type Applier

type Applier interface {
	Apply(ctx context.Context, cmd *pb.Command) (cluster.ApplyResult, error)
}

Applier proposes commands to the Raft cluster.

type ClusterAdmin

type ClusterAdmin interface {
	CreateJoinToken(ctx context.Context, role pki.Role, tenantID string, ttl time.Duration, actor *pb.Actor) (string, time.Time, error)
	Remove(ctx context.Context, nodeID, requestedBy string) (membership.Removal, error)
	Members() ([]cluster.Member, uint64, error)
	Leader() (address, id string)
	ID() string
}

ClusterAdmin is what the cluster administration endpoints need from the cluster host. cmd/pulsequorum fills it from the host's authority, membership manager and Raft node.

type Deps

type Deps struct {
	State   store.State
	Metrics store.Metrics
	Cluster Applier
	// ClusterAdmin serves the cluster administration (FA-CLU-08); nil answers 503.
	ClusterAdmin ClusterAdmin
	// Replication reports the state of the heartbeat replication to the other
	// voters for the cluster listing (FA-REP-05); nil omits the lag.
	Replication interface {
		Status() []replication.PeerStatus
	}
	// ClockOffsets returns the fresh clock offsets of the peers in
	// milliseconds, by node ID (ADR 0020); nil omits them.
	ClockOffsets func() map[string]int64
	// SSRFProtectionByNode returns whether SSRF protection is on for each node
	// that answered recently, including this node (ADR 0030). Nil means unknown.
	SSRFProtectionByNode func() map[string]bool
	// ProbeSessions returns merged active probe sessions by probe ID (ADR 0034).
	ProbeSessions func() map[string]ProbeSessionView
	Registry      *checker.Registry
	// SSRFPolicy checks the destination hosts of saved monitors; nil when
	// SSRF protection is off (ADR 0030).
	SSRFPolicy checker.AddressPolicy
	// CheckEnv runs on-demand checks (POST /monitors/{id}/test).
	CheckEnv *checker.Env
	NodeID   string
	// Authenticator verifies bearer credentials; nil denies every protected
	// operation (auth.DenyAll).
	Authenticator auth.Authenticator
	// Now is the clock for uptime ranges; nil = time.Now.
	Now func() time.Time
	// Keyring encrypts and decrypts channel secrets (ADR 0011, 0014).
	Keyring alert.Keyring
	// Alerts validates channels and sends test messages.
	Alerts *alert.Sender
	// Local is the local authentication (AUTH_MODE=local); nil otherwise.
	Local *auth.Local
	// Stream and Tickets serve the live WebSocket stream; nil disables it.
	Stream  *stream.Hub
	Tickets *auth.Tickets
	// StreamClosing is closed when the server shuts down; open streams end then.
	StreamClosing <-chan struct{}
	// Degraded reports the degraded state of this voter (ADR 0024) for the
	// health endpoint; nil omits it.
	Degraded interface{ State() degraded.State }
}

Deps are the services the handlers use. Fields may be nil in tests that do not exercise the corresponding endpoints.

type Handlers

type Handlers struct {
	Unimplemented
	// contains filtered or unexported fields
}

Handlers implements gen.StrictServerInterface.

func (*Handlers) BulkMonitors

BulkMonitors applies one action to several monitors of the caller's tenant.

func (*Handlers) ChangeMyPassword

ChangeMyPassword verifies the current password, stores the new one, ends all other sessions and starts a new one for this client.

func (*Handlers) CloneMonitor

CloneMonitor copies a monitor; the copy starts paused (FA-MON-05).

func (*Handlers) CreateApiToken

CreateApiToken creates an API token of the caller's tenant and returns its secret once (ADR 0031, section 1). The request has no Idempotency-Key: a retry would get the stored result of the first attempt, whose secret is lost, so every request creates a new token.

func (*Handlers) CreateJoinToken

CreateJoinToken issues a one-time token. The secret is returned once and never logged; the response must not be cached.

func (*Handlers) CreateMaintenanceWindow

CreateMaintenanceWindow validates the input and creates the window through Raft.

func (*Handlers) CreateMonitor

CreateMonitor validates the input and creates the monitor through Raft.

func (*Handlers) CreateNotificationChannel

CreateNotificationChannel validates the input, encrypts the secrets and creates the channel through Raft.

func (*Handlers) CreatePrivateProbeJoinToken added in v0.0.4

CreatePrivateProbeJoinToken issues a one-time join token bound to the caller's tenant (FA-PRB-05, ADR 0035). Restricted to interactive tenant admins; API tokens are rejected by middleware and by the FSM actor check.

func (*Handlers) CreateStreamTicket

CreateStreamTicket issues a ticket for the caller (FA-AUTH-11).

func (*Handlers) CreateSystemChannel

CreateSystemChannel creates a system channel. The event system is included server-side.

func (*Handlers) CreateTenant

CreateTenant creates a tenant. Without an ID the server generates a UUID.

func (*Handlers) CreateUser

CreateUser creates a local user. The password is hashed here; the FSM only accepts Argon2id hashes.

func (*Handlers) DeleteMaintenanceWindow

DeleteMaintenanceWindow removes the window. Alerts and uptime accounting return to normal from the next evaluation on.

func (*Handlers) DeleteMonitor

DeleteMonitor removes the monitor; its measurement data expires with the retention (FA-MON-07).

func (*Handlers) DeleteNotificationChannel

DeleteNotificationChannel removes the channel. Its monitor links and pending deliveries are removed with it by the schema.

func (*Handlers) DeletePlan

DeletePlan deletes a plan that no tenant uses. The plans default and system cannot be deleted.

func (*Handlers) DeleteSystemChannel

DeleteSystemChannel removes a system channel.

func (*Handlers) DeleteTenant

DeleteTenant deletes a suspended tenant with all its data (ADR 0029). The caller confirms the tenant name. The default and system tenants cannot be deleted.

func (*Handlers) DeleteUser

DeleteUser removes a user and, by cascade, its sessions.

func (*Handlers) GetHealth

GetHealth returns the public node status.

func (*Handlers) GetIncident

GetIncident returns one incident of the caller's tenant.

func (*Handlers) GetMaintenanceWindow

GetMaintenanceWindow returns one window of the caller's tenant.

func (*Handlers) GetMe

GetMe returns the caller.

func (*Handlers) GetMonitor

GetMonitor returns one monitor.

func (*Handlers) GetNotificationChannel

GetNotificationChannel returns one channel of the caller's tenant.

func (*Handlers) GetOwnTenant

GetOwnTenant returns the caller's tenant with its effective limits and usage. The tenant comes from the token only (FA-TEN-02); the organization binding, the overrides and the source are not shown.

func (*Handlers) GetPlan

GetPlan returns one plan. The system plan is not found.

func (*Handlers) GetSystemChannel

GetSystemChannel returns one system channel. Channels of tenants are not found.

func (*Handlers) GetTenant

GetTenant returns one tenant. The system tenant is not found.

func (*Handlers) GetUptime

GetUptime returns the uptime of a monitor over a range, for the consensus or one node (FA-UPT-01).

func (*Handlers) ListAdminAudit

ListAdminAudit returns the audit log of all tenants, including the platform actions of the system tenant, or of the tenant named by the filter.

func (*Handlers) ListApiTokens

ListApiTokens returns the API tokens of the caller's tenant, newest first.

func (*Handlers) ListAssignableNodes added in v0.0.4

ListAssignableNodes returns the voters, public probes, and own private probes selectable in monitor assignment (ADR 0035). Foreign private probes and cluster addresses are never exposed.

func (*Handlers) ListAudit

ListAudit returns the audit log of the caller's tenant. API tokens with the role tenant-admin may read it (ADR 0031).

func (*Handlers) ListClusterNodes

ListClusterNodes returns the Raft configuration with quorum warnings (FA-CLU-11).

func (*Handlers) ListHeartbeats

ListHeartbeats returns raw heartbeats of a monitor, oldest first.

func (*Handlers) ListIncidents

ListIncidents returns the caller's incidents, newest first (FA-INC-02).

func (*Handlers) ListMaintenanceWindows

ListMaintenanceWindows returns the maintenance windows of the caller's tenant.

func (*Handlers) ListMonitorTypes

ListMonitorTypes lists the checker plugins with their JSON Schema (FA-API-06).

func (*Handlers) ListMonitors

ListMonitors returns a page of the caller's monitors.

func (*Handlers) ListNotificationChannels

ListNotificationChannels returns the channels of the caller's tenant.

func (*Handlers) ListPlans

ListPlans returns the plans with the number of tenants on each.

func (*Handlers) ListPrivateProbes added in v0.0.4

ListPrivateProbes returns the private probes registered for the caller's tenant (FA-PRB-05, ADR 0035). Foreign probes and cluster addresses are never exposed.

func (*Handlers) ListSystemAlerts

ListSystemAlerts returns the replicated state of the system alerts (FA-OBS-01, ADR 0025). Platform admins only. The query active=true (default) returns only the alerts that are active now.

func (*Handlers) ListSystemChannels

ListSystemChannels returns the system channels, secrets masked.

func (*Handlers) ListTenants

ListTenants returns the tenants with plan, limits and usage, the system tenant hidden.

func (*Handlers) ListUsers

ListUsers returns the users of the caller's tenant (admins only).

func (*Handlers) Login

Login checks the credentials (throttled per account and IP, FA-AUTH-04).

func (*Handlers) Logout

Logout revokes the token family and clears the cookie.

func (*Handlers) PauseMonitor

PauseMonitor stops checks of a monitor (FA-MON-04).

func (*Handlers) PutPlan

PutPlan creates or replaces a plan. A lowered limit keeps the stock of the tenants on the plan; only new objects and shorter intervals are rejected.

func (*Handlers) Refresh

Refresh rotates the refresh cookie (FA-AUTH-03). The custom header guards against cross-site requests in addition to SameSite=Strict.

func (*Handlers) RemoveClusterNode

RemoveClusterNode takes a node out of the cluster. Any voter accepts the request; a follower forwards it to the leader, which does the work. The leader itself and the last voter cannot be removed. 503 asks the caller to retry when no leader can be reached.

func (*Handlers) RemovePrivateProbe added in v0.0.4

RemovePrivateProbe revokes and removes a private probe owned by the caller's tenant (FA-PRB-05, ADR 0035). Foreign or unknown probes answer 404.

func (*Handlers) ResumeMonitor

ResumeMonitor restarts checks of a paused monitor.

func (*Handlers) ResumeTenant

ResumeTenant lifts the suspension of a tenant.

func (*Handlers) RevokeApiToken

RevokeApiToken deletes an API token of the caller's tenant. Another tenant's token is not found. Its audit entries stay.

func (*Handlers) Setup

Setup creates the first platform admin with the one-time token (FA-AUTH-01).

func (*Handlers) SuspendTenant

SuspendTenant suspends a tenant (ADR 0029). Its users are rejected, its sessions revoked, its checks and alerts stop; the data is kept.

func (*Handlers) TestMonitor

TestMonitor runs the check once on this node without storing the result.

func (*Handlers) TestNotificationChannel

TestNotificationChannel sends a test message synchronously (FA-ALR-08). It bypasses the outbox and does not change the channel state.

func (*Handlers) TestSystemChannel

TestSystemChannel sends a test system alert to a system channel synchronously.

func (*Handlers) UpdateMaintenanceWindow

UpdateMaintenanceWindow replaces the window's settings. The write is conditional on the revision that was read just before (ErrConflict otherwise).

func (*Handlers) UpdateMonitor

UpdateMonitor replaces the monitor's configuration.

func (*Handlers) UpdateNotificationChannel

UpdateNotificationChannel replaces the channel's settings. An omitted URL or a masked value keeps the stored secret (channelDocument).

func (*Handlers) UpdateSystemChannel

UpdateSystemChannel replaces the settings of a system channel.

func (*Handlers) UpdateTenant

UpdateTenant changes the set fields of a tenant. Omitted fields stay as they are; limits replace all overrides.

func (*Handlers) UpdateUser

UpdateUser changes display name, role, disabled flag or (admin reset) the password. Unchanged fields keep their current values. A password change or disabling ends the user's sessions in the FSM.

type ProbeSessionView added in v0.0.4

type ProbeSessionView struct {
	ConnectedVoterID string
	LastMessageMs    int64
	Buffer           *pb.ProbeBufferStatus
}

ProbeSessionView describes a live probe session for the cluster and probe listings (ADR 0034, 0035).

type Problem

type Problem struct {
	Status     int
	Title      string
	Detail     string
	Fields     []checker.FieldError
	RetryAfter int // seconds; 0 = no header
}

Problem is an error that is sent as RFC 9457 problem details.

func (*Problem) Error

func (p *Problem) Error() string

type Unimplemented

type Unimplemented struct{}

Unimplemented answers every operation with 501 Not Implemented. Handlers embeds it, so an operation goes live once Handlers defines the method.

func (Unimplemented) BulkMonitors

BulkMonitors is not implemented yet.

func (Unimplemented) ChangeMyPassword

ChangeMyPassword is not implemented yet.

func (Unimplemented) CloneMonitor

CloneMonitor is not implemented yet.

func (Unimplemented) CreateApiToken

CreateApiToken is not implemented yet.

func (Unimplemented) CreateJoinToken

CreateJoinToken is not implemented yet.

func (Unimplemented) CreateMaintenanceWindow

CreateMaintenanceWindow is not implemented yet.

func (Unimplemented) CreateMonitor

CreateMonitor is not implemented yet.

func (Unimplemented) CreateNotificationChannel

CreateNotificationChannel is not implemented yet.

func (Unimplemented) CreatePrivateProbeJoinToken added in v0.0.4

CreatePrivateProbeJoinToken is not implemented yet.

func (Unimplemented) CreateStreamTicket

CreateStreamTicket is not implemented yet.

func (Unimplemented) CreateSystemChannel

CreateSystemChannel is not implemented yet.

func (Unimplemented) CreateTenant

CreateTenant is not implemented yet.

func (Unimplemented) CreateUser

CreateUser is not implemented yet.

func (Unimplemented) DeleteMaintenanceWindow

DeleteMaintenanceWindow is not implemented yet.

func (Unimplemented) DeleteMonitor

DeleteMonitor is not implemented yet.

func (Unimplemented) DeleteNotificationChannel

DeleteNotificationChannel is not implemented yet.

func (Unimplemented) DeletePlan

DeletePlan is not implemented yet.

func (Unimplemented) DeleteSystemChannel

DeleteSystemChannel is not implemented yet.

func (Unimplemented) DeleteTenant

DeleteTenant is not implemented yet.

func (Unimplemented) DeleteUser

DeleteUser is not implemented yet.

func (Unimplemented) GetHealth

GetHealth is not implemented yet.

func (Unimplemented) GetIncident

GetIncident is not implemented yet.

func (Unimplemented) GetMaintenanceWindow

GetMaintenanceWindow is not implemented yet.

func (Unimplemented) GetMe

GetMe is not implemented yet.

func (Unimplemented) GetMonitor

GetMonitor is not implemented yet.

func (Unimplemented) GetNotificationChannel

GetNotificationChannel is not implemented yet.

func (Unimplemented) GetOwnTenant

GetOwnTenant is not implemented yet.

func (Unimplemented) GetPlan

GetPlan is not implemented yet.

func (Unimplemented) GetSystemChannel

GetSystemChannel is not implemented yet.

func (Unimplemented) GetTenant

GetTenant is not implemented yet.

func (Unimplemented) GetUptime

GetUptime is not implemented yet.

func (Unimplemented) ListAdminAudit

ListAdminAudit is not implemented yet.

func (Unimplemented) ListApiTokens

ListApiTokens is not implemented yet.

func (Unimplemented) ListAssignableNodes added in v0.0.4

ListAssignableNodes is not implemented yet.

func (Unimplemented) ListAudit

ListAudit is not implemented yet.

func (Unimplemented) ListClusterNodes

ListClusterNodes is not implemented yet.

func (Unimplemented) ListHeartbeats

ListHeartbeats is not implemented yet.

func (Unimplemented) ListIncidents

ListIncidents is not implemented yet.

func (Unimplemented) ListMaintenanceWindows

ListMaintenanceWindows is not implemented yet.

func (Unimplemented) ListMonitorTypes

ListMonitorTypes is not implemented yet.

func (Unimplemented) ListMonitors

ListMonitors is not implemented yet.

func (Unimplemented) ListNotificationChannels

ListNotificationChannels is not implemented yet.

func (Unimplemented) ListPlans

ListPlans is not implemented yet.

func (Unimplemented) ListPrivateProbes added in v0.0.4

ListPrivateProbes is not implemented yet.

func (Unimplemented) ListSystemAlerts

ListSystemAlerts is not implemented yet.

func (Unimplemented) ListSystemChannels

ListSystemChannels is not implemented yet.

func (Unimplemented) ListTenants

ListTenants is not implemented yet.

func (Unimplemented) ListUsers

ListUsers is not implemented yet.

func (Unimplemented) Login

Login is not implemented yet.

func (Unimplemented) Logout

Logout is not implemented yet.

func (Unimplemented) PauseMonitor

PauseMonitor is not implemented yet.

func (Unimplemented) PutPlan

PutPlan is not implemented yet.

func (Unimplemented) Refresh

Refresh is not implemented yet.

func (Unimplemented) RemoveClusterNode

RemoveClusterNode is not implemented yet.

func (Unimplemented) RemovePrivateProbe added in v0.0.4

RemovePrivateProbe is not implemented yet.

func (Unimplemented) ResumeMonitor

ResumeMonitor is not implemented yet.

func (Unimplemented) ResumeTenant

ResumeTenant is not implemented yet.

func (Unimplemented) RevokeApiToken

RevokeApiToken is not implemented yet.

func (Unimplemented) Setup

Setup is not implemented yet.

func (Unimplemented) SuspendTenant

SuspendTenant is not implemented yet.

func (Unimplemented) TestMonitor

TestMonitor is not implemented yet.

func (Unimplemented) TestNotificationChannel

TestNotificationChannel is not implemented yet.

func (Unimplemented) TestSystemChannel

TestSystemChannel is not implemented yet.

func (Unimplemented) UpdateMaintenanceWindow

UpdateMaintenanceWindow is not implemented yet.

func (Unimplemented) UpdateMonitor

UpdateMonitor is not implemented yet.

func (Unimplemented) UpdateNotificationChannel

UpdateNotificationChannel is not implemented yet.

func (Unimplemented) UpdateSystemChannel

UpdateSystemChannel is not implemented yet.

func (Unimplemented) UpdateTenant

UpdateTenant is not implemented yet.

func (Unimplemented) UpdateUser

UpdateUser is not implemented yet.

Directories

Path Synopsis
Package gen provides primitives to interact with the openapi HTTP API.
Package gen provides primitives to interact with the openapi HTTP API.
internal
stubgen command
Command stubgen writes unimplemented.go: one 501 stub per operation of gen.StrictServerInterface, so new OpenAPI operations compile immediately.
Command stubgen writes unimplemented.go: one 501 stub per operation of gen.StrictServerInterface, so new OpenAPI operations compile immediately.

Jump to

Keyboard shortcuts

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