recipe

package
v2.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEYWORD_VAR     = "var"
	KEYWORD_COMMAND = "command"
	KEYWORD_PACKAGE = "pkg"

	OPTION_UNSAFE_ACTIONS = "unsafe-actions"
	OPTION_REQUIRE_ROOT   = "require-root"
	OPTION_FAST_FINISH    = "fast-finish"
	OPTION_LOCK_WORKDIR   = "lock-workdir"
	OPTION_DELAY          = "delay"

	ACTION_EXIT = "exit"
	ACTION_WAIT = "wait"

	ACTION_EXPECT          = "expect"
	ACTION_WAIT_OUTPUT     = "wait-output"
	ACTION_OUTPUT_MATCH    = "output-match"
	ACTION_OUTPUT_CONTAINS = "output-contains"
	ACTION_OUTPUT_TRIM     = "output-trim"
	ACTION_PRINT           = "print"

	ACTION_CHDIR      = "chdir"
	ACTION_MODE       = "mode"
	ACTION_OWNER      = "owner"
	ACTION_EXIST      = "exist"
	ACTION_READABLE   = "readable"
	ACTION_WRITABLE   = "writable"
	ACTION_EXECUTABLE = "executable"
	ACTION_DIR        = "dir"
	ACTION_EMPTY      = "empty"
	ACTION_EMPTY_DIR  = "empty-dir"

	ACTION_CHECKSUM      = "checksum"
	ACTION_CHECKSUM_READ = "checksum-read"
	ACTION_FILE_CONTAINS = "file-contains"

	ACTION_COPY   = "copy"
	ACTION_MOVE   = "move"
	ACTION_TOUCH  = "touch"
	ACTION_MKDIR  = "mkdir"
	ACTION_REMOVE = "remove"
	ACTION_CHMOD  = "chmod"

	ACTION_BACKUP         = "backup"
	ACTION_BACKUP_RESTORE = "backup-restore"

	ACTION_PROCESS_WORKS = "process-works"
	ACTION_WAIT_PID      = "wait-pid"
	ACTION_WAIT_FS       = "wait-fs"
	ACTION_CONNECT       = "connect"
	ACTION_APP           = "app"
	ACTION_SIGNAL        = "signal"
	ACTION_ENV           = "env"
	ACTION_ENV_SET       = "env-set"

	ACTION_USER_EXIST  = "user-exist"
	ACTION_USER_ID     = "user-id"
	ACTION_USER_GID    = "user-gid"
	ACTION_USER_GROUP  = "user-group"
	ACTION_USER_SHELL  = "user-shell"
	ACTION_USER_HOME   = "user-home"
	ACTION_GROUP_EXIST = "group-exist"
	ACTION_GROUP_ID    = "group-id"

	ACTION_SERVICE_PRESENT = "service-present"
	ACTION_SERVICE_ENABLED = "service-enabled"
	ACTION_SERVICE_WORKS   = "service-works"

	ACTION_HTTP_STATUS     = "http-status"
	ACTION_HTTP_HEADER     = "http-header"
	ACTION_HTTP_CONTAINS   = "http-contains"
	ACTION_HTTP_JSON       = "http-json"
	ACTION_HTTP_SET_AUTH   = "http-set-auth"
	ACTION_HTTP_SET_HEADER = "http-set-header"

	ACTION_LIB_LOADED = "lib-loaded"
	ACTION_LIB_HEADER = "lib-header"
	ACTION_LIB_CONFIG = "lib-config"
	ACTION_LIB_EXIST  = "lib-exist"
	ACTION_LIB_LINKED = "lib-linked"

	ACTION_PYTHON_MODULE  = "python-module"
	ACTION_PYTHON3_MODULE = "python3-module"
)
View Source
const MAX_VAR_NESTING = 32

MAX_VAR_NESTING maximum variables nesting

Variables

View Source
var DynamicVariables = []string{
	"WORKDIR",
	"TIMESTAMP",
	"DATE",
	"HOSTNAME",
	"IP",
	"PYTHON_SITELIB",
	"PYTHON2_SITELIB",
	"PYTHON_SITEARCH",
	"PYTHON2_SITEARCH",
	"PYTHON3_SITELIB",
	"PYTHON3_SITEARCH",
	"PYTHON_SITELIB_LOCAL",
	"PYTHON2_SITELIB_LOCAL",
	"PYTHON3_SITELIB_LOCAL",
	"PYTHON_SITEARCH_LOCAL",
	"PYTHON2_SITEARCH_LOCAL",
	"PYTHON3_SITEARCH_LOCAL",
	"ERLANG_BIN_DIR",
}

