require

package
v0.19.1239 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package require applies existing RBAC permissions to HTTP routes and non-HTTP callers. HTTP helpers return ordinary Gin groups whose child routes inherit the permission check. Install authentication and org-resolution middleware on the parent router before registering protected routes. Public and global route classification stays with the listener's middleware.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDeclared added in v0.19.1239

func IsDeclared(ctx *gin.Context) bool

IsDeclared reports whether the matched route was registered through Route or OrgRoute. It is available before authentication and does not mean access was granted; the later permission guard must still run.

func Org added in v0.19.1159

func Org(ctx context.Context) (string, error)

Org returns the selected org ID from context. Empty org means the caller must select_org or pass X-Nuon-Org-ID. Use for non-Gin callers (MCP tool handlers). It does not check permissions; use Read or Write for authorization.

func OrgRoute added in v0.19.1239

func OrgRoute(router gin.IRouter) *gin.RouterGroup

OrgRoute returns a group requiring permission on the selected org, inferred using permissions.FromRequest: GET/HEAD read, POST create, PUT/PATCH update, and DELETE delete. Unsupported methods fail closed at request time. Use Route with KindOrg and an explicit verb when the operation differs from this mapping.

org := require.OrgRoute(api)
org.GET("/v1/orgs/current", handler)

func PermissionDeniedError added in v0.19.1239

func PermissionDeniedError(acct *app.Account, orgID string, perm permissions.Permission, scope string) stderr.ErrAuthorization

PermissionDeniedError phrases a 403 in terms of the access level the request needs rather than the raw permission key, so the message reads sensibly from any action that triggered the check.

func Read added in v0.19.1159

func Read(ctx context.Context) (string, error)

Read requires a selected org and PermissionRead on that org object.

func Route

func Route(router gin.IRouter, kind permissions.ResourceKind, verb permissions.Permission, paramName string) *gin.RouterGroup

Route returns a group requiring verb on the resource named by paramName in the request path, within the selected org. For KindOrg it checks the org itself and ignores paramName. The explicit verb is authoritative, regardless of the HTTP method. Resource denials return 404 to avoid disclosing existence; org denials return 403.

require.Route(api, permissions.KindStack, permissions.PermissionRead, "install_id").
	GET("/v1/stacks/:install_id/config", handler)

func ScopeFromPath added in v0.19.1239

func ScopeFromPath(fullPath string) string

ScopeFromPath derives the denied-error scope from the route, naming the resource the request operates on: /v1/service-accounts/:id becomes "service accounts in this organization".

func Write added in v0.19.1159

func Write(ctx context.Context) (string, error)

Write requires a non-read-only token role, a selected org, and PermissionCreate on that org object.

Types

This section is empty.

Jump to

Keyboard shortcuts

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