runner

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CancelOp added in v0.5.0

func CancelOp(r Runner, err error, start time.Time) op.Op

CancelOp wraps op.NewCancel to resolve the Runner.ID() and Params into concrete types.

func Params

func Params(r Runner) map[string]any

Params takes a Runner and returns a map of its public fields

func TimeoutOp added in v0.5.0

func TimeoutOp(r Runner, err error, start time.Time) op.Op

TimeoutOp wraps op.NewTimeout to resolve the Runner.ID() and Params into concrete types.

Types

type Command added in v0.5.0

type Command struct {
	// Parameters that are not shared/common
	Command string `json:"command"`
	Format  string `json:"format"`

	Timeout    Timeout          `json:"timeout"`
	Redactions []*redact.Redact `json:"redactions"`
	// contains filtered or unexported fields
}

Command runs shell commands.

func NewCommand added in v0.5.0

func NewCommand(cfg CommandConfig) (*Command, error)

NewCommand provides a runner for bin commands.

func NewCommandWithContext added in v0.5.0

func NewCommandWithContext(ctx context.Context, cfg CommandConfig) (*Command, error)

NewCommandWithContext provides a runner for bin commands that includes a context.

func (Command) ID added in v0.5.0

func (c Command) ID() string

func (Command) Run added in v0.5.0

func (c Command) Run() op.Op

Run executes the Command

type CommandConfig added in v0.5.0

type CommandConfig struct {
	// Command is the command line string that this runner should execute.
	Command string

	// Format is the desired output format. Valid options are "string" or "json"; the default will be "string" when
	// creating an object from the constructor functions NewCommand and NewCommandWithContext.
	Format string

	// Timeout specifies the amount of time that the runner should be allowed to execute before cancellation.
	Timeout time.Duration

	// Redactions includes any redactions to apply to the output of the runner.
	Redactions []*redact.Redact
}

CommandConfig is the configuration object passed into NewCommand or NewCommandWithContext. It includes the fields that those constructors will use to configure the Command object that they return.

type CommandConfigError added in v0.5.0

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

func (CommandConfigError) Error added in v0.5.0

func (e CommandConfigError) Error() string

func (CommandConfigError) Unwrap added in v0.5.0

func (e CommandConfigError) Unwrap() error

type CommandExecError

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

func (CommandExecError) Error

func (e CommandExecError) Error() string

func (CommandExecError) Unwrap

func (e CommandExecError) Unwrap() error

type CommandParseError added in v0.5.0

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

func (CommandParseError) Error added in v0.5.0

func (e CommandParseError) Error() string

func (CommandParseError) Unwrap added in v0.5.0

func (e CommandParseError) Unwrap() error

type Copy added in v0.5.0

type Copy struct {
	SourceDir string    `json:"source_directory"`
	Filter    string    `json:"filter"`
	DestDir   string    `json:"destination_directory"`
	Since     time.Time `json:"since"`
	Until     time.Time `json:"until"`
	// Redactions includes any redactions to apply to the output of the runner.
	Redactions []*redact.Redact `json:"redactions"`
	// Timeout specifies the amount of time that the runner should be allowed to execute before cancellation.
	Timeout Timeout `json:"timeout"`
	// contains filtered or unexported fields
}

Copy copies files to temp dir based on a filter.

func NewCopy added in v0.5.0

func NewCopy(cfg CopyConfig) (*Copy, error)

NewCopy provides a Runner for copying files to temp dir based on a filter.

func NewCopyWithContext added in v0.5.0

func NewCopyWithContext(ctx context.Context, cfg CopyConfig) (*Copy, error)

func (Copy) ID added in v0.5.0

func (c Copy) ID() string

func (Copy) Run added in v0.5.0

func (c Copy) Run() op.Op

Run satisfies the Runner interface and copies the filtered source files to the destination.

type CopyConfig added in v0.5.0

type CopyConfig struct {
	// Path is the file path to the directory or file to copy to the DestDir.
	Path    string
	DestDir string
	Since   time.Time
	Until   time.Time
	// Redactions includes any redactions to apply to the output of the runner.
	Redactions []*redact.Redact
	// Timeout specifies the amount of time that the runner should be allowed to execute before cancellation.
	Timeout time.Duration
}

type CopyConfigError added in v0.5.0

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

func (CopyConfigError) Error added in v0.5.0

func (e CopyConfigError) Error() string

func (CopyConfigError) Unwrap added in v0.5.0

func (e CopyConfigError) Unwrap() error

type CopyFilesError

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

func (CopyFilesError) Error

func (e CopyFilesError) Error() string

func (CopyFilesError) Unwrap

func (e CopyFilesError) Unwrap() error

type FindFilesError

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

func (FindFilesError) Error

func (e FindFilesError) Error() string

func (FindFilesError) Unwrap

func (e FindFilesError) Unwrap() error

type FormatUnknownError

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

func (FormatUnknownError) Error

func (e FormatUnknownError) Error() string

type HTTP added in v0.5.0

type HTTP struct {
	// Parameters that are not shared/common
	Path   string            `json:"path"`
	Client *client.APIClient `json:"client"`

	Timeout    Timeout          `json:"timeout"`
	Redactions []*redact.Redact `json:"redactions"`
	// contains filtered or unexported fields
}

