http

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConfigDocument = goerr.New("invalid workspace configuration document",
	goerr.T(errutil.TagBenign))

ErrInvalidConfigDocument marks a DB check failure caused by the configuration in the request rather than by the server. The DBConsistencyChecker implementation wraps parse and validation failures with it so this handler can answer 400 instead of 500.

The benign tag lives on the sentinel rather than being applied where the response is written: goerr.HasTag resolves an error that contains a goerr.Join result through Errors.HasTag, which inspects only the joined errors, so a tag attached to an outer wrapper of a joined error is never found. As one of the joined errors, the sentinel is.

View Source
var ErrMCPAuthorizationDenied = goerr.New("authorization denied")

ErrMCPAuthorizationDenied is returned to the MCP client when the Rego policy denies a tool call (result.allow is false).

Functions

func NewMCPHandler

func NewMCPHandler(
	caseUC *usecase.CaseUseCase,
	actionUC *usecase.ActionUseCase,
	registry *model.WorkspaceRegistry,
	policy interfaces.PolicyClient,
	env map[string]string,
) http.Handler

NewMCPHandler builds the http.Handler that serves the MCP endpoint over Streamable HTTP (mounted at /mcp by the Server). policy is mandatory: every tool call is authorized against data.auth.mcp before any data is read.

The transport runs in Stateless mode so each HTTP request carries its own authorization and the request context (populated by withMCPRequestContext) flows into the tool handlers — there is no cross-request session state held in process memory.

func SlackSignatureMiddleware

func SlackSignatureMiddleware(signingSecret string) func(http.Handler) http.Handler

SlackSignatureMiddleware creates a middleware that verifies Slack request signatures

Types

type AuthUseCase

type AuthUseCase = usecase.AuthUseCaseInterface

type ConfigDocument added in v0.3.0

type ConfigDocument struct {
	// Name identifies the document in error messages — a multipart part's file
	// name, or dbCheckDefaultDocumentName for a raw body.
	Name string
	// Data is the raw TOML document.
	Data []byte
}

ConfigDocument is one workspace configuration (TOML) document taken from a request.

type DBCheckHandler added in v0.3.0

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

DBCheckHandler exposes POST /api/validate/db: the `validate --check-db` consistency report over HTTP, against workspace configuration supplied in the request instead of the configuration this process was started with.

The endpoint is intentionally unauthenticated, on the same assumption as POST /hooks/tick: the deployment fronts it with IAP / internal-network policy. The response body names Case, Action and Memo ids and echoes offending field values, so exposing it publicly would leak workspace data.

Unlike the tick hook this responds synchronously — the report IS the result, so it cannot be dispatched to the background. A workspace with many Cases takes as long as the scan takes; call it from tooling that tolerates that, not from a browser request path.

func NewDBCheckHandler added in v0.3.0

func NewDBCheckHandler(checker DBConsistencyChecker) *DBCheckHandler

NewDBCheckHandler builds the handler.

func (*DBCheckHandler) ServeHTTP added in v0.3.0

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

ServeHTTP implements http.Handler.

type DBConsistencyChecker added in v0.3.0

type DBConsistencyChecker interface {
	CheckDBConsistency(ctx context.Context, docs []ConfigDocument) (*usecase.ValidationResult, error)
}

DBConsistencyChecker checks the persisted data of every workspace defined by the supplied configuration documents. The implementation lives in pkg/cli, which owns both TOML parsing and the usecase; a configuration-level failure MUST be wrapped with ErrInvalidConfigDocument.

type Options

type Options func(*Server)

func WithAuth

func WithAuth(authUC AuthUseCase) Options

func WithDBCheck added in v0.3.0

func WithDBCheck(handler *DBCheckHandler) Options

WithDBCheck wires the POST /api/validate/db endpoint so operator tooling can run the `validate --check-db` consistency report against workspace configuration it submits. nil handler leaves the route unregistered.

func WithGraphiQL

func WithGraphiQL(enabled bool) Options

func WithMCP

func WithMCP(handler http.Handler) Options

