Documentation
¶
Index ¶
- Constants
- func AccessLog(log *slog.Logger, trustedProxies ...*net.IPNet) func(http.Handler) http.Handler
- func Authenticate(cfg *AuthConfig, sessions SessionStore, pats PATLookup) func(http.Handler) http.Handler
- func BodyLimit(n int64) func(http.Handler) http.Handler
- func CORS(allowedOrigins []string, allowCredentials bool) func(http.Handler) http.Handler
- func CSRFConditional(cfg *CSRFConfig, secure bool) func(http.Handler) http.Handler
- func CSRFMaskedToken(r *http.Request) string
- func ClientIP(r *http.Request, trustedProxies ...*net.IPNet) string
- func ClientMetadata(next http.Handler) http.Handler
- func ClientMetadataFrom(ctx context.Context) (platform, version, os string)
- func ConfigHandler(d ConfigDeps) http.HandlerFunc
- func DecodeJSON(w http.ResponseWriter, r *http.Request, dst any) bool
- func DeriveCSRFKey(signingSecret []byte) []byte
- func ErrConflict(w http.ResponseWriter, msg string)
- func ErrForbidden(w http.ResponseWriter, msg string)
- func ErrInternal(w http.ResponseWriter)
- func ErrNotFound(w http.ResponseWriter, msg string)
- func ErrPayloadTooLarge(w http.ResponseWriter, msg string)
- func ErrTimeout(w http.ResponseWriter)
- func ErrUnauthenticated(w http.ResponseWriter, msg string)
- func ErrUnavailable(w http.ResponseWriter, msg string)
- func ErrValidation(w http.ResponseWriter, msg string)
- func HashIP(ip, secret string) string
- func HashToken(token string) string
- func MintToken() (string, error)
- func P(fn func(w http.ResponseWriter, r *http.Request, p *Principal)) http.HandlerFunc
- func ParseOrigins(raw string) []string
- func ParseTrustedProxies(raw string) []*net.IPNet
- func PoolStats(pool *pgxpool.Pool) (acquired, idle, total int32)
- func PrincipalHolder() func(http.Handler) http.Handler
- func RateLimit(l Limiter, dimension string, perMinute int, keyFn func(r *http.Request) string) func(http.Handler) http.Handler
- func Recover(log *slog.Logger) func(http.Handler) http.Handler
- func RequestID(r *http.Request) string
- func RequestIDFromCtx(ctx context.Context) string
- func RequestIDMiddleware(next http.Handler) http.Handler
- func RequireAuth(next http.Handler) http.Handler
- func RequireHuman(next http.HandlerFunc) http.HandlerFunc
- func SecurityHeaders(next http.Handler) http.Handler
- func Timeout(d time.Duration) func(http.Handler) http.Handler
- func TimeoutExcept(d time.Duration, exemptPrefixes ...string) func(http.Handler) http.Handler
- func WithPrincipal(ctx context.Context, p *Principal) context.Context
- func WriteErr(w http.ResponseWriter, err error)
- func WriteError(w http.ResponseWriter, status int, code, message string, details any)
- func WriteJSON(w http.ResponseWriter, status int, v any)
- type AuthConfig
- type CSRFConfig
- type CheckFunc
- type ConfigDeps
- type CredentialScope
- type Error
- func NewConflict(msg string) *Error
- func NewError(status int, code, message string) *Error
- func NewForbidden(msg string) *Error
- func NewNotFound(msg string) *Error
- func NewQuotaExceeded(msg string) *Error
- func NewRateLimited(msg string) *Error
- func NewUnauthenticated(msg string) *Error
- func NewValidation(msg string) *Error
- type ErrorBody
- type FailOpenLimiter
- type Health
- type Limiter
- type PATLookup
- type Principal
- type PrincipalCell
- type ProjectScope
- type SessionStore
- type Source
Constants ¶
View Source
const ( HeaderClientPlatform = "X-Client-Platform" HeaderClientVersion = "X-Client-Version" HeaderClientOS = "X-Client-OS" )
View Source
const ( CodeUnauthenticated = "E_UNAUTHENTICATED" CodeForbidden = "E_FORBIDDEN" CodeNotFound = "E_NOT_FOUND" CodeValidation = "E_VALIDATION" CodeConflict = "E_CONFLICT" CodeRateLimited = "E_RATE_LIMITED" CodeQuotaExceeded = "E_QUOTA_EXCEEDED" CodeInternal = "E_INTERNAL" CodeTimeout = "E_TIMEOUT" CodePayloadTooLarge = "E_PAYLOAD_TOO_LARGE" )
View Source
const ClientUnknown = "unknown"
View Source
const DefaultPATPrefix = "tk_"
View Source
const HeaderRequestID = "X-Request-Id"
Variables ¶
This section is empty.
Functions ¶
func Authenticate ¶
func Authenticate(cfg *AuthConfig, sessions SessionStore, pats PATLookup) func(http.Handler) http.Handler
func CSRFConditional ¶
func CSRFMaskedToken ¶
func ClientMetadataFrom ¶
func ConfigHandler ¶
func ConfigHandler(d ConfigDeps) http.HandlerFunc
func DecodeJSON ¶
func DeriveCSRFKey ¶
func ErrConflict ¶
func ErrConflict(w http.ResponseWriter, msg string)
func ErrForbidden ¶
func ErrForbidden(w http.ResponseWriter, msg string)
func ErrInternal ¶
func ErrInternal(w http.ResponseWriter)
func ErrNotFound ¶
func ErrNotFound(w http.ResponseWriter, msg string)
func ErrPayloadTooLarge ¶
func ErrPayloadTooLarge(w http.ResponseWriter, msg string)
func ErrTimeout ¶
func ErrTimeout(w http.ResponseWriter)
func ErrUnauthenticated ¶
func ErrUnauthenticated(w http.ResponseWriter, msg string)
func ErrUnavailable ¶
func ErrUnavailable(w http.ResponseWriter, msg string)
func ErrValidation ¶
func ErrValidation(w http.ResponseWriter, msg string)
func P ¶
func P(fn func(w http.ResponseWriter, r *http.Request, p *Principal)) http.HandlerFunc
func ParseOrigins ¶
func ParseTrustedProxies ¶
func RequestIDFromCtx ¶
func RequireHuman ¶
func RequireHuman(next http.HandlerFunc) http.HandlerFunc
func TimeoutExcept ¶
func WriteErr ¶
func WriteErr(w http.ResponseWriter, err error)
func WriteError ¶
func WriteError(w http.ResponseWriter, status int, code, message string, details any)
Types ¶
type AuthConfig ¶
type AuthConfig struct {
CookieName string
CookieDomain string
Secure bool
SessionTTL time.Duration
AbsoluteTTL time.Duration
IPHashSecret string
PATPrefix string
}
func DefaultAuthConfig ¶
func DefaultAuthConfig() AuthConfig
func (*AuthConfig) ClearSessionCookie ¶
func (c *AuthConfig) ClearSessionCookie(w http.ResponseWriter)
func (*AuthConfig) SetSessionCookie ¶
func (c *AuthConfig) SetSessionCookie(w http.ResponseWriter, token string, exp time.Time)
type CSRFConfig ¶
type ConfigDeps ¶
type CredentialScope ¶
type CredentialScope struct {
WorkspaceIDs []string `json:"workspace_ids,omitempty"`
Permissions []string `json:"permissions,omitempty"`
}
func (*CredentialScope) AllowsPermission ¶
func (s *CredentialScope) AllowsPermission(perm string) bool
func (*CredentialScope) AllowsWorkspace ¶
func (s *CredentialScope) AllowsWorkspace(workspaceID string) bool
type Error ¶
func NewConflict ¶
func NewForbidden ¶
func NewNotFound ¶
func NewQuotaExceeded ¶
func NewRateLimited ¶
func NewUnauthenticated ¶
func NewValidation ¶
type FailOpenLimiter ¶
type FailOpenLimiter struct{}
type Health ¶
type Health struct {
// contains filtered or unexported fields
}
func (*Health) Liveness ¶
func (h *Health) Liveness() http.HandlerFunc
func (*Health) Readiness ¶
func (h *Health) Readiness() http.HandlerFunc
type Principal ¶
type Principal struct {
UserID string
Email string
Name string
Source Source
SessionID string
PATID string
WorkspaceID string
Role string
Project *ProjectScope
Scope *CredentialScope
AgentID string
IsPlatformAdmin bool
ImpersonatedBy string
}
func PrincipalFrom ¶
func PrincipalFromRequest ¶
type PrincipalCell ¶
type PrincipalCell struct {
// contains filtered or unexported fields
}
func (*PrincipalCell) Get ¶
func (c *PrincipalCell) Get() *Principal
func (*PrincipalCell) Set ¶
func (c *PrincipalCell) Set(p *Principal)
type ProjectScope ¶
type SessionStore ¶
type SessionStore interface {
CreateSession(ctx context.Context, userID, ipHash, userAgent string, now time.Time) (token string, exp time.Time, err error)
VerifySession(ctx context.Context, token string, now time.Time) (*Principal, error)
RenewSession(ctx context.Context, token string, now time.Time) (exp time.Time, renewed bool, err error)
RevokeSession(ctx context.Context, token string) error
}
Click to show internal directories.
Click to hide internal directories.