users

package
v0.0.0-...-8ef749c Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixUsers         = "users/"
	PrefixJobs          = "jobs/"
	FileProfileFilename = "profile.hjson"
	FileMasterFilename  = "masterParams.hjson"
	FileEcoFilename     = "ecoParams.hjson"

	FileJobOutput = "output.hjson"
	//FileJobOutput         = "output.json"
	FileJobProcessingFlag = ".processing"
)

Prefixes for file structure of iGenDec

View Source
const (
	TraitWW   = trait("WW")
	TraitMW   = trait("MW")
	TraitSTAY = trait("STAY")
	TraitCD   = trait("CD")
	TraitHP   = trait("HP")
)

Types of traits

View Source
const (
	ComponentDirect   = component("D")
	ComponentMaternal = component("M")
)

Types of components

View Source
const (
	PasswordMinLength = 8
	PasswordMaxLength = 64
)

Password variables

Variables

View Source
var (
	ErrUserExists      = errors.New("user exists")
	ErrUserDoesntExist = errors.New("user does not exist")
)

Database errors

View Source
var (
	ErrInvalidPassword   = errors.New("Invalid password")
	ErrIncorrectPassword = errors.New("Incorrect password")
	ErrUserHasNoPassword = errors.New("User does not have a password")
)

Password errors

View Source
var UsersPath string

Functions

func Init

func Init()

Init sets up the packages database If you want to change the type

func PathToJobFile

func PathToJobFile(user, job, file string) string

PathToJobFile returns the path to a job file for a user If you want the general path, pass in empty string for jobfile parameter

func PathToJobsDir

func PathToJobsDir(user string) string

PathToJobsDir returns the path to the directory where we keep all of the jobs

func PathToUserDir

func PathToUserDir(user string) string

PathToUserDir returns the path to a directory for a user

func PathToUserFile

func PathToUserFile(user, file string) string

PathToUserFile returns the path to a general file for a user

Types

type Access

type Access []AccessPath

func (Access) BestMatch

func (a Access) BestMatch(path string) (AccessPath, bool)

type AccessPath

type AccessPath struct {
	Path string
	Deny bool
}

func (AccessPath) Match

func (a AccessPath) Match(path string) (matches bool, matchLen int, wildcardMatch bool)

type IndexElement

type IndexElement struct {
	Trait                 trait     `json:"trait"`
	Component             component `json:"component"`
	MarginalEconomicValue float64   `json:"mev"`
	Emphasis              float64   `json:"emphasis"`
	Correlation           float64   `json:"correlation"`
	GeneticStdDev         float64   `json:"geneticStdDev"`
	DisplayMEV            string
}

IndexElement holds the details of a trait thats output from iGenDec

func (IndexElement) Key

func (ic IndexElement) Key() string

Key returns the trait and component joined by a comma to conform to how we otherwise find this

type Job

type Job struct {
	Name           string
	Status         JobStatus
	Endpoint       string
	Output         []IndexElement `json:"indexElement"`
	Comment        string
	TargetDatabase string
	// contains filtered or unexported fields
}

Job holds information on a job run through create page

func (*Job) Run

func (job *Job) Run(databasePath string) error

Run uses the exec package to run the iGenDec job with the starters binary starters needs to be in the path

func (*Job) Zip

func (job *Job) Zip() ([]byte, error)

Zip compresses all the job files and returns the zipped archive as bytes

type JobStatus

type JobStatus string

JobStatus are the possible states a job can have

const (
	Passed     JobStatus = "passed"
	Failed     JobStatus = "failed"
	Processing JobStatus = "processing"
)

Statuses for a job

type LocalDatabase

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

LocalDatabase structure is an implementation of Database interface for keeping files in local tree

func NewLocalDatabase

func NewLocalDatabase(root string) *LocalDatabase

NewLocalDatabase returns a new local implementation of Database

func (*LocalDatabase) Create

func (db *LocalDatabase) Create(user *User) error

Create makes a new user

func (*LocalDatabase) DeleteJob

func (db *LocalDatabase) DeleteJob(user, job string) error

DeleteJob will remove the given job if it exists

func (*LocalDatabase) Get

func (db *LocalDatabase) Get(username string) (*User, error)

Get returns a user

func (*LocalDatabase) GetEcoParams

func (db *LocalDatabase) GetEcoParams(user string) (*params.EcoParams, error)

GetEcoParams returns ecoParams.hjson file for the user

func (*LocalDatabase) GetIndexParams

func (db *LocalDatabase) GetIndexParams(user string) (*params.MasterParams, error)

