core

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Unknown vote
	Unknown PreconditionVote = 0
	// Stop the process
	Stop = 1
	// Proceed the process can be ran
	Proceed = 2
)
View Source
const (
	// None ...
	None VersionComparationOperator = "None"
	// LessThan ...
	LessThan = "LessThan"
	// LessThanOrEqual ...
	LessThanOrEqual = "LessThanOrEqual"
	// Equal ...
	Equal = "Equal"
	// GreaterThanOrEqual ...
	GreaterThanOrEqual = "GreaterThanOrEqual"
	// GreaterThan ...
	GreaterThan = "GreaterThan"
)
View Source
const ErrFmtCreateProcess = "Unable to create Process for %s. Check configuration: missing Host, SSHTunnel or Container key?"

ErrFmtCreateProcess format used for error in process creation.

Variables

View Source
var BuildTime = ""

BuildTime of the running app.

View Source
var GitCommit = ""

GitCommit is the Git hash and a "+CHANGES" suffix if there are uncommitted changes.

View Source
var Version = ""

Version of the running app.

Functions

func ConfigureUI

func ConfigureUI(mainLogger Logger, processLoggerConfig LoggerConfig)

ConfigureUI allows to the main package to set main logger instance and configure the process logger instances.

func Decrypt

func Decrypt(data []byte, passphrase string) ([]byte, error)

Decrypt a secret using passphrase

func DecryptBase64

func DecryptBase64(encoded string, passphrase string) ([]byte, error)

DecryptBase64 decrypt a secret encoded in base 64

func Encrypt

func Encrypt(data []byte, passphrase string) ([]byte, error)

Encrypt a secret using passphrase

func EncryptToBase64

func EncryptToBase64(data []byte, passphrase string) (string, error)

EncryptToBase64 encypt secret and encode in base 64

func IsRunpfileValid

func IsRunpfileValid(runpfile *Runpfile) (bool, []error)

IsRunpfileValid returns a boolean rapresenting if any Runpfile value is valid and a list of errors.

func RandomKey

func RandomKey() string

RandomKey generates a random string usable as key to encrypt secrets

func ResetColor added in v0.5.1

func ResetColor()

ResetColor resets the foreground and background to original colors

func ResolveRunpfilePath

func ResolveRunpfilePath(rp string) (string, error)

ResolveRunpfilePath Returns the path to the Runpfile and error

Types

type ApplicationContext

type ApplicationContext struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ApplicationContext is a singleton object containing some global variables.

func GetApplicationContext

func GetApplicationContext() *ApplicationContext

GetApplicationContext returns the singleton instance of the application context.

func (*ApplicationContext) AddReport

func (c *ApplicationContext) AddReport(message string)

AddReport add a report string to the reports list.

func (*ApplicationContext) GetReport

func (c *ApplicationContext) GetReport() []string

GetReport returns all reports.

func (*ApplicationContext) GetRunningProcesses

func (c *ApplicationContext) GetRunningProcesses() map[string]RunpProcess

GetRunningProcesses returns all running processes.

func (*ApplicationContext) RegisterRunningProcess

func (c *ApplicationContext) RegisterRunningProcess(proc RunpProcess)

RegisterRunningProcess add process to the list of running ones.

func (*ApplicationContext) RemoveRunningProcess

func (c *ApplicationContext) RemoveRunningProcess(proc RunpProcess)

RemoveRunningProcess add process.

type Auth

type Auth struct {
	Secret string
	// encrypted secret in base 64
	EncryptedSecret string `yaml:"encrypted_secret"`
	IdentityFile    string `yaml:"identity_file"`
}

Auth is auth

type AwaitCondition

type AwaitCondition struct {
	Resource string
	Timeout  string
}

AwaitCondition defines time to wait for a resource.

type ContainerProcess

type ContainerProcess struct {
	// image
	Image string
	// if not used it will be created
	Name string
	// in format docker-compose
	Ports []string
	// rm Automatically remove the container when it exits
	SkipRm bool `yaml:"skip_rm"`
	// in format docker-compose
	Volumes     []string
	VolumesFrom []string `yaml:"volumes_from"`
	Mounts      []string
	ShmSize     string `yaml:"shm_size"`
	Command     string

	// generics
	WorkingDir string `yaml:"workdir"`
	Env        map[string]string
	Await      AwaitCondition
	// contains filtered or unexported fields
}

