admin

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 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 exposes the /admin/v1 organization-scoped admin API: user / session / role / audit / oauth-account management.

Extracted from root handlers_admin.go in PR F of the 2026-06 architecture reorg. Collapsed from internal/admin/handlers into internal/admin in PR H (2026-06-22): the handlers/ subdir was the only child so the extra nesting added no value. The agent + delegation admin routes live in a sibling package (internal/agent/handlers) and are mounted as a subtree of the same /admin/v1/organizations/{orgID} route via the mountAgents callback supplied at Mount time.

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 entire /admin/v1 tree under r. requireAuth wraps every route; requirePermission gates each endpoint per the v1.0 spec section 9 table. mountAgents (optional, may be nil) attaches the agent + delegation subroutes under the same /organizations/{orgID} scope.

type MountAgents

type MountAgents func(r chi.Router)

MountAgents wires the sibling internal/agent/handlers Mount onto an existing chi router scoped under /admin/v1/organizations/{orgID}. Supplied by root because the agent handler has its own constructor + service dependencies.

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. Declared here (not imported from root) so the extracted 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