app

package
v0.1.29 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const AdminUserID = "_admin"

Variables

View Source
var (
	ErrDuplicateUsername  = fmt.Errorf("username already exists")
	ErrUsernameTaken      = fmt.Errorf("username already taken")
	ErrCredentialNotFound = fmt.Errorf("credential not found")
)
View Source
var ErrFileNotFound = fmt.Errorf("file not found")
View Source
var ErrPasswordTooShort = fmt.Errorf("password must be at least %d characters long", passwordMinLength)
View Source
var FeatureFlagIsOn = func(context.Context, string) bool { return false }

Functions

This section is empty.

Types

type App

type App struct {
	Log
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, cfg Config) (*App, error)

func (*App) CreateUser added in v0.1.13

func (a *App) CreateUser(ctx context.Context, args CreateUserArgs) error

func (*App) DeleteExpiredFiles

func (a *App) DeleteExpiredFiles(ctx context.Context) error

func (*App) DeleteFiles

func (a *App) DeleteFiles(ctx context.Context, owner blinkfile.UserID, deleteFiles []blinkfile.FileID) error

func (*App) DeleteUsers added in v0.1.20

func (a *App) DeleteUsers(ctx context.Context, userIDs []blinkfile.UserID) error

func (*App) DownloadFile

func (a *App) DownloadFile(ctx context.Context, userID blinkfile.UserID, fileID blinkfile.FileID, password string) (blinkfile.FileHeader, error)

func (*App) IsAuthenticated

func (a *App) IsAuthenticated(ctx context.Context, token Token) (blinkfile.UserID, bool, error)

func (*App) ListFiles

func (a *App) ListFiles(ctx context.Context, owner blinkfile.UserID) ([]blinkfile.FileHeader, error)

func (*App) ListUsers added in v0.1.13

func (a *App) ListUsers(ctx context.Context) ([]blinkfile.User, error)

func (*App) Login

func (a *App) Login(ctx context.Context, username blinkfile.Username, password string, requestData SessionRequestData) (Session, error)

func (*App) Logout

func (a *App) Logout(ctx context.Context, token Token) error

func (*App) SubscribeToFileChanges added in v0.1.8

func (a *App) SubscribeToFileChanges(userID blinkfile.UserID) (<-chan FileEvent, func())

func (*App) UploadFile

func (a *App) UploadFile(ctx context.Context, args UploadFileArgs) error

type Clock

type Clock interface {
	Now() time.Time
}

type Config

type Config struct {
	Log
	AdminUsername     string
	AdminPassword     string
	SessionExpiration time.Duration
	SessionRepo
	FileRepo
	UserRepo
	CredentialRepo
	GenerateToken func() (Token, error)
	Clock
	PasswordHasher
	GenerateFileID func() (blinkfile.FileID, error)
	GenerateUserID func() (blinkfile.UserID, error)
}

type CreateUserArgs added in v0.1.13

type CreateUserArgs struct {
	Username blinkfile.Username
	Password string
}

type CredentialRepo added in v0.1.22

type CredentialRepo interface {
	Set(context.Context, Credentials) error
	GetByUsername(context.Context, blinkfile.Username) (Credentials, error)
	Remove(context.Context, blinkfile.UserID) error
}

type Credentials

type Credentials struct {
	blinkfile.UserID
	blinkfile.Username
	PasswordHash string
}

type DefaultClock

type DefaultClock struct{}

func (*DefaultClock) Now

func (c *DefaultClock) Now() time.Time

type Error

type Error struct {
	Type   ErrorType
	Title  string
	Detail string
	Err    error
	Status int
}

func Err

func Err(t ErrorType, err error) *Error

func ErrUser

func ErrUser(title, detail string, err error) *Error

func (*Error) AddDetail

func (e *Error) AddDetail(detail string) *Error

func (*Error) AddStatus

func (e *Error) AddStatus(status int) *Error

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type ErrorType

type ErrorType string
const (
	ErrUnknown     ErrorType = "unknown"
	ErrBadRequest  ErrorType = "bad-request"
	ErrInternal    ErrorType = "internal"
	ErrAuthnFailed ErrorType = "authn-failed"
	ErrAuthzFailed ErrorType = "authz-failed"
	ErrRepo        ErrorType = "repo"
	ErrNotFound    ErrorType = "not-found"
)

type EventType added in v0.1.8

type EventType string
const (
	FileDownloaded EventType = "downloaded"
	FileUploaded   EventType = "uploaded"
	FileDeleted    EventType = "deleted"
)

type FileEvent added in v0.1.8

type FileEvent struct {
	blinkfile.FileHeader
	Change EventType
}

type Log

type Log interface {
	Printf(ctx context.Context, format string, v ...any)
	Errorf(ctx context.Context, format string, v ...any)
}

type PasswordHasher

type PasswordHasher interface {
	Hash(data []byte) (hash string)
	Match(hash string, data []byte) (matched bool, err error)
}

type Session

type Session struct {
	Token
	blinkfile.UserID
	LoggedIn time.Time
	Expires  time.Time
	SessionRequestData
}

type SessionRepo

type SessionRepo interface {
	Save(context.Context, Session) error
	Get(context.Context, Token) (Session, bool, error)
	Delete(context.Context, Token) error
	DeleteAllUserSessions(context.Context, blinkfile.UserID) (int, error)
}

type SessionRequestData

type SessionRequestData struct {
	UserAgent string
	IP        string
}

type Token

type Token string

type UploadFileArgs

type UploadFileArgs struct {
	Filename      string
	Owner         blinkfile.UserID
	Reader        io.ReadCloser
	Size          int64
	Password      string
	ExpiresIn     longduration.LongDuration
	Expires       time.Time
	DownloadLimit int64
}

type UserRepo added in v0.1.16

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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