script

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package script provides types to represent a parsed script file.

Index

Constants

This section is empty.

Variables

View Source
var (
	CmdAs         = "AS"
	CmdAuthConfig = "AUTHCONFIG"
	CmdCapture    = "CAPTURE"
	CmdCopy       = "COPY"
	CmdEnv        = "ENV"
	CmdFrom       = "FROM"
	CmdKubeConfig = "KUBECONFIG"
	CmdKubeGet    = "KUBEGET"
	CmdOutput     = "OUTPUT"
	CmdRun        = "RUN"
	CmdWorkDir    = "WORKDIR"

	Defaults = struct {
		FromValue         string
		WorkdirValue      string
		KubeConfigValue   string
		AuthPKValue       string
		OutputValue       string
		HostAddr          string
		ServicePort       string
		ConnectionRetries string
		ConnectionTimeout string
	}{
		FromValue:    "local",
		WorkdirValue: "/tmp/crashdir",
		KubeConfigValue: func() string {
			kubecfg := os.Getenv("KUBECONFIG")
			if kubecfg == "" {
				kubecfg = filepath.Join(os.Getenv("HOME"), ".kube", "config")
			}
			return kubecfg
		}(),
		AuthPKValue: func() string {
			return filepath.Join(os.Getenv("HOME"), ".ssh", "id_rsa")
		}(),
		OutputValue:       "out.tar.gz",
		HostAddr:          "127.0.0.1",
		ServicePort:       "22",
		ConnectionRetries: "30",
		ConnectionTimeout: "2m",
	}
)
View Source
var (
	Cmds = map[string]CommandMeta{
		CmdAs:         CommandMeta{Name: CmdAs, MinArgs: 1, MaxArgs: 2, Supported: true},
		CmdAuthConfig: CommandMeta{Name: CmdAuthConfig, MinArgs: 1, MaxArgs: 3, Supported: true},
		CmdCapture:    CommandMeta{Name: CmdCapture, MinArgs: 1, MaxArgs: 3, Supported: true},
		CmdCopy:       CommandMeta{Name: CmdCopy, MinArgs: 1, MaxArgs: -1, Supported: true},
		CmdEnv:        CommandMeta{Name: CmdEnv, MinArgs: 1, MaxArgs: -1, Supported: true},
		CmdFrom:       CommandMeta{Name: CmdFrom, MinArgs: 1, MaxArgs: -1, Supported: true},
		CmdKubeConfig: CommandMeta{Name: CmdKubeConfig, MinArgs: 1, MaxArgs: 1, Supported: true},
		CmdKubeGet:    CommandMeta{Name: CmdKubeGet, MinArgs: 1, MaxArgs: -1, Supported: true},
		CmdOutput:     CommandMeta{Name: CmdOutput, MinArgs: 1, MaxArgs: 1, Supported: true},
		CmdRun:        CommandMeta{Name: CmdRun, MinArgs: 1, MaxArgs: 3, Supported: true},
		CmdWorkDir:    CommandMeta{Name: CmdWorkDir, MinArgs: 1, MaxArgs: 1, Supported: true},
	}
)

Functions

func ExpandEnv added in v0.1.1

func ExpandEnv(str string) string

ExpandEnv searches str for $value or ${value} which is then evaluated using os.ExpandEnv. expandVar supports escaping expansion using \$. For instance, when \$value or \${value} is encountered, it is not expanded, leaving the original values in the string as $value or ${value}.

Types

type ArgMap

type ArgMap = map[string]string

type AsCommand

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

AsCommand represents AS directive:

AS userid:"userid" [groupid:"groupid"]

Param userid required; groupid optional

func NewAsCommand

func NewAsCommand(index int, rawArgs string) (*AsCommand, error)

NewAsCommand returns *AsCommand with parsed arguments

func (*AsCommand) Args

func (c *AsCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*AsCommand) GetCredentials

func (c *AsCommand) GetCredentials() (uid, gid int, err error)

GetCredentials returns the uid and gid value extracted from Args

func (*AsCommand) GetGroupId

func (c *AsCommand) GetGroupId() string

GetGroupId returns the gid specified in AS

func (*AsCommand) GetUserId

func (c *AsCommand) GetUserId() string

GetUserId returns the userid specified in AS

func (*AsCommand) Index

func (c *AsCommand) Index() int

Index is the position of the command in the script

func (*AsCommand) Name

func (c *AsCommand) Name() string

Name represents the name of the command

