admin

package
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 12 Imported by: 0 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 serves the /admin/v1 organization-scoped API: user, session, role, audit and OAuth account management. The agent and delegation admin routes live in a sibling package and mount as a subtree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuditService

type AuditService interface {
	QueryAudit(ctx context.Context, q models.AuditQuery) ([]models.AuditEvent, string, error)
	EmitAudit(ctx context.Context, action string, target models.TargetRef, meta map[string]any)
	HashEmailForAudit(email string) string
}

AuditService is the audit query + emit surface.

type Handler

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

Handler owns the 12 /admin/v1 endpoints (plus the requireOrgMatch middleware that gates the entire /organizations/{orgID} subtree).

func New

func New(
	storage Storage,
	rbac RBACService,
	audit AuditService,
	pathPrefix string,
	userFromCtx UserFromCtx,
	sessFromCtx SessionFromCtx,
) *Handler

New constructs a Handler. pathPrefix is the operator-supplied /admin path override (defaults to /admin/v1 when empty).

func (*Handler) Mount

func (h *Handler) Mount(r chi.Router, requireAuth func(http.Handler) http.Handler, requirePermission PermissionGate, mountAgents MountAgents)

Mount wires the whole /admin/v1 tree under r. Each endpoint is gated by requirePermission, per the RBAC seed table.

func (*Handler) WithLifecycle added in v2.10.0

func (h *Handler) WithLifecycle(l Lifecycle) *Handler

WithLifecycle enables the account lifecycle endpoints. It returns h.

type Lifecycle added in v2.10.0

type Lifecycle interface {
	SetMustChangePassword(ctx context.Context, userID models.ULID, required bool) error
	DisableUser(ctx context.Context, userID models.ULID) error
	EnableUser(ctx context.Context, userID models.ULID) error
	DeleteUser(ctx context.Context, userID models.ULID) error
}

Lifecycle is the optional account lifecycle surface. With it, PATCH /users/{userID} accepts mustChangePassword and disabled, and DELETE /users/{userID}/account deletes the account. Disabling and deleting require super_admin.

type MountAgents

type MountAgents func(r chi.Router)

MountAgents wires the agent and delegation subroutes under /admin/v1/organizations/{orgID}. Root supplies it.

type PermissionGate

type PermissionGate func(permission string) func(http.Handler) http.Handler

PermissionGate returns a middleware that rejects requests whose session lacks the named permission.

type RBACService

type RBACService interface {
	GrantRole(ctx context.Context, actorID, userID, roleID models.ULID) error
	RevokeRole(ctx context.Context, actorID, userID, roleID models.ULID) error
	CreateRole(ctx context.Context, orgID models.ULID, name, description string, permissions []string) (models.Role, error)
	UpdateRole(ctx context.Context, roleID models.ULID, name, description string, permissions []string) (models.Role, error)
	DeleteRole(ctx context.Context, roleID models.ULID) error
}

RBACService is the role-mutation surface used by the user / role endpoints.

type SessionFromCtx

type SessionFromCtx func(r *http.Request) (*models.Session, bool)

SessionFromCtx pulls the authenticated session from the request context.

type Storage

type Storage interface {
	ListUsersByOrganization(ctx context.Context, orgID models.ULID, offset, limit int, f models.SCIMUserFilter) ([]models.User, int, error)
	UserByID(ctx context.Context, id models.ULID) (*models.User, error)
	UserByEmail(ctx context.Context, email string) (*models.User, error)
	CreateUser(ctx context.Context, u models.User) (models.User, error)
	UpsertOrganizationMember(ctx context.Context, m models.OrganizationMember) error
	DeleteOrganizationMember(ctx context.Context, orgID, userID models.ULID) error
	OrganizationMemberRole(ctx context.Context, orgID, userID models.ULID) (string, error)
	RolesForUser(ctx context.Context, userID models.ULID, orgID *models.ULID) ([]models.Role, error)
	RoleByID(ctx context.Context, id models.ULID) (*models.Role, error)
	RolesByOrganization(ctx context.Context, orgID *models.ULID) ([]models.Role, error)
	RevokeSession(ctx context.Context, id models.ULID) error
}

Storage is the persistence surface this handler needs. It is declared here so the package does not import root.

type UserFromCtx

type UserFromCtx func(r *http.Request) (*models.User, bool)

UserFromCtx pulls the authenticated user from the request context.

Jump to

Keyboard shortcuts

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