httpserver

package
v0.0.0-...-02e3363 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJSON

func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any) bool

func New

func New(deps Dependencies) http.Handler

func ProjectIDFromContext

func ProjectIDFromContext(ctx context.Context) (project.ID, bool)

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

func RequireToken(repo token.Repository) func(http.Handler) http.Handler

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 APIError

type APIError struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"`
}

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.

type ErrorCode

type ErrorCode string
const (
	CodeValidationError ErrorCode = "validation_error"
	CodeUnauthorized    ErrorCode = "unauthorized"
	CodeNotFound        ErrorCode = "not_found"
	CodeConflict        ErrorCode = "conflict"
	CodeInternalError   ErrorCode = "internal_error"
)

Jump to

Keyboard shortcuts

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