ContainerProcess implements RunpProcess.

func (*ContainerProcess) AwaitResource

func (p *ContainerProcess) AwaitResource() string

AwaitResource returns the await resource.

func (*ContainerProcess) AwaitTimeout

func (p *ContainerProcess) AwaitTimeout() string

AwaitTimeout returns the await timeout.

func (*ContainerProcess) Dir

func (p *ContainerProcess) Dir() string

Dir for the sub process

func (*ContainerProcess) ID

func (p *ContainerProcess) ID() string

ID for the sub process

func (*ContainerProcess) IsStartable

func (p *ContainerProcess) IsStartable() (bool, error)

IsStartable ...

func (*ContainerProcess) SetDir

func (p *ContainerProcess) SetDir(wd string)

SetDir for the sub process

func (*ContainerProcess) SetID

func (p *ContainerProcess) SetID(id string)

SetID for the sub process

func (*ContainerProcess) SetPreconditions added in v0.5.4

func (p *ContainerProcess) SetPreconditions(preconditions Preconditions)

SetPreconditions set preconditions.

func (*ContainerProcess) ShouldWait

func (p *ContainerProcess) ShouldWait() bool

ShouldWait returns if the process has await set.

func (*ContainerProcess) StartCommand

func (p *ContainerProcess) StartCommand() (RunpCommand, error)

StartCommand returns the command starting the process.

func (*ContainerProcess) StopCommand

func (p *ContainerProcess) StopCommand() (RunpCommand, error)

StopCommand returns the command stopping the process.

func (*ContainerProcess) StopTimeout

func (p *ContainerProcess) StopTimeout() time.Duration

StopTimeout duration to wait to force kill process

func (*ContainerProcess) String

func (p *ContainerProcess) String() string

String representation of process

func (*ContainerProcess) VerifyPreconditions added in v0.5.4

func (p *ContainerProcess) VerifyPreconditions() PreconditionVerifyResult

VerifyPreconditions check if process can be started

type Endpoint

type Endpoint struct {
	Host string
	Port int
}

Endpoint is server

func (*Endpoint) String

func (e *Endpoint) String() string

type EnvironmentSettings added in v0.6.0

type EnvironmentSettings struct {
	ContainerRunnerExe string `yaml:"container_runner"`
}

EnvironmentSettings represents settings for the current box.

type EtcHostsPrecondition added in v0.7.0

type EtcHostsPrecondition struct {
	Contains map[string][]string
	// contains filtered or unexported fields
}

EtcHostsPrecondition verify /etc/hosts contains given host.

func (*EtcHostsPrecondition) IsSet added in v0.7.0

func (p *EtcHostsPrecondition) IsSet() bool

IsSet ...

func (*EtcHostsPrecondition) Verify added in v0.7.0

Verify ...

type ExecCommandStopper

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

ExecCommandStopper is the component calling the actual command stopping the process.

func (*ExecCommandStopper) Pid

func (c *ExecCommandStopper) Pid() int

Pid ...

func (*ExecCommandStopper) Run

func (c *ExecCommandStopper) Run() error

Run ...

func (*ExecCommandStopper) Start

func (c *ExecCommandStopper) Start() error

Start ...

func (*ExecCommandStopper) Stderr

func (c *ExecCommandStopper) Stderr(stderr io.Writer)

Stderr ...

func (*ExecCommandStopper) Stdout

func (c *ExecCommandStopper) Stdout(stdout io.Writer)

Stdout ...

func (*ExecCommandStopper) Stop

func (c *ExecCommandStopper) Stop() error

Stop ...

func (*ExecCommandStopper) String

func (c *ExecCommandStopper) String() string

func (*ExecCommandStopper) Wait

func (c *ExecCommandStopper) Wait() error

Wait waits for the command to exit.

type ExecCommandWrapper

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

ExecCommandWrapper is wrapper for *exec.Cmd

func (*ExecCommandWrapper) Pid

func (c *ExecCommandWrapper) Pid() int

Pid return PID for this command wrapper

func (*ExecCommandWrapper) Run

func (c *ExecCommandWrapper) Run() error

Run ...

func (*ExecCommandWrapper) Start

func (c *ExecCommandWrapper) Start() error

