Documentation
¶
Overview ¶
Package config defines the shared configuration types, validation functions, and sentinel errors used across the API packages. It exists to break the import cycle between the top-level api package and the routes subpackage.
Index ¶
- Constants
- Variables
- func BuildUpdateParams(opts Options) types.UpdateParams
- func FormatEndpoints(endpointMap EnabledEndpointsMap) string
- func SetEndpointConfig(endpointMap EnabledEndpointsMap, cfg *types.RunConfig)
- func TimeoutMiddleware() fiber.Handler
- func ValidateUpdateOptions(opts Options) error
- type EnabledEndpointsMap
- type Options
Constants ¶
const ( // HandlerTimeout defines the maximum duration for non-update handlers to // complete. This prevents slow Docker API calls from blocking connections // indefinitely. HandlerTimeout = 30 * time.Second // DefaultCheckTimeout defines the default maximum duration for the /v1/check // API endpoint. DefaultCheckTimeout = 5 * time.Minute // DefaultUpdateTimeout defines the default maximum duration for the /v1/update // API endpoint. DefaultUpdateTimeout = 10 * time.Minute )
const ( EndpointHealth = "health" EndpointUpdate = "update" EndpointMetrics = "metrics" EndpointContainers = "containers" EndpointCheck = "check" EndpointHistory = "history" EndpointImages = "images" EndpointConfig = "config" EndpointEvents = "events" EndpointSwagger = "swagger" )
Canonical HTTP API endpoint names corresponding to valid values for the http-api-endpoints configuration option.
Variables ¶
var ( // ErrMissingRunUpdatesWithNotifications indicates RunUpdatesWithNotifications was not provided. ErrMissingRunUpdatesWithNotifications = errors.New("RunUpdatesWithNotifications must be provided when EnableUpdateAPI is set") // ErrMissingFilterByImage indicates FilterByImage was not provided when an // endpoint that builds image-scoped filters is enabled. ErrMissingFilterByImage = errors.New("FilterByImage must be provided when update or check API is enabled") // ErrMissingDefaultMetrics indicates DefaultMetrics was not provided when // an endpoint that requires the metrics store is enabled. ErrMissingDefaultMetrics = errors.New("DefaultMetrics must be provided when update, metrics, or history API is enabled") // ErrMissingAPIToken indicates the API token is empty or unset. ErrMissingAPIToken = errors.New("API token is empty or unset") // ErrMissingEventsAPIToken indicates events token is not set when events API is enabled. ErrMissingEventsAPIToken = errors.New("events API token is required when events API is enabled") // ErrMissingEventBroadcaster indicates EventBroadcaster was not provided when events API is enabled. ErrMissingEventBroadcaster = errors.New("EventBroadcaster must be provided when events API is enabled") // ErrMissingTLSConfig indicates only one of TLS cert/key was provided. ErrMissingTLSConfig = errors.New("TLS requires both TLS Cert Path and TLS Key Path to be set") // ErrMissingLogger indicates Options.Logger was nil when an API endpoint is enabled. ErrMissingLogger = errors.New("API Logger must be provided when any HTTP API endpoint is enabled") )
var ( // ErrUnknownEndpoint is returned when an endpoint name is not recognized. ErrUnknownEndpoint = errors.New("unknown HTTP API endpoint") // ErrAllMustBeAlone is returned when "all" appears with other names. ErrAllMustBeAlone = errors.New(`"all" must be the only value in http-api-endpoints`) )
var AllEndpointNames = []string{ EndpointHealth, EndpointUpdate, EndpointMetrics, EndpointContainers, EndpointCheck, EndpointHistory, EndpointImages, EndpointConfig, EndpointEvents, EndpointSwagger, }
AllEndpointNames is the ordered list of every known endpoint name.
Functions ¶
func BuildUpdateParams ¶
func BuildUpdateParams(opts Options) types.UpdateParams
BuildUpdateParams returns the complete UpdateParams snapshot for HTTP-triggered updates.
Policy fields come only from BaseParams so HTTP, schedule, and run-once paths share the same config.UpdateParams construction. RunOnce is forced false for HTTP sessions.
Parameters:
- opts: API configuration options.
Returns:
- types.UpdateParams: Parameters for the update pipeline.
func FormatEndpoints ¶
func FormatEndpoints(endpointMap EnabledEndpointsMap) string
FormatEndpoints returns a stable comma-separated list of endpoint names in AllEndpointNames order (only those present in the map).
Parameters:
- endpointMap: Endpoint map to format.
Returns:
- string: Comma-separated names, or empty if map is empty.
func SetEndpointConfig ¶
func SetEndpointConfig(endpointMap EnabledEndpointsMap, cfg *types.RunConfig)
SetEndpointConfig populates the runtime configuration with the HTTP API Endpoints parsed from the http-api-endpoints configuration option.
Parameters:
- endpointMap: Enabled endpoints.
- cfg: RunConfig to update.
func TimeoutMiddleware ¶
TimeoutMiddleware returns a Fiber middleware that enforces a per-request timeout for all wrapped handlers. This prevents slow Docker API calls from blocking connections indefinitely.
func ValidateUpdateOptions ¶
ValidateUpdateOptions validates that all required update options are set.
Parameters:
- opts: API configuration options to validate.
Returns:
- error: Non-nil if any required option is missing.
Types ¶
type EnabledEndpointsMap ¶
type EnabledEndpointsMap map[string]struct{}
EnabledEndpointsMap is the map of enabled HTTP API endpoints.
func ParseAPIEndpoints ¶
func ParseAPIEndpoints(values []string) (EnabledEndpointsMap, error)
ParseAPIEndpoints parses an endpoint allowlist.
Filter rules:
- Values may already be split on commas or spaces by flag/env parsing
- Each entry is still trimmed and lowercased
- The special value "all" (alone) expands to every known endpoint
- Duplicates are ignored
- An empty list yields an empty set
Parameters:
- values: Endpoint names, or a single "all".
Returns:
- EndpointMap: Parsed map of endpoint names.
- error: Non-nil if the value is invalid.
func ParseLegacyOptions
deprecated
func ParseLegacyOptions(update, metrics, containers bool) EnabledEndpointsMap
ParseLegacyOptions builds a map of endpoints from legacy enable configuration options (update, metrics, containers).
Deprecated: Prefer ParseAPIEndpoints with http-api-endpoints. Legacy flags will be removed in the v2 release.
Parameters:
- update: Whether http-api-update is set.
- metrics: Whether http-api-metrics is set.
- containers: Whether http-api-containers is set.
Returns:
- EndpointMap: Mapped endpoint names.
TODO: Remove ParseLegacyOptions when legacy HTTP API flags are removed in v2.
func ResolveEndpoints ¶
func ResolveEndpoints(endpoints []string, legacyUpdate, legacyMetrics, legacyContainers bool) (EnabledEndpointsMap, error)
ResolveEndpoints selects the active endpoint map from the canonical allowlist and/or legacy configuration options.
Rules:
- Parse the allowlist when non-empty (unknown names fail and "all" expands fully).
- Union with any legacy update/metrics/containers flags (deduplicated).
- When legacy flags are used, log one deprecation warning with the final equivalent allowlist value.
- Empty allowlist and no legacy flags is equivalent to an empty map (API off).
Parameters:
- endpoints: Values from http-api-endpoints.
- legacyUpdate: Legacy http-api-update.
- legacyMetrics: Legacy http-api-metrics.
- legacyContainers: Legacy http-api-containers.
Returns:
- EndpointMap: Resolved enabled endpoints.
- error: Non-nil if the allowlist contains invalid values.
TODO: Drop legacy parameters when removing legacy HTTP API configuration options in v2.
func (EnabledEndpointsMap) Contains ¶
func (m EnabledEndpointsMap) Contains(name string) bool
Contains returns whether or not the value is in the map of enabled endpoints.
func (EnabledEndpointsMap) Empty ¶
func (m EnabledEndpointsMap) Empty() bool
Empty reports whether or not the map of enabled endpoints is empty.
type Options ¶
type Options struct {
// Logger is the zerolog logger for the HTTP API server and middleware.
// Required when any HTTP API endpoint is enabled.
// SetupAndStartAPI returns ErrMissingLogger if it is nil.
// The composition root should pass a child with notify=no when high-volume
// request/auth logs must not trigger notification hooks.
// New also attaches notify=no on request and rate-limit log paths.
Logger *zerolog.Logger
// Host is the HTTP bind host (empty means all interfaces).
Host string
// Port is the HTTP bind port.
Port string
// Token authenticates HTTP API requests.
Token string
// EventsToken authenticates the events SSE endpoint.
EventsToken string
// RateLimit is the maximum authentication requests per minute per IP.
RateLimit int
// EnableUpdateAPI enables the /v1/update endpoint.
EnableUpdateAPI bool
// EnableMetricsAPI enables the metrics endpoint.
EnableMetricsAPI bool
// EnableContainersAPI enables the containers listing endpoint.
EnableContainersAPI bool
// EnableCheckAPI enables the /v1/check endpoint.
EnableCheckAPI bool
// EnableSwaggerAPI enables the Swagger UI endpoint.
EnableSwaggerAPI bool
// EnableHealthAPI enables health probe endpoints.
EnableHealthAPI bool
// EnableHistoryAPI enables the history endpoint.
EnableHistoryAPI bool
// EnableImagesAPI enables the images endpoint.
EnableImagesAPI bool
// EnableConfigAPI enables the config inspection endpoint.
EnableConfigAPI bool
// EnableEventsAPI enables the events SSE endpoint.
EnableEventsAPI bool
// UnblockHTTPAPI keeps scheduled polls running when the HTTP API is enabled.
UnblockHTTPAPI bool
// NoStartupMessage suppresses startup logs and notifications.
NoStartupMessage bool
// TLSCertPath is the path to the TLS certificate file.
TLSCertPath string
// TLSKeyPath is the path to the TLS key file.
TLSKeyPath string
// CORSAllowedOrigins lists allowed CORS origins.
CORSAllowedOrigins []string
// TrustedProxies lists trusted proxy IPs or CIDRs.
TrustedProxies []string
// ProxyHeader is the header used for the real client IP behind a reverse proxy.
ProxyHeader string
// Filter is the process-wide container filter predicate.
Filter types.Filter
// FilterDesc is a human-readable description of the filter for startup messaging.
FilterDesc string
// UpdateLock serializes concurrent update sessions.
UpdateLock chan bool
// BaseParams is the complete update policy snapshot from config.UpdateParams.
BaseParams types.UpdateParams
// IncludeStopped is exposed on the config API (client list option).
IncludeStopped bool
// IncludeRestarting is exposed on the config API (client list option).
IncludeRestarting bool
// LabelEnable is exposed on the config API (filter option).
LabelEnable bool
// Client is the Docker client used by API handlers.
Client container.Client
// Notifier sends update and check status messages.
Notifier types.Notifier
// NotificationSplitByContainer sends one notification per updated container when true.
NotificationSplitByContainer bool
// Scope limits operations to containers matching this Watchtower scope.
Scope string
// Version is the Watchtower version string used in startup messaging.
Version string
// Startup holds resolved values for blocking-mode startup messaging.
Startup logging.StartupParams
// RunUpdatesWithNotifications runs the scan-and-update pipeline for HTTP update requests.
RunUpdatesWithNotifications func(context.Context, types.Filter, types.UpdateParams) *mt.Metric
// FilterByImage builds an image-scoped filter for update and check requests.
FilterByImage func([]string, types.Filter) types.Filter
// DefaultMetrics returns the process metrics store.
DefaultMetrics func() *mt.Metrics
// WriteStartupMessage writes the blocking-mode startup message when the update API starts.
WriteStartupMessage func(logging.StartupParams)
// EventBroadcaster publishes action events to SSE subscribers.
EventBroadcaster *events.Broadcaster
// OnUnexpectedServerStop is invoked when the HTTP server exits with an
// unexpected error while running in non-blocking mode. Callers typically
// cancel the process context so scheduling shuts down with the API.
OnUnexpectedServerStop func(error)
// CheckTimeout is the maximum duration for the /v1/check API endpoint.
// If zero, DefaultCheckTimeout is used.
CheckTimeout time.Duration
// UpdateTimeout is the maximum duration for the /v1/update API endpoint.
// If zero, DefaultUpdateTimeout is used.
UpdateTimeout time.Duration
}
Options holds transport and runtime configuration for SetupAndStartAPI.