users

package
v0.0.0-...-1a3a2fa Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const StoreCtxKey storeCtxKey = "store"

Variables

View Source
var (
	ErrAPIKeyKindInvalid = errors.New("invalid API key kind")
	ErrAPIKeyExpired     = errors.New("API key expired or disabled")
)
View Source
var (
	ErrNoSuchUser     = errors.New("no such user")
	ErrNoUIDSpecified = errors.New("no user ID specified")
	ErrDuplicateName  = errors.New("a key with that name already exists for that user")
	ErrBadPassword    = errors.New("bad password")
)

Functions

func CtxWithStore

func CtxWithStore(ctx context.Context, s Store) context.Context

func HashPassword

func HashPassword(pass string) (string, error)

func NewPlainPassword

func NewPlainPassword(pass string) (pp plainPassword, err error)

func NewStore

func NewStore(db database.Store) *store

Types

type APIKey

type APIKey struct {
	OwnerID   UserID          `json:"ownerID"`
	Name      *string         `json:"name"`
	Kind      APIKeyKind      `json:"kind"`
	CreatedAt jsontypes.Time  `json:"createdAt"`
	Expires   *jsontypes.Time `json:"expires,omitempty"`
	Disabled  bool            `json:"disabled"`
	Scopes    []string        `json:"scopes,omitempty"`
	Key       string          `json:"key,omitzero"`
	JWTID     *uuid.UUID      `json:"-"`
	Hash      *string         `json:"-"`
}

func (*APIKey) GetResourceName

func (*APIKey) GetResourceName() string

type APIKeyKind

type APIKeyKind int
const (
	APIKeyKindRdio APIKeyKind = iota + 1
	APIKeyKindAPIKey
)

func (*APIKeyKind) MarshalJSON

func (k *APIKeyKind) MarshalJSON() ([]byte, error)

func (*APIKeyKind) MarshalText

func (k *APIKeyKind) MarshalText() ([]byte, error)

func (*APIKeyKind) Parse

func (k *APIKeyKind) Parse(s string) error

func (APIKeyKind) String

func (k APIKeyKind) String() string

func (*APIKeyKind) UnmarshalJSON

func (k *APIKeyKind) UnmarshalJSON(b []byte) error

func (*APIKeyKind) UnmarshalText

func (k *APIKeyKind) UnmarshalText(t []byte) error

func (APIKeyKind) Valid

func (k APIKeyKind) Valid() bool

type HashedPassword

type HashedPassword string

func (HashedPassword) Hash

func (hp HashedPassword) Hash() (string, error)

func (HashedPassword) String

func (hp HashedPassword) String() string

type Password

type Password interface {
	// Hash returns the hash of the password.
	Hash() (string, error)

	// String returns the raw field as it is (plain or hashed)
	String() string
}

Password is a password field; it can be hashed or plain.

type Store

type Store interface {
	// GetUser gets a user by username. This is for use by the system, not for presentation to the API.
	GetUser(ctx context.Context, username string) (*User, error)

	// GetUserPrivCheck gets a user by  username, checking context Subject and masking.
	GetUserPrivCheck(ctx context.Context, username string) (*User, error)

	// UserPrefs gets the preferences for the specified user and app name.
	UserPrefs(ctx context.Context, username string, appName string) ([]byte, error)

	// SetUserPrefs sets the preferences for the specified user and app name.
	SetUserPrefs(ctx context.Context, username string, appName string, prefs []byte) error

	// Invalidate clears the user cache.
	Invalidate()

	// UpdateUser updates a user's record
	UpdateUser(ctx context.Context, username string, user UserUpdate) error

	// RecordLogin records a users's login.
	RecordLogin(ctx context.Context, username, source string) error

	// GetUserByAPIKey gets a user by API key.
	GetAPIKey(ctx context.Context, keyKind APIKeyKind, b64hash *string, jwtID *uuid.UUID) (database.GetAPIKeyRow, error)

	// CreateAPIKey creates a new API key.
	CreateAPIKey(ctx context.Context, ak *APIKey) error

	// ChangePassword changes a user's password.
	ChangePassword(ctx context.Context, username string, newPassword string) error

	// AddUser adds a user to the store.
	AddUser(ctx context.Context, user *User) (*User, error)

	// ValidatePassword does a time-constant validation of the password and returns the User.
	ValidatePassword(ctx context.Context, username, password string) (*User, error)

	// HUP invalidates the cache.
	HUP(*config.Config)
}

func FromCtx

func FromCtx(ctx context.Context) Store

type User

type User struct {
	ID            UserID
	Username      string
	Password      Password
	Email         string
	RealName      *string
	Roles         []string
	DisabledAt    *jsontypes.Time
	LastLoginAt   *jsontypes.Time
	LastLoginFrom *netip.Addr
	Prefs         json.RawMessage
	PasswordSetAt time.Time
}

A User is a user record.

func From

func From(ctx context.Context) (*User, error)

func FromDBUser

func FromDBUser(dbu database.User) *User

func FromSubject

func FromSubject(sub entities.Subject) (*User, error)

func UserCheck

func UserCheck(ctx context.Context, rsc entities.Resource, actions string) (*User, error)

UserCheck is like authz.Check but also returns the *User. It accepts a '+' delimited list of accepted actions as a string (like "read+delete+create")

func (*User) GetName

func (u *User) GetName() string

func (*User) GetResourceName

func (*User) GetResourceName() string

func (*User) GetRoles

func (u *User) GetRoles() []string

func (*User) HasRole

func (u *User) HasRole(role string) bool

func (*User) Mask

func (u *User) Mask() *User

func (*User) String

func (u *User) String() string

type UserID

type UserID int

func (UserID) Int

func (u UserID) Int() int

func (*UserID) Int32Ptr

func (u *UserID) Int32Ptr() *int32

func (UserID) IsValid

func (u UserID) IsValid() bool

type UserUpdate

type UserUpdate struct {
	Email    *string  `json:"email"`
	RealName *string  `json:"realName"`
	Roles    []string `json:"roles"`
}

Jump to

Keyboard shortcuts

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