Documentation
¶
Overview ¶
Package handler owns the HTTP surface: the five canonical admin endpoints and the typed /api/v1 read endpoints.
Index ¶
- Constants
- Variables
- func AcquireClaimHandler(deps ClaimDeps, scope func(*http.Request) (ClaimScope, bool)) http.HandlerFunc
- func NewHandler(ctx context.Context, index *vaultapi.Index, store storage.PageStorage, ...) http.Handler
- func ReadClaimHandler(deps ClaimDeps, scope func(*http.Request) (ClaimScope, bool)) http.HandlerFunc
- func ReleaseClaimHandler(deps ClaimDeps, scope func(*http.Request) (ClaimScope, bool)) http.HandlerFunc
- func RenewClaimHandler(deps ClaimDeps, scope func(*http.Request) (ClaimScope, bool)) http.HandlerFunc
- func RepoClaimScope() func(*http.Request) (ClaimScope, bool)
- func TaskClaimScope(index *vaultapi.Index) func(*http.Request) (ClaimScope, bool)
- type ClaimDeps
- type ClaimScope
- type TaskDocument
Constants ¶
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.
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.
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 ¶
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, store storage.PageStorage, gatewaySecret string, vaultPath string, tasksDir 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
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
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.
type TaskDocument ¶ added in v0.15.0
type TaskDocument struct {
ID string `json:"id"`
Title string `json:"title"`
Frontmatter map[string]any `json:"frontmatter"`
Body string `json:"body"`
}
TaskDocument is one task read in full: the identifier the index resolves, the title, the whole frontmatter block and the markdown body. The listing serves the flat projection; this serves the page, which is what a caller that needs to read or rewrite a task's content actually wants.