Start ...

func (*ExecCommandWrapper) Stderr

func (c *ExecCommandWrapper) Stderr(stderr io.Writer)

Stderr set the stderr writer

func (*ExecCommandWrapper) Stdout

func (c *ExecCommandWrapper) Stdout(stdout io.Writer)

Stdout set the stdout writer

func (*ExecCommandWrapper) Stop

func (c *ExecCommandWrapper) Stop() error

Stop ...

func (*ExecCommandWrapper) String

func (c *ExecCommandWrapper) String() string

func (*ExecCommandWrapper) Wait

func (c *ExecCommandWrapper) Wait() error

Wait waits for the command to exit.

type HostProcess

type HostProcess struct {
	// command line
	CommandLine string `yaml:"command"`
	// executable
	Executable string
	Args       []string
	Shell      Shell
	// generic
	WorkingDir string `yaml:"workdir"`
	Env        map[string]string
	Await      AwaitCondition
	// contains filtered or unexported fields
}

HostProcess implements RunpProcess.

func (*HostProcess) AwaitResource

func (p *HostProcess) AwaitResource() string

AwaitResource returns the await resource.

func (*HostProcess) AwaitTimeout

func (p *HostProcess) AwaitTimeout() string

AwaitTimeout returns the await timeout.

func (*HostProcess) Dir

func (p *HostProcess) Dir() string

Dir for the sub process

func (*HostProcess) ID

func (p *HostProcess) ID() string

ID for the sub process

func (*HostProcess) IsStartable

func (p *HostProcess) IsStartable() (bool, error)

IsStartable always true.

func (*HostProcess) SetDir

func (p *HostProcess) SetDir(wd string)

SetDir for the sub process

func (*HostProcess) SetID

func (p *HostProcess) SetID(id string)

SetID for the sub process

func (*HostProcess) SetPreconditions added in v0.5.4

func (p *HostProcess) SetPreconditions(preconditions Preconditions)

SetPreconditions set preconditions.

func (*HostProcess) ShouldWait

func (p *HostProcess) ShouldWait() bool

ShouldWait returns if the process has await set.

func (*HostProcess) StartCommand

func (p *HostProcess) StartCommand() (RunpCommand, error)

StartCommand returns the command starting the process.

func (*HostProcess) StopCommand

func (p *HostProcess) StopCommand() (RunpCommand, error)

StopCommand returns the command stopping the process.

func (*HostProcess) StopTimeout

func (p *HostProcess) StopTimeout() time.Duration

StopTimeout duration to wait to force kill process

func (*HostProcess) String

func (p *HostProcess) String() string

String representation of process

func (*HostProcess) VerifyPreconditions added in v0.5.4

func (p *HostProcess) VerifyPreconditions() PreconditionVerifyResult

VerifyPreconditions check if process can be started

type Logger

type Logger interface {
	WriteLinef(format string, a ...interface{}) (int, error)
	Debugf(format string, a ...interface{}) (int, error)
	WriteLine(line string) (int, error)
	Debug(line string) (int, error)
	Write(p []byte) (int, error)
}

Logger writes out messages from the main program and output from the running processes.

func CreateMainLogger

func CreateMainLogger(proc string, longest int, format string, debug bool, colorize bool) Logger

CreateMainLogger creates logger instance for main process (runp).

type LoggerConfig

type LoggerConfig struct {
	Debug bool
	Color bool
}

LoggerConfig contains configuration for a logger.

type OsPrecondition added in v0.5.4

type OsPrecondition struct {
	// linux | darwin | windows
	Inclusions []string
	// contains filtered or unexported fields
}

OsPrecondition verify os.

func (*OsPrecondition) IsSet added in v0.5.4

func (p *OsPrecondition) IsSet() bool

IsSet ...

func (*OsPrecondition) Verify added in v0.5.4

Verify ...

type Precondition added in v0.5.4

type Precondition interface {
	IsSet() bool
	Verify() PreconditionVerifyResult
}

Precondition is.

type PreconditionVerifyResult added in v0.5.4

type PreconditionVerifyResult struct {
	Vote    PreconditionVote
	Reasons []string
}

PreconditionVerifyResult ...

type PreconditionVote added in v0.5.4

type PreconditionVote int64

PreconditionVote ...

func (PreconditionVote) String added in v0.5.4

