handler

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: BSD-2-Clause Imports: 25 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 handler owns the HTTP surface: the five canonical admin endpoints and the typed /api/v1 read endpoints.

Index

Constants

View Source
const DefaultLeaseSeconds = 300

DefaultLeaseSeconds is the lease a claim gets when the caller names none. Five minutes is long enough that a working run renews once rather than continuously, and short enough that a run that died frees its key quickly instead of blocking it until someone notices.

View Source
const MaxLeaseSeconds = 86400

MaxLeaseSeconds bounds a requested lease. The bound exists because time.Duration(ttl) * time.Second overflows int64 nanoseconds above ~9.2e9 s, and an overflowed lease renders lease_until in the past — a claim that is expired the moment it is taken. A day is longer than any run needs.

View Source
const RenewLeadSeconds = 60

RenewLeadSeconds is how long before expiry a holder should renew. The response states the instant rather than leaving the caller to re-derive it.

Variables

View Source
var MergeCallerLog = glog.Infof

MergeCallerLog records one line per merge request naming its caller. It is a variable rather than a direct glog call, matching vaultapi.MergeLog, so the specs can assert the line without depending on glog's file sinks. Production never reassigns it.

Functions

func AcquireClaimHandler added in v0.14.0

func AcquireClaimHandler(
	deps ClaimDeps,
	scope func(*http.Request) (ClaimScope, bool),
) http.HandlerFunc

AcquireClaimHandler takes a claim. A conflict means another holder has it and answers 409 claim_held with the holder that won.

func NewHandler

func NewHandler(
	ctx context.Context,
	index *vaultapi.Index,
	gatewaySecret string,
	vaultPath string,
	vaultName string,
	writer gitrest.Client,
	clock libtime.CurrentDateTime,
	taskPublisher publisher.TaskPublisher,
	refs gitrest.RefClient,
) http.Handler

NewHandler builds the service router. When gatewaySecret is non-empty every /api/v1/* request must carry it in X-Gateway-Secret; the admin endpoints stay unauthenticated, matching the fleet's contract.

The write endpoints need five things the read endpoints do not: vaultPath, to read the original bytes before re-rendering them; vaultName, which stamps the change event so a consumer sharing one topic across vaults can tell its own tasks apart; writer, to hand the rendered file to git-rest; clock, so an approval's instant is injected rather than read from the wall clock; and taskPublisher, which turns a landed write into a change event.

func ReadClaimHandler added in v0.14.0

func ReadClaimHandler(
	deps ClaimDeps,
	scope func(*http.Request) (ClaimScope, bool),
) http.HandlerFunc

ReadClaimHandler reports the current holder, or 404 when the claim is free.

func ReleaseClaimHandler added in v0.14.0

func ReleaseClaimHandler(
	deps ClaimDeps,
	scope func(*http.Request) (ClaimScope, bool),
) http.HandlerFunc

ReleaseClaimHandler releases a claim. The token is mandatory: releasing someone else's claim because you hold a stale one is the failure the compare-and-swap exists to prevent.

func RenewClaimHandler added in v0.14.0

func RenewClaimHandler(
	deps ClaimDeps,
	scope func(*http.Request) (ClaimScope, bool),
) http.HandlerFunc

RenewClaimHandler extends a held claim. A conflict means the lease was lost and answers 409 lease_lost.

func RepoClaimScope added in v0.14.0

func RepoClaimScope() func(*http.Request) (ClaimScope, bool)

RepoClaimScope resolves the {owner} and {repo} path variables to a repo claim scope. It fails only for a name that cannot be part of a claim key: a repository needs no index entry to be claimed.

func TaskClaimScope added in v0.14.0

func TaskClaimScope(index *vaultapi.Index) func(*http.Request) (ClaimScope, bool)

TaskClaimScope resolves the {id} path variable to a task claim scope.

Types

type ClaimDeps added in v0.14.0

type ClaimDeps struct {
	Refs  gitrest.RefClient
	Clock libtime.CurrentDateTime
}

ClaimDeps is what the claim handlers need: the index to resolve an identifier, the ref client that carries the claim to git-rest, and an injected clock so a lease instant is computed from a supplied time rather than the wall clock.

type ClaimScope added in v0.14.0

type ClaimScope struct {
	Scope string
	ID    string
	Key   string
}

ClaimScope is one claim's address: the key the transport stores it under and the identifier the typed API answers with.

func NewClaimScope added in v0.14.0

func NewClaimScope(scope string, id string, key string) ClaimScope

NewClaimScope builds an address for a claim. It is exported so the handlers can be exercised without an index: the resolver's job is to produce one of these, and a test that supplies it directly is testing the handler, not the resolver.

Jump to

Keyboard shortcuts

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