Documentation
¶
Overview ¶
Package api serves the JSON API and the live WebSocket that the embedded dashboard runs on.
Index ¶
- type AuthStatus
- type DispatchState
- type Origin
- type Server
- func (s *Server) Origin() Origin
- func (s *Server) Peering() *dispatch.Service
- func (s *Server) RequireAuth(next http.Handler) http.Handler
- func (s *Server) RetentionRef() store.Retention
- func (s *Server) Routes() *http.ServeMux
- func (s *Server) SetOrigin(o Origin)
- func (s *Server) SetPeering(d *dispatch.Service)
- func (s *Server) SetRetention(r store.Retention)
- type Settings
- type SummaryResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthStatus ¶
type AuthStatus struct {
// Required reports whether this install protects itself with a password at
// all. False for a loopback-only bind.
Required bool `json:"required"`
// NeedsSetup means no password exists yet and one must be created.
NeedsSetup bool `json:"needs_setup"`
// Authenticated reports whether the caller is signed in.
Authenticated bool `json:"authenticated"`
// Version and Build identify this install on the one screen that is shown
// before anybody can sign in. A person looking at a login box has no other
// way to tell what they are looking at, and a bug report from that screen
// is otherwise unattributable to a build.
Version string `json:"version,omitempty"`
Build string `json:"build,omitempty"`
// LockedOut reports whether this client has failed too many logins.
LockedOut bool `json:"locked_out"`
// Exposed reports whether the server is reachable beyond this machine,
// which the UI says out loud so nobody is surprised by their own exposure.
Exposed bool `json:"exposed"`
MinPasswordLen int `json:"min_password_len"`
}
AuthStatus is what the dashboard asks for before rendering anything, so it knows whether to show the setup screen, the login screen, or the app.
type DispatchState ¶
type DispatchState struct {
// Enabled reports whether peering is running at all. When false, nothing
// this instance observes has ever left the machine.
Enabled bool `json:"enabled"`
// PeerID identifies this instance to the people it pairs with, grouped for
// reading aloud.
PeerID string `json:"peer_id,omitempty"`
// Listen is where peers reach this instance.
Listen string `json:"listen,omitempty"`
// Peers is every pairing and its current state.
Peers []dispatch.PeerState `json:"peers"`
}
DispatchState is what the dashboard is told about peering.
type Origin ¶
type Origin struct {
Lat float64 `json:"lat"`
Lon float64 `json:"lon"`
Label string `json:"label"`
Country string `json:"country,omitempty"`
City string `json:"city,omitempty"`
// Known is false until the origin has been located, which lets the UI draw
// arcs from a neutral position rather than from a wrong one.
Known bool `json:"known"`
}
Origin is this network's position on the map.
type Server ¶
type Server struct {
Store *store.Store
Bus *pipeline.Bus
Probe capture.Probe
// Version identifies the build in /api/summary.
Version string
// Build is the commit count, shown beside the version. Two builds of one
// version are otherwise indistinguishable to somebody reporting a fault.
Build string
// CaptureInterfaces lists the devices capture could run on, and names the
// one it is actually using. A function rather than the source itself, so
// this package needs no capture build tag and --offline can leave it nil.
//
// Exists because the automatic choice was unreportable: on Windows every
// device is named \Device\NPF_{GUID}, the startup log was the only place
// the pick appeared, and choosing a virtual adapter with no traffic on it
// looks exactly like a working install with a quiet network.
CaptureInterfaces func() (active string, all []patrol.Interface, err error)
// Auth guards the data endpoints.
Auth *auth.Authenticator
// SaveHash persists a newly created password hash.
SaveHash func(hash string) error
// Exposed reports whether the server is reachable beyond this machine.
Exposed bool
// DataDir is shown in settings so the user knows where their data lives.
DataDir string
// RDAP resolves registration detail on demand. Optional: a nil resolver
// simply means the Rap Sheet shows no registration section.
RDAP *enrich.RDAP
// Labeller categorizes domains. Optional: a nil labeller means lookups are
// shown unlabelled, which is a degradation rather than a failure.
Labeller *enrich.Labeller
// StartPeering brings peer sharing up, and is supplied by whatever is
// hosting this server, building the service needs a listen address, a
// data directory and a logger, none of which the API layer knows about.
//
// Nil means this host cannot start peering at runtime, which is a real
// case: an instance reading somebody else's database offline has nothing
// to share and no business sharing it.
StartPeering func(context.Context) (*dispatch.Service, error)
// IngestHealth reports whether observations are reaching storage. Optional;
// when nil the endpoint reports that health is not being tracked rather
// than claiming everything is fine.
IngestHealth func() any
// StartedAt is when this process began serving, for the uptime reading.
StartedAt time.Time
// contains filtered or unexported fields
}
Server holds everything the handlers need.
func (*Server) RequireAuth ¶
RequireAuth wraps the data API so that nothing is served to a caller who is not signed in.
The dashboard's own static assets stay public: they contain no data, and the login screen has to be able to style itself.
func (*Server) RetentionRef ¶
RetentionRef returns the live retention policy, so the pruner always reads the current value rather than a copy taken at startup.
func (*Server) SetPeering ¶
SetPeering installs, replaces or clears the peer-sharing service.
Passing nil turns the dashboard's privacy claim back into the strong one, so this is the single place that decides whether "nothing leaves this machine" is currently true.
func (*Server) SetRetention ¶
SetRetention updates the retention policy in place.
type Settings ¶
type Settings struct {
RetentionRawHours int `json:"retention_raw_hours"`
RetentionRollupDays int `json:"retention_rollup_days"`
StorageMaxMB int64 `json:"storage_max_mb"`
DBBytes int64 `json:"db_bytes"`
DataDir string `json:"data_dir"`
}
Settings the user may change from the dashboard. Deliberately few: anything that needs configuring before the tool is useful does not belong here.
type SummaryResponse ¶
type SummaryResponse struct {
store.Summary
Mode string `json:"mode"`
Capabilities any `json:"capabilities"`
Origin Origin `json:"origin"`
Version string `json:"version"`
Build string `json:"build"`
Host string `json:"host"`
Since int64 `json:"since"`
// Notes is English prose for API consumers; NoteCodes is what the dashboard
// translates.
Notes []string `json:"notes,omitempty"`
NoteCodes []string `json:"note_codes,omitempty"`
}
SummaryResponse is the dashboard header payload.