api

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: GPL-3.0 Imports: 28 Imported by: ? 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 provides the extensible HTTP Admin API server.

Index

Constants

View Source
const (
	// DefaultHTTPReadHeaderTimeout bounds receipt of request headers.
	DefaultHTTPReadHeaderTimeout = 10 * time.Second
	// DefaultHTTPReadTimeout bounds receipt of headers and request bodies. Custom
	// HTTP servers serving Astra Admin should apply an equivalent finite limit.
	DefaultHTTPReadTimeout = 30 * time.Second
	// DefaultHTTPIdleTimeout bounds idle keep-alive connections.
	DefaultHTTPIdleTimeout = 60 * time.Second
)
View Source
const ProtocolVersion = 1

ProtocolVersion is the server-driven admin manifest contract version.

Variables

This section is empty.

Functions

func DecodeJSON added in v2.0.1

func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any) error

DecodeJSON decodes one bounded JSON value from a request body.

func WriteError

func WriteError(w http.ResponseWriter, err error)

WriteError writes a typed engine error without exposing its wrapped cause.

Types

type AdmissionConfig added in v2.0.1

type AdmissionConfig struct {
	ExchangeGlobalConcurrent int
	ExchangePerIPConcurrent  int
	ExchangeGlobalRate       int
	ExchangePerIPRate        int
	ExchangeRateWindow       time.Duration
	ExchangeSourceBuckets    int
	LogStreamsGlobal         int
	LogStreamsPerPrincipal   int
}

AdmissionConfig bounds unauthenticated session exchange work and authenticated log streams. Zero values select conservative defaults.

func (AdmissionConfig) Validate added in v2.0.1

func (c AdmissionConfig) Validate() error

type Dependencies

type Dependencies struct {
	App                 *appcore.App
	EngineVersion       string
	Store               storage.Store
	Plugins             *plugin.Registry
	Users               storage.UserRepository
	Chats               storage.ChatRepository
	Events              observability.EventLogStore
	Audits              observability.AuditLogStore
	Metrics             observability.MetricsStore
	Logs                *logging.Stream
	Auth                auth.Verifier
	InsecureDevelopment bool // Grants development-only owner access when Auth is nil.
	Authorization       *auth.Registry
	WebAuth             *auth.WebAuthService
	Control             *admincontrol.Server
	OperationRepository storage.OperationRepository
	Maintenance         storage.AdminMaintenance
	MaintenanceConfig   MaintenanceConfig
	Admission           AdmissionConfig
	Logger              *slog.Logger
}

Dependencies configures system repositories, observability and authentication.

type MaintenanceConfig added in v2.0.1

type MaintenanceConfig struct {
	Disabled bool
	Interval time.Duration
	Timeout  time.Duration
	Batch    int
}

MaintenanceConfig controls bounded cleanup of expired Admin credentials, sessions, tickets, and operation records. Zero values select defaults.

func (MaintenanceConfig) Validate added in v2.0.1

func (c MaintenanceConfig) Validate() error

Validate reports whether the configured non-zero limits are safe. Zero values are valid and resolve to documented defaults.

type ProtectedHandlerFunc

type ProtectedHandlerFunc func(http.ResponseWriter, *http.Request, *auth.Claims)

ProtectedHandlerFunc handles an authorized request with verified claims.

type Server

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

Server serves built-in system endpoints and application-defined routes.

func New

func New() *Server

New creates a server with system routes and no external dependencies.

func NewInsecureDevelopmentServer added in v2.0.2

func NewInsecureDevelopmentServer() *Server

NewInsecureDevelopmentServer creates an unauthenticated local-development server.

func NewWithDependencies

func NewWithDependencies(deps Dependencies) *Server

NewWithDependencies creates a server and derives repositories from Store when set.

func NewWithPlugins

func NewWithPlugins(plugins *plugin.Registry) *Server

NewWithPlugins creates a server backed by a plugin registry.

func (*Server) AuditDispatcherStats added in v2.0.1

func (s *Server) AuditDispatcherStats() observability.AuditDispatcherStats

AuditDispatcherStats reports bounded audit rejection, persistence failure and overload.

func (*Server) Handle

func (s *Server) Handle(pattern string, handler http.Handler)

Handle registers an application route using net/http ServeMux patterns.

func (*Server) HandleFunc

func (s *Server) HandleFunc(pattern string, handler http.HandlerFunc)

HandleFunc registers an application handler using net/http ServeMux patterns.

func (*Server) HandleModule added in v2.0.1

func (s *Server) HandleModule(moduleID, pattern, permission string, handler http.Handler) (err error)

HandleModule registers an authenticated handler below /admin/modules/{id}.

func (*Server) HandleProtected

func (s *Server) HandleProtected(pattern, permission string, handler ProtectedHandlerFunc)

HandleProtected registers a route guarded by the configured verifier and permission.

func (*Server) Listen

func (s *Server) Listen(addr string) error

Listen serves HTTP requests on addr and blocks until the server stops.

func (*Server) NewHTTPServer added in v2.0.1

func (s *Server) NewHTTPServer(addr string) *http.Server

NewHTTPServer returns the bounded HTTP server configuration used by Listen. WriteTimeout is intentionally unset because Control and log streams are long-lived; upgraded Control connections own their deadlines after hijack.

func (*Server) RegisterAdminProvider added in v2.0.1

func (s *Server) RegisterAdminProvider(provider plugin.AdminModuleProvider) error

RegisterAdminProvider installs one plugin's executable Admin API hooks.

func (*Server) RegisterModule added in v2.0.1

func (s *Server) RegisterModule(module resources.Module) error

RegisterModule adds a detached, declarative module manifest.

func (*Server) RegisterPluginModules added in v2.0.1

func (s *Server) RegisterPluginModules(registry *plugin.Registry) error

RegisterPluginModules installs executable admin hooks, then atomically validates and publishes all declarative UI providers. Call it once before serving; a returned error means the server must not be served. Module hooks retain their historical partial-registration behavior on error.

func (*Server) RegisterUI added in v2.0.1

func (s *Server) RegisterUI(provider string, descriptor adminui.Descriptor) error

RegisterUI validates and atomically registers a declarative UI descriptor.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Shutdown added in v2.0.1

func (s *Server) Shutdown(ctx context.Context) error

Shutdown broadcasts the Control v1 shutdown event and closes active sockets.

Jump to

Keyboard shortcuts

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