localserver

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Overview

Package localserver is the HTTP side of the local OVDB server: the hardening middleware chain, the local API (/api/local/v1/…), the landing page, and the openvaultdb-go data API (/v1/…) mounted behind them. It exists only in local mode; legacy `ovdb serve` never uses it (REQ:local-mode-only-for-new-surfaces).

The data API serves the databases registered in <OVDB home>/databases, mounted by the setup.Registry this server owns.

Index

Constants

View Source
const (
	// SessionTTL is the sliding expiry of an ovdb.localhost session: every
	// use pushes it out again.
	SessionTTL = 30 * 24 * time.Hour
	// FallbackSessionTTL is the absolute lifetime of a session created on a
	// fallback host. It does not slide.
	FallbackSessionTTL = 8 * time.Hour
)

Session lifetimes (REQ:sessions).

Browsers send a host's cookies to every port on that host (RFC 6265 §8.5): naming the cookie with the port avoids clashes, not disclosure. Any other program listening on 127.0.0.1 or localhost receives the console cookie when the browser visits it, and 127.0.0.1 and localhost are where dev servers live. So only sign-ins on ovdb.localhost get the long, sliding, persisted session people expect; a sign-in through a fallback host (127.0.0.1, localhost, [::1]) gets a browser-session cookie and a short fixed lifetime, limiting what a leaked cookie is worth. Sessions also cannot manage tokens or CORS origins (see route and putConfig).

View Source
const AuthStoreFile = "auth.json"

AuthStoreFile holds scoped tokens, hashed, in OVDB home.

View Source
const LocalAPIPrefix = "/api/local/v1/"

LocalAPIPrefix is the versioned local API root.

View Source
const LoginLinkTTL = 10 * time.Minute

LoginLinkTTL is how long a login code stays valid (REQ:login-links).

View Source
const SessionsFile = "sessions.json"

SessionsFile holds console sessions, hashed, in the runtime directory. It survives restarts: runtime.removeRuntimeFiles keeps it.

Variables

This section is empty.

Functions

func Endpoints

func Endpoints() []string

Endpoints lists the local API as "METHOD path".

func Run

func Run(ctx context.Context, opts RunOptions) error

Run is the local server process: it takes the home lock, binds loopback, publishes server.json once it serves, and runs until ctx is cancelled or an authenticated shutdown arrives. It removes its runtime files on exit.

func SessionCookieName added in v0.9.0

func SessionCookieName(port int) string

SessionCookieName is the console cookie for a port. Cookies ignore ports, so two OVDB servers on one host need different names.

Types

type Handler added in v0.9.0

type Handler struct {
	http.Handler
	// contains filtered or unexported fields
}

Handler is the local-mode handler with its full middleware chain.

func New

func New(opts Options) (*Handler, error)

New builds the local-mode handler. It reads server.cors from config.yaml once: like the port, a change applies at the next start.

func (*Handler) Close added in v0.11.0

func (h *Handler) Close()

Close unmounts every registered database, releasing engine resources, and removes mounts.json. Call it after the HTTP server has shut down.

func (*Handler) Flush added in v0.9.0

func (h *Handler) Flush() error

Flush writes pending session renewals; call it when the server stops.

func (*Handler) MountDatabases added in v0.11.0

func (h *Handler) MountDatabases(ctx context.Context)

MountDatabases mounts the registered databases, each within its deadline, returning when all are settled or ctx ends. Run calls it in the background once the server listens, so no storage can keep the server from starting or stopping.

type LoginLink struct {
	Schema      int       `json:"schema"`
	URL         string    `json:"url"`
	FallbackURL string    `json:"fallback_url"`
	ExpiresAt   time.Time `json:"expires_at"`
}

LoginLink is the body of POST /api/local/v1/login-links.

type LoginLinkRequest

type LoginLinkRequest struct {
	Next string `json:"next,omitempty"`
}

LoginLinkRequest is its optional request body.

type Options

type Options struct {
	Dirs   paths.Dirs
	Record runtime.Record // this run's server.json content
	Secret string
	// RequestShutdown is called once the shutdown response is written.
	RequestShutdown func()
	Now             func() time.Time // time.Now when nil
	// ErrorLog receives recovered panics; they are redacted before writing.
	ErrorLog io.Writer
	// Console serves the web console and apps to signed-in browsers;
	// web.Handler() when nil.
	Console http.Handler
	// Telemetry sends web console events from this process; a web-channel
	// recorder over Dirs.Home and this process's environment when nil.
	Telemetry *telemetry.Recorder
	// Databases are mounted next to the registry's (tests).
	Databases map[string]*core.Database
	// MountTimeout bounds each registered database's mount;
	// setup.DefaultMountTimeout when zero.
	MountTimeout time.Duration
	// Getenv is the server's environment, for the AI agent skill directories
	// the web console offers; os.Getenv when nil.
	Getenv func(string) string
	// DataTugLookPath resolves whether datatug is on PATH for Explore data
	// (capability row 22); exec.LookPath when nil (tests).
	DataTugLookPath explore.LookPath
}

Options configure one local server.

type RunOptions

type RunOptions struct {
	Dirs    paths.Dirs
	Port    int
	Version string
	Listen  runtime.ListenFunc // net.Listen when nil
	Log     io.Writer          // server.log in a detached server
	// FailBeforeReady makes the process exit after taking the lock and
	// before it is ready; tests use it to prove server_start_failed.
	FailBeforeReady bool
}

RunOptions configure the server process.

type TelemetryEvents added in v0.18.0

type TelemetryEvents struct {
	Events []telemetry.Wire `json:"events"`
}

TelemetryEvents is the body of POST /api/local/v1/telemetry/events: the web page's pre-consent buffer, posted only after Turn on.

type TelemetryEventsResult added in v0.18.0

type TelemetryEventsResult struct {
	Schema   int  `json:"schema"`
	Accepted int  `json:"accepted"`
	Sent     bool `json:"sent"`
}

TelemetryEventsResult says how many events were accepted into the closed set and whether this process sent them.

Jump to

Keyboard shortcuts

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