api

package
v0.4.10 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package api serves the Scout REST API under /scout/api/ and the live WebSocket at /scout/ws/live.

Index

Constants

View Source
const (
	TokenTTL = 12 * time.Hour
)

Auth defaults.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

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

Auth issues and verifies dashboard JWTs (HS256) and rate-limits logins.

func NewAuth

func NewAuth(secret []byte, username, password string) *Auth

NewAuth returns an authenticator for one username/password.

func (*Auth) Login

func (a *Auth) Login(c *gin.Context)

Login checks credentials and returns a token. Failed attempts are counted per client IP; after maxFailures in failureWindow, logins return 429.

func (*Auth) Middleware

func (a *Auth) Middleware() gin.HandlerFunc

Middleware rejects requests without a valid token. It reads the Authorization: Bearer header, or ?token= for WebSocket upgrades.

func (*Auth) Verify

func (a *Auth) Verify(raw string) (string, error)

Verify parses and validates a token, returning its subject.

type Deps

type Deps struct {
	Auth     *Auth
	Store    storage.Store
	Engine   *engine.Engine
	Bus      *engine.Bus
	Kill     *engine.KillSwitch
	Settings Settings
	Scoring  scoring.Options
	// Go runs background work (scans) tied to Scout's lifecycle, so shutdown
	// cancels and waits for it.
	Go     func(func(ctx context.Context))
	Logger *slog.Logger
	// Schedules lists configured schedules with next run times.
	Schedules func() any
	// AI is the optional AI client; nil means AI features are off.
	AI *ai.Client
	// Routes is the app's route table exposed by scout.Mount.
	Routes []core.Route
}

Deps are what the API needs. The root package wires them in, so api never imports it.

type Server

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

Server serves /scout/api/* and /scout/ws/live.

func New

func New(d Deps) *Server

New returns an API server and starts tracking scan progress.

func (*Server) Register

func (s *Server) Register(g *gin.RouterGroup)

Register mounts the API on the /scout group.

type Settings

type Settings struct {
	AppName      string                    `json:"app_name"`
	Environment  core.Environment          `json:"environment"`
	Mode         core.Mode                 `json:"mode"`
	Targets      []core.Target             `json:"targets"`
	Scope        core.Scope                `json:"scope"`
	Criticality  []scoring.CriticalityRule `json:"criticality"`
	RateLimit    int                       `json:"rate_limit"`
	Concurrency  int                       `json:"concurrency"`
	CheckTimeout time.Duration             `json:"check_timeout_ns"`
	Retention    time.Duration             `json:"retention_ns"`
	Window       any                       `json:"window,omitempty"`
	Version      string                    `json:"version"`
}

Settings is the read-only configuration the dashboard shows. It never carries secrets.

Jump to

Keyboard shortcuts

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