admin

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package admin serves the voting-config endpoint by proxying the GitHub Pages CDN (valargroup/token-holder-voting-config).

Server registration, approval, and removal happen via GitHub PRs on the config repo — no write endpoints here.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterRoutes

func RegisterRoutes(
	router *mux.Router,
	getAdmin func() *Admin,
	logger log.Logger,
)

RegisterRoutes registers admin HTTP routes on the given mux router.

func RegisterUIConfigRoutes added in v0.5.6

func RegisterUIConfigRoutes(router *mux.Router, logger log.Logger)

RegisterUIConfigRoutes registers GET /api/ui-config on the given router.

All values are resolved once at registration time from environment vars. Changing them requires a restart, which matches how the rest of the daemon reads its configuration.

func RunWatchdog added in v0.5.7

func RunWatchdog(ctx context.Context, adm *Admin, interval time.Duration, logger log.Logger)

RunWatchdog periodically probes every vote server and PIR endpoint listed in voting-config.json and fires Sentry alerts on failure. It blocks until ctx is cancelled.

Types

type Admin

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

Admin fetches and caches the voting-config from the GitHub Pages CDN.

func New

func New(cfg Config, logger log.Logger) (*Admin, error)

New creates a new Admin from the given configuration.

func (*Admin) GetVotingConfig added in v0.5.0

func (a *Admin) GetVotingConfig() (*VotingConfig, error)

GetVotingConfig returns the cached voting config, refreshing if stale.

func (*Admin) RefreshConfig added in v0.5.7

func (a *Admin) RefreshConfig() (*VotingConfig, error)

RefreshConfig forces a reload of voting-config from the CDN and returns the new value. Used by the fleet health watchdog on every tick so it picks up newly added/removed servers without a process restart.

type Config

type Config struct {
	// Disable turns off the admin server entirely.
	Disable bool `mapstructure:"disable"`

	// ConfigURL is the GitHub Pages CDN URL for the voting-config JSON.
	ConfigURL string `mapstructure:"config_url"`

	// WatchdogInterval is how often the fleet health watchdog probes all
	// vote servers and PIR endpoints listed in voting-config.json. Set to
	// 0 to disable the watchdog. Default: 5 minutes.
	WatchdogInterval time.Duration `mapstructure:"watchdog_interval"`
}

Config holds the admin server configuration, read from app.toml admin.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default admin configuration.

type ServiceEntry

type ServiceEntry struct {
	URL             string `json:"url"`
	Label           string `json:"label"`
	OperatorAddress string `json:"operator_address,omitempty"`
}

ServiceEntry is the wire format for a server in the voting-config response.

type UIConfigResponse added in v0.5.6

type UIConfigResponse struct {
	// Mode is "dev" or "prod". The UI uses this to gate developer-only widgets.
	Mode UIMode `json:"mode"`
	// DevPIRControls is a denormalised flag for the most common gate so the UI
	// does not need to know the meaning of each mode value.
	DevPIRControls bool `json:"dev_pir_controls"`
	// PrecomputedBaseURL is the bucket origin that this svoted's PIR siblings
	// fetch their snapshots from. The UI composes the manifest URL as
	// "<base>/snapshots/<height>/manifest.json" using a shared subpath
	// constant. Resolved at startup from SVOTE_PRECOMPUTED_BASE_URL with a
	// production-bucket default. Has no trailing slash.
	PrecomputedBaseURL string `json:"precomputed_base_url"`
}

UIConfigResponse is the wire format returned by GET /api/ui-config.

It carries everything the static admin UI bundle needs to know about the svoted instance it's served by. New fields should be additive — older UI builds must continue to work against newer servers.

type UIMode added in v0.5.6

type UIMode string

UIMode controls which features the admin UI exposes.

"prod" hides developer-only controls such as the in-process PIR rebuild triggers. "dev" enables them. Production deployments must explicitly set SVOTE_UI_MODE=dev to opt in to the developer surface; the default is "prod" so a forgotten environment file can never accidentally expose them.

const (
	UIModeProd UIMode = "prod"
	UIModeDev  UIMode = "dev"

	// DefaultPrecomputedBaseURL is the production DigitalOcean Spaces bucket
	// where the publish-snapshot workflow uploads pre-computed PIR snapshots.
	// Per-deployment overrides go through SVOTE_PRECOMPUTED_BASE_URL so a
	// staging svoted can point at a staging bucket.
	DefaultPrecomputedBaseURL = "https://vote.fra1.digitaloceanspaces.com"
)

type VotingConfig

type VotingConfig struct {
	Version     int            `json:"version"`
	VoteServers []ServiceEntry `json:"vote_servers"`
	PIRServers  []ServiceEntry `json:"pir_endpoints"`
	// SnapshotHeight is the canonical Orchard nullifier-tree snapshot height
	// for the current voting round. PIR servers must serve this exact height,
	// and the admin UI auto-populates round drafts from it.
	SnapshotHeight *uint64 `json:"snapshot_height,omitempty"`
}

VotingConfig is the wire format returned by GET /api/voting-config.

Jump to

Keyboard shortcuts

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