models

package
v0.0.0-...-ed2ac0f Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HASHCOST = 10
)

Variables

View Source
var (
	ErrKeyNotFound           = errors.New("no key found")
	ErrInvalidHostIdentifier = errors.New("invalid host identifier")
	ErrHostAlreadyKnown      = errors.New("host already known")
	ErrTableNotFound         = errors.New("table not found")
)
View Source
var (
	ErrUserNotFound      = errors.New("no user found")
	ErrUserAlreadyExists = errors.New("user already exists")
	ErrRegisteringUser   = errors.New("error registering user")
)
View Source
var (
	ErrInvalidPassword = errors.New("invalid password")
)

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func HashPassword

func HashPassword(password string) (string, error)

Types

type Key

type Key interface {
	// GetID returns the key's ID.
	GetID() uint
	// GetIdentifier returns the key's identifier.
	GetIdentifier() string
	// GetKey returns the key's key.
	GetKey() string
	// GetCreatedAt returns the key's creation time.
	GetCreatedAt() time.Time
	// GetUpdatedAt returns the key's last update time.
	GetUpdatedAt() time.Time
	// IsDeleted returns true if the key is deleted.
	IsDeleted() bool
}

func NewKey

func NewKey(identifier, key string) Key

type KeyDB

type KeyDB interface {
	// SetHostKey sets the private key for the host
	SetHostKey(ctx context.Context, pemBytes []byte) error
	// returns the private key for the host, pem encoded
	GetHostKey(ctx context.Context) (pemBytes []byte, err error)
	// adds a new known host to the database
	AddKnownHost(ctx context.Context, hostIdentifier string, key ssh.PublicKey) error
	// checks if the given host is known
	CheckKnownHost(ctx context.Context, hostIdentifier string, key ssh.PublicKey) (bool, error)
}

func NewKeyDB

func NewKeyDB(db *dbconnect.DB) (KeyDB, error)

type KeyDBImpl

type KeyDBImpl struct {
	*dbconnect.DB
}

func (*KeyDBImpl) AddKnownHost

func (db *KeyDBImpl) AddKnownHost(ctx context.Context, hostIdentifier string, key ssh.PublicKey) (err error)

func (*KeyDBImpl) CheckKnownHost

func (db *KeyDBImpl) CheckKnownHost(ctx context.Context, hostIdentifier string, key ssh.PublicKey) (ok bool, err error)

func (*KeyDBImpl) GetHostKey

func (db *KeyDBImpl) GetHostKey(ctx context.Context) (pemString []byte, err error)

func (*KeyDBImpl) InitKeyTable

func (db *KeyDBImpl) InitKeyTable(ctx context.Context, privatePem string) error

func (*KeyDBImpl) SetHostKey

func (db *KeyDBImpl) SetHostKey(ctx context.Context, pemBytes []byte) error

type KeyImpl

type KeyImpl struct {
	ID         uint
	Identifier string
	Key        string
	// contains filtered or unexported fields
}

func (*KeyImpl) GetCreatedAt

func (k *KeyImpl) GetCreatedAt() time.Time

func (*KeyImpl) GetID

func (k *KeyImpl) GetID() uint

func (*KeyImpl) GetIdentifier

func (k *KeyImpl) GetIdentifier() string

func (*KeyImpl) GetKey

func (k *KeyImpl) GetKey() string

func (*KeyImpl) GetUpdatedAt

func (k *KeyImpl) GetUpdatedAt() time.Time

func (*KeyImpl) IsDeleted

func (k *KeyImpl) IsDeleted() bool

type User

type User interface {
	// GetID returns the user's ID.
	GetID() uint
	// GetUsername returns the user's username.
	GetUsername() string
	// GetNickname returns the user's nickname.
	GetNickname() string
	// GetEmail returns the user's email.
	GetEmail() string
	// GetCreatedAt returns the user's creation time.
	GetCreatedAt() time.Time
	// GetUpdatedAt returns the user's last update time.
	GetUpdatedAt() time.Time
	// IsDeleted returns true if the user is deleted.
	IsDeleted() bool
	// String returns a string representation of the user.
	String() string
}

type UserDB

type UserDB interface {
	// Register registers a new user in the database.
	Register(ctx context.Context, user User, password string) error
	// GetAll retrieves all users from the database.
	GetAll(ctx context.Context) ([]User, error)
	// GetUser retrieves a user from the database by its ID.
	GetUser(ctx context.Context, where map[string]interface{}, limit int) (User, error)
	// GetByUsername retrieves a user from the database by its username.
	GetByUsername(ctx context.Context, username string) (User, error)
	// GetByEmail retrieves a user from the database by its email.
	GetByEmail(ctx context.Context, email string) (User, error)
	// Update updates a user in the database.
	Update(ctx context.Context, user User) error
	// UpdatePassword updates a user's password in the database.
	UpdatePassword(ctx context.Context, user User, password string) error
	// DeleteUser deletes a user from the database.
	DeleteUser(ctx context.Context, id uint) error
	// Authenticate authenticates a user by its username and password.
	Authenticate(ctx context.Context, username, password string) (User, error)
}

func NewUserDB

func NewUserDB(db *dbconnect.DB) (UserDB, error)

type UserDBImpl

type UserDBImpl struct {
	*dbconnect.DB
}

func (*UserDBImpl) Authenticate

func (db *UserDBImpl) Authenticate(ctx context.Context, username, password string) (User, error)

func (*UserDBImpl) DeleteUser

func (db *UserDBImpl) DeleteUser(ctx context.Context, id uint) error

func (*UserDBImpl) GetAll

func (db *UserDBImpl) GetAll(ctx context.Context) (users []User, err error)

func (*UserDBImpl) GetByEmail

func (db *UserDBImpl) GetByEmail(ctx context.Context, email string) (user User, err error)

func (*UserDBImpl) GetByUsername

func (db *UserDBImpl) GetByUsername(ctx context.Context, username string) (user User, err error)

func (*UserDBImpl) GetUser

func (db *UserDBImpl) GetUser(ctx context.Context, where map[string]interface{}, limit int) (user User, err error)

func (*UserDBImpl) Register

func (db *UserDBImpl) Register(ctx context.Context, user User, passwordHash string) error

func (*UserDBImpl) Update

func (db *UserDBImpl) Update(ctx context.Context, user User) (err error)

func (*UserDBImpl) UpdatePassword

func (db *UserDBImpl) UpdatePassword(ctx context.Context, user User, passwordHash string) error

type UserImpl

type UserImpl struct {
	ID       uint
	Username string
	Nickname sql.NullString
	Email    string
	// contains filtered or unexported fields
}

func NewUser

func NewUser(username, nickname string, email string) *UserImpl

func (*UserImpl) GetCreatedAt

func (u *UserImpl) GetCreatedAt() time.Time

func (*UserImpl) GetEmail

func (u *UserImpl) GetEmail() string

func (*UserImpl) GetID

func (u *UserImpl) GetID() uint

func (*UserImpl) GetNickname

func (u *UserImpl) GetNickname() string

func (*UserImpl) GetUpdatedAt

func (u *UserImpl) GetUpdatedAt() time.Time

func (*UserImpl) GetUsername

func (u *UserImpl) GetUsername() string

func (*UserImpl) IsDeleted

func (u *UserImpl) IsDeleted() bool

func (*UserImpl) String

func (u *UserImpl) String() string

type UserPassword

type UserPassword struct {
	ID     *uint
	UserID uint
	Hash   string
}

Jump to

Keyboard shortcuts

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