Documentation
¶
Overview ¶
Code generated by apic; DO NOT EDIT.
Index ¶
- Variables
- func RegisterGeneratedAPI(mux *http.ServeMux, srv ServerInterface, opts APIOptions)
- type APIOptions
- type CatchAllServerInterface
- type OAuth2Error
- type RouteInfo
- type ServerInterface
- type StatusError
- type UnimplementedServer
- func (UnimplementedServer) Gallery(_ http.ResponseWriter, _ *http.Request, _ *types.GalleryUploadReq) (*types.GalleryUploadResp, error)
- func (UnimplementedServer) GetItemID(_ http.ResponseWriter, _ *http.Request, _ *types.ItemGetReq) (*types.ItemGetResp, error)
- func (UnimplementedServer) GetItems(_ http.ResponseWriter, _ *http.Request, _ *types.ItemListReq) (*types.ItemListResp, error)
- func (UnimplementedServer) GetModuleLatest(_ http.ResponseWriter, _ *http.Request, _ *map[string]any) (map[string]any, error)
- func (UnimplementedServer) PostItems(_ http.ResponseWriter, _ *http.Request, _ *types.ItemCreateReq) (*types.ItemCreateResp, error)
- func (UnimplementedServer) PostUpload(_ http.ResponseWriter, _ *http.Request, _ *types.ItemUploadReq) (*types.ItemUploadResp, error)
- func (UnimplementedServer) PutItemID(_ http.ResponseWriter, _ *http.Request, _ *types.ItemUpdateReq) (*types.ItemUpdateResp, error)
- func (UnimplementedServer) RemoveItem(_ http.ResponseWriter, _ *http.Request, _ *types.ItemDeleteReq) (*types.ItemDeleteResp, error)
- func (UnimplementedServer) Tags(_ http.ResponseWriter, _ *http.Request, _ *types.TagCreateReq) (*types.TagCreateResp, error)
- type WebauthnInfo
Constants ¶
This section is empty.
Variables ¶
var ErrBadRequest = errors.New("bad request") // → 400 (post-validation business 400)
var ErrConflict = errors.New("conflict") // → 409
var ErrForbidden = errors.New("forbidden") // → 403 (post-auth business denial)
var ErrNilCatchAllHandler = errors.New("nil catch-all handler")
var ErrNotFound = errors.New("not found") // → 404
var ErrNotImplemented = errors.New("not implemented") // → 501
Generated handler error sentinels. Returning one of these from a ServerInterface method maps to the matching HTTP status code via the per-route error-mapping switch. Anything else non-nil falls through to 500. A *StatusError lets a handler carry a custom code + message while still using the generated response envelope.
A-NEW-4 (docs/GENERATOR_BUGS.md).
var ErrUnprocessable = errors.New("unprocessable") // → 422
Functions ¶
func RegisterGeneratedAPI ¶
func RegisterGeneratedAPI(mux *http.ServeMux, srv ServerInterface, opts APIOptions)
RegisterGeneratedAPI registers generated HTTP routes with validation and middleware.
GAP-0076: when the configuration declares at least one route with auth: "jwt" but the caller supplied a nil opts.AuthJWT, this function panics with securex.ErrAuthVerifierRequired BEFORE any route is registered. The same guard fires for auth: "api_key" + nil opts.Auth via securex.ErrAuthAPIKeyRequired. Use securex.NewTestVerifier() as the unit-test escape hatch.
Types ¶
type APIOptions ¶
type APIOptions struct {
Auth func(*http.Request) error
AuthJWT func(*http.Request) error
// AuthMTLS is invoked for routes whose config declared auth: "mtls"
// AFTER the basic securex.VerifyMTLS gate has accepted the request.
// Use this hook to enforce deployment-specific issuer-label policy
// (PIV/CAC/custom) using policy.SupportedIssuers. Returning a non-nil
// error rejects the request with 401.
AuthMTLS func(*http.Request, securex.MTLSPolicy) error
// MTLSRuntimes holds the boot-constructed CRL/OCSP revocation checkers
// and CAC/PIV certificate-policy verifier for every mtls route whose
// config declares crl/ocsp/cac_piv/principal_mapping (L-51), keyed by
// "METHOD /path". server_lib.go.tmpl's Serve constructs this map ONCE
// at boot (mtlsx.CRLChecker/OCSPChecker hold response caches and make
// network calls, so they must never be rebuilt per request) and passes
// it straight through here. A nil map, or a route missing from it, is
// the zero securex.MTLSRuntime{} -- "no CRL/OCSP/CAC-PIV enforcement
// for this route" -- which is exactly pre-L-51 behavior, so this field
// is fully backward compatible with hand-built APIOptions literals
// (tests, custom entrypoints) that never set it.
MTLSRuntimes map[string]securex.MTLSRuntime
// AuthWebhook resolves a per-route HMAC secret keyed on the
// WebhookPolicy.Name supplied at codegen. Returning (nil, err)
// rejects the request with a generic 401 envelope before any
// signature check. The generator wires server.go.tmpl to populate
// this from rc.Security.Webhooks; consumers that supply their own
// resolver (e.g. a Vault-backed lookup) pass it via
// APIOptions{AuthWebhook: myFunc}.
AuthWebhook func(name string) ([]byte, error)
// CookieName is the name of the HttpOnly cookie carrying the session JWT
// for routes with auth: "cookie". Empty falls back to "session" at
// request time. Wired by server_lib from security.auth.cookie_name.
CookieName string
// CSRF, when non-nil, enforces signed double-submit CSRF tokens on
// cookie-authenticated state-changing requests and powers the issuance
// endpoint. Wired by server_lib from security.csrf.
CSRF *csrfx.Signer
CSRFCookieName string
CSRFHeaderName string
// CSRFSessionID extracts the session identifier a token is bound to
// (default: verified claims Subject).
CSRFSessionID func(*http.Request) string
GlobalRate float64
GlobalBurst float64
}
APIOptions configures cross-cutting concerns for generated routes.
type CatchAllServerInterface ¶
type CatchAllServerInterface interface {
HandleRoute(w http.ResponseWriter, r *http.Request, route RouteInfo, req any) (any, error)
}
CatchAllServerInterface adapts one generic handler to the generated ServerInterface. Return the generated response type for the route or write directly to w and return nil.
type OAuth2Error ¶
OAuth2Error is the RFC 6749 §5.2 error response shape, used for OIDC / OAuth2 protocol routes (oidc_token, oidc_authorize, oidc_userinfo, oidc_revoke, oidc_introspect, etc.). Returning it from a ServerInterface method causes the generated wrapper to render {"error": Code, "error_description": Description, "error_uri": URI} with Cache-Control: no-store and Pragma: no-cache per RFC 6749 §5.1.
Status defaults to 400 when zero — use 401 for invalid_client per §5.2.
A-NEW-5 (docs/GENERATOR_BUGS.md).
func (*OAuth2Error) Error ¶
func (e *OAuth2Error) Error() string
func (*OAuth2Error) Unwrap ¶
func (e *OAuth2Error) Unwrap() error
type RouteInfo ¶
type RouteInfo struct {
Method string
Path string
MuxPattern string
MethodName string
BodyMode string
Auth string
Surface string
Sensitivity string
Profile string
RequestType string
ResponseType string
RequestSchema string
ResponseSchema string
HasTypedRequest bool
HasTypedResponse bool
PathParams []string
RequiredRoles []string
RequiredScopes []string
RequiredAttributes map[string]string
// APPSEC-Gen-F-006: surface the per-route WebAuthn ceremony policy
// (ceremony, phase, attestation, user_verification, discoverable)
// so catch-all handlers can read it without re-parsing the config.
Webauthn *WebauthnInfo
// APPSEC-15 (Plan 02 follow-up): per-route mTLS CA bundle path so
// catch-all handlers can construct their own per-route
// mtlsx.Verifier. Empty when the operation declares no mtls block
// or no ca_bundle_path. Server-construction-time wiring still
// goes through api.WithMTLS for the listener.
MTLSCABundlePath string
}
RouteInfo describes one generated HTTP route for catch-all handlers.
type ServerInterface ¶
type ServerInterface interface {
Gallery(w http.ResponseWriter, r *http.Request, req *types.GalleryUploadReq) (*types.GalleryUploadResp, error)
GetItems(w http.ResponseWriter, r *http.Request, req *types.ItemListReq) (*types.ItemListResp, error)
PostItems(w http.ResponseWriter, r *http.Request, req *types.ItemCreateReq) (*types.ItemCreateResp, error)
RemoveItem(w http.ResponseWriter, r *http.Request, req *types.ItemDeleteReq) (*types.ItemDeleteResp, error)
GetItemID(w http.ResponseWriter, r *http.Request, req *types.ItemGetReq) (*types.ItemGetResp, error)
PutItemID(w http.ResponseWriter, r *http.Request, req *types.ItemUpdateReq) (*types.ItemUpdateResp, error)
Tags(w http.ResponseWriter, r *http.Request, req *types.TagCreateReq) (*types.TagCreateResp, error)
PostUpload(w http.ResponseWriter, r *http.Request, req *types.ItemUploadReq) (*types.ItemUploadResp, error)
GetModuleLatest(w http.ResponseWriter, r *http.Request, req *map[string]any) (map[string]any, error)
}
ServerInterface defines the business logic contract for generated HTTP endpoints. Embed UnimplementedServer and override only the methods you need.
Streaming endpoints (route declared "streaming": true in the apic config) use a different method contract: func(http.ResponseWriter, *http.Request, *ReqType) error. For those the generated wrapper still performs every pre-handler concern -- auth/role/scope checks, rate limiting, body size limits, request parsing and validation, the standard JSON error envelope for *pre-handler* failures -- and then hands control to the user handler, which owns the entire 200 response: it must write its own status line, Content-Type, and body, flushing as it goes via http.Flusher.
Streaming-handler error contract: if the handler returns a non-nil error *before writing any bytes*, the wrapper emits the standard error envelope (500, or 501 for ErrNotImplemented). If the handler has *already written bytes* and then returns an error, the response headers are already on the wire -- the wrapper logs the error (http_handler_err audit event) but cannot change the status; the handler is responsible for signalling the failure in-band (e.g. truncating the stream / writing an error chunk). The cleanest discipline is: a streaming handler never returns an error after it has written anything.
func NewCatchAllServer ¶
func NewCatchAllServer(handler CatchAllServerInterface) ServerInterface
NewCatchAllServer wraps a generic route handler so it satisfies ServerInterface.
type StatusError ¶
StatusError lets a handler return a custom HTTP status code + message while still using the standard JSON error envelope. Use this for codes the sentinel set does not cover (410 Gone, 423 Locked, etc.) or when the message needs to be more specific than the sentinel's default text. Optionally wrap a sentinel via Err for callers that errors.Is them.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
func (*StatusError) Unwrap ¶
func (e *StatusError) Unwrap() error
type UnimplementedServer ¶
type UnimplementedServer struct{}
UnimplementedServer returns 501 Not Implemented for every endpoint. Embed it in your server struct and override the methods you implement.
Task 4.2 (GENWA-R1/C1): for the four webauthn_* profiles the body is specialized to dispatch the ceremony into the package-level webAuthnSrv (built by RegisterGeneratedAPI from security.webauthn). Consumers that embed UnimplementedServer inherit a working ceremony out of the box; consumers that override the method on their own ServerInterface impl still own the dispatch (Pattern A — preserves the override surface).
func (UnimplementedServer) Gallery ¶
func (UnimplementedServer) Gallery(_ http.ResponseWriter, _ *http.Request, _ *types.GalleryUploadReq) (*types.GalleryUploadResp, error)
func (UnimplementedServer) GetItemID ¶
func (UnimplementedServer) GetItemID(_ http.ResponseWriter, _ *http.Request, _ *types.ItemGetReq) (*types.ItemGetResp, error)
func (UnimplementedServer) GetItems ¶
func (UnimplementedServer) GetItems(_ http.ResponseWriter, _ *http.Request, _ *types.ItemListReq) (*types.ItemListResp, error)
func (UnimplementedServer) GetModuleLatest ¶
func (UnimplementedServer) GetModuleLatest(_ http.ResponseWriter, _ *http.Request, _ *map[string]any) (map[string]any, error)
func (UnimplementedServer) PostItems ¶
func (UnimplementedServer) PostItems(_ http.ResponseWriter, _ *http.Request, _ *types.ItemCreateReq) (*types.ItemCreateResp, error)
func (UnimplementedServer) PostUpload ¶
func (UnimplementedServer) PostUpload(_ http.ResponseWriter, _ *http.Request, _ *types.ItemUploadReq) (*types.ItemUploadResp, error)
func (UnimplementedServer) PutItemID ¶
func (UnimplementedServer) PutItemID(_ http.ResponseWriter, _ *http.Request, _ *types.ItemUpdateReq) (*types.ItemUpdateResp, error)
func (UnimplementedServer) RemoveItem ¶
func (UnimplementedServer) RemoveItem(_ http.ResponseWriter, _ *http.Request, _ *types.ItemDeleteReq) (*types.ItemDeleteResp, error)
func (UnimplementedServer) Tags ¶
func (UnimplementedServer) Tags(_ http.ResponseWriter, _ *http.Request, _ *types.TagCreateReq) (*types.TagCreateResp, error)