tasks

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskTypeCmdRun = "cmd.run"
	FileManaged    = "file.managed"
	PkgInstalled   = "pkg.installed"
	PkgRemoved     = "pkg.removed"
	PkgUpgraded    = "pkg.uptodate"

	NameField       = "name"
	NamesField      = "names"
	CwdField        = "cwd"
	UserField       = "user"
	ShellField      = "shell"
	EnvField        = "env"
	CreatesField    = "creates"
	RequireField    = "require"
	OnlyIf          = "onlyif"
	Unless          = "unless"
	SourceField     = "source"
	SourceHashField = "source_hash"
	MakeDirsField   = "makedirs"
	ReplaceField    = "replace"
	SkipVerifyField = "skip_verify"
	ContentsField   = "contents"
	GroupField      = "group"
	ModeField       = "mode"
	EncodingField   = "encoding"
	Version         = "version"
	Refresh         = "refresh"
)
View Source
const DefaultFileMode = 0744

Variables

This section is empty.

Functions

func ValidateRequired

func ValidateRequired(val, path string) error

func ValidateRequiredMany

func ValidateRequiredMany(vals []string, path string) error

Types

type BuildRouter

type BuildRouter struct {
	Builders map[string]Builder
}

func NewBuilderRouter

func NewBuilderRouter(builders map[string]Builder) BuildRouter

func (BuildRouter) Build

func (br BuildRouter) Build(typeName, path string, ctx interface{}) (Task, error)

type Builder

type Builder interface {
	Build(typeName, path string, context interface{}) (Task, error)
}

type CmdRunTask

type CmdRunTask struct {
	TypeName string
	Path     string
	NamedTask
	WorkingDir            string
	User                  string
	Shell                 string
	Envs                  conv.KeyValues
	MissingFilesCondition []string
	Require               []string
	OnlyIf                []string
	Unless                []string
}

func (*CmdRunTask) GetName

func (crt *CmdRunTask) GetName() string

func (*CmdRunTask) GetPath

func (crt *CmdRunTask) GetPath() string

func (*CmdRunTask) GetRequirements

func (crt *CmdRunTask) GetRequirements() []string

func (*CmdRunTask) String

func (crt *CmdRunTask) String() string

func (*CmdRunTask) Validate

func (crt *CmdRunTask) Validate() error

type CmdRunTaskBuilder

type CmdRunTaskBuilder struct {
}

func (CmdRunTaskBuilder) Build

func (crtb CmdRunTaskBuilder) Build(typeName, path string, ctx interface{}) (Task, error)

type CmdRunTaskExecutor

type CmdRunTaskExecutor struct {
	Runner    exec2.Runner
	FsManager FsManager
}

func (*CmdRunTaskExecutor) Execute

func (crte *CmdRunTaskExecutor) Execute(ctx context.Context, task Task) ExecutionResult

type ExecutionResult

type ExecutionResult struct {
	Err        error
	Duration   time.Duration
	StdErr     string
	StdOut     string
	IsSkipped  bool
	SkipReason string
	Pids       []int
}

func (*ExecutionResult) String

func (tr *ExecutionResult) String() string

func (*ExecutionResult) Succeeded

func (tr *ExecutionResult) Succeeded() bool

returns true if task succeeded or was skipped

type Executor

type Executor interface {
	Execute(ctx context.Context, task Task) ExecutionResult
}

type ExecutorRouter

type ExecutorRouter struct {
	Executors map[string]Executor
}

func (ExecutorRouter) GetExecutor

func (er ExecutorRouter) GetExecutor(task Task) (Executor, error)

type FileManagedTask

type FileManagedTask struct {
	MakeDirs     bool
	Replace      bool
	SkipVerify   bool
	SkipTLSCheck bool
	Mode         os.FileMode
	TypeName     string
	Path         string
	Name         string
	SourceHash   string
	Contents     sql.NullString
	User         string
	Group        string
	Encoding     string
	Source       utils.Location
	Creates      []string
	OnlyIf       []string
	Require      []string
}