HTTP hits APIs.

func NewHTTP added in v0.5.0

func NewHTTP(cfg HttpConfig) (*HTTP, error)

func NewHTTPWithContext added in v0.5.0

func NewHTTPWithContext(ctx context.Context, cfg HttpConfig) (*HTTP, error)

func (HTTP) ID added in v0.5.0

func (h HTTP) ID() string

func (HTTP) Run added in v0.5.0

func (h HTTP) Run() op.Op

Run executes a GET request to the Path using the Client

type HTTPConfigError added in v0.5.0

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

func (HTTPConfigError) Error added in v0.5.0

func (e HTTPConfigError) Error() string

func (HTTPConfigError) Unwrap added in v0.5.0

func (e HTTPConfigError) Unwrap() error

type HttpConfig added in v0.5.0

type HttpConfig struct {
	// Client is the client.APIClient that will be used to make HTTP requests.
	Client *client.APIClient

	// Path is the path portion of the URL that the runner will hit.
	Path string

	// Timeout specifies the amount of time that the runner should be allowed to execute before cancellation.
	Timeout time.Duration

	// Redactions includes any redactions to apply to the output of the runner.
	Redactions []*redact.Redact
}

HttpConfig is the configuration object passed into NewHTTP or NewHTTPWithContext. It includes the fields that those constructors will use to configure the HTTP object that they return.

type MakeDirError

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

func (MakeDirError) Error

func (e MakeDirError) Error() string

func (MakeDirError) Unwrap

func (e MakeDirError) Unwrap() error

type Runner

type Runner interface {
	ID() string
	Run() op.Op
}

Runner runs things to get information.

func Exclude

func Exclude(excludes []string, runners []Runner) ([]Runner, error)

Exclude takes a slice of matcher strings and a slice of ops. If any of the runner identifiers match the exclude according to filepath.Match() then it will not be present in the returned runner slice. NOTE(mkcp): This is precisely identical to Select() except we flip the match check. Maybe we can perform both rounds of filtering in one pass one rather than iterating over all the ops several times. Not likely to be a huge speed increase though... we're not even remotely bottlenecked on runner filtering.

func Select

func Select(selects []string, runners []Runner) ([]Runner, error)

Select takes a slice of matcher strings and a slice of ops. The only ops returned will be those matching the given select strings according to filepath.Match()

type Shell added in v0.5.0

type Shell struct {
	Command    string           `json:"command"`
	Shell      string           `json:"shell"`
	Redactions []*redact.Redact `json:"redactions"`
	Timeout    Timeout          `json:"timeout"`
	// contains filtered or unexported fields
}

Shell runs shell commands in a real unix shell.

func NewShell added in v0.5.0

func NewShell(cfg ShellConfig) (*Shell, error)

NewShell provides a runner for arbitrary shell code.

func NewShellWithContext added in v0.5.0

func NewShellWithContext(ctx context.Context, cfg ShellConfig) (*Shell, error)

NewShellWithContext provides a runner for arbitrary shell code.

func (Shell) ID added in v0.5.0

func (s Shell) ID() string

func (Shell) Run added in v0.5.0

func (s Shell) Run() op.Op

Run ensures a shell exists and optimistically executes the given Command string

type ShellConfig added in v0.5.0

type ShellConfig struct {
	Command    string
	Redactions []*redact.Redact
	Timeout    time.Duration
}

type ShellExecError

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

func (ShellExecError) Error

func (e ShellExecError) Error() string

func (ShellExecError) Unwrap

func (e ShellExecError) Unwrap() error

type Timeout added in v0.5.0

type Timeout time.Duration

Timeout is a time.Duration, which allows for custom JSON marshalling. When marshalled, it will be converted into a duration string, rather than an integer representing nanoseconds. For example, 3000000000 becomes "3s".

func (Timeout) MarshalJSON added in v0.5.0

func (t Timeout) MarshalJSON() ([]byte, error)
Example

ExampleTimeout_MarshalJSON provides some examples to demonstrate the usefulness of the Timeout struct as it relates to marshalling to JSON. Because results from diagnostic runs are written as JSON, this provides a more human-readable format than what the time.Duration type provides.

var (
	b        []byte
	duration time.Duration
	timeout  Timeout
)

// When a time.Duration is marshalled to JSON, it renders as an integer,
// representing the number of nanoseconds in the duration.
duration = 3 * time.Second
b, _ = json.Marshal(duration)
fmt.Println(string(b)) // 3000000000

// When a Timeout is marshalled to JSON, it renders in the same format
// that Go uses to parse from strings into time.Duration, providing a
// more human-readable output format.
timeout = Timeout(duration)
b, _ = json.Marshal(timeout)
fmt.Println(string(b)) // "3s"

// More complex time durations are also supported for human-readable output.
timeout = Timeout((2 * time.Hour) + (31 * time.Minute) + (12 * time.Second))
b, _ = json.Marshal(timeout)
fmt.Println(string(b)) // "2h31m12s"
Output:

3000000000
"3s"
"2h31m12s"

type UnmarshalError

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

func (UnmarshalError) Error

func (e UnmarshalError) Error() string

func (UnmarshalError) Unwrap

func (e UnmarshalError) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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