GetIndexParams returns indexParams.hjson file for the user

func (*LocalDatabase) GetJobFilename

func (db *LocalDatabase) GetJobFilename(user, job, file string) string

GetJobFilename returns the path to the given job file

func (*LocalDatabase) ListJobs

func (db *LocalDatabase) ListJobs(user string) []string

ListJobs returns a list of the jobs a user has

func (*LocalDatabase) SetEcoParams

func (db *LocalDatabase) SetEcoParams(user string, ep *params.EcoParams) error

SetEcoParams writes the given eco params to the database

func (*LocalDatabase) SetMasterParams

func (db *LocalDatabase) SetMasterParams(user string, ip *params.MasterParams) error

SetMasterParams writes the given index params to the database

func (*LocalDatabase) Update

func (db *LocalDatabase) Update(user *User) error

Update takes in the details of a user and overwrites the current profile entry

type User

type User struct {
	Firstname string
	Surname   string

	Email string

	Location string

	Username string

	// Password - hashed and salted
	Password []byte

	// Access is an array of paths we can use
	// to define what datasets the user has access to.
	// Each path should directly correlate with the
	// structure of the epds directory
	Access Access
}

User has the fields a user needs

func NewUser

func NewUser(username string) *User

NewUser returns a new user with only the Username field filled in Use 'user.NewUser(username).Get()' to get a user from the database

func NewUserFromBytes

func NewUserFromBytes(data []byte) (*User, error)

NewUserFromBytes returns a new user by parsing the bytes with JSON

func (*User) Bytes

func (u *User) Bytes() ([]byte, error)

Bytes returns JSON marshalled bytes

func (*User) ComparePassword

func (u *User) ComparePassword(password string) error

ComparePassword returns true if the password is this users, false otherwise If the user doesn't have a password, returns false

func (*User) CreateJob

func (u *User) CreateJob(name string, ip *params.MasterParams, ep *params.EcoParams) (*Job, error)

CreateJob creates a job out of the current context, saves it and returns the job

func (*User) DeleteJob

func (u *User) DeleteJob(name string) error

DeleteJob will permantly remove a job

func (*User) Exists

func (u *User) Exists() bool

Exists returns true if the user exists

func (*User) Get

func (u *User) Get() (*User, error)

Get a user from the database. Will populate the callers fields

func (*User) GetAllJobs

func (u *User) GetAllJobs() ([]*Job, error)

GetAllJobs gets every job this user has

func (*User) GetEcoParams

func (u *User) GetEcoParams() (*params.EcoParams, error)

GetEcoParams gets the ecoParams.hjson file from the server for this user

func (*User) GetIndexParams

func (u *User) GetIndexParams() (*params.MasterParams, error)

GetIndexParams gets the indexParams.hjson file from the server for this user If it doesn't exist, will return default struct

func (*User) GetJob

func (u *User) GetJob(name string) (*Job, error)

GetJob returns a job object that has the basic output and the status of the given job. If something unknown is queried will return a job with a failed status

func (*User) GetJobParams

func (u *User) GetJobParams(name string) (*params.MasterParams, *params.EcoParams, error)

GetJobParams will return the parameters used in the given job Will return error if the job doesn't exist or parameter files can't be loaded

func (*User) ListJobs

func (u *User) ListJobs() []string

ListJobs returns a list of the jobs the user has stored in the database Forwards the database function

func (*User) Save

func (u *User) Save() error

Save the user to the database This is a create operation, to update use user.Update()

func (*User) SaveEcoParams

func (u *User) SaveEcoParams(ep *params.EcoParams) error

SaveEcoParams will overwrite the current eco params file for this user with the given params Wraps database method

func (*User) SaveMasterParams

func (u *User) SaveMasterParams(ip *params.MasterParams) error

SaveMasterParams will overwrite the current index params file for this user with the given params Wraps database method

func (*User) SetJobParamsAsActive

func (u *User) SetJobParamsAsActive(name string) error

SetJobParamsAsActive will set this jobs indexparams and ecoparams as the active index/eco params

func (*User) String

func (u *User) String() string

String returns the representation of a user for debugging

func (*User) ToMap

func (u *User) ToMap(m map[string]interface{}) map[string]interface{}

ToMap returns the values we need from the struct in a fiber compatible map

func (*User) Update

func (u *User) Update() error

Update the users details in the database This will fail if the user doesn't exist

func (*User) ValidateAndHashPassword

func (u *User) ValidateAndHashPassword(password string) (err error)

ValidateAndHashPassword validates and hashes the provided password and saves it to the user struct

Jump to

Keyboard shortcuts

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