models

package
v0.0.0-...-383e6fc Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2020 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package models has all the type definitions of DRLM Core It's also the responsible of interacting with the DB (e.g. adding records, updating, deleting, querying...)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsErrUsrPwdStrength

func IsErrUsrPwdStrength(err error) bool

IsErrUsrPwdStrength checks if an error is a password strength error

Types

type Agent

type Agent struct {
	gorm.Model
	Host     string `gorm:"unique;not null"`
	Accepted bool   `gorm:"not null"`

	MinioKey string `gorm:"not null"`
	Secret   string `gorm:"unique;not null"` // The secret is used for authentication

	SSHPort     int `gorm:"not null"`
	SSHUser     string
	SSHHostKeys string `gorm:"size:9999"` // The different keys are splitted with `|||` between each one

	Version       string
	Arch          os.Arch
	OS            os.OS
	OSVersion     string
	Distro        string
	DistroVersion string

	Jobs    []*Job    `gorm:"-"`
	Plugins []*Plugin `gorm:"-"`
}

Agent (s) are the clients of DRLM Core that are installed in the servers

func AgentList

func AgentList(ctx *context.Context) ([]*Agent, error)

AgentList returns a list with all the agents

func (*Agent) Add

func (a *Agent) Add(ctx *context.Context) error

Add creates a new agent in the DB

func (*Agent) BeforeCreate

func (a *Agent) BeforeCreate() error

BeforeCreate is a hook that gets executed before creating an agent

func (*Agent) Delete

func (a *Agent) Delete(ctx *context.Context) error

Delete removes an agent from the DB

func (*Agent) Load

func (a *Agent) Load(ctx *context.Context) error

Load loads the agent from the DB using the host

func (*Agent) LoadJobs

func (a *Agent) LoadJobs(ctx *context.Context) error

LoadJobs loads all the jobs of an agent

func (*Agent) LoadPlugins

func (a *Agent) LoadPlugins(ctx *context.Context) error

LoadPlugins loads all the jobs of an agent

func (*Agent) Update

func (a *Agent) Update(ctx *context.Context) error

Update updates the agent in the DB

type Job

type Job struct {
	gorm.Model

	PluginID   uint      `gorm:"not null"`
	Plugin     *Plugin   `gorm:"-"`
	AgentHost  string    `gorm:"not null"`
	Status     JobStatus `gorm:"not null"`
	Time       time.Time
	Config     string `gorm:"not null"`
	BucketName string `gorm:"not null;unique"`
	Info       string

	Mux            sync.Mutex `gorm:"-"`
	ReconnAttempts int
}

Job is an individual job of the scheduler

func JobList

func JobList(ctx *context.Context) ([]*Job, error)

JobList returns a list with all the jobs

func (*Job) Add

func (j *Job) Add(ctx *context.Context) error

Add creates a new job in the DB

func (*Job) Load

func (j *Job) Load(ctx *context.Context) error

Load loads the job from the DB

func (*Job) Update

func (j *Job) Update(ctx *context.Context) error

Update updates the job in the DB

type JobStatus

type JobStatus int

JobStatus is the status of a job

const (
	// JobStatusUnknown is when a job status is not known
	JobStatusUnknown JobStatus = iota
	// JobStatusScheduled is when a job has been scheduled
	JobStatusScheduled
	// JobStatusRunning is when a job is currently running
	JobStatusRunning
	// JobStatusFinished is when a job has already finished
	JobStatusFinished
	// JobStatusFailed is when a job has failed during the execution
	JobStatusFailed
	// JobStatusCancelled is when a job has been cancelled during the execution
	JobStatusCancelled
)

type Plugin

type Plugin struct {
	gorm.Model
	Repo      string `gorm:"not null"`
	Name      string `gorm:"not null"`
	Version   string `gorm:"not null"`
	AgentHost string `gorm:"not null"`
	Agent     *Agent `gorm:"foreignkey:Host;association_foreignkey:AgentHost"`
	// TODO: This should be stored in the DB
	Arch []os.Arch `gorm:"-"`
	OS   []os.OS   `gorm:"-"`
}

Plugin is an individual plugin that's installed in an Agent

func (*Plugin) Add

func (p *Plugin) Add(ctx *context.Context) error

Add adds a new plugin in the DB

func (*Plugin) String

func (p *Plugin) String() string

type User

type User struct {
	gorm.Model
	Username string     `gorm:"unique;not null"`
	Password string     `gorm:"not null"`
	AuthType types.Type `gorm:"not null"`
}

User is an individual user of DRLM Core

func UserList

func UserList(ctx *context.Context) ([]*User, error)

UserList returns a list with all the users

func (*User) Add

func (u *User) Add(ctx *context.Context) error

Add creates a new user in the DB

func (*User) Delete

func (u *User) Delete(ctx *context.Context) error

Delete removes an user from the DB using the username

func (*User) Load

func (u *User) Load(ctx *context.Context) error

Load loads the user from the DB using the username

Jump to

Keyboard shortcuts

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