script

package
v0.1.0-alpha.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: Apache-2.0 Imports: 14 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"
	CmdOutput     = "OUTPUT"
	CmdWorkDir    = "WORKDIR"

	Defaults = struct {
		FromValue       string
		WorkdirValue    string
		KubeConfigValue string
		AuthPKValue     string
		OutputValue     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",
	}
)
View Source
var (
	Cmds = map[string]CommandMeta{
		CmdAs:         CommandMeta{Name: CmdAs, MinArgs: 1, MaxArgs: 1, Supported: true},
		CmdAuthConfig: CommandMeta{Name: CmdAuthConfig, MinArgs: 1, MaxArgs: 3, Supported: true},
		CmdCapture:    CommandMeta{Name: CmdCapture, MinArgs: 1, MaxArgs: 1, 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},
		CmdOutput:     CommandMeta{Name: CmdOutput, MinArgs: 1, MaxArgs: 1, Supported: true},
		CmdWorkDir:    CommandMeta{Name: CmdWorkDir, MinArgs: 1, MaxArgs: 1, Supported: true},
	}
)

Functions

This section is empty.

Types

type AsCommand

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

AsCommand represents AS directive in a script

func NewAsCommand

func NewAsCommand(index int, args []string) (*AsCommand, error)

NewAsCommand returns *AsCommand with parsed arguments

func (*AsCommand) Args

func (c *AsCommand) Args() []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 captures auth configuration for a runtime

func NewAuthConfigCommand

func NewAuthConfigCommand(index int, args []string) (*AuthConfigCommand, error)

NewAuthConfigCommand parses the args and return a value of type *AuthCommand from: AUTHCONFIG username:<user-name> private-key:<path/to/key> api-key:<api-key-value>

func (*AuthConfigCommand) Args

func (c *AuthConfigCommand) Args() []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 {
	// contains filtered or unexported fields
}

CaptuerCommand represents CAPTURE in a script

func NewCaptureCommand

func NewCaptureCommand(index int, args []string) (*CaptureCommand, error)

NewCaptureCommand returns *CaptureCommand with parsed arguments

func (*CaptureCommand) Args

func (c *CaptureCommand) Args() []string

Args returns a slice of raw command arguments

func (*CaptureCommand) GetCliString

func (c *CaptureCommand) GetCliString() string

GetCliString returns the raw CLI command string

func (*CaptureCommand) GetParsedCli

func (c *CaptureCommand) GetParsedCli() (string, []string)

GetParsedCli returns the CLI command name to be captured and its arguments

func (*CaptureCommand) Index

func (c *CaptureCommand) Index() int

Index is the position of the command in the script

func (*CaptureCommand) Name

func (c *CaptureCommand) Name() string

Name represents the name of the command

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 slice of raw command arguments
	Args() []string
}

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 COPY command in a script

func NewCopyCommand

func NewCopyCommand(index int, args []string) (*CopyCommand, error)

NewCopyCommand returns *CopyCommand

func (*CopyCommand) Args

func (c *CopyCommand) Args() []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

type EnvCommand

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

EnvCommand represents ENV directive in a script

func NewEnvCommand

func NewEnvCommand(index int, args []string) (*EnvCommand, error)

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

func (*EnvCommand) Args

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

Args returns a slice of raw command arguments

func (*EnvCommand) Envs

func (c *EnvCommand) Envs() []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 in a script

func NewFromCommand

func NewFromCommand(index int, args []string) (*FromCommand, error)

NewFromCommand parses the args and returns *FromCommand

func (*FromCommand) Args

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

Args returns a slice of raw command arguments

func (*FromCommand) Index

func (c *FromCommand) Index() int

Index is the position of the command in the script

func (*FromCommand) Machines

func (c *FromCommand) Machines() []Machine

Machines returns a slice of Machines to which to connect

func (*FromCommand) Name

func (c *FromCommand) Name() string

Name represents the name of the command

type KubeConfigCommand

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

KubeConfigCommand represents a KUBECONFIG directive in the script

func NewKubeConfigCommand

func NewKubeConfigCommand(index int, args []string) (*KubeConfigCommand, error)

NewKubeConfigCommand creates a value of type KubeConfigCommand in a script

func (*KubeConfigCommand) Args

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

Args returns a slice of raw command arguments

func (*KubeConfigCommand) Config

func (c *KubeConfigCommand) Config() string

Config returns the path to the config file

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

type Machine

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

Machine represents a source machine

func NewMachine

func NewMachine(host, port 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 address

func (*Machine) Port

func (m *Machine) Port() string

Port returns the port of the address

type OutputCommand

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

OutputCommand representes a OUTPUT directive in as script as OUTPUT path:<output-dir>

func NewOutputCommand

func NewOutputCommand(index int, args []string) (*OutputCommand, error)

NewOutputCommand parses args and returns a new *OutputCommand value

func (*OutputCommand) Args

func (c *OutputCommand) Args() []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

Dir returns the parsed path for directory

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 directive in as script

func NewWorkdirCommand

func NewWorkdirCommand(index int, args []string) (*WorkdirCommand, error)

NewWorkdirCommand parses args and returns a new *WorkdirCommand value

func (*WorkdirCommand) Args

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

Args returns a slice of raw command arguments

func (*WorkdirCommand) Dir

func (c *WorkdirCommand) Dir() string

Dir returns the parsed path for directory

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

Jump to

Keyboard shortcuts

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