Documentation
¶
Index ¶
- func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any) bool
- func New(deps Dependencies) http.Handler
- func ProjectIDFromContext(ctx context.Context) (project.ID, bool)
- func RequireToken(repo token.Repository) func(http.Handler) http.Handler
- func WriteError(w http.ResponseWriter, code ErrorCode, message string)
- type APIError
- type Dependencies
- type ErrorCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
func New ¶
func New(deps Dependencies) http.Handler
func ProjectIDFromContext ¶
ProjectIDFromContext returns the Project scope RequireToken resolved for the current request, if any. Endpoint handlers that need to enforce cross-Project isolation on a specific resource compare this against that resource's owning Project — see RequireToken's doc comment for why that comparison belongs at the handler, not here.
func RequireToken ¶
RequireToken returns middleware enforcing a valid, Project-scoped bearer token (specs/decisions/authentication.md) on every request it wraps, attaching the resolved Project scope to the request context on success.
Missing, malformed, invalid, and revoked tokens are all rejected identically with unauthorized — a response never reveals which of those applied, matching token.Verify's contract.
This middleware only establishes *who* is asking (which Project a token belongs to). It does not know which resource a given endpoint is about, so it cannot by itself enforce "a token from Project X can never authorize a request scoped to Project Y" — that comparison (this Project's ID vs. the target resource's owning Project) is each endpoint handler's responsibility, using ProjectIDFromContext. Per specs/protocols/http.md, a mismatch there must be reported as not_found, not unauthorized, so a cross-Project access attempt is indistinguishable from the resource genuinely not existing.
func WriteError ¶
func WriteError(w http.ResponseWriter, code ErrorCode, message string)
Types ¶
type Dependencies ¶
type Dependencies struct {
Tokens token.Repository
Projects project.Repository
Applications application.Repository
Releases release.Repository
}
Dependencies are the repositories New's routes need. Passed explicitly (.rules/architecture.md's Explicit dependencies) rather than constructed internally, so httpserver never decides how they're backed — that's cmd/server's job.