func (e PreconditionVote) String() string

type Preconditions added in v0.5.4

type Preconditions struct {
	Os    OsPrecondition
	Runp  RunpVersionPrecondition
	Hosts EtcHostsPrecondition
}

Preconditions ...

func (*Preconditions) Verify added in v0.5.4

Verify ...

type RunpCommand

type RunpCommand interface {
	Pid() int
	Stdout(stdout io.Writer)
	Stderr(stderr io.Writer)
	Start() error
	Run() error
	Stop() error
	Wait() error
}

RunpCommand is the interface for all command types: host, container, aws process...

type RunpProcess

type RunpProcess interface {
	ID() string
	VerifyPreconditions() PreconditionVerifyResult
	SetPreconditions(Preconditions)
	SetID(string)
	StartCommand() (RunpCommand, error)
	StopCommand() (RunpCommand, error)
	StopTimeout() time.Duration
	Dir() string
	SetDir(string)
	ShouldWait() bool
	AwaitResource() string
	AwaitTimeout() string
	IsStartable() (bool, error)
}

RunpProcess is wrapper for running process

type RunpUnit

type RunpUnit struct {
	Name          string
	Description   string
	StopTimeout   string `yaml:"stop_timeout"`
	Preconditions Preconditions

	Host      *HostProcess
	Container *ContainerProcess
	SSHTunnel *SSHTunnelProcess `yaml:"ssh_tunnel"`
	// contains filtered or unexported fields
}

RunpUnit is...

func (*RunpUnit) Kind added in v0.7.0

func (u *RunpUnit) Kind() string

Kind describes the unit in `runp ls`.

func (*RunpUnit) Process

func (u *RunpUnit) Process() RunpProcess

Process returns the sub process

func (*RunpUnit) SkipDirResolution

func (u *RunpUnit) SkipDirResolution() bool

SkipDirResolution avoid resolve dir for containers

type RunpVersionPrecondition added in v0.5.4

type RunpVersionPrecondition struct {
	Operator VersionComparationOperator
	Version  string
}

RunpVersionPrecondition checks Runp version.

func (*RunpVersionPrecondition) IsSet added in v0.5.4

func (p *RunpVersionPrecondition) IsSet() bool

IsSet ...

func (*RunpVersionPrecondition) Verify added in v0.5.4

Verify ...

type Runpfile

type Runpfile struct {
	Name        string
	Description string
	Version     string
	Vars        map[string]string
	Root        string
	Units       map[string]*RunpUnit
	SecretKey   string `yaml:"-"`
	Include     []string
}

Runpfile is the model containing the full configuration.

func LoadRunpfileFromPath

func LoadRunpfileFromPath(runpfilePath string) (*Runpfile, error)

LoadRunpfileFromPath returns an Runpfile object reading file from path.

type RunpfileExecutor

type RunpfileExecutor struct {
	LoggerFactory func(string, int, LoggerConfig) Logger
	// contains filtered or unexported fields
}

RunpfileExecutor Executor implementation for Runpfile.

func NewExecutor

func NewExecutor(rf *Runpfile) *RunpfileExecutor

NewExecutor creates new RunpfileExecutor

func (*RunpfileExecutor) Start

func (e *RunpfileExecutor) Start()

Start call start on all processes.

type SSHTunnelCommandStopper

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

SSHTunnelCommandStopper is the component calling the actual command stopping the process.

func (*SSHTunnelCommandStopper) Pid

func (c *SSHTunnelCommandStopper) Pid() int

Pid ...

func (*SSHTunnelCommandStopper) Run

func (c *SSHTunnelCommandStopper) Run() error

Run ...

func (*SSHTunnelCommandStopper) Start

func (c *SSHTunnelCommandStopper) Start() error

Start ...

func (*SSHTunnelCommandStopper) Stderr

func (c *SSHTunnelCommandStopper) Stderr(stderr io.Writer)

Stderr ...

func (*SSHTunnelCommandStopper) Stdout

func (c *SSHTunnelCommandStopper) Stdout(stdout io.Writer)

Stdout ...

func (*SSHTunnelCommandStopper) Stop

func (c *SSHTunnelCommandStopper) Stop() error

Stop ...

func (*SSHTunnelCommandStopper) String

func (c *SSHTunnelCommandStopper) String() string

