command

package
v3.2.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const MaxEnvironSizeInBytes = 128 * 1000 * 1000 // 128 MB

MaxEnvironSizeInBytes is the maximum size of an environment variable including equal sign and NUL separators.

This size is an artificial limit as Linux and macOS do not have a real limit.

View Source
const SessionListCapacity = 1024

SessionListCapacity is a maximum number of sessions stored in a single SessionList.

Variables

View Source
var EnvDumpCommand = func() string {
	path, err := os.Executable()
	if err != nil {
		panic(errors.WithMessage(err, "failed to get the executable path"))
	}
	return strings.Join([]string{path, "env", "dump", "--insecure"}, " ")
}()

EnvDumpCommand is a command that dumps the environment variables. It is declared as a var, because it must be replaced in tests. Equivalent is `env -0`.

View Source
var SignalToProcessGroup = true

SignalToProcessGroup is used in tests to disable sending signals to a process group.

Functions

func SetWinsize

func SetWinsize(cmd *VirtualCommand, winsize *Winsize) error

Types

type Command added in v3.2.7

type Command interface {
	Pid() int
	Running() bool
	Start(context.Context) error
	Signal(os.Signal) error
	Wait() error
}

type Config

Config contains a serializable configuration for a command. It's agnostic to the runtime or particular execution settings.

func NewConfigFromCodeBlock

func NewConfigFromCodeBlock(block *document.CodeBlock) (*Config, error)

type DockerCommand added in v3.2.7

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

func NewDocker added in v3.2.7

func NewDocker(cfg *Config, docker *dockerexec.Docker, opts Options) *DockerCommand

func (*DockerCommand) Pid added in v3.2.7

func (c *DockerCommand) Pid() int

func (*DockerCommand) Running added in v3.2.7

func (c *DockerCommand) Running() bool

func (*DockerCommand) Signal added in v3.2.7

func (c *DockerCommand) Signal(os.Signal) error

func (*DockerCommand) Start added in v3.2.7

func (c *DockerCommand) Start(ctx context.Context) (err error)

func (*DockerCommand) Wait added in v3.2.7

func (c *DockerCommand) Wait() (err error)

type DockerKernel added in v3.2.7

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

func NewDockerKernel added in v3.2.7

func NewDockerKernel(cfg *config.DockerKernel, logger *zap.Logger) (*DockerKernel, error)

func (*DockerKernel) Command added in v3.2.7

func (k *DockerKernel) Command(cfg *Config, opts Options) Command

func (*DockerKernel) Environ added in v3.2.7

func (k *DockerKernel) Environ() []string

func (*DockerKernel) LookPath added in v3.2.7

func (k *DockerKernel) LookPath(path string) (string, error)

type Kernel added in v3.2.7

type Kernel interface {
	Command(*Config, Options) Command
	Environ() []string
	LookPath(string) (string, error)
}

Kernel represents an execution environment for commands. It abstracts all OS-specific details and provides a unified interface.

type LocalKernel added in v3.2.7

type LocalKernel struct{}

func NewLocalKernel added in v3.2.7

func NewLocalKernel(cfg *config.LocalKernel) *LocalKernel

func (*LocalKernel) Command added in v3.2.7

func (k *LocalKernel) Command(cfg *Config, opts Options) Command

func (*LocalKernel) Environ added in v3.2.7

func (k *LocalKernel) Environ() []string

func (*LocalKernel) LookPath added in v3.2.7

func (k *LocalKernel) LookPath(path string) (string, error)

type NativeCommand

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

func NewNative

func NewNative(cfg *Config, opts Options) *NativeCommand

func (*NativeCommand) Pid

func (c *NativeCommand) Pid() int

func (*NativeCommand) Running

func (c *NativeCommand) Running() bool

func (*NativeCommand) Signal added in v3.2.7

func (c *NativeCommand) Signal(sig os.Signal) error

func (*NativeCommand) Start

func (c *NativeCommand) Start(ctx context.Context) (err error)

func (*NativeCommand) Wait

func (c *NativeCommand) Wait() (err error)

type Options added in v3.2.7

type Options struct {
	Kernel  Kernel
	Logger  *zap.Logger
	Session *Session
	Stdin   io.Reader
	Stdout  io.Writer
	Stderr  io.Writer
}

type ProgramResolver

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

ProgramResolver uses a list of ProgramResolverSource to resolve environment variables found in a shell program.

func NewProgramResolver

func NewProgramResolver(mode ProgramResolverMode, sensitiveEnvNames []string, sources ...ProgramResolverSource) *ProgramResolver

