recipe

package
v5.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SYMBOL_COMMAND_GROUP   = "+"
	SYMBOL_NEGATIVE_ACTION = "!"
	SYMBOL_SEPARATOR       = ":"

	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_UNBUFFER          = "unbuffer"
	OPTION_HTTPS_SKIP_VERIFY = "https-skip-verify"
	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_LINK       = "link"
	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_TRUNCATE = "truncate"
	ACTION_CLEANUP  = "cleanup"

	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_LIB_RPATH    = "lib-rpath"
	ACTION_LIB_SONAME   = "lib-soname"
	ACTION_LIB_EXPORTED = "lib-exported"

	ACTION_PYTHON_MODULE  = "python-module"
	ACTION_PYTHON3_MODULE = "python3-module"
)
View Source
const MAX_GROUP_ID uint8 = 255

MAX_GROUP_ID is maximum group ID

View Source
const MAX_VARIABLE_SIZE int = 512

MAX_VARIABLE_SIZE is maximum length of variable value

View Source
const MAX_VAR_NESTING int = 32

MAX_VAR_NESTING is maximum variables nesting

View Source
const TEARDOWN_TAG = "teardown"

TEARDOWN_TAG is teardown tag

Variables

View Source
var DynamicVariables = []string{
	"WORKDIR",
	"TIMESTAMP",
	"DATE",
	"HOSTNAME",
	"IP",
	"ARCH",
	"ARCH_BITS",
	"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_UNBUFFER, 1, 1, true, false},
	{OPTION_HTTPS_SKIP_VERIFY, 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_LINK, 2, 2, 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_TRUNCATE, 1, 1, false, false},
	{ACTION_CLEANUP, 1, 1, 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_LIB_RPATH, 2, 2, false, true},
	{ACTION_LIB_SONAME, 2, 2, false, true},
	{ACTION_LIB_EXPORTED, 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 {
	Arguments []string // Arguments
	Name      string   // Name
	Command   *Command // Link to command
	Line      uint16   // Line in recipe
	Negative  bool     // Negative check flag
}

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 Actions

type Actions []*Action

Actions is a slice with actions

func (Actions) Has

func (a Actions) Has(index int) bool

Has returns true if slice contains action with given index

func (Actions) Last

func (a Actions) Last() *Action

Last returns the last action from slice

type Command

type Command struct {
	Actions     Actions // Slice with actions
	User        string  // User name
	Tag         string  // Tag
	Cmdline     string  // Command line
	Description string  // Description
	Recipe      *Recipe // Link to recipe
	Line        uint16  // Line in recipe file

	GroupID uint8 // Unique command group ID

	Data *Storage // Data storage
}

Command contains command with all actions aligo:ignore

func NewCommand

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

NewCommand create new command struct

func (*Command) AddAction

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

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) Index

func (c *Command) Index() int

Index returns command index

type Commands

type Commands []*Command

Commands is a slice with commands

func (Commands) Has

func (c Commands) Has(index int) bool

Has returns true if slice contains command with given index

func (Commands) Last

func (c Commands) Last() *Command

Last returns the last command from slice

type Recipe

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

Recipe contains recipe data aligo:ignore

func NewRecipe

func NewRecipe(file string) *Recipe

NewRecipe create new recipe struct

func (*Recipe) AddCommand

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

AddCommand appends command to command slice

func (*Recipe) AddVariable

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

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) HasTeardown

func (r *Recipe) HasTeardown() bool

HasTeardown returns true if recipe contains command with teardown tag

func (*Recipe) SetVariable

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

SetVariable sets RW variable

type Storage

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

Storage is data storage

func (*Storage) Get

func (s *Storage) Get(key string) interface{}

Get returns object with given key from storage

func (*Storage) Has

func (s *Storage) Has(key string) bool

Has returns true if storage contains object with given key

func (*Storage) Set

func (s *Storage) Set(key string, value interface{})

Set adds new object into storage with given key

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
}

Variable contains variable data

Jump to

Keyboard shortcuts

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