handlers

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP added in v0.20.0

func ClientIP(r *http.Request) string

ClientIP extracts the caller's IP for per-IP limiting. It honors the left-most X-Forwarded-For entry (set by a trusted proxy/CDN in front of a public deployment) and falls back to the connection's RemoteAddr. Behind a proxy that doesn't set the header, all callers collapse to the proxy IP — a deployment concern, not a code one.

Types

type BranchDiffHandler

type BranchDiffHandler struct {
	// contains filtered or unexported fields
}

BranchDiffHandler serves raw branch patch diffs.

func NewBranchDiffHandler

func NewBranchDiffHandler(reg *registry.Registry, maxConcurrent int) *BranchDiffHandler

NewBranchDiffHandler creates a handler that resolves the per-request repo from the registry. maxConcurrent bounds simultaneous git diff subprocesses; 0 takes the default.

func (*BranchDiffHandler) ServeHTTP

func (h *BranchDiffHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles GET branch diff endpoint.

type BranchesHandler

type BranchesHandler struct {
	// contains filtered or unexported fields
}

BranchesHandler serves branch data.

func NewBranchesHandler

func NewBranchesHandler(reg *registry.Registry) *BranchesHandler

NewBranchesHandler creates a handler that resolves the per-request repo from the registry.

func (*BranchesHandler) ServeHTTP

func (h *BranchesHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles GET branches endpoints.

type ConfigHandler added in v0.20.0

type ConfigHandler struct {
	// contains filtered or unexported fields
}

ConfigHandler serves server capabilities at GET /api/v1/config. It carries no repo state — the values are fixed at server startup — and is served without a session so the web client can discover whether auth is required before attempting a login.

func NewConfigHandler added in v0.20.0

func NewConfigHandler(readOnly, authRequired, singleRepo bool) *ConfigHandler

NewConfigHandler creates a handler that reports the given capabilities.

func (*ConfigHandler) ServeHTTP added in v0.20.0

func (h *ConfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP returns the capability payload.

type EventsHandler

type EventsHandler struct {
	// contains filtered or unexported fields
}

EventsHandler streams server-sent events from the per-repo broadcaster. Each connection is scoped to one repo: subscribers to /repos/A/events only see events broadcast on repo A.

func NewEventsHandler

func NewEventsHandler(reg *registry.Registry, limits SSELimits) *EventsHandler

NewEventsHandler creates a handler that resolves the per-request repo from the registry and streams from that repo's broadcaster. limits bound concurrent connections so an unauthenticated public deployment can't be exhausted by clients opening unbounded streams; zero fields take the package defaults.

func (*EventsHandler) ServeHTTP

func (h *EventsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles the SSE connection for one repo.

type InstallationTokenProvider added in v0.20.0

type InstallationTokenProvider interface {
	InstallationToken(ctx context.Context, owner, name string) (string, error)
}

InstallationTokenProvider mints a durable GitHub App installation token for a repo. Onboarding clones with it (not the user's token) so the same credential works for the background sync loop later. The concrete implementation is *github.AppTokenProvider.

type ManagedSyncer added in v0.20.0

type ManagedSyncer interface {
	SyncRepo(ctx context.Context, repo registry.RepoRef) error
}

ManagedSyncer mirror-fetches and refreshes a managed repo by its GitHub coordinates, synchronously. The concrete implementation is *reposync.Syncer. The manual-sync handler uses the synchronous form (not the coalescer) so it can report success or failure back to the caller.

type OnboardHandler added in v0.20.0

type OnboardHandler struct {
	// contains filtered or unexported fields
}

OnboardHandler serves POST /api/v1/repos: a logged-in user asks the server to clone a GitHub repo and start serving it. The user's token authorizes the request (they must be able to see the repo); the clone itself uses a durable GitHub App installation token so the same credential serves later background syncs. The repo is recorded against the user's login so only they see it (see visibleTo).

func NewOnboardHandler added in v0.20.0

func NewOnboardHandler(reg *registry.Registry, st RepoPersister, cipher *auth.Cipher, reposRoot string, tokens InstallationTokenProvider) *OnboardHandler

NewOnboardHandler wires an onboarding handler. store, cipher, and tokens may be nil (persistence / auth / GitHub App not configured), in which case requests are refused with a clear 503; the handler guards at request time so it is safe to mount unconditionally.

func (*OnboardHandler) ServeHTTP added in v0.20.0

func (h *OnboardHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RepoHandler

type RepoHandler struct {
	// contains filtered or unexported fields
}

RepoHandler serves repository metadata.

func NewRepoHandler

func NewRepoHandler(reg *registry.Registry) *RepoHandler

NewRepoHandler creates a handler that resolves the per-request repo from the registry.

func (*RepoHandler) ServeHTTP

func (h *RepoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles GET repo endpoints.

type RepoPersister added in v0.20.0

type RepoPersister interface {
	AddRepo(ctx context.Context, r store.Repo) (store.Repo, error)
}

RepoPersister is the slice of the repo store the onboarding handler needs. A nil RepoPersister means persistence is unavailable (no -database-url) and onboarding is refused.

type RepoSyncTrigger added in v0.20.0

type RepoSyncTrigger interface {
	Trigger(repo registry.RepoRef)
}

RepoSyncTrigger requests an asynchronous, coalesced sync of a managed repo by its GitHub coordinates. The concrete implementation is *reposync.Coalescer; the handler takes the narrow interface so handlers stays decoupled from reposync, and so the receiver never blocks on a fetch.

type ReposListHandler added in v0.18.1

type ReposListHandler struct {
	// contains filtered or unexported fields
}

ReposListHandler serves GET /api/v1/repos — the unscoped index of repos the server is configured to serve. Clients use this to render a picker before scoping subsequent calls to /api/v1/repos/{repoID}/...

func NewReposListHandler added in v0.18.1

func NewReposListHandler(reg *registry.Registry) *ReposListHandler

NewReposListHandler creates a handler backed by reg.

func (*ReposListHandler) ServeHTTP added in v0.18.1

func (h *ReposListHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP returns one RepoSummary per registry entry, sorted by ID.

type SSELimits added in v0.20.0

type SSELimits struct {
	// MaxGlobal caps concurrent SSE connections across all repos. 0 -> default.
	MaxGlobal int
	// MaxPerIP caps concurrent SSE connections from a single client IP.
	// 0 -> default.
	MaxPerIP int
	// MaxLifetime force-closes a connection after this duration. EventSource
	// clients reconnect transparently, so a bounded lifetime caps how long
	// any single connection can hold resources. 0 -> default.
	MaxLifetime time.Duration
}

SSELimits bounds concurrent Server-Sent Events connections. Zero fields fall back to the package defaults, so callers can set only what they want to override.

type StacksHandler

type StacksHandler struct {
	// contains filtered or unexported fields
}

StacksHandler serves stack data.

func NewStacksHandler

func NewStacksHandler(reg *registry.Registry) *StacksHandler

NewStacksHandler creates a handler that resolves the per-request repo from the registry.

func (*StacksHandler) ServeHTTP

func (h *StacksHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles GET stacks endpoints.

type SubmitHandler

type SubmitHandler struct {
	// contains filtered or unexported fields
}

SubmitHandler handles POST requests to submit a stack.

func NewSubmitHandler

func NewSubmitHandler(reg *registry.Registry) *SubmitHandler

NewSubmitHandler creates a handler that resolves the per-request repo from the registry.

func (*SubmitHandler) ServeHTTP

func (h *SubmitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles the submit request.

type SyncHandler added in v0.20.0

type SyncHandler struct {
	// contains filtered or unexported fields
}

SyncHandler serves POST /api/v1/repos/{repoID}/sync: force an immediate refresh of one repo on demand. It is the manual complement to the webhook and interval refreshes, and the primary way to pull remote changes on a local server that GitHub cannot reach with a webhook.

The refresh path depends on whether the repo is a server-managed mirror:

  • Managed mirror: mirror-fetch from the remote, then rebuild. The checkout runs detached, so fetching every branch is safe.
  • Local -cwd working repo: only re-read the on-disk refs and rebuild. It is never mirror-fetched, because that detaches HEAD and would corrupt the operator's working tree (see safety-invariants.md). Pulling the remote on a working repo is the human's job (git fetch / stackit sync); this just reflects whatever is on disk right now.

func NewSyncHandler added in v0.20.0

func NewSyncHandler(reg *registry.Registry, syncer ManagedSyncer) *SyncHandler

NewSyncHandler wires a manual-sync handler over the registry and syncer.

func (*SyncHandler) ServeHTTP added in v0.20.0

func (h *SyncHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ViewAssembler

type ViewAssembler struct {
	// contains filtered or unexported fields
}

ViewAssembler builds the combined /view payload.

func NewViewAssembler

func NewViewAssembler(eng engine.BranchReader, gh github.Client, remote string, visibility Visibility) *ViewAssembler

func (*ViewAssembler) Build

type ViewHandler

type ViewHandler struct {
	// contains filtered or unexported fields
}

ViewHandler serves the combined view payload for the frontend.

func NewViewHandler

func NewViewHandler(reg *registry.Registry, visibility Visibility) *ViewHandler

NewViewHandler creates a handler that resolves the per-request repo from the registry. Assembly logic lives in ViewAssembler so this handler stays transport-focused. visibility controls whether the operator identity is included in the payload (omitted for a public read-only server).

func (*ViewHandler) ServeHTTP

func (h *ViewHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles GET view endpoints.

type Visibility added in v0.20.0

type Visibility int

Visibility controls whether a handler may expose operator- or viewer-identifying fields in its response. A public (read-only) server must not leak who is running it, so identity fields like currentUser are omitted under VisibilityPublic.

const (
	// VisibilityPrivate is the authenticated/local posture: responses may
	// include the operator/viewer identity.
	VisibilityPrivate Visibility = iota
	// VisibilityPublic is the anonymous read-only posture: identity fields
	// are omitted so an unauthenticated caller can't learn who runs the
	// server (and so reads don't trigger GitHub calls on the operator's
	// token).
	VisibilityPublic
)

type WebhookHandler added in v0.20.0

type WebhookHandler struct {
	// contains filtered or unexported fields
}

WebhookHandler receives GitHub webhook deliveries at POST /api/v1/webhooks/github and turns a push into a refresh of the matching managed checkout. It is the low-latency complement to the interval sync loop; the loop remains as a backstop for missed deliveries and for metadata-ref pushes, which GitHub does not deliver push events for.

The route bypasses the session/CSRF gate (GitHub can't carry either) and is authenticated solely by the HMAC signature, so it must fail closed when no secret is configured — otherwise it would be an open refresh trigger.

func NewWebhookHandler added in v0.20.0

func NewWebhookHandler(secret string, trigger RepoSyncTrigger) *WebhookHandler

NewWebhookHandler wires a webhook receiver. An empty secret or nil trigger leaves the endpoint disabled (it 404s), so it is safe to mount unconditionally and gate purely on configuration.

func (*WebhookHandler) ServeHTTP added in v0.20.0

func (h *WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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