type AuthConfigCommand

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

AuthConfigCommand represents AUTHCONFIG directive:

AUTHCONFIG username:"username" private-key:"/path/to/key api-key:key"

Param username is required

func NewAuthConfigCommand

func NewAuthConfigCommand(index int, rawArgs string) (*AuthConfigCommand, error)

NewAuthConfigCommand parses the rawArgs and returns an *AuthCommand

func (*AuthConfigCommand) Args

func (c *AuthConfigCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*AuthConfigCommand) GetPrivateKey

func (c *AuthConfigCommand) GetPrivateKey() string

GetPrivateKey returns the path of the private key configured

func (*AuthConfigCommand) GetUsername

func (c *AuthConfigCommand) GetUsername() string

GetUsername returns the User ID configured

func (*AuthConfigCommand) Index

func (c *AuthConfigCommand) Index() int

Index is the position of the command in the script

func (*AuthConfigCommand) Name

func (c *AuthConfigCommand) Name() string

Name represents the name of the command

type CaptureCommand

type CaptureCommand struct {
	*RunCommand
}

CaptureCommand represents CAPTURE directive which can have one of the following two forms as shown below:

CAPTURE <command-string>
CAPTURE cmd:"<command-string>" name:"cmd-name" desc:"cmd-desc"

The former takes no named parameter. When the latter form is used, parameter cmd: is required.

func NewCaptureCommand

func NewCaptureCommand(index int, rawArgs string) (*CaptureCommand, error)

NewCaptureCommand returns *CaptureCommand with parsed arguments

func (*CaptureCommand) GetEcho added in v0.2.1

func (c *CaptureCommand) GetEcho() string

GetEcho returns the echo param for command. When set to {yes|true|on} the result of the command will be redirected to the stdout|stderr

func (*CaptureCommand) GetEffectiveCmd

func (c *CaptureCommand) GetEffectiveCmd() ([]string, error)

GetEffectiveCmd returns the shell (if any) and command as a slice of strings

func (*CaptureCommand) GetEffectiveCmdStr

func (c *CaptureCommand) GetEffectiveCmdStr() (string, error)

GetEffectiveCmdStr returns the effective command as a string which wraps the command around a shell quote if necessary

func (*CaptureCommand) GetParsedCmd

func (c *CaptureCommand) GetParsedCmd() (string, []string, error)

GetParsedCmd returns the effective parsed command as commandName followed by a slice of command arguments

type Command

type Command interface {
	// Index is the position of the command in the script
	Index() int
	// Name represents the name of the command
	Name() string
	// Args returns a map of parsed arguments
	Args() ArgMap
}

Command is an abtract representatio of command in a script

type CommandMeta

type CommandMeta struct {
	Name      string
	MinArgs   int
	MaxArgs   int
	Supported bool
}

type CopyCommand

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

CopyCommand represents a COPY directive which may have one of the following two forms:

COPY path0 path1 ... pathN
COPY paths:"path0 path1 ... pathN"

The former uses no named parameters while the latter uses named parameter (i.e. paths)

func NewCopyCommand

func NewCopyCommand(index int, rawArgs string) (*CopyCommand, error)

NewCopyCommand returns *CopyCommand

func (*CopyCommand) Args

func (c *CopyCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*CopyCommand) Index

func (c *CopyCommand) Index() int

Index is the position of the command in the script

func (*CopyCommand) Name

func (c *CopyCommand) Name() string

Name represents the name of the command

func (*CopyCommand) Paths

func (c *CopyCommand) Paths() []string

Paths returned a []string of paths to copy

type EnvCommand

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

EnvCommand represents ENV directive which can have one of the following forms:

ENV var0=val0 var1=val0 ... varN=valN
ENV vars:"var0=val0 var1=val0 ... varN=valN"

Supports multiple ENV in one script.

func NewEnvCommand

func NewEnvCommand(index int, rawArgs string) (*EnvCommand, error)

NewEnvCommand returns parses the args as environment variables and returns *EnvCommand

func (*EnvCommand) Args

func (c *EnvCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*EnvCommand) Envs

func (c *EnvCommand) Envs() map[string]string

Envs returns slice of the parsed declared environment variables

func (*EnvCommand) Index

func (c *EnvCommand) Index() int

Index is the position of the command in the script

func (*EnvCommand) Name

func (c *EnvCommand) Name() string

Name represents the name of the command

type FromCommand

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

FromCommand represents FROM directive which may take one of the following forms:

FROM host0:port host1:port ... hostN:port
FROM hosts:"host0:port host1:port ... hostN:port"

Each host must be specified as an address endpoint with host:port.

func NewFromCommand

func NewFromCommand(index int, rawArgs string) (*FromCommand, error)

NewFromCommand parses the args and returns *FromCommand

func (*FromCommand) Args

func (c *FromCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*FromCommand) ConnectionRetries added in v0.2.1

func (c *FromCommand) ConnectionRetries() int

ConnectionRetries returns the maximum number of connection retries

func (*FromCommand) ConnectionTimeout added in v0.2.1

func (c *FromCommand) ConnectionTimeout() time.Duration

ConnectionTimeout returns the duration to get a connection to servers

func (*FromCommand) Hosts added in v0.2.1

func (c *FromCommand) Hosts() []string

Hosts returns direct host address to source from

func (*FromCommand) Index

func (c *FromCommand) Index() int

Index is the position of the command in the script

func (*FromCommand) Labels added in v0.2.1

func (c *FromCommand) Labels() string

Labels returns label filter used to select node to source from

func (*FromCommand) Name

func (c *FromCommand) Name() string

Name represents the name of the command

func (*FromCommand) Nodes added in v0.2.1

func (c *FromCommand) Nodes() []string

Nodes returns node names/ips

func (*FromCommand) Port added in v0.2.1

func (c *FromCommand) Port() string

Port returns the default connection port

type KubeConfigCommand

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

KubeConfigCommand represents a KUBECONFIG directive which can have one of the following forms:

KUBECONFIG path/to/kubeconfig
KUBECONFIG path:"path/to/kubeconfig"

func NewKubeConfigCommand

func NewKubeConfigCommand(index int, rawArgs string) (*KubeConfigCommand, error)

NewKubeConfigCommand creates a value of type KubeConfigCommand in a script

func (*KubeConfigCommand) Args

func (c *KubeConfigCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*KubeConfigCommand) Index

func (c *KubeConfigCommand) Index() int

Index is the position of the command in the script

func (*KubeConfigCommand) Name

func (c *KubeConfigCommand) Name() string

Name represents the name of the command

func (*KubeConfigCommand) Path

func (c *KubeConfigCommand) Path() string

Config returns the path to the config file

type KubeGetCommand added in v0.2.0

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

KubeGetCommand represents a KUBEGET directive which can have the following forms:

KUBEGET objects namespaces:<namespace> groups:<api-grou-name> kinds:<object-kind> versions:<object-version> names:<object-name> labels:<object-labels>
KUBEGET logs namespaces:<namespace> labels:<object-labels> containers:<list-of-containers-names>
KUBEGET all labels:<label-list>

The first param (what-param) is required param that indicates what resource to get with valid values of `objects`, `logs` and `all`. That param can also appear with the name `what`:

KUBEGET what:"all" labels:<label-list>

func NewKubeGetCommand added in v0.2.0

func NewKubeGetCommand(index int, rawArgs string) (*KubeGetCommand, error)

NewKubeGetCommand creates a value of type *KubeGetCommand from a script

func (*KubeGetCommand) Args added in v0.2.0

func (c *KubeGetCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*KubeGetCommand) Containers added in v0.2.0

func (c *KubeGetCommand) Containers() string

Containers returns a slice of container names from which to retrieve logs

func (*KubeGetCommand) Groups added in v0.2.0

func (c *KubeGetCommand) Groups() string

Groups returns slice of groups from which to retrieve objects

func (*KubeGetCommand) Index added in v0.2.0

func (c *KubeGetCommand) Index() int

Index is the position of the command in the script

func (*KubeGetCommand) Kinds added in v0.2.0

func (c *KubeGetCommand) Kinds() string

Kinds returns a slice of object kinds to retrieve

func (*KubeGetCommand) Labels added in v0.2.0

func (c *KubeGetCommand) Labels() string

Labels returns a slice of resource labels to match

func (*KubeGetCommand) Name added in v0.2.0

func (c *KubeGetCommand) Name() string

Name represents the name of the command

func (*KubeGetCommand) Names added in v0.2.0

func (c *KubeGetCommand) Names() string

Names returns a slice of resource names to retrieve

func (*KubeGetCommand) Namespaces added in v0.2.0

func (c *KubeGetCommand) Namespaces() string

Namespaces returns a slice of namespaces from which to retrieve objects

func (*KubeGetCommand) Versions added in v0.2.0