func (*ProgramResolver) IsEnvSensitive added in v3.2.2

func (r *ProgramResolver) IsEnvSensitive(name string) bool

func (*ProgramResolver) Resolve

func (r *ProgramResolver) Resolve(reader io.Reader, writer io.Writer) (*ProgramResolverResult, error)

Resolve resolves the environment variables found in a shell program. It might modify the program and write it provided writer.

type ProgramResolverMode

type ProgramResolverMode uint8
const (
	// ProgramResolverModeAuto is a default which prompts for all unresolved variables.
	ProgramResolverModeAuto ProgramResolverMode = iota
	// ProgramResolverModePromptAll always prompts even if variables are resolved.
	ProgramResolverModePromptAll
	// ProgramResolverModeSkipAll does not prompt even if variables are unresolved.
	// All variables will be marked as resolved.
	ProgramResolverModeSkipAll
)

type ProgramResolverResult

type ProgramResolverResult struct {
	Variables       []ProgramResolverVarResult
	ModifiedProgram bool
}

type ProgramResolverSource

type ProgramResolverSource func() []string

func ProgramResolverSourceFunc

func ProgramResolverSourceFunc(env []string) ProgramResolverSource

type ProgramResolverStatus

type ProgramResolverStatus uint8
const (
	// ProgramResolverStatusUnresolved indicates a variable is unresolved.
	ProgramResolverStatusUnresolved ProgramResolverStatus = iota
	// ProgramResolverStatusUnresolvedWithMessage indicates a variable is unresolved but it has a message.
	// It typically means that the variable is of form `export FOO=this is a message`.
	ProgramResolverStatusUnresolvedWithMessage
	// ProgramResolverStatusUnresolvedWithPlaceholder indicates a variable is unresolved but it has a placeholder.
	// It typically means that the variable is of form `export FOO="this is a placeholder"`.
	ProgramResolverStatusUnresolvedWithPlaceholder
	// ProgramResolverStatusUnresolvedWithSecret indicates a variable is unresolved and needs to be treated with sensitivity.
	// It typically means that the variable is a password, certificate, or access key.
	ProgramResolverStatusUnresolvedWithSecret
	// ProgramResolverStatusResolved indicates a variable is resolved.
	ProgramResolverStatusResolved
)

type ProgramResolverVarResult

type ProgramResolverVarResult struct {
	// Status indicates the status of the result.
	Status ProgramResolverStatus

	// Name is the name of the variable.
	// It is set always.
	Name string

	// OriginalValue is the original value of the variable.
	// It's either a placeholder (`export FOO="this is a placeholder"`) or
	// a message (`export FOO=this is a message`).
	OriginalValue string

	// Value is the resolved value of the variable.
	// It is set only if Status is ProgramResolverStatusResolved.
	Value string
}

type Session

type Session struct {
	ID string
	// contains filtered or unexported fields
}

Session is an object which lifespan contains multiple executions. It's used to exchange information between executions. Currently, it only keeps track of environment variables.

func MustNewSessionWithEnv

func MustNewSessionWithEnv(env ...string) *Session

func NewSession

func NewSession() *Session

func NewSessionWithEnv

func NewSessionWithEnv(env ...string) (*Session, error)

func (*Session) DeleteEnv

func (s *Session) DeleteEnv(keys ...string)

func (*Session) GetEnv

func (s *Session) GetEnv() []string

func (*Session) SetEnv

func (s *Session) SetEnv(env ...string) error

type SessionList

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

func NewSessionList

func NewSessionList() (*SessionList, error)

func (*SessionList) Add

func (sl *SessionList) Add(session *Session)

func (*SessionList) Delete

func (sl *SessionList) Delete(id string) bool

func (*SessionList) Get

func (sl *SessionList) Get(id string) (*Session, bool)

func (*SessionList) List

func (sl *SessionList) List() []*Session

func (*SessionList) Newest

func (sl *SessionList) Newest() (*Session, bool)

type VirtualCommand

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

func NewVirtual

func NewVirtual(cfg *Config, opts Options) *VirtualCommand

func (*VirtualCommand) Pid

func (c *VirtualCommand) Pid() int

func (*VirtualCommand) Running

func (c *VirtualCommand) Running() bool

func (*VirtualCommand) Signal added in v3.2.7

func (c *VirtualCommand) Signal(sig os.Signal) error

func (*VirtualCommand) Start

func (c *VirtualCommand) Start(ctx context.Context) (err error)

func (*VirtualCommand) Wait

func (c *VirtualCommand) Wait() (err error)

type Winsize

type Winsize pty.Winsize

Jump to

Keyboard shortcuts

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