users

package
v0.0.0-...-059fb3b Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoostrapUsername = "admin"
	BoostrapPassword = "duckcloud"
)
View Source
const (
	SecretMinLength = 8
	SecretMaxLength = 200
)

Variables

View Source
var (
	ErrAlreadyExists     = fmt.Errorf("user already exists")
	ErrUsernameTaken     = fmt.Errorf("username taken")
	ErrInvalidUsername   = fmt.Errorf("invalid username")
	ErrInvalidPassword   = fmt.Errorf("invalid password")
	ErrLastAdmin         = fmt.Errorf("can't remove the last admin")
	ErrInvalidStatus     = fmt.Errorf("invalid status")
	ErrUnauthorizedSpace = fmt.Errorf("unauthorized space")
)
View Source
var ExampleAlice = User{
	// contains filtered or unexported fields
}
View Source
var ExampleBob = User{
	// contains filtered or unexported fields
}
View Source
var ExampleDeletingAlice = User{
	// contains filtered or unexported fields
}
View Source
var ExampleInitializingBob = User{
	// contains filtered or unexported fields
}
View Source
var UsernameRegexp = regexp.MustCompile("^[0-9a-zA-Z-]+$")

Functions

This section is empty.

Types

type CreateCmd

type CreateCmd struct {
	CreatedBy *User
	Username  string
	Password  secret.Text
	IsAdmin   bool
}

CreateCmd represents an user creation request.

func (CreateCmd) Validate

func (t CreateCmd) Validate() error

Validate the CreateUserRequest fields.

type FakeUserBuilder

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

func NewFakeUser

func NewFakeUser(t testing.TB) *FakeUserBuilder

func (*FakeUserBuilder) Build

func (f *FakeUserBuilder) Build() *User

func (*FakeUserBuilder) BuildAndStore

func (f *FakeUserBuilder) BuildAndStore(ctx context.Context, db *sql.DB) *User

func (*FakeUserBuilder) WithAdminRole

func (f *FakeUserBuilder) WithAdminRole() *FakeUserBuilder

func (*FakeUserBuilder) WithPassword

func (f *FakeUserBuilder) WithPassword(password string) *FakeUserBuilder

func (*FakeUserBuilder) WithStatus

func (f *FakeUserBuilder) WithStatus(status Status) *FakeUserBuilder

func (*FakeUserBuilder) WithUsername

func (f *FakeUserBuilder) WithUsername(username string) *FakeUserBuilder

type MockService

type MockService struct {
	mock.Mock
}

MockService is an autogenerated mock type for the Service type

func NewMockService

func NewMockService(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockService

NewMockService creates a new instance of MockService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockService) AddToDeletion

func (_m *MockService) AddToDeletion(ctx context.Context, userID uuid.UUID) error

AddToDeletion provides a mock function with given fields: ctx, userID

func (*MockService) Authenticate

func (_m *MockService) Authenticate(ctx context.Context, username string, password secret.Text) (*User, error)

Authenticate provides a mock function with given fields: ctx, username, password

func (*MockService) Bootstrap

func (_m *MockService) Bootstrap(ctx context.Context) (*User, error)

Bootstrap provides a mock function with given fields: ctx

func (*MockService) Create

func (_m *MockService) Create(ctx context.Context, user *CreateCmd) (*User, error)

Create provides a mock function with given fields: ctx, user

func (*MockService) GetAll

func (_m *MockService) GetAll(ctx context.Context, paginateCmd *sqlstorage.PaginateCmd) ([]User, error)

GetAll provides a mock function with given fields: ctx, paginateCmd

func (*MockService) GetAllWithStatus

func (_m *MockService) GetAllWithStatus(ctx context.Context, status Status, cmd *sqlstorage.PaginateCmd) ([]User, error)

GetAllWithStatus provides a mock function with given fields: ctx, status, cmd

func (*MockService) GetByID

func (_m *MockService) GetByID(ctx context.Context, userID uuid.UUID) (*User, error)

GetByID provides a mock function with given fields: ctx, userID

func (*MockService) HardDelete

func (_m *MockService) HardDelete(ctx context.Context, userID uuid.UUID) error

HardDelete provides a mock function with given fields: ctx, userID

func (*MockService) MarkInitAsFinished

func (_m *MockService) MarkInitAsFinished(ctx context.Context, userID uuid.UUID) (*User, error)

MarkInitAsFinished provides a mock function with given fields: ctx, userID

func (*MockService) UpdateUserPassword

func (_m *MockService) UpdateUserPassword(ctx context.Context, cmd *UpdatePasswordCmd) error

UpdateUserPassword provides a mock function with given fields: ctx, cmd

type Service

type Service interface {
	Create(ctx context.Context, user *CreateCmd) (*User, error)
	Bootstrap(ctx context.Context) (*User, error)
	GetByID(ctx context.Context, userID uuid.UUID) (*User, error)
	Authenticate(ctx context.Context, username string, password secret.Text) (*User, error)
	GetAll(ctx context.Context, paginateCmd *sqlstorage.PaginateCmd) ([]User, error)
	AddToDeletion(ctx context.Context, userID uuid.UUID) error
	HardDelete(ctx context.Context, userID uuid.UUID) error
	GetAllWithStatus(ctx context.Context, status Status, cmd *sqlstorage.PaginateCmd) ([]User, error)
	MarkInitAsFinished(ctx context.Context, userID uuid.UUID) (*User, error)
	UpdateUserPassword(ctx context.Context, cmd *UpdatePasswordCmd) error
}

func Init

func Init(
	tools tools.Tools,
	db *sql.DB,
	scheduler scheduler.Service,
) Service

type Status

type Status string
const (
	Initializing Status = "initializing"
	Active       Status = "active"
	Deleting     Status = "deleting"
)

type UpdatePasswordCmd

type UpdatePasswordCmd struct {
	UserID      uuid.UUID
	NewPassword secret.Text
}

func (UpdatePasswordCmd) Validate

func (t UpdatePasswordCmd) Validate() error

type User

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

User representation

func (User) CreatedAt

func (u User) CreatedAt() time.Time

func (User) CreatedBy

func (u User) CreatedBy() uuid.UUID

func (User) ID

func (u User) ID() uuid.UUID

func (User) IsAdmin

func (u User) IsAdmin() bool

func (*User) MarshalJSON

func (u *User) MarshalJSON() ([]byte, error)

func (User) PasswordChangedAt

func (u User) PasswordChangedAt() time.Time

func (User) Status

func (u User) Status() Status

func (User) Username

func (u User) Username() string

Jump to

Keyboard shortcuts

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