db

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const SessionSecretKeyLength = 32
View Source
const ShareSecretKeyLength = auth.KeySize

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type DB

type DB interface {
	// Close will close the database.
	Close() error

	// SaveUser saves a new user, or updates an existing user, identified by
	// user.Email.
	SaveUser(user model.User) error

	// GetUser retrieves a user from the database by email.
	GetUser(email string) (model.User, error)

	// GetUserForAccessKey returns the user with the provided access key.
	GetUserForAccessKey(key string) (model.User, error)

	// GetUsers returns all users in the database.
	GetUsers() ([]model.User, error)

	// DeleteUser deletes the user with  the provided email address. who is
	// recorded in the deletion log as the person/system that performed the
	// deletion.
	DeleteUser(email, who string) error

	// DeleteInactiveUsers deletes users based on inactivity. The function
	// takes two times: the oldest allowed inactive time (time since last
	// print job) for verified accounts, and oldest allowed creation time for
	// new accounts that are still unverified. For verified accounts with no
	// print jobs, the inactive time is based on sign-up time. Returns the
	// number of users deleted (which may still be >0 when err != nil).
	DeleteInactiveUsers(inactive, unverified time.Time) (int, error)

	// LogJob will record that a job was just processed for the user with the
	// provided email address. This will add to the job log and update the
	// user's record with the last job time and increase the job count for the
	// user.
	LogJob(email, jobinfo string, pages int, pdf []byte) error

	// GetUserJobLog returns up to size rows from the job log for the user
	// with the provided email address. Jobs are returned in descending order
	// of time.
	GetUserJobLog(email string, size int) ([]model.JobLogEntry, error)

	// GetJobLog returns up to size rows from the job log in descending order
	// of time.
	GetJobLog(size int) ([]model.JobLogEntry, error)

	// GetJob returns the details of one job.
	GetJob(id uint64) (model.JobLogEntry, error)

	// GetPDF will get the PDF file for the give job ID.
	GetPDF(job uint64) ([]byte, error)

	// CleanPDFs will delete the stored PDFs from before the provided date.
	CleanPDFs(cutoff time.Time)

	// GetSessionSecret will return a 32-byte random value to use as the
	// session secret key. If none exists in the database, this function will
	// generate one and save it. Essentially, on first startup, each new
	// database generates a random value which will be used for the life of
	// the database file.
	GetSessionSecret() ([]byte, error)

	// GetShareSecret will return a 32-byte random value to use as the PDF
	// link authentication key. If none exists in the database, this function
	// will generate one and save it. Essentially, on first startup, each new
	// database generates a random value which will be used for the life of
	// the database file.
	GetShareSecret() ([]byte, error)

	// We also use our database as an autocert cache
	autocert.Cache
}

func NewDB

func NewDB(path string) (DB, error)

Jump to

Keyboard shortcuts

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