admin

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package admin adds administrator operations to Canopy.

The module implements canopy.Module and canopy.RouteModule. Add it through canopy.Config.Modules. The store must implement canopy.AdminStore.

An AdminAuthorizer decides who is an admin. The default treats a user with the role "admin" as an administrator. Override it for custom rules.

The module can list and create users, set roles, ban and unban users, list and revoke sessions, and impersonate a user. A ban takes effect at once, because the module revokes the banned user's sessions and the core rejects a banned user. Impersonation records the admin on the session through ImpersonatedBy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminAuthorizer

type AdminAuthorizer interface {
	IsAdmin(ctx context.Context, data canopy.SessionData) bool
}

AdminAuthorizer decides if a session may use the admin API.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module adds admin operations: list and create users, set roles, ban and unban, list and revoke sessions, and impersonation. It implements canopy.Module and canopy.RouteModule.

func New

func New(o Options) *Module

New returns an admin module.

func (*Module) ID

func (m *Module) ID() string

func (*Module) Init

func (m *Module) Init(core canopy.Core) error

func (*Module) Routes

func (m *Module) Routes() []canopy.Route

type Options

type Options struct {
	// Authorizer decides who is an admin. The default is a RoleAuthorizer
	// built from AdminRoles.
	Authorizer AdminAuthorizer
	// AdminRoles lists the user roles that grant admin access. The
	// default is ["admin"]. It is used only when Authorizer is nil.
	AdminRoles []string
	// ImpersonationParentCookieName is the HttpOnly cookie that preserves
	// proof of the original admin session during impersonation.
	ImpersonationParentCookieName string
}

Options configures the admin module.

type RoleAuthorizer

type RoleAuthorizer struct {
	Roles []string
}

RoleAuthorizer treats a user as an admin when the user role is in the list.

func (RoleAuthorizer) IsAdmin

func (a RoleAuthorizer) IsAdmin(ctx context.Context, data canopy.SessionData) bool

Jump to

Keyboard shortcuts

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