httpapi

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package httpapi holds the primitives every Atlas HTTP handler is written against: how a response is written, who the caller is, and where the request came from.

It exists because a handler cannot move out of the `api` package while the helpers it depends on live there — a per-area service (ADR-0147) would either import `api` (a cycle) or grow its own copy of the response envelope, and a second copy of that envelope is how one endpoint quietly starts answering in a different shape. Keeping them here means the wire contract has exactly one definition no matter which package serves the route.

Nothing here touches engine or design-time state; reaching that still goes through github.com/pblumer/atlas/api/runloop, which is a separate boundary on purpose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

ClientIP is the host part of a request's remote address, without the source port. Rate limiting buckets on it, so it must be stable across the many connections one caller opens. An address that carries no port is used as-is.

func Error

func Error(w http.ResponseWriter, status int, msg string)

Error writes the API's error envelope: a JSON object carrying a single human-readable "error". Every non-2xx response in Atlas has this shape, so clients can parse one thing.

func JSON

func JSON(w http.ResponseWriter, status int, v any)

JSON writes v as the response body with the given status. Encoding errors are deliberately swallowed: the status line and headers are already on the wire by then, so there is no way left to report a failure to the client, and the alternative — panicking mid-response — turns a malformed body into a dropped connection.

func WithPrincipal

func WithPrincipal(ctx context.Context, p *Principal) context.Context

WithPrincipal returns ctx carrying p as the request's authenticated caller. The auth middleware is its only caller.

Types

type Principal

type Principal struct {
	UserID   string
	Username string
	Roles    []string
}

Principal is an authenticated caller: a person with a session, the in-process MCP adapter's service identity, or a peer authenticated by a deploy token (ADR-0044/0129). A request with no principal is unauthenticated — either auth is off, or nothing valid was presented.

func PrincipalFrom

func PrincipalFrom(ctx context.Context) *Principal

PrincipalFrom returns the request's authenticated principal, or nil when the request is unauthenticated (auth disabled, or no valid session). Handlers branch on nil; a zero-valued Principal would read as a real caller with an empty name, so a miss is never one.

func (*Principal) HasRole

func (p *Principal) HasRole(role string) bool

HasRole reports whether the principal carries a role. A principal with no roles carries none, so the authorization gates fail closed.

Jump to

Keyboard shortcuts

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