accounts

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package accounts holds the business rules for administrator accounts. The admin API and the `admin` CLI both go through Service, so they share validation, password hashing and the rule that some enabled account can always manage accounts; Store.MutateAdmins makes that rule atomic.

Index

Constants

This section is empty.

Variables

View Source
var ErrLastAccountManager = errors.New("admin: at least one enabled account must keep admin:accounts")

ErrLastAccountManager prevents leaving no enabled account that can manage accounts. There is no override: `admin create` and `admin set --enable` never remove a manager, so they recover a store without one.

Functions

func ManagesAccounts

func ManagesAccounts(a Account) bool

ManagesAccounts reports whether a is an enabled account manager.

Types

type Account

type Account = configstore.AdminAccount

Account is one administrator.

type MemoryStore

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

MemoryStore is an in-process Store with the same semantics as the SQL store, for tests and embedded use.

func NewMemoryStore

func NewMemoryStore(seed ...Account) *MemoryStore

NewMemoryStore returns a store holding seed.

func (*MemoryStore) GetAdmin

func (m *MemoryStore) GetAdmin(_ context.Context, username string) (Account, error)

GetAdmin implements Store.

func (*MemoryStore) ListAdmins

func (m *MemoryStore) ListAdmins(context.Context) ([]Account, error)

ListAdmins implements Store.

func (*MemoryStore) MutateAdmins

func (m *MemoryStore) MutateAdmins(_ context.Context, fn func([]Account) ([]Account, error)) ([]Account, error)

MutateAdmins implements Store.

type Patch

type Patch struct {
	Permissions []string
	Disabled    *bool
}

Patch lists the account settings to change; nil fields stay as they are.

type Service

type Service struct {
	Store Store
}

Service applies the account rules on top of a Store.

func (Service) Create

func (s Service) Create(ctx context.Context, username, password string, permissions []string) (Account, error)

Create adds an account.

func (Service) Get

func (s Service) Get(ctx context.Context, username string) (Account, error)

Get returns one account.

func (Service) List

func (s Service) List(ctx context.Context) ([]Account, error)

List returns every account ordered by username.

func (Service) SetPassword

func (s Service) SetPassword(ctx context.Context, username, password string) (Account, error)

SetPassword replaces an account's password, which ends its sessions.

func (Service) Update

func (s Service) Update(ctx context.Context, username string, p Patch) (Account, error)

Update changes an account's permissions or disabled flag.

type Store

type Store interface {
	GetAdmin(ctx context.Context, username string) (Account, error)
	ListAdmins(ctx context.Context) ([]Account, error)
	MutateAdmins(ctx context.Context, fn func(all []Account) ([]Account, error)) ([]Account, error)
}

Store persists accounts. MutateAdmins runs fn on a consistent snapshot of every account and writes the accounts it returns; concurrent calls are serialized (see configstore.SQLStore.MutateAdmins).

Jump to

Keyboard shortcuts

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