models

package
v0.6.0-next.7 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	Name        string      `json:"name" gorm:"unique,notnull"`
	ID          string      `json:"id" gorm:"<-:create;primarykey"`
	IDShort     string      `json:"-" gorm:"<-:create;notnull;unique"`
	Cron        string      `json:"cron,omitempty"`
	Nodes       StringArray `json:"nodes" gorm:"notnull;type:bytes"`
	Tasks       TaskMap     `json:"tasks" gorm:"notnull;type:bytes"`
	TaskHistory StringArray `json:"task_history,omitempty" gorm:"<-:update;type:bytes"`
	CreatedAt   time.Time   `json:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at"`
}

Job contains the information for a given job.

func (*Job) BeforeCreate

func (j *Job) BeforeCreate(_ *gorm.DB) (err error)

BeforeCreate generates the job ID before saving.

func (*Job) GetIDShort

func (j *Job) GetIDShort() string

GetIDShort returns the first 8 bytes of the job ID.

type JobTask

type JobTask struct {
	Plugin  string    `json:"plugin"`
	Details StringMap `json:"details" gorm:"type:bytes"`
	Node    string    `json:"node,omitempty"`
}

JobTask represents a single task in a job.

type JobWithTasks

type JobWithTasks struct {
	Job
	TaskHistory TaskArray `json:"task_history"`
}

JobWithTasks is a regular Job, but with an expanded TaskHistory.

type Node

type Node struct {
	Name       string            `json:"name" gorm:"<-:create;notnull;unique"`
	ID         string            `json:"id" gorm:"<-:create;primarykey"`
	IDShort    string            `json:"-" gorm:"<-:create;notnull;unique"`
	PrivateKey []byte            `json:"-" gorm:"<-:create;notnull"`
	PublicKey  []byte            `json:"-" gorm:"<-:create;notnull"`
	HostKey    []byte            `json:"-" gorm:"<-:create;notnull;unique"`
	IP         string            `json:"ip" gorm:"<-:create;notnull"`
	Username   string            `json:"username" gorm:"<-:create;notnull;default:root"`
	Password   string            `json:"password,omitempty" gorm:"-"`
	Port       string            `json:"port" gorm:"<-:create;default:22"`
	Config     *ssh.ClientConfig `json:"-" gorm:"-"`
	CreatedAt  time.Time
	UpdatedAt  time.Time
}

Node contains information about a node.

func (*Node) AfterFind

func (n *Node) AfterFind(_ *gorm.DB) (err error)

AfterFind runs the setup for a node

func (*Node) BeforeCreate

func (n *Node) BeforeCreate(_ *gorm.DB) (err error)

BeforeCreate gets the short ID before saving.

func (*Node) GetIDShort

func (n *Node) GetIDShort() string

GetIDShort returns the first 8 bytes of the node ID.

func (*Node) Setup

func (n *Node) Setup() error

Setup is responsible for creating an SSH client.

type StringArray

type StringArray []string

StringArray provides SQL scanner bindings for an array of strings.

func (*StringArray) Scan

func (a *StringArray) Scan(value interface{}) error

Scan un-marshals a stored value into a StringArray

func (StringArray) Value

func (a StringArray) Value() (driver.Value, error)

Value marshals a StringArray to a SQL usable value

type StringMap

type StringMap map[string]string

StringMap provides SQL scanner bindings for a map of strings.

func (*StringMap) Scan

func (m *StringMap) Scan(value interface{}) error

Scan unmarshals a stored value into a StringMap

func (StringMap) Value

func (m StringMap) Value() (driver.Value, error)

Value marshals a StringMap to a SQL usable value

type Task

type Task struct {
	State     TaskState   `json:"state" gorm:"notnull"`
	Plugin    string      `json:"plugin" gorm:"<-:create;notnull"`
	ID        string      `json:"id" gorm:"<-:create;primarykey"`
	IDShort   string      `json:"-" gorm:"<-:create;notnull;unique"`
	Node      string      `json:"node" gorm:"<-:create;notnull"`
	Details   StringMap   `json:"details" gorm:"<-:create;"`
	Log       StringArray `json:"log,omitempty" gorm:"<-:update;type:bytea"`
	ExitCode  int         `json:"exit_code" gorm:"notnull"`
	Command   string      `json:"-" gorm:"-"`
	CreatedAt time.Time   `json:"created_at"`
	UpdatedAt time.Time   `json:"updated_at"`
}

Task defines the information of a task.

func (*Task) BeforeCreate

func (t *Task) BeforeCreate(_ *gorm.DB) (err error)

BeforeCreate initializes the default values for a Task.

func (*Task) GetIDShort

func (t *Task) GetIDShort() string

GetIDShort returns the first 8 bytes of the task ID.

func (*Task) ToSafe

func (t *Task) ToSafe() safe.Task

ToSafe converts a Task into a plugin-safe safe.Task wrapper.

type TaskArray

type TaskArray []Task

TaskArray provides SQL scanner bindings for an array of Tasks.

func (*TaskArray) Scan

func (a *TaskArray) Scan(value interface{}) error

Scan unmarshals a stored value into a TaskArray.

func (TaskArray) Value

func (a TaskArray) Value() (driver.Value, error)

Value marshals a TaskArray to a SQL usable value.

type TaskMap

type TaskMap map[string]JobTask

TaskMap provides SQL scanner bindings for a map of JobTasks.

func (*TaskMap) Scan

func (m *TaskMap) Scan(value interface{}) error

Scan unmarshals a stored value into a TaskMap

func (TaskMap) Value

func (m TaskMap) Value() (driver.Value, error)

Value marshals a TaskMap to a SQL usable value

type TaskState

type TaskState int

TaskState represents the current state of the task.

const (
	// StateDone should be given if the task is complete.
	StateDone TaskState = iota
	// StateError should be given if the task fails.
	StateError
	// StateRunning should be given if the task is running.
	StateRunning
	// StateAborted should be given if the task is aborted (stopped while running).
	StateAborted
	// StateCancelled should be given if the queued task is canceled.
	StateCancelled

	// StateQueued should be given while the task is waiting to be executed.
	StateQueued
	// StateOther should be avoided.
	StateOther TaskState = 10
	// StateInternalError should only be given if the task fails prior to execution.
	StateInternalError TaskState = 11
)

type User

type User struct {
	ID       uint8  `json:"id" gorm:"<-:create;primarykey;type:serial"`
	Username string `json:"username" gorm:"<-:create;notnull;unique"`
	Password string `json:"password" gorm:"->:false;notnull;column:password_hash"`
}

User contains the info for a user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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