httpapi

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: Apache-2.0 Imports: 63 Imported by: 0

Documentation

Overview

Package httpapi is the HTTP driving adapter: it maps routes to use case services.

Index

Constants

View Source
const PrincipalOperator = "operator"

PrincipalOperator is the fallback principal id (the bootstrap admin also uses it, so historical "operator" attribution stays coherent). Once auth is wired, the real authenticated user is stamped into the context per request.

Variables

This section is empty.

Functions

func PrincipalFrom

func PrincipalFrom(ctx context.Context) string

PrincipalFrom returns the authenticated principal's id from ctx (the value used as the actor on every attributable action), defaulting to operator if unset.

func TenantFrom

func TenantFrom(ctx context.Context) string

TenantFrom returns the authenticated principal's tenant from ctx – the tenant that scopes the request's data and stamps new records. Empty = the single default tenant (single-tenant mode).

Types

type Authenticator

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

Authenticator validates the bearer token on each request via the Resolver and stamps the resolved principal into the request context for attribution.

func NewAuthenticator

func NewAuthenticator(resolve Resolver) *Authenticator

NewAuthenticator builds an authenticator from a token resolver.

func (*Authenticator) Middleware

func (a *Authenticator) Middleware(publicPaths map[string]bool, next http.Handler) http.Handler

Middleware enforces a valid bearer token on every route except publicPaths (no anonymous access) and stamps the authenticated principal into the context.

type Principal

type Principal struct {
	ID   string
	Name string
	Role string
	// TenantID is the tenant the principal belongs to – it scopes the request's data and stamps
	// new records. Empty = the single default tenant (single-tenant mode).
	TenantID string
}

Principal is the authenticated subject for a request.

type Resolver

type Resolver func(ctx context.Context, token string) (Principal, bool)

Resolver maps a presented bearer token to a Principal. ok=false means the token is unknown/disabled (→ 401). Implemented over the users service in the wiring.

type Router

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

Router wires HTTP routes to use case services.

func NewRouter

func NewRouter(log *slog.Logger, auth *Authenticator, eng *enguc.Service, sca *scauc.Service, aup *aupuc.Service, findings *findingsuc.Service, export *exportuc.Service, report *reportuc.Service, evidence *evidenceuc.Service, recon *reconuc.Service, logs ports.LogStream, transfer *transferuc.Service, audit *audituc.Service, vex *vexuc.Service, users *usersuc.Service, credentials *credentialsuc.Service) *Router

NewRouter builds the HTTP router.

func (*Router) EnableAgent

func (rt *Router) EnableAgent(orch *orchestrator.Orchestrator, sessions ports.AgentSessionStore, approvals *approval.Service, approvalStore ports.ApprovalStore, queue ports.JobQueue, concurrency, queueDepth int)

EnableAgent wires the AI agent routes. concurrency bounds inline (non-durable) runs; queueDepth bounds the DURABLE path – the max number of not-yet-terminal agent jobs admitted before the API returns 503 (with Retry-After), so a flood / retry-storm / dead-letter re-drive cannot grow the jobs table without bound. Call after NewRouter; if never called the agent endpoints are not registered (fail-safe: SYNAPSE_AGENT_ENABLED=false leaves off).

func (*Router) Handler

func (rt *Router) Handler() http.Handler

Handler returns the root http.Handler. Middleware chain (outermost first): normalize-path → auth → AUP gate → routes. Per-route RBAC is applied at registration via authz(perm, …) – not a path-set. Normalizing first ensures the public/AUP-exempt path-sets (matched on the request path) see exactly the path the ServeMux will route on (closes the raw-vs-cleaned path mismatch).

func (*Router) SetAgentDecisionStore

func (rt *Router) SetAgentDecisionStore(ds ports.DecisionStore)

SetAgentDecisionStore wires the read-only decision log behind GET …/decisions.

func (*Router) SetAgentPlanStore

func (rt *Router) SetAgentPlanStore(ps ports.PlanStore)

SetAgentPlanStore wires the read-only execution-plan view behind GET …/plan.

func (*Router) SetAgentRunContext

func (rt *Router) SetAgentRunContext(ctx context.Context)

SetAgentRunContext binds inline agent runs to a server-lifetime context (cancelled on shutdown) so a SIGTERM stops in-flight runs instead of leaving detached goroutines.

func (*Router) SetAutoVerifier

func (rt *Router) SetAutoVerifier(s autoVerifierService)

SetAutoVerifier wires the optional automated LLM judgment-verifier (nil ⇒ the auto-verify route is not registered). It seals a distinct-verifier verdict on each proposed gated judgment.

func (*Router) SetDASTWorkflow

func (rt *Router) SetDASTWorkflow(s dastWorkflowService)

SetDASTWorkflow wires the governed safe-DAST proposal/approval/run endpoints.

func (*Router) SetExploitation

func (rt *Router) SetExploitation(v findingVerifier)

SetExploitation wires the evidence-gated finding-verify endpoint.

func (*Router) SetJudgments

func (rt *Router) SetJudgments(s judgmentService)

SetJudgments wires the AI judgment lifecycle endpoints. nil ⇒ routes are not registered.

func (*Router) SetProjects

func (rt *Router) SetProjects(s projectService)

func (*Router) SetQualityGates

func (rt *Router) SetQualityGates(s qualityGateService)

SetQualityGates wires quality gate management endpoints.

func (*Router) SetQualityProfiles

func (rt *Router) SetQualityProfiles(s qualityProfileService)

SetQualityProfiles wires the quality-profile management endpoints. nil ⇒ routes are not registered.

func (*Router) SetRules

func (rt *Router) SetRules(s rulesService)

SetRules wires the rule catalog endpoints. nil ⇒ not registered.

func (*Router) SetRuntimeVerifier

func (rt *Router) SetRuntimeVerifier(s runtimeVerifierService)

SetRuntimeVerifier wires typed runtime-verifier result ingestion. nil means the route is absent.

func (*Router) SetThreatModel

func (rt *Router) SetThreatModel(s threatModelService)

SetThreatModel wires the architecture threat-model ingest/read endpoints. nil ⇒ not registered.

func (*Router) SetWriteupDrafts

func (rt *Router) SetWriteupDrafts(s writeupDraftService)

SetWriteupDrafts wires the human sign-off endpoints for AI-proposed write-up drafts. nil ⇒ not registered.

Jump to

Keyboard shortcuts

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