Documentation
¶
Index ¶
- Constants
- Variables
- func GetOrganizationId(c *gin.Context) int
- func GetProjectId(c *gin.Context) (uuid.UUID, error)
- func GetUserEmail(c *gin.Context) string
- func GetUserId(c *gin.Context) int
- func GetUserOrgRole(c *gin.Context) string
- func IngestAdmission(c *gin.Context)
- func InitRequireAdminAccess()
- func InitRequireOrganizationAccess()
- func InitRequireProjectAccess()
- func InitRequireWriteAccess()
- func InitUseAppAuth()
- func InitUseClientAuth()
- func InitUseSourceMapAuth()
- func OnCommit(c *gin.Context, fn func())
- func RateLimitPerIP(maxRequests int, window time.Duration) gin.HandlerFunc
- func RateLimitPerUser(maxRequests int, window time.Duration) gin.HandlerFunc
- func Transactional(c *gin.Context)
- func UseGzip(c *gin.Context)
- type BearerIdentity
- type FixedWindowLimiter
Constants ¶
const OrganizationIdContextKey = "organizationId"
const ProjectContextKey = "project"
const ProjectIdContextKey = "project_id"
const UserEmailContextKey = "userEmail"
const UserIdContextKey = "userId"
const UserOrgRoleContextKey = "userOrgRole"
Variables ¶
var ( CORSReport = cors("POST, OPTIONS", "Content-Type, Content-Encoding, Authorization", "", "") MCPCors = cors("GET, POST, DELETE, OPTIONS", mcpAllowHeaders, "Mcp-Session-Id, WWW-Authenticate", "600") WellKnownCors = cors("GET, OPTIONS", mcpAllowHeaders, "", "600") OAuthCors = cors("POST, OPTIONS", mcpAllowHeaders, "", "600") )
var ErrInvalidBearer = errors.New("invalid bearer token")
var ErrProjectIdNotInContext = errors.New("projectId not found in context - ensure RequireProjectAccess middleware is applied")
var RequireAdminAccess gin.HandlerFunc
var RequireOrganizationAccess gin.HandlerFunc
RequireOrganizationAccess mirrors RequireAdminAccess but accepts any org role (readonly included): it only requires membership in the :organizationId organization. Sets the same context keys.
var RequireProjectAccess gin.HandlerFunc
RequireProjectAccess middleware validates that the authenticated user has access to the requested project. A user can access a project if they are a member of the project's organization. This middleware should be applied AFTER UseAppAuth.
var RequireWriteAccess gin.HandlerFunc
RequireWriteAccess middleware checks if the user has write access to the project's organization. It blocks access for users with 'readonly' role. This middleware should be applied AFTER UseAppAuth.
var UseAppAuth func(c *gin.Context)
var UseClientAuth func(c *gin.Context)
var UseSourceMapAuth func(c *gin.Context)
Functions ¶
func GetOrganizationId ¶
func GetProjectId ¶
GetProjectId retrieves the project ID from the Gin context
func GetUserEmail ¶
func GetUserOrgRole ¶
func IngestAdmission ¶ added in v1.9.5
func InitRequireAdminAccess ¶
func InitRequireAdminAccess()
func InitRequireOrganizationAccess ¶ added in v1.9.10
func InitRequireOrganizationAccess()
func InitRequireProjectAccess ¶
func InitRequireProjectAccess()
func InitRequireWriteAccess ¶
func InitRequireWriteAccess()
func InitUseAppAuth ¶
func InitUseAppAuth()
func InitUseClientAuth ¶
func InitUseClientAuth()
func InitUseSourceMapAuth ¶
func InitUseSourceMapAuth()
func OnCommit ¶ added in v1.9.10
OnCommit queues fn to run after the Transactional middleware successfully commits the request transaction; queued fns are dropped on rollback. Use it for side effects that must only fire once the transaction's writes are visible to other connections (e.g. waking the outbox drain worker, which would otherwise poll before the enqueued row exists and go back to sleep).
func RateLimitPerIP ¶ added in v1.8.14
func RateLimitPerIP(maxRequests int, window time.Duration) gin.HandlerFunc
RateLimitPerIP returns a fixed-window per-IP rate limiter for unauthenticated endpoints that persist state per request (e.g. the device-authorize endpoint, which inserts a main-DB row per call).
func RateLimitPerUser ¶ added in v1.9.10
func RateLimitPerUser(maxRequests int, window time.Duration) gin.HandlerFunc
RateLimitPerUser keys the limit by the authenticated user (UseAppAuth must run first), so users behind a shared NAT don't exhaust each other's budget and an attacker cannot widen theirs by rotating IPs. Requests without a resolved user fall back to the client IP so the limit still holds.
func Transactional ¶
Types ¶
type BearerIdentity ¶ added in v1.8.15
func AuthenticateBearer ¶ added in v1.8.15
func AuthenticateBearer(tokenString string) (*BearerIdentity, error)
type FixedWindowLimiter ¶ added in v1.9.10
type FixedWindowLimiter struct {
// contains filtered or unexported fields
}
FixedWindowLimiter is a fixed-window in-memory rate limiter keyed by an arbitrary string (IP, user id, phone number, ...). Stale buckets are swept on each call, so the map stays bounded by the number of distinct keys seen within one window.
func NewFixedWindowLimiter ¶ added in v1.9.10
func NewFixedWindowLimiter(maxRequests int, window time.Duration) *FixedWindowLimiter
func (*FixedWindowLimiter) Allow ¶ added in v1.9.10
func (l *FixedWindowLimiter) Allow(key string) bool
Allow consumes one slot for key and reports whether the request is within the limit.
Source Files
¶
- cors.middleware.go
- ingest_admission.go
- rate_limit.middleware.go
- require_admin_access.middleware.go
- require_organization_access.middleware.go
- require_project_access.middleware.go
- require_write_access.middleware.go
- transactional.middleware.go
- use_app_auth.middleware.go
- use_client_auth.middleware.go
- use_gzip_decompress.middleware.go
- use_source_map_auth.middleware.go