store

package
v0.0.0-...-caea6a0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	TeamExistsErr       = errors.New("Team already exists")
	UnknownTeamErr      = errors.New("Unknown team")
	UnknownTokenErr     = errors.New("Unknown token")
	NoFrontendErr       = errors.New("lab requires at least one frontend")
	InvalidFlagValueErr = errors.New("Incorrect value for flag")
	UnknownChallengeErr = errors.New("Unknown challenge")
)
View Source
var (
	EmptyExTags         = errors.New("Exercise cannot have zero tags")
	ImageNotDefinedErr  = errors.New("image cannot be empty")
	MemoryNotDefinedErr = errors.New("memory cannot be empty")
)
View Source
var (
	UserStoreNoFileErr = errors.New("Unable to find user store file")
	UserExistsErr      = errors.New("User already exists")
	UserNotFoundErr    = errors.New("User not found")
	PasswdTooShortErr  = errors.New("Password too short, requires atleast six characters")

	SignupKeyExistsErr   = errors.New("Signup key already exists")
	SignupKeyNotFoundErr = errors.New("Signup key not found")
)
View Source
var (
	TagEmptyErr = errors.New("Tag cannot be empty")
)

Functions

func NewEventConfigStore

func NewEventConfigStore(conf EventConfig, hooks ...func(EventConfig) error) *eventconfigstore

func NewEventFile

func NewEventFile(dir string, filename string, file RawEventFile) *eventfile

func NewTeamStore

func NewTeamStore(opts ...TeamStoreOpt) *teamstore

func WithPostTeamHook

func WithPostTeamHook(hook func(teams []Team) error) func(ts *teamstore)

func WithTeams

func WithTeams(teams []Team) func(ts *teamstore)

Types

type Archiver

type Archiver interface {
	ArchiveDir() string
	Archive() error
}

type Challenge

type Challenge struct {
	OwnerID     string     `yaml:"-"`
	FlagTag     Tag        `yaml:"tag"`
	FlagValue   string     `yaml:"-"`
	CompletedAt *time.Time `yaml:"completed-at,omitempty"`
}

type ContainerOptions

type ContainerOptions struct {
	DockerConf docker.ContainerConfig
	Records    []RecordConfig
	Challenges []Challenge
}

type DockerConfig

type DockerConfig struct {
	Envs                   []EnvVarConfig `yaml:"env"`
	ExerciseInstanceConfig `yaml:",inline"`
}

func (DockerConfig) Validate

func (df DockerConfig) Validate() error

type EmptyVarErr

type EmptyVarErr struct {
	Var  string
	Type string
}

func (*EmptyVarErr) Error

func (eve *EmptyVarErr) Error() string

type EnvVarConfig

type EnvVarConfig struct {
	EnvVar string `yaml:"env"`
	Value  string `yaml:"value"`
}

func (EnvVarConfig) Validate

func (evc EnvVarConfig) Validate() error

type EventConfig

type EventConfig struct {
	Name       string     `yaml:"name"`
	Tag        Tag        `yaml:"tag"`
	Available  int        `yaml:"available"`
	Capacity   int        `yaml:"capacity"`
	Lab        Lab        `yaml:"lab"`
	StartedAt  *time.Time `yaml:"started-at,omitempty"`
	FinishedAt *time.Time `yaml:"finished-at,omitempty"`
}

func (EventConfig) Validate

func (e EventConfig) Validate() error

type EventConfigStore

type EventConfigStore interface {
	Read() EventConfig
	SetCapacity(n int) error
	Finish(time.Time) error
}

type EventFile

type EventFile interface {
	TeamStore
	EventConfigStore
	Archiver
}

type EventFileHub

type EventFileHub interface {
	CreateEventFile(EventConfig) (EventFile, error)
	GetUnfinishedEvents() ([]EventFile, error)
}

func NewEventFileHub

func NewEventFileHub(path string) (EventFileHub, error)

type ExerTagExistsErr

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

func (*ExerTagExistsErr) Error

func (eee *ExerTagExistsErr) Error() string

type Exercise

type Exercise struct {
	Name        string         `yaml:"name"`
	Tags        []Tag          `yaml:"tags"`
	DockerConfs []DockerConfig `yaml:"docker"`
	VboxConfs   []VboxConfig   `yaml:"vbox"`
}

func (Exercise) ContainerOpts

func (e Exercise) ContainerOpts() []ContainerOptions

func (Exercise) Flags

func (e Exercise) Flags() []FlagConfig

func (Exercise) Validate

func (e Exercise) Validate() error

type ExerciseInstanceConfig

type ExerciseInstanceConfig struct {
	Flags          []FlagConfig   `yaml:"flag"`
	Records        []RecordConfig `yaml:"dns"`
	InstanceConfig `yaml:",inline"`
}

func (ExerciseInstanceConfig) Validate

func (eic ExerciseInstanceConfig) Validate() error

type ExerciseStore

type ExerciseStore interface {
	GetExercisesByTags(...Tag) ([]Exercise, error)
	CreateExercise(Exercise) error
	DeleteExerciseByTag(Tag) error
	ListExercises() []Exercise
}

func NewExerciseFile

func NewExerciseFile(path string) (ExerciseStore, error)

func NewExerciseStore

func NewExerciseStore(exercises []Exercise, hooks ...func([]Exercise) error) (ExerciseStore, error)

