admin

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package admin owns the gateway's operator writes and the read models that the REST API and the dashboard contract share. Both callers go through it, so the manual-route priority offset and the proxy base path are applied in one place, and a route loaded and saved unchanged is left unchanged.

Index

Constants

View Source
const ManualPriorityOffset = 100

ManualPriorityOffset is added to every manual route's priority so manual routes sort above discovered ones at the same specificity. Operators never see it: the service adds it on the way in and removes it on the way out.

View Source
const Redacted = "[redacted]"

Redacted replaces a sensitive header value. The header's name stays, so an operator can see that it is set.

View Source
const RedactedPassword = "xxxxx"

RedactedPassword is what url.URL.Redacted shows in place of a password.

Variables

View Source
var (
	// ErrNotFound is returned for a route id the table does not hold.
	ErrNotFound = errors.New("route not found")
	// ErrNotManual is wrapped by SourceError.
	ErrNotManual = errors.New("route is not manual")
	// ErrConflict is wrapped by ConflictError.
	ErrConflict = errors.New("route conflicts with an existing route")
)

Functions

func RedactHeaders

func RedactHeaders(p bastion.HeaderPolicy) bastion.HeaderPolicy

RedactHeaders returns a copy of p with sensitive values replaced.

func RedactTransform

func RedactTransform(t *bastion.TransformConfig) *bastion.TransformConfig

RedactTransform returns a copy of t with sensitive values replaced.

func RedactURL

func RedactURL(raw string) string

RedactURL hides the password in a URL's userinfo. A URL without userinfo, or one that does not parse, comes back unchanged.

func SensitiveHeader

func SensitiveHeader(name string) bool

SensitiveHeader reports whether a header's value may carry a credential.

Types

type ConflictError

type ConflictError struct {
	Path    string
	OtherID string
}

ConflictError refuses a manual route that would serve the same path and an overlapping method as another manual route.

func (*ConflictError) Error

func (e *ConflictError) Error() string

func (*ConflictError) Unwrap

func (e *ConflictError) Unwrap() error

type Deps

type Deps struct {
	// Routes is the live route table. Required.
	Routes bastion.RouteRegistry
	// Health, when set, has targets a write removes deregistered from it.
	Health *health.Monitor
	// Breakers, when set, supplies circuit state for read models and has the
	// breakers of removed targets dropped.
	Breakers bastion.CircuitControl
	// BasePath is bastion's Config.BasePath: the prefix every manual route's
	// path is served under.
	BasePath string
	// Persisted reports whether a route store is wired. Nil means nothing
	// written through the service survives a restart.
	Persisted func() bool
}

Deps is what the service needs from the gateway.

type RouteDetail

type RouteDetail struct {
	RouteSummary
	Input          *RouteInput               `json:"input,omitempty"` // manual routes only
	StripPrefix    bool                      `json:"stripPrefix"`
	AddPrefix      string                    `json:"addPrefix"`
	RewritePath    string                    `json:"rewritePath"`
	Headers        bastion.HeaderPolicy      `json:"headers"`
	Retry          *bastion.RetryConfig      `json:"retry,omitempty"`
	Timeout        *bastion.TimeoutConfig    `json:"timeout,omitempty"`
	RateLimit      *bastion.RateLimitConfig  `json:"rateLimit,omitempty"`
	Auth           *bastion.RouteAuthConfig  `json:"auth,omitempty"`
	CircuitBreaker *bastion.CBConfig         `json:"circuitBreaker,omitempty"`
	Cache          *bastion.RouteCacheConfig `json:"cache,omitempty"`
	TrafficPolicy  *bastion.TrafficPolicy    `json:"trafficPolicy,omitempty"`
	Transform      *bastion.TransformConfig  `json:"transform,omitempty"`
	MetadataKeys   []string                  `json:"metadataKeys"`
	Version        int64                     `json:"version"`
	CreatedAt      time.Time                 `json:"createdAt"`
	Targets        []TargetView              `json:"targets"`
}

type RouteFilter

type RouteFilter struct{ Source, Protocol string }

type RouteInput

type RouteInput struct {
	Path     string `json:"path"`     // without BasePath
	Priority int    `json:"priority"` // without ManualPriorityOffset
}

type RouteSummary

