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
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 ¶
MountAgents wires the agent and delegation subroutes under /admin/v1/organizations/{orgID}. Root supplies it.
type PermissionGate ¶
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 ¶
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.