run

package
v0.0.0-...-5eba800 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WorkDir

func WorkDir(f func(string)) error

WorkDir creates a temporary work directory, runs an action, and removes the directory afterwards. Returns a non-nil error in case of issues.

Types

type DockerRunnerOptions

type DockerRunnerOptions struct {
	Privileged bool
	Binds      []string
}

type ExitCodeError

type ExitCodeError struct {
	Code int
}

ExitCodeError is an error representing the exit code of Diginfra

func (*ExitCodeError) Error

func (c *ExitCodeError) Error() string

type FileAccessor

type FileAccessor interface {
	Name() string
	Content() ([]byte, error)
}

FileAccessor is an interface defining a file with given name and content to be used within a Runner, and that abstracts the logic with which content is retrieved.

func NewBytesFileAccessor

func NewBytesFileAccessor(name string, content []byte) FileAccessor

NewBytesFileAccessor creates a FileAccessor that has a byte buf as its content

func NewLocalFileAccessor

func NewLocalFileAccessor(name, path string) FileAccessor

NewLocalFileAccessor creates a FileAccessor of which content is the content of a file in the local filesystem

func NewStringFileAccessor

func NewStringFileAccessor(name, content string) FileAccessor

NewStringFileAccessor creates a FileAccessor that has a string as its content

type Runner

type Runner interface {
	// Run runs Diginfra with the given options and returns when it finishes its
	// execution or when the context deadline is exceeded.
	// Returns a non-nil error in case of failure.
	Run(ctx context.Context, options ...RunnerOption) error
	// WorkDir return the absolute path to the working directory assigned
	// to the runner.
	WorkDir() string
}

Runner runs Diginfra with a given set of options

func NewDockerRunner

func NewDockerRunner(image, entrypoint string, options *DockerRunnerOptions) (Runner, error)

NewDockerRunner returns a runner that runs a container image with Docker

func NewExecutableRunner

func NewExecutableRunner(executable string) (Runner, error)

NewExecutableRunner returns a runner that runs a local executable binary

type RunnerOption

type RunnerOption func(*runOpts)

RunnerOption is an option for running Diginfra

func WithArgs

func WithArgs(args ...string) RunnerOption

WithArgs is an option for running Diginfra with a given set of CLI arguments

func WithEnvVars

func WithEnvVars(vars map[string]string) RunnerOption

WithEnvVars is an option for running Diginfra with a given set of environment varibles

func WithFiles

func WithFiles(files ...FileAccessor) RunnerOption

WithFiles is an option for running Diginfra with some files to be used during execution and/or referenced in the CLI args (e.g. rules files, config files, capture files, etc...). For example, if you run Diginfra with `-c` (through WithArgs), you should add the referenced config file with WithFiles.

func WithStderr

func WithStderr(writer io.Writer) RunnerOption

WithStderr is an option for running Diginfra by writing stderr on a given writer

func WithStdout

func WithStdout(writer io.Writer) RunnerOption

WithStdout is an option for running Diginfra by writing stdout on a given writer

Jump to

Keyboard shortcuts

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