DynamicVariables contains list of dynamic variables

View Source
var Tokens = []TokenInfo{
	{KEYWORD_VAR, 2, 2, true, false},
	{KEYWORD_COMMAND, 1, 2, true, false},
	{KEYWORD_PACKAGE, 1, 999, true, false},

	{OPTION_UNSAFE_ACTIONS, 1, 1, true, false},
	{OPTION_REQUIRE_ROOT, 1, 1, true, false},
	{OPTION_FAST_FINISH, 1, 1, true, false},
	{OPTION_LOCK_WORKDIR, 1, 1, true, false},
	{OPTION_DELAY, 1, 1, true, false},

	{ACTION_EXIT, 1, 2, false, true},
	{ACTION_WAIT, 1, 1, false, false},

	{ACTION_EXPECT, 1, 2, false, false},
	{ACTION_WAIT_OUTPUT, 1, 1, false, false},
	{ACTION_OUTPUT_MATCH, 1, 1, false, true},
	{ACTION_OUTPUT_CONTAINS, 1, 1, false, true},
	{ACTION_OUTPUT_TRIM, 0, 0, false, false},
	{ACTION_PRINT, 1, 1, false, false},

	{ACTION_CHDIR, 1, 1, false, false},
	{ACTION_MODE, 2, 2, false, true},
	{ACTION_OWNER, 2, 2, false, true},
	{ACTION_EXIST, 1, 1, false, true},
	{ACTION_READABLE, 2, 2, false, true},
	{ACTION_WRITABLE, 2, 2, false, true},
	{ACTION_EXECUTABLE, 2, 2, false, true},
	{ACTION_DIR, 1, 1, false, true},
	{ACTION_EMPTY, 1, 1, false, true},
	{ACTION_EMPTY_DIR, 1, 1, false, true},

	{ACTION_CHECKSUM, 2, 2, false, true},
	{ACTION_CHECKSUM_READ, 2, 2, false, false},
	{ACTION_FILE_CONTAINS, 2, 2, false, true},

	{ACTION_COPY, 2, 2, false, false},
	{ACTION_MOVE, 2, 2, false, false},
	{ACTION_TOUCH, 1, 1, false, false},
	{ACTION_MKDIR, 1, 1, false, false},
	{ACTION_REMOVE, 1, 1, false, false},
	{ACTION_CHMOD, 2, 2, false, false},

	{ACTION_BACKUP, 1, 1, false, false},
	{ACTION_BACKUP_RESTORE, 1, 1, false, false},

	{ACTION_PROCESS_WORKS, 1, 1, false, true},
	{ACTION_WAIT_PID, 1, 2, false, true},
	{ACTION_WAIT_FS, 1, 2, false, true},
	{ACTION_CONNECT, 2, 2, false, true},
	{ACTION_APP, 1, 1, false, true},
	{ACTION_SIGNAL, 1, 2, false, false},
	{ACTION_ENV, 2, 2, false, true},
	{ACTION_ENV_SET, 2, 2, false, false},

	{ACTION_USER_EXIST, 1, 1, false, true},
	{ACTION_USER_ID, 2, 2, false, true},
	{ACTION_USER_GID, 2, 2, false, true},
	{ACTION_USER_GROUP, 2, 2, false, true},
	{ACTION_USER_SHELL, 2, 2, false, true},
	{ACTION_USER_HOME, 2, 2, false, true},
	{ACTION_GROUP_EXIST, 1, 1, false, true},
	{ACTION_GROUP_ID, 2, 2, false, true},

	{ACTION_SERVICE_PRESENT, 1, 1, false, true},
	{ACTION_SERVICE_ENABLED, 1, 1, false, true},
	{ACTION_SERVICE_WORKS, 1, 1, false, true},

	{ACTION_HTTP_STATUS, 3, 4, false, true},
	{ACTION_HTTP_HEADER, 4, 5, false, true},
	{ACTION_HTTP_CONTAINS, 3, 4, false, true},
	{ACTION_HTTP_JSON, 4, 4, false, true},
	{ACTION_HTTP_SET_AUTH, 2, 2, false, false},
	{ACTION_HTTP_SET_HEADER, 2, 2, false, false},

	{ACTION_LIB_LOADED, 1, 1, false, true},
	{ACTION_LIB_HEADER, 1, 1, false, true},
	{ACTION_LIB_CONFIG, 1, 1, false, true},
	{ACTION_LIB_EXIST, 1, 1, false, true},
	{ACTION_LIB_LINKED, 2, 2, false, true},

	{ACTION_PYTHON_MODULE, 1, 1, false, false},
	{ACTION_PYTHON3_MODULE, 1, 1, false, false},
}