func (c *KubeGetCommand) Versions() string

Versions returns slice of resource versions to retrieve

func (*KubeGetCommand) What added in v0.2.0

func (c *KubeGetCommand) What() string

What returns the type of resource to get (i.e. objects, logs, all)

type Machine

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

Machine represents a machine as defined in FROM

func NewMachine

func NewMachine(host, port, name string) *Machine

NewMachine returns a new *Machine

func (*Machine) Address

func (m *Machine) Address() string

Address returns the host:port address

func (*Machine) Host

func (m *Machine) Host() string

Host returns the host of the node address

func (*Machine) Name added in v0.2.1

func (m *Machine) Name() string

Name is a identifier for the machine

func (*Machine) Port

func (m *Machine) Port() string

Port returns the port of the node address

type OutputCommand

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

OutputCommand representes a OUTPUT directive which can have one of the following forms:

OUTPUT /path/to/output
OUTPUT path:/path/to/output

func NewOutputCommand

func NewOutputCommand(index int, rawArgs string) (*OutputCommand, error)

NewOutputCommand parses args and returns a new *OutputCommand value

func (*OutputCommand) Args

func (c *OutputCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*OutputCommand) Index

func (c *OutputCommand) Index() int

Index is the position of the command in the script

func (*OutputCommand) Name

func (c *OutputCommand) Name() string

Name represents the name of the command

func (*OutputCommand) Path

func (c *OutputCommand) Path() string

Path returns the parsed path for directory

type RunCommand

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

RunCommand represents RUN directive which can have one of the following two forms as shown below:

RUN <command-string>
RUN cmd:"<command-string>" shell:"shell-path" desc:"cmd-desc"

The former takes no named parameter. When the latter form is used, parameter cmd: is required.

func NewRunCommand

func NewRunCommand(index int, rawArgs string) (*RunCommand, error)

NewRunCommand returns *RunCommand with parsed arguments

func (*RunCommand) Args

func (c *RunCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*RunCommand) GetCmdShell

func (c *RunCommand) GetCmdShell() string

GetCmdShell returns shell program and arguments for running the command string (i.e. /bin/bash -c)

func (*RunCommand) GetCmdString

func (c *RunCommand) GetCmdString() string

GetCmdString returns the raw CLI command string

func (*RunCommand) GetEcho added in v0.2.1

func (c *RunCommand) GetEcho() string

GetEcho returns the echo param for command. When set to {yes|true|on} the result of the command will be redirected to the stdout|stderr

func (*RunCommand) GetEffectiveCmd

func (c *RunCommand) GetEffectiveCmd() ([]string, error)

GetEffectiveCmd returns the shell (if any) and command as a slice of strings

func (*RunCommand) GetEffectiveCmdStr

func (c *RunCommand) GetEffectiveCmdStr() (string, error)

GetEffectiveCmdStr returns the effective command as a string which wraps the command around a shell quote if necessary

func (*RunCommand) GetParsedCmd

func (c *RunCommand) GetParsedCmd() (string, []string, error)

GetParsedCmd returns the effective parsed command as commandName followed by a slice of command arguments

func (*RunCommand) Index

func (c *RunCommand) Index() int

Index is the position of the command in the script

func (*RunCommand) Name

func (c *RunCommand) Name() string

Name represents the name of the command

type Script

type Script struct {
	Preambles map[string][]Command // directive commands in the script
	Actions   []Command            // action commands
}

Script is a collection of commands

func Parse

func Parse(reader io.Reader) (*Script, error)

Parse parses the textual script from reader into an *Script representation

type WorkdirCommand

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

WorkdirCommand representes a WORKDIR which may have one of the following forms:

WORKDIR /path/to/workdir
WORKDIR path:/path/to/workdir

func NewWorkdirCommand

func NewWorkdirCommand(index int, rawArgs string) (*WorkdirCommand, error)

NewWorkdirCommand parses args and returns a new *WorkdirCommand value

func (*WorkdirCommand) Args

func (c *WorkdirCommand) Args() map[string]string

Args returns a slice of raw command arguments

func (*WorkdirCommand) Index

func (c *WorkdirCommand) Index() int

Index is the position of the command in the script

func (*WorkdirCommand) Name

func (c *WorkdirCommand) Name() string

Name represents the name of the command

func (*WorkdirCommand) Path

func (c *WorkdirCommand) Path() string

Path returns the parsed path for directory

Jump to

Keyboard shortcuts

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