Documentation ¶
Overview ¶
Package util provides utility operations used in building sansshell system services.
Index ¶
Constants ¶
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 ¶
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 ¶
TrimString will return the given string truncated to MAX_BUF size so it can be used in grpc error replies.
Types ¶
type CommandRun ¶
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 ¶
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.
type KeyValue ¶
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.