Documentation
¶
Index ¶
- Constants
- Variables
- func CtxWithStore(ctx context.Context, s Store) context.Context
- func HashPassword(pass string) (string, error)
- func NewPlainPassword(pass string) (pp plainPassword, err error)
- func NewStore(db database.Store) *store
- type APIKey
- type APIKeyKind
- func (k *APIKeyKind) MarshalJSON() ([]byte, error)
- func (k *APIKeyKind) MarshalText() ([]byte, error)
- func (k *APIKeyKind) Parse(s string) error
- func (k APIKeyKind) String() string
- func (k *APIKeyKind) UnmarshalJSON(b []byte) error
- func (k *APIKeyKind) UnmarshalText(t []byte) error
- func (k APIKeyKind) Valid() bool
- type HashedPassword
- type Password
- type Store
- type User
- type UserID
- type UserUpdate
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") )
Functions ¶
func HashPassword ¶
func NewPlainPassword ¶
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 ¶
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)
}
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 FromDBUser ¶
func UserCheck ¶
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) GetResourceName ¶
type UserUpdate ¶
Click to show internal directories.
Click to hide internal directories.