Documentation
¶
Index ¶
- Constants
- Variables
- func Allowed(ctx context.Context, permission string) bool
- func ConfigureEnvironmentScope(cfg EnvironmentScopeConfig)
- func EnvironmentKeyFromContext(ctx context.Context) string
- func Join(resource string, action Action) string
- func Require(ctx context.Context, permission string) error
- func WithChecker(ctx context.Context, checker Checker) context.Context
- func WithClaims(ctx context.Context, claims interfaces.AuthClaims) context.Context
- func WithEnvironmentKey(ctx context.Context, key string) context.Context
- func WithPermissions(ctx context.Context, perms ...string) context.Context
- func WithSession(ctx context.Context, session interfaces.RoleCapableSession) context.Context
- type Action
- type Checker
- type CheckerFunc
- type EnvironmentScopeConfig
- type Error
- type PermissionSet
- type Permissioner
- type Set
- type Strategy
- type StrategyFunc
Constants ¶
const ( ResourceContentTypes = "content_types" ResourceBlocks = "blocks" ResourceEnvironments = "environments" ResourceContent = "content" ResourcePages = "pages" ResourceMenus = "menus" )
const ( ContentTypesRead = "content_types:read" ContentTypesCreate = "content_types:create" ContentTypesUpdate = "content_types:update" ContentTypesDelete = "content_types:delete" ContentTypesPublish = "content_types:publish" BlocksRead = "blocks:read" BlocksCreate = "blocks:create" BlocksUpdate = "blocks:update" BlocksDelete = "blocks:delete" EnvironmentsRead = "environments:read" EnvironmentsCreate = "environments:create" EnvironmentsUpdate = "environments:update" EnvironmentsDelete = "environments:delete" ContentRead = "content:read" ContentCreate = "content:create" ContentUpdate = "content:update" ContentDelete = "content:delete" PagesRead = "pages:read" PagesCreate = "pages:create" PagesUpdate = "pages:update" PagesDelete = "pages:delete" MenusRead = "menus:read" MenusCreate = "menus:create" MenusUpdate = "menus:update" MenusDelete = "menus:delete" )
const ( StrategyEnvFirst = "env_first" StrategyGlobalFirst = "global_first" StrategyCustom = "custom" )
Variables ¶
var ErrPermissionDenied = errors.New("permissions: denied")
Functions ¶
func ConfigureEnvironmentScope ¶ added in v0.23.1
func ConfigureEnvironmentScope(cfg EnvironmentScopeConfig)
ConfigureEnvironmentScope updates the global environment permission scope configuration.
func EnvironmentKeyFromContext ¶ added in v0.23.1
EnvironmentKeyFromContext returns the stored environment key, if any.
func Require ¶
Require enforces a permission requirement when a checker is available on the context.
func WithChecker ¶
WithChecker stores a permission checker on the context.
func WithClaims ¶
func WithClaims(ctx context.Context, claims interfaces.AuthClaims) context.Context
WithClaims stores auth claims on the context for permission checks.
func WithEnvironmentKey ¶ added in v0.23.1
WithEnvironmentKey stores the environment key on the context for permission checks.
func WithPermissions ¶
WithPermissions stores a static permission set on the context.
func WithSession ¶
func WithSession(ctx context.Context, session interfaces.RoleCapableSession) context.Context
WithSession stores a role-capable session on the context for permission checks.
Types ¶
type Checker ¶
func CheckerFromContext ¶
CheckerFromContext returns the configured permission checker if available.
type CheckerFunc ¶
func (CheckerFunc) Allowed ¶
func (fn CheckerFunc) Allowed(permission string) bool
type EnvironmentScopeConfig ¶ added in v0.23.1
EnvironmentScopeConfig configures environment-scoped permission resolution.
type PermissionSet ¶
type PermissionSet struct {
Read string `json:"read,omitempty"`
Create string `json:"create,omitempty"`
Update string `json:"update,omitempty"`
Delete string `json:"delete,omitempty"`
Publish string `json:"publish,omitempty"`
}
PermissionSet captures common CRUD permission tokens.
func BlockLibraryPermissions ¶
func BlockLibraryPermissions() PermissionSet
BlockLibraryPermissions returns permissions for block library actions.
func BuilderContentTypePermissions ¶
func BuilderContentTypePermissions() PermissionSet
BuilderContentTypePermissions returns permissions for content type builder actions.
func ContentTypePermissions ¶
func ContentTypePermissions(slug string) PermissionSet
ContentTypePermissions returns the permission set for a specific content type slug.
func ResourcePermissions ¶
func ResourcePermissions(resource string, includePublish bool) PermissionSet
ResourcePermissions creates a permission set for a resource.
func (PermissionSet) List ¶
func (p PermissionSet) List() []string
List returns the non-empty permissions in the set.
type Permissioner ¶
type Strategy ¶ added in v0.23.1
Strategy resolves permission tokens for an environment scope.
var ( EnvFirstStrategy Strategy = StrategyFunc(func(permission, envKey string) []string { if permission == "" { return nil } if envKey == "" { return []string{permission} } scoped := scopePermission(permission, envKey) if scoped == permission { return []string{permission} } return []string{scoped, permission} }) GlobalFirstStrategy Strategy = StrategyFunc(func(permission, envKey string) []string { if permission == "" { return nil } if envKey == "" { return []string{permission} } scoped := scopePermission(permission, envKey) if scoped == permission { return []string{permission} } return []string{permission, scoped} }) )
type StrategyFunc ¶ added in v0.23.1
StrategyFunc adapts a function into a Strategy.
func (StrategyFunc) Resolve ¶ added in v0.23.1
func (fn StrategyFunc) Resolve(permission, envKey string) []string