func (*FileManagedTask) GetName

func (crt *FileManagedTask) GetName() string

func (*FileManagedTask) GetPath

func (crt *FileManagedTask) GetPath() string

func (*FileManagedTask) GetRequirements

func (crt *FileManagedTask) GetRequirements() []string

func (*FileManagedTask) String

func (crt *FileManagedTask) String() string

func (*FileManagedTask) Validate

func (crt *FileManagedTask) Validate() error

type FileManagedTaskBuilder

type FileManagedTaskBuilder struct {
}

func (FileManagedTaskBuilder) Build

func (fmtb FileManagedTaskBuilder) Build(typeName, path string, ctx interface{}) (Task, error)

type FileManagedTaskExecutor

type FileManagedTaskExecutor struct {
	FsManager   FsManager
	HashManager HashManager
	Runner      exec2.Runner
}

func (*FileManagedTaskExecutor) Execute

func (fmte *FileManagedTaskExecutor) Execute(ctx context.Context, task Task) ExecutionResult

type FsManager

type FsManager interface {
	FileExists(filePath string) (bool, error)
	Remove(filePath string) error
	DownloadFile(ctx context.Context, targetLocation string, sourceURL *url.URL, skipTLSCheck bool) error
	MoveFile(sourceFilePath, targetFilePath string) error
	CopyLocalFile(sourceFilePath, targetFilePath string, mode os.FileMode) error
	WriteFile(name, contents string, mode os.FileMode) error
	ReadFile(filePath string) (content string, err error)
	CreateDirPathIfNeeded(targetFilePath string, mode os.FileMode) error
	Chmod(targetFilePath string, mode os.FileMode) error
	Chown(targetFilePath string, userName, groupName string) error
	Stat(name string) (os.FileInfo, error)
	ReadEncodedFile(encodingName, fileName string) (contentsUtf8 string, err error)
}

type HashManager

type HashManager interface {
	HashEquals(hashStr, filePath string) (hashEquals bool, actualCache string, err error)
	HashSum(hashAlgoName, filePath string) (hashSum string, err error)
}

type NamedTask

type NamedTask struct {
	Name  string
	Names []string
}

func (*NamedTask) GetNames

func (nt *NamedTask) GetNames() []string

type PackageManager

type PackageManager interface {
	ExecuteTask(ctx context.Context, t *PkgTask) (output string, err error)
}

type PkgActionType

type PkgActionType int
const (
	ActionInstall PkgActionType = iota + 1
	ActionUninstall
	ActionUpdate
)

type PkgTask

type PkgTask struct {
	ActionType PkgActionType
	TypeName   string
	Path       string
	NamedTask
	Shell         string
	Version       string
	ShouldRefresh bool
	Require       []string
	OnlyIf        []string
	Unless        []string
}

func (*PkgTask) GetName

func (pt *PkgTask) GetName() string

func (*PkgTask) GetPath

func (pt *PkgTask) GetPath() string

func (*PkgTask) GetRequirements

func (pt *PkgTask) GetRequirements() []string

func (*PkgTask) String

func (pt *PkgTask) String() string

func (*PkgTask) Validate

func (pt *PkgTask) Validate() error

type PkgTaskBuilder

type PkgTaskBuilder struct {
}

func (PkgTaskBuilder) Build

func (fmtb PkgTaskBuilder) Build(typeName, path string, ctx interface{}) (Task, error)

type PkgTaskExecutor

type PkgTaskExecutor struct {
	PackageManager PackageManager
	Runner         exec2.Runner
}

func (*PkgTaskExecutor) Execute

func (pte *PkgTaskExecutor) Execute(ctx context.Context, task Task) ExecutionResult

type Script

type Script struct {
	ID    string
	Tasks []Task
}

type Scripts

type Scripts []Script

type Task

type Task interface {
	GetName() string
	Validate() error
	GetPath() string
	GetRequirements() []string
}

Jump to

Keyboard shortcuts

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