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
- Variables
- func RedactHeaders(p bastion.HeaderPolicy) bastion.HeaderPolicy
- func RedactTransform(t *bastion.TransformConfig) *bastion.TransformConfig
- func RedactURL(raw string) string
- func SensitiveHeader(name string) bool
- type ConflictError
- type Deps
- type RouteDetail
- type RouteFilter
- type RouteInput
- type RouteSummary
- type Service
- func (s *Service) CreateRoute(dto bastion.RouteDTO) (*bastion.Route, error)
- func (s *Service) DeleteRoute(id string) error
- func (s *Service) Entry(id string) (bastion.RouteDTO, error)
- func (s *Service) GetRoute(id string) (RouteDetail, error)
- func (s *Service) ListRoutes(f RouteFilter) []RouteSummary
- func (s *Service) SetEnabled(id string, enabled bool) (bool, error)
- func (s *Service) Targets() map[string]TargetRef
- func (s *Service) UpdateRoute(id string, dto bastion.RouteDTO) (*bastion.Route, error)
- func (s *Service) Upstreams() []Upstream
- type SourceError
- type TargetRef
- type TargetView
- type Upstream
- type UpstreamRoute
- type ValidationError
Constants ¶
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.
const Redacted = "[redacted]"
Redacted replaces a sensitive header value. The header's name stays, so an operator can see that it is set.
const RedactedPassword = "xxxxx"
RedactedPassword is what url.URL.Redacted shows in place of a password.
Variables ¶
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 ¶
RedactURL hides the password in a URL's userinfo. A URL without userinfo, or one that does not parse, comes back unchanged.
func SensitiveHeader ¶
SensitiveHeader reports whether a header's value may carry a credential.
Types ¶
type ConflictError ¶
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 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 (*Service) CreateRoute ¶
CreateRoute adds a manual route from entered values.
func (*Service) DeleteRoute ¶
DeleteRoute removes a manual route.
func (*Service) Entry ¶
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 ¶
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 ¶
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 ¶
UpdateRoute replaces a manual route from entered values.
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 ValidationError ¶
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