Tokens is slice with tokens info

Functions

This section is empty.

Types

type Action

type Action struct {
	Name      string   // Name
	Arguments []string // Arguments
	Negative  bool     // Is negative
	Line      uint16   // Line in recipe

	Command *Command // Link to command
}

Action contains action name and slice with arguments

func (*Action) GetF

func (a *Action) GetF(index int) (float64, error)

GetF returns argument with given index as float64

func (*Action) GetI

func (a *Action) GetI(index int) (int, error)

GetI returns argument with given index as int

func (*Action) GetS

func (a *Action) GetS(index int) (string, error)

GetS returns argument with given index as string

func (*Action) Has

func (a *Action) Has(index int) bool

Has returns true if an argument with given is exist

func (*Action) Index

func (a *Action) Index() int

Index returns action index

type Command

type Command struct {
	User        string    // User name
	Tag         string    // Tag
	Cmdline     string    // Command line
	Description string    // Description
	Actions     []*Action // Slice with actions
	Line        uint16    // Line in recipe

	Recipe *Recipe // Link to recipe
	// contains filtered or unexported fields
}

Command contains command with all actions

func NewCommand

func NewCommand(args []string, line uint16) *Command

NewCommand create new command struct

func (*Command) AddAction

func (c *Command) AddAction(action *Action)

AddAction appends command to actions slice

func (*Command) GetCmdline

func (c *Command) GetCmdline() string

GetCmdline returns command line with rendered variables

func (*Command) GetCmdlineArgs

func (c *Command) GetCmdlineArgs() []string

GetCmdlineArgs returns command line arguments, including the command as [0]

func (*Command) GetProp

func (c *Command) GetProp(name string) interface{}

GetProp returns property with given name

func (*Command) HasProp

func (c *Command) HasProp(name string) bool

HasProp returns true if the property is present in the store

func (*Command) Index

func (c *Command) Index() int

Index returns command index

func (*Command) SetProp

func (c *Command) SetProp(name string, value interface{})

SetProp sets property with given name

type Recipe

type Recipe struct {
	File          string     // Path to recipe
	Dir           string     // Working dir
	UnsafeActions bool       // Allow unsafe actions
	RequireRoot   bool       // Require root privileges
	FastFinish    bool       // Fast finish flag
	LockWorkdir   bool       // Locking workdir flag
	Delay         float64    // Delay between commands
	Packages      []string   // Package list
	Commands      []*Command // Commands
	// contains filtered or unexported fields
}

Recipe contains recipe data

func NewRecipe

func NewRecipe(file string) *Recipe

NewRecipe create new recipe struct

func (*Recipe) AddCommand

func (r *Recipe) AddCommand(cmd *Command, tag string)

AddCommand appends command to command slice

func (*Recipe) AddVariable

func (r *Recipe) AddVariable(name, value string)

AddVariable adds new RO variable

func (*Recipe) GetPackages

func (r *Recipe) GetPackages() string

GetPackages flatten packages slice to string

func (*Recipe) GetVariable

func (r *Recipe) GetVariable(name string) string

GetVariable returns variable value as string

func (*Recipe) SetVariable

func (r *Recipe) SetVariable(name, value string) error

SetVariable sets RW variable

type TokenInfo

type TokenInfo struct {
	Keyword       string
	MinArgs       int
	MaxArgs       int
	Global        bool
	AllowNegative bool
}

TokenInfo contains info about supported token

type Variable

type Variable struct {
	Value      string
	IsReadOnly bool
}

Jump to

Keyboard shortcuts

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