Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrUserAlreadyExists = errors.New("the user already exists") ErrUserNotFound = errors.New("the given user could not be found") ErrAuthTokenAlreadyPresent = errors.New("the given auth token is already present within the database") )
var DefaultUserID = uuid.UUID{}
DefaultUserID is used for old file entries with no specified author.
var ( // ErrEntryNotFound indicates that there is no such file in the file storage. ErrEntryNotFound = errors.New("the given entry was not found in the file storage") )
Functions ¶
This section is empty.
Types ¶
type FileEntry ¶
type FileEntry struct {
// Id holds a unique ID which identifies the Entry inside the backend. This is mandatory because the CallReference
// can be changed by the user.
Id uuid.UUID
// CallReference is a unique string identifying the entry inside the database and resolving it
// via web.
CallReference string
// DeleteReference is a unique string which can be used to delete the file entry with a simple
// GET request to allow simple deletion links.
DeleteReference string
// Author holds a unique UserId which can be used to identify the uploader.
Author uuid.UUID
// Filename is the name of the file with its extension (e.g. no-virus.exe).
Filename string
// ContentType is the MIME-Type of the uploaded file (e.g. image/png).
ContentType string
// UploadDate is the exact time of when the file was uploaded.
UploadDate time.Time
// Reader allows to read the file entry`s content.
ReadCloseSeeker ReadCloseSeeker
// Size holds the total size of the file entry`s content in bytes.
Size int64
}
FileEntry represents an uploaded file and its metadata inside the storage. It has extra fields to resolve the file`s content.
type FileService ¶
type FileService interface {
// Store saves the entry data to the storage. If something went wrong, an error is returned.
Store(filename, contentType string, size int64, author uuid.UUID, reader io.Reader) (entry *FileEntry, err error)
// Request searches for an entry by using the specified CallReference. It returns an error if something goes wrong.
Request(callReference string) (entry *FileEntry, err error)
// Delete deletes an entry using the provided delete reference. It returns an error if something goes wrong.
Delete(deleteReference string) (err error)
}
FileService holds all functions needed for a usable file service implementation.
type PasswordHashAlgorithm ¶
type PasswordHashAlgorithm string
PasswordHashAlgorithm is used to represent a password hashing algorithm in order to allow multiple different hashing implementations.
const ( // PasswordHashArgon2ID is the identical name for the expensive key derivation function Argon2Id. PasswordHashArgon2ID PasswordHashAlgorithm = "argon2id" // LatestPasswordHashAlgorithm declares the default used and latest password hash algorithm. LatestPasswordHashAlgorithm = PasswordHashArgon2ID )
type ReadCloseSeeker ¶
type ReadCloseSeeker interface {
io.ReadCloser
io.Seeker
}
ReadCloseSeeker combines both, io.ReaderCloser and io.Seeker into one interface. It is used within the FileEntry type. Allow access via the built in interface and implement the Read, Close and Seek methods.
type User ¶
type User struct {
// ID is a unqiue ID which can be used to identify the user.
ID uuid.UUID
// Username is the name of the user to e.g. login with.
Username string
// AuthorizationToken holds the auth token for the user to use when uploading file entries.
AuthorizationToken string
// PasswordHashAlgorithm indicates the hashing algorithm which this user entry is using.
PasswordHashAlgorithm PasswordHashAlgorithm
}
User contains the basic user data.
func (User) IsUsingLatestPasswordHashAlgorithm ¶
IsUsingLatestPasswordHashAlgorithm indicates whether the user is using the latest password hash algorithm (LatestPasswordHashAlgorithm).
type UserService ¶
type UserService interface {
// CreateNewUser creates a new user by using the specified Username. After a successful creation, a user instance
// is returned. It returns an error (err) if something went wrong.
CreateNewUser(username string, password []byte) (user *User, err error)
// CheckPassword checks the user`s password and whether the username is existent inside the database. Ok is true if
// the check was successful. If the user could not be found a ErrUserNotFound is returned.
CheckPassword(username string, password []byte) (ok bool, user *User, err error)
// UpdateUsername updates the user`s username and sets the value of the user instance. It
// returns an error (err) if something went wrong.
UpdateUsername(id uuid.UUID, newUsername string) (err error)
// ResolveAuthorizationToken resolves the authorization token and sets the value of the user
// instance. It returns an error (err) if something went wrong.
ResolveAuthorizationToken(id uuid.UUID) (token string, err error)
// RefreshAuthorizationToken updates the user`s authorization token and returns the fresh one. It returns an error
// (err) if something went wrong.
RefreshAuthorizationToken(id uuid.UUID) (token string, err error)
// ListUsers returns all users who exist in the database. It returns an error (err) if something goes wrong.
ListUsers() (users []*User, err error)
// GetUserByAuthorizationToken retrieves the user by using the passed authorization token. It returns an error (err)
// if something went wrong.
GetUserByAuthorizationToken(token string) (ok bool, user *User, err error)
// GetUserByUsername retrieves the user by using the provided username. It returns an error (err) if something goes wrong.
GetUserByUsername(username string) (user *User, err error)
// DeleteUser deletes the user by searching for the user`s ID. It returns an error (err) if
// something went wrong.
DeleteUser(id uuid.UUID) (err error)
// UpdatePassword updates the user`s password. It returns an error (err) if something went wrong.
UpdatePassword(id uuid.UUID, password []byte) (err error)
}
UserService contains the basic functions for interacting with the user database and their passwords.