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 ¶
- Variables
- func ManagesAccounts(a Account) bool
- type Account
- type MemoryStore
- type Patch
- type Service
- func (s Service) Create(ctx context.Context, username, password string, permissions []string) (Account, error)
- func (s Service) Get(ctx context.Context, username string) (Account, error)
- func (s Service) List(ctx context.Context) ([]Account, error)
- func (s Service) SetPassword(ctx context.Context, username, password string) (Account, error)
- func (s Service) Update(ctx context.Context, username string, p Patch) (Account, error)
- type Store
Constants ¶
This section is empty.
Variables ¶
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 ¶
ManagesAccounts reports whether a is an enabled account manager.
Types ¶
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) 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 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) SetPassword ¶
SetPassword replaces an account's password, which ends its sessions.
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).