type FlagConfig

type FlagConfig struct {
	Tag    Tag    `yaml:"tag"`
	Name   string `yaml:"name"`
	EnvVar string `yaml:"env"`
	Static string `yaml:"static"`
	Points uint   `yaml:"points"`
}

func (FlagConfig) Validate

func (fc FlagConfig) Validate() error

type FrontendStore

type FrontendStore interface {
	GetFrontends(...string) []InstanceConfig
	SetMemoryMB(string, uint) error
	SetCpu(string, float64) error
	// contains filtered or unexported methods
}

func NewFrontendsFile

func NewFrontendsFile(path string) (FrontendStore, error)

type InstanceConfig

type InstanceConfig struct {
	Image    string  `yaml:"image"`
	MemoryMB uint    `yaml:"memoryMB"`
	CPU      float64 `yaml:"cpu"`
}

func (InstanceConfig) Validate

func (ic InstanceConfig) Validate() error

type InvalidTagSyntaxErr

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

func (*InvalidTagSyntaxErr) Error

func (ite *InvalidTagSyntaxErr) Error() string

type Lab

type Lab struct {
	Frontends []InstanceConfig `yaml:"frontends"`
	Exercises []Tag            `yaml:"exercises"`
}

type RawEventFile

type RawEventFile struct {
	EventConfig `yaml:",inline"`
	Teams       []Team `yaml:"teams,omitempty"`
}

type RecordConfig

type RecordConfig struct {
	Type  string `yaml:"type"`
	Name  string `yaml:"name"`
	RData string `yaml:"rdata"`
}

func (RecordConfig) Format

func (rc RecordConfig) Format(ip string) string

func (RecordConfig) Validate

func (rc RecordConfig) Validate() error

type SignupKey

type SignupKey struct {
	WillBeSuperUser bool   `yaml:"super-user,omitempty"`
	Value           string `yaml:"value,omitempty"`
}

func NewSignupKey

func NewSignupKey() SignupKey

func (SignupKey) String

func (sk SignupKey) String() string

type SignupKeyStore

type SignupKeyStore interface {
	CreateSignupKey(SignupKey) error
	GetSignupKey(string) (SignupKey, error)
	DeleteSignupKey(SignupKey) error
	ListSignupKeys() []SignupKey
}

func NewSignupKeyStore

func NewSignupKeyStore(keys []SignupKey, hooks ...func([]SignupKey) error) SignupKeyStore

type Tag

type Tag string

func NewTag

func NewTag(s string) (Tag, error)

func (Tag) Validate

func (t Tag) Validate() error

type Team

type Team struct {
	Id               string            `yaml:"id"`
	Email            string            `yaml:"email"`
	Name             string            `yaml:"name"`
	HashedPassword   string            `yaml:"hashed-password"`
	SolvedChallenges []Challenge       `yaml:"solved-challenges,omitempty"`
	Metadata         map[string]string `yaml:"metadata,omitempty"`
	CreatedAt        *time.Time        `yaml:"created-at,omitempty"`
	ChalMap          map[Tag]Challenge `yaml:"-"`
}

func NewTeam

func NewTeam(email, name, password string, chals ...Challenge) Team

func (*Team) AddChallenge

func (t *Team) AddChallenge(c Challenge)

func (*Team) AddMetadata

func (t *Team) AddMetadata(key, value string)

func (*Team) DataCollection

func (t *Team) DataCollection() bool

func (*Team) DataConsent

func (t *Team) DataConsent() bool

func (*Team) IsCorrectFlag

func (t *Team) IsCorrectFlag(tag Tag, v string) error

func (*Team) SolveChallenge

func (t *Team) SolveChallenge(tag Tag, v string) error

type TeamStore

type TeamStore interface {
	CreateTeam(Team) error
	GetTeamByToken(string) (Team, error)
	GetTeamByEmail(string) (Team, error)
	GetTeamByName(string) (Team, error)
	GetTeams() []Team
	SaveTeam(Team) error
	CreateTokenForTeam(string, Team) error
	DeleteToken(string) error
}

type TeamStoreOpt

type TeamStoreOpt func(ts *teamstore)

type UnknownExerTagErr

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

func (*UnknownExerTagErr) Error

func (uee *UnknownExerTagErr) Error() string

type User

type User struct {
	Username       string    `yaml:"username"`
	HashedPassword string    `yaml:"hashed-password"`
	SuperUser      bool      `yaml:"super-user"`
	CreatedAt      time.Time `yaml:"created-at"`
}

func NewUser

func NewUser(username, password string) (User, error)

func (User) IsCorrectPassword

func (u User) IsCorrectPassword(pass string) bool

type UserStore

type UserStore interface {
	DeleteUserByUsername(string) error
	CreateUser(User) error
	GetUserByUsername(string) (User, error)
	ListUsers() []User
}

func NewUserStore

func NewUserStore(users []User, hooks ...func([]User) error) UserStore

type UsersFile

type UsersFile interface {
	UserStore
	SignupKeyStore
}

func NewUserFile

func NewUserFile(path string) (UsersFile, error)

type VboxConfig

type VboxConfig struct {
	ExerciseInstanceConfig `yaml:",inline"`
}

func (VboxConfig) Validate

func (vc VboxConfig) Validate() error

Jump to

Keyboard shortcuts

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