api

package
v1.12.2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package api hosts the HTTP control-plane for watchtower (token auth, /v1/update, /v1/metrics).

Index

Constants

View Source
const (

	// DefaultListenAddr is used when --http-api-host isn't set. Binds to
	// every interface on port 8080, matching the pre-v1.12 behavior.
	DefaultListenAddr = ":8080"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Token      string
	ListenAddr string
	// contains filtered or unexported fields
}

API is the http server responsible for serving the HTTP API endpoints

func New

func New(token string) *API

New is a factory function creating a new API instance

func (*API) RegisterFunc

func (api *API) RegisterFunc(path string, fn http.HandlerFunc)

RegisterFunc is a wrapper around http.HandleFunc that also sets the flag used to determine whether to launch the API

func (*API) RegisterHandler

func (api *API) RegisterHandler(path string, handler http.Handler)

RegisterHandler is a wrapper around http.Handler that also sets the flag used to determine whether to launch the API

func (*API) RegisterPublicHandler added in v1.11.0

func (api *API) RegisterPublicHandler(path string, handler http.Handler)

RegisterPublicHandler registers a handler without token auth. Used for the Prometheus /v1/metrics endpoint when --http-api-metrics-no-auth is set — Prometheus scraping is conventionally unauthenticated on trusted networks and bearer-token plumbing for every scraper is friction-for-no-gain in that setup. Network-level controls (localhost bind, reverse proxy, firewall) are expected to provide the real access boundary.

func (*API) RequireToken

func (api *API) RequireToken(fn http.HandlerFunc) http.HandlerFunc

RequireToken is wrapper around http.HandleFunc that checks token validity using a constant-time comparison so watchtower isn't a timing oracle for operators who expose :8080 to an untrusted network.

func (*API) Start

func (api *API) Start(block bool) error

Start the API and serve over HTTP. Requires an API Token to be set.

Directories

Path Synopsis
Package audit exposes the HTTP handler for the /v1/audit endpoint.
Package audit exposes the HTTP handler for the /v1/audit endpoint.
Package metrics exposes the Prometheus /v1/metrics HTTP handler.
Package metrics exposes the Prometheus /v1/metrics HTTP handler.
Package update exposes the HTTP handler for the /v1/update API endpoint.
Package update exposes the HTTP handler for the /v1/update API endpoint.

Jump to

Keyboard shortcuts

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