user

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

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

Go to latest
Published: Dec 24, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PasswordCharRepeatLimit = 4
)
View Source
const RootUsername = "root"

RootUsername is a reserved username for the admin deploying the application

Variables

View Source
var (
	ErrEmptyUsername   = errors.New("username cannot be empty")
	ErrShortUsername   = errors.New("username is too short")
	ErrLongUsername    = errors.New("username is too long")
	ErrInvalidUsername = errors.New("invalid username")

	ErrEmptyName   = errors.New("name cannot be empty")
	ErrShortName   = errors.New("name is too short")
	ErrLongName    = errors.New("name is too long")
	ErrInvalidName = errors.New("invalid name")

	ErrEmptyPassword   = errors.New("password cannot be empty")
	ErrShortPassword   = errors.New("password is too short")
	ErrLongPassword    = errors.New("password is too long")
	ErrInvalidPassword = errors.New("invalid password")
)

Functions

func ValidateName

func ValidateName(name string) error

ValidateName verifies if the input name is valid, returning an error if invalid

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword verifies if the input password is valid, returning an error if invalid

func ValidateUsername

func ValidateUsername(username string) error

ValidateUsername verifies if the input username is valid, returning an error if invalid

Types

type Repository

type Repository interface {
	// Create will create a user `u`, returning its ID and an error
	Create(ctx context.Context, u *User) (uint64, error)
	// Get returns the user identified by `username`, and an error
	Get(ctx context.Context, username string) (*User, error)
	// List returns all the users, and an error
	List(ctx context.Context) ([]*User, error)
	// Update will update the user `username` with its updated version `updated`. Returns an error
	Update(ctx context.Context, username string, updated *User) error
	// Delete removes the user identified by `username`, returning an error
	Delete(ctx context.Context, username string) error
}

Repository describes the actions exposed by the users store

func WithTrace

func WithTrace(r Repository) Repository

type Session

type Session struct {
	User  `json:"user"`
	Token string `json:"token"`
}

Session is an authorized user, accompanied by a JWT

type User

type User struct {
	ID        uint64    `json:"id"`
	Username  string    `json:"username"`
	Name      string    `json:"name"`
	Hash      string    `json:"-"`
	Salt      string    `json:"-"`
	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

User is a person (or entity) that uses the application to store secrets. They will have a unique username.

Jump to

Keyboard shortcuts

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