WithMCP wires the MCP (Model Context Protocol) endpoint at /mcp. The handler already embeds its own authorization (Rego policy) and request-context middleware, so it is mounted as-is. nil handler leaves the route unregistered.

func WithSlackCommand

func WithSlackCommand(handler *SlackCommandHandler) Options

func WithSlackInteraction

func WithSlackInteraction(handler *SlackInteractionHandler) Options

func WithSlackService

func WithSlackService(svc slack.Service) Options

func WithSlackWebhook

func WithSlackWebhook(handler *SlackWebhookHandler, signingSecret string) Options

func WithTickHook

func WithTickHook(handler *TickHookHandler) Options

WithTickHook wires the POST /hooks/tick handler so external schedulers (Cloud Scheduler, internal cron) can trigger a sweep over scheduled Jobs. nil handler leaves the route unregistered.

func WithWorkspaceRegistry

func WithWorkspaceRegistry(registry *model.WorkspaceRegistry) Options

type Server

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

func New

func New(gqlHandler http.Handler, opts ...Options) (*Server, error)

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

type SlackCommandHandler

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

SlackCommandHandler handles Slack slash command requests

func NewSlackCommandHandler

func NewSlackCommandHandler(slackUC *usecase.SlackUseCases) *SlackCommandHandler

NewSlackCommandHandler creates a new Slack command handler

func (*SlackCommandHandler) ServeHTTP

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

ServeHTTP handles Slack slash command webhook requests. It supports both /hooks/slack/command and /hooks/slack/command/{ws_id} paths.

type SlackInteractionHandler

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

SlackInteractionHandler handles Slack interactive component payloads (button clicks, modal submissions, etc.)

All usecase dependencies are required at construction time; this handler is only wired when Slack webhooks are enabled, and at that point every Slack surface (action buttons, slash command modals, draft buttons) is in play. Optional wiring previously left fields nil and forced every entry point to guard against zero-value handlers — a fragile pattern that masked real wiring regressions behind silent skips.

func NewSlackInteractionHandler

func NewSlackInteractionHandler(
	actionUC *usecase.ActionUseCase,
	agentUC *usecase.AgentUseCase,
	slackUC *usecase.SlackUseCases,
	caseUC *usecase.CaseUseCase,
	mentionProposalUC *usecase.MentionProposalUseCase,
	jobRunner *jobuc.JobRunner,
) *SlackInteractionHandler

NewSlackInteractionHandler creates a new Slack interaction handler. Every dependency except jobRunner is mandatory; jobRunner may be nil in deployments that do not run interactive Jobs.

func (*SlackInteractionHandler) ServeHTTP

ServeHTTP handles Slack interaction webhook requests

type SlackWebhookHandler

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

SlackWebhookHandler handles Slack Events API webhook requests

func NewSlackWebhookHandler

func NewSlackWebhookHandler(slackUC *usecase.SlackUseCases) *SlackWebhookHandler

NewSlackWebhookHandler creates a new Slack webhook handler

func (*SlackWebhookHandler) ServeHTTP

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

ServeHTTP handles Slack webhook requests

type TickHookHandler

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

TickHookHandler exposes POST /hooks/tick. The endpoint is intentionally unauthenticated: the assumption is that the deployment fronts it with IAP / internal-network policy. Body is ignored.

The handler returns 200 immediately and dispatches the sweep in the background, mirroring the Slack hook ack-fast pattern: external schedulers (Cloud Scheduler) treat a delayed response as failure (and may retry, doubling the work) while the LLM round-trips inside the sweep can comfortably exceed any reasonable HTTP timeout.

func NewTickHookHandler

func NewTickHookHandler(scanner TickScanner) *TickHookHandler

NewTickHookHandler builds the handler.

func (*TickHookHandler) ServeHTTP

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

ServeHTTP implements http.Handler.

type TickScanner

type TickScanner interface {
	Scan(ctx context.Context) error
}

TickScanner is the narrow surface the HTTP layer needs to fire a scheduled-Job sweep. The runtime implementation lives in pkg/usecase/job.ScheduledScanner; this interface keeps the HTTP layer off the usecase import.

Jump to

Keyboard shortcuts

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