Documentation
¶
Overview ¶
Package auth implements gateway key authentication and authorization middleware.
Index ¶
- Variables
- func DynamicMiddleware(resolver AuthorizerResolver, options MiddlewareOptions, next http.Handler) http.Handler
- func Middleware(authorizer *Authorizer, options MiddlewareOptions, next http.Handler) http.Handler
- func WithIdentity(ctx context.Context, identity *Identity) context.Context
- type AuditEvent
- type AuditRecorder
- type AuthorizationRule
- type Authorizer
- type AuthorizerResolver
- type Identity
- type KeyConfig
- type MiddlewareOptions
- type Options
- type Permission
- type ProxyLimitResult
- type ProxyLimiter
- type ProxyUsageRecorder
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrInvalidGatewayKey = errors.New("invalid gateway key")
View Source
var ErrMissingGatewayKey = errors.New("missing gateway key")
Functions ¶
func DynamicMiddleware ¶
func DynamicMiddleware(resolver AuthorizerResolver, options MiddlewareOptions, next http.Handler) http.Handler
func Middleware ¶
func Middleware(authorizer *Authorizer, options MiddlewareOptions, next http.Handler) http.Handler
Types ¶
type AuditEvent ¶
type AuditRecorder ¶
type AuditRecorder func(r *http.Request, event AuditEvent)
type AuthorizationRule ¶
type AuthorizationRule struct {
Resource string
Action string
Scope string
Permission Permission
Methods []string
Path string
Public bool
}
func AuthorizationMatrix ¶
func AuthorizationMatrix() []AuthorizationRule
AuthorizationMatrix documents the enforced gateway policy in resource/action terms.
type Authorizer ¶
type Authorizer struct {
// contains filtered or unexported fields
}
func NewAuthorizer ¶
func NewAuthorizer(options Options) (*Authorizer, error)
func (*Authorizer) Authenticate ¶
func (a *Authorizer) Authenticate(r *http.Request) (*Identity, error)
func (*Authorizer) Enabled ¶
func (a *Authorizer) Enabled() bool
func (*Authorizer) HeaderName ¶
func (a *Authorizer) HeaderName() string
type AuthorizerResolver ¶
type AuthorizerResolver func(r *http.Request) (*Authorizer, error)
type Identity ¶
type Identity struct {
KeyID string
OrgID string
WorkspaceID string
Team string
Role string
// contains filtered or unexported fields
}
func (*Identity) HasPermission ¶
func (i *Identity) HasPermission(permission Permission) bool
type MiddlewareOptions ¶
type MiddlewareOptions struct {
APIPrefix string
OpenAIPrefix string
AnthropicPrefix string
ProxyLimiter ProxyLimiter
ProxyUsageRecorder ProxyUsageRecorder
AuditRecorder AuditRecorder
}
type Permission ¶
type Permission string
const ( PermissionProxyWrite Permission = "proxy:write" PermissionAnalyticsRead Permission = "analytics:read" PermissionKeysManage Permission = "keys:manage" )
type ProxyLimitResult ¶
type ProxyLimiter ¶
type ProxyLimiter func(r *http.Request, identity *Identity) (*ProxyLimitResult, error)
type ProxyUsageRecorder ¶
Click to show internal directories.
Click to hide internal directories.