type RouteSummary struct {
	ID             string                `json:"id"`
	Path           string                `json:"path"`
	Methods        []string              `json:"methods"` // empty = any method
	Protocol       bastion.RouteProtocol `json:"protocol"`
	Source         bastion.RouteSource   `json:"source"`
	ServiceName    string                `json:"serviceName"`
	Priority       int                   `json:"priority"` // effective, as sorted
	Enabled        bool                  `json:"enabled"`
	TargetCount    int                   `json:"targetCount"`
	HealthyTargets int                   `json:"healthyTargets"`
	Editable       bool                  `json:"editable"` // manual
	Config         bool                  `json:"config"`   // from the config file
	UpdatedAt      time.Time             `json:"updatedAt"`
}

type Service

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

Service answers operator reads and performs operator writes.

func New

func New(d Deps) (*Service, error)

New builds a Service.

func (*Service) CreateRoute

func (s *Service) CreateRoute(dto bastion.RouteDTO) (*bastion.Route, error)

CreateRoute adds a manual route from entered values.

func (*Service) DeleteRoute

func (s *Service) DeleteRoute(id string) error

DeleteRoute removes a manual route.

func (*Service) Entry

func (s *Service) Entry(id string) (bastion.RouteDTO, error)

Entry returns a manual route's values as the operator entered them, with nothing redacted. It is for merging a partial update, never for display.

func (*Service) GetRoute

func (s *Service) GetRoute(id string) (RouteDetail, error)

GetRoute returns one route with its targets. Header values that may carry credentials are redacted, and metadata is reduced to its keys.

func (*Service) ListRoutes

func (s *Service) ListRoutes(f RouteFilter) []RouteSummary

ListRoutes returns the routes in match order, filtered by source and protocol when either is set.

func (*Service) SetEnabled

func (s *Service) SetEnabled(id string, enabled bool) (bool, error)

SetEnabled turns a manual route on or off. It writes a copy: the live route is read by the proxy without a lock.

func (*Service) Targets

func (s *Service) Targets() map[string]TargetRef

Targets indexes every live target id. A breaker whose id is not here belongs to a target no route uses any more.

func (*Service) UpdateRoute

func (s *Service) UpdateRoute(id string, dto bastion.RouteDTO) (*bastion.Route, error)

UpdateRoute replaces a manual route from entered values.

func (*Service) Upstreams

func (s *Service) Upstreams() []Upstream

Upstreams groups every live target by URL. An upstream is healthy only when every entry for it is, and reports its worst breaker state.

type SourceError

type SourceError struct {
	ID     string
	Source bastion.RouteSource
}

SourceError refuses a write to a route the service does not manage: FARP and discovery rebuild their routes on every update, so a change made here would silently revert.

func (*SourceError) Error

func (e *SourceError) Error() string

func (*SourceError) Unwrap

func (e *SourceError) Unwrap() error

type TargetRef

type TargetRef struct {
	URL    string
	Routes []UpstreamRoute
}

type TargetView

type TargetView struct {
	ID              string               `json:"id"`
	URL             string               `json:"url"`
	Weight          int                  `json:"weight"`
	Tags            []string             `json:"tags"`
	Healthy         bool                 `json:"healthy"`
	CircuitState    bastion.CircuitState `json:"circuitState"`
	Stats           bastion.TargetStats  `json:"stats"`
	TLS             bool                 `json:"tls"`
	HealthCheckPath string               `json:"healthCheckPath,omitempty"`
	OpenAPI         string               `json:"openapi,omitempty"`
	MetadataKeys    []string             `json:"metadataKeys"`
}

type Upstream

type Upstream struct {
	URL           string               `json:"url"`
	Healthy       bool                 `json:"healthy"`      // every entry healthy
	CircuitState  bastion.CircuitState `json:"circuitState"` // worst entry
	ActiveConns   int64                `json:"activeConns"`
	TotalRequests int64                `json:"totalRequests"`
	TotalErrors   int64                `json:"totalErrors"`
	AvgLatencyMs  float64              `json:"avgLatencyMs"` // request-weighted
	Routes        []UpstreamRoute      `json:"routes"`
}

type UpstreamRoute

type UpstreamRoute struct {
	RouteID  string `json:"routeId"`
	Path     string `json:"path"`
	TargetID string `json:"targetId"`
}

type ValidationError

type ValidationError struct {
	Field   string
	Message string
}

ValidationError describes bad operator input. Field names the input it is about, so a form can put the message beside it.

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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