db

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2019 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RightDownload refers to the right to download/view a file.
	RightDownload = "fs.download"
	// RightFsView refers to the right to view everything related to
	// the filesystem and history.
	RightFsView = "fs.view"
	// RightFsEdit refers to the right to edit the filesystem.
	// This includes pinning.
	RightFsEdit = "fs.edit"
	// RightRemotesView is the right to view the remote list.
	RightRemotesView = "remotes.view"
	// RightRemotesEdit is the right to edit the remote list.
	RightRemotesEdit = "remotes.edit"
)

Variables

View Source
var (
	// DefaultRights is a list of rights that users will get
	// if no other explicit rights are given. They are identical
	// to the admin role currently.
	DefaultRights = []string{
		RightDownload,
		RightFsView,
		RightFsEdit,
		RightRemotesView,
		RightRemotesEdit,
	}

	// AllRights is a map that can be quickly used to check
	// if a right is valid or not.
	AllRights = map[string]bool{
		RightDownload:    true,
		RightFsView:      true,
		RightFsEdit:      true,
		RightRemotesView: true,
		RightRemotesEdit: true,
	}
)

Functions

func HashPassword

func HashPassword(password string) (string, string, error)

HashPassword creates a new hash and salt from a password.

func UserToCapnp

func UserToCapnp(user *User, seg *capnp_lib.Segment) (*capnp.User, error)

UserToCapnp converts a User to a capnp.User.

Types

type User

type User struct {
	Name         string
	PasswordHash string
	Salt         string
	Folders      []string
	Rights       []string
}

User is one user that is stored in the database. The passwords are stored as scrypt hash with added salt.

func UserFromCapnp

func UserFromCapnp(capUser capnp.User) (*User, error)

UserFromCapnp takes a capnp.user and returns a regular User from it.

func (User) CheckPassword

func (u User) CheckPassword(password string) (bool, error)

CheckPassword checks if `password` matches the stored one.

type UserDatabase

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

UserDatabase is a badger db that stores user information, using the user name as unique key.

func NewUserDatabase

func NewUserDatabase(path string) (*UserDatabase, error)

NewUserDatabase creates a new UserDatabase at `path` or loads an existing one.

func (*UserDatabase) Add

func (ub *UserDatabase) Add(name, password string, folders []string, rights []string) error

Add adds a new user to the database. If the user exists already, it is overwritten.

func (*UserDatabase) Close

func (ub *UserDatabase) Close() error

Close cleans up all the resources used by a badger db.

func (*UserDatabase) Get

func (ub *UserDatabase) Get(name string) (User, error)

Get returns a User, if it exists. If it does not exist, an error will be returned.

func (*UserDatabase) List

func (ub *UserDatabase) List() ([]User, error)

List returns all users currently in the database.

func (*UserDatabase) Remove

func (ub *UserDatabase) Remove(name string) error

Remove removes an existing user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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