util

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package util provides utility operations used in building sansshell system services.

Index

Constants

View Source
const MaxBuf = 1024

MaxBuf is the maximum we should allow stdout or stderr to be when sending back in an error string. grpc has limits on how large a returned error can be (generally 4-8k depending on language).

Variables

View Source
var StreamingChunkSize = 128 * 1024

StreamingChunkSize is the chunk size we use when sending replies on a stream. TODO(jchacon): Make this configurable

Functions

func TrimString

func TrimString(s string) string

TrimString will return the given string truncated to MAX_BUF size so it can be used in grpc error replies.

func ValidPath

func ValidPath(path string) error

ValidPath ensures the path passed in is both absolute and clean.

Types

type CommandRun

type CommandRun struct {
	Stdout   *bytes.Buffer
	Stderr   *bytes.Buffer
	Error    error
	ExitCode int
}

CommandRun groups all of the status and output from executing a command.

func RunCommand

func RunCommand(ctx context.Context, bin string, args []string, opts ...Option) (*CommandRun, error)

RunCommand will take the given binary and args and execute it returning all relevent state (stdout, stderr, errors, etc).

The binary must be a clean absolute path or an error will result and nothing will be run. Any other errors (starting or from waiting) are recorded in the Error field. Errors returned directly will be a status.Error and Error will be whatever the exec library returns.

type ExecuteState

type ExecuteState struct {
	Conn *proxy.Conn
	Out  []io.Writer
	Err  []io.Writer
}

ExecuteState is used by client packages in services to pass relevant state down to subcommands.

type IntSliceFlags

type IntSliceFlags []int64

IntSliceFlags is a custom flag for a list of ints in a comma separated list.

func (*IntSliceFlags) Set

func (i *IntSliceFlags) Set(val string) error

Set - see flag.Value

func (*IntSliceFlags) String

func (i *IntSliceFlags) String() string

String - see flag.Value

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

KeyValue is used below with KeyValueSliceFlag to construct foo=bar,baz=foo type of flags.

type KeyValueSliceFlag

type KeyValueSliceFlag []*KeyValue

KeyValueSliceFlag is a custom flag for a list of strings in a comma separated list of the form key=value,key=value

func (*KeyValueSliceFlag) Set

func (i *KeyValueSliceFlag) Set(val string) error

Set - see flag.Value

func (*KeyValueSliceFlag) String

func (i *KeyValueSliceFlag) String() string

String - see flag.Value

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option will run the apply operation to change required checking/state before executing RunCommand.

func FailOnStderr

func FailOnStderr() Option

FailOnStderr is an option where the command will return an error if any output appears on stderr regardless of exit code. As we're often parsing the text output of specific commands as root this is a sanity check we're getting expected output. i.e. ps never returns anything on stderr so if some run does that's suspect. Up to callers to decide as some tools (yum...) like to emit stderr as debugging as they run.

type StringSliceFlag

type StringSliceFlag struct {
	Target *[]string
}

StringSliceFlag is the parsed form of a flag using "foo,bar,baz" style.

func (*StringSliceFlag) Set

func (s *StringSliceFlag) Set(val string) error

Set - see flag.Value

func (*StringSliceFlag) String

func (s *StringSliceFlag) String() string

String - see flag.String

Jump to

Keyboard shortcuts

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