func (*SSHTunnelCommandStopper) Wait

func (c *SSHTunnelCommandStopper) Wait() error

Wait ...

type SSHTunnelCommandWrapper

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

SSHTunnelCommandWrapper ...

func (*SSHTunnelCommandWrapper) Pid

func (c *SSHTunnelCommandWrapper) Pid() int

Pid ...

func (*SSHTunnelCommandWrapper) Run

func (c *SSHTunnelCommandWrapper) Run() error

Run ...

func (*SSHTunnelCommandWrapper) Start

func (c *SSHTunnelCommandWrapper) Start() error

Start ...

func (*SSHTunnelCommandWrapper) Stderr

func (c *SSHTunnelCommandWrapper) Stderr(stderr io.Writer)

Stderr ...

func (*SSHTunnelCommandWrapper) Stdout

func (c *SSHTunnelCommandWrapper) Stdout(stdout io.Writer)

Stdout ...

func (*SSHTunnelCommandWrapper) Stop

func (c *SSHTunnelCommandWrapper) Stop() error

Stop ...

func (*SSHTunnelCommandWrapper) String

func (c *SSHTunnelCommandWrapper) String() string

func (*SSHTunnelCommandWrapper) Wait

func (c *SSHTunnelCommandWrapper) Wait() error

Wait ...

type SSHTunnelProcess

type SSHTunnelProcess struct {
	WorkingDir string `yaml:"workdir"`
	Env        map[string]string
	Await      AwaitCondition

	User   string
	Auth   Auth
	Local  Endpoint
	Jump   Endpoint
	Target Endpoint
	// command executed to test connection to jump server
	TestCommand string `yaml:"test_command"`
	// contains filtered or unexported fields
}

SSHTunnelProcess implements RunpProcess.

func (*SSHTunnelProcess) AwaitResource

func (p *SSHTunnelProcess) AwaitResource() string

AwaitResource returns the await resource.

func (*SSHTunnelProcess) AwaitTimeout

func (p *SSHTunnelProcess) AwaitTimeout() string

AwaitTimeout returns the await timeout.

func (*SSHTunnelProcess) Dir

func (p *SSHTunnelProcess) Dir() string

Dir for the sub process

func (*SSHTunnelProcess) ID

func (p *SSHTunnelProcess) ID() string

ID for the sub process

func (*SSHTunnelProcess) IsStartable

func (p *SSHTunnelProcess) IsStartable() (bool, error)

IsStartable always true.

func (*SSHTunnelProcess) SetDir

func (p *SSHTunnelProcess) SetDir(wd string)

SetDir for the sub process

func (*SSHTunnelProcess) SetID

func (p *SSHTunnelProcess) SetID(id string)

SetID for the sub process

func (*SSHTunnelProcess) SetPreconditions added in v0.5.4

func (p *SSHTunnelProcess) SetPreconditions(preconditions Preconditions)

SetPreconditions set preconditions.

func (*SSHTunnelProcess) ShouldWait

func (p *SSHTunnelProcess) ShouldWait() bool

ShouldWait returns if the process has await set.

func (*SSHTunnelProcess) StartCommand

func (p *SSHTunnelProcess) StartCommand() (RunpCommand, error)

StartCommand returns the command starting the process.

func (*SSHTunnelProcess) StopCommand

func (p *SSHTunnelProcess) StopCommand() (RunpCommand, error)

StopCommand returns the command stopping the process.

func (*SSHTunnelProcess) StopTimeout

func (p *SSHTunnelProcess) StopTimeout() time.Duration

StopTimeout duration to wait to force kill process

func (*SSHTunnelProcess) String

func (p *SSHTunnelProcess) String() string

String representation of process

func (*SSHTunnelProcess) VerifyPreconditions added in v0.5.4

func (p *SSHTunnelProcess) VerifyPreconditions() PreconditionVerifyResult

VerifyPreconditions check if process can be started

type Shell

type Shell struct {
	Path string
	Args []string
}

Shell represents the shell used to invoke command.

type StartPlan

type StartPlan struct {
	Await AwaitCondition
}

StartPlan defines how and when start process.

type VersionComparationOperator added in v0.5.4

type VersionComparationOperator string

VersionComparationOperator ...

Jump to

Keyboard shortcuts

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