common

package
v0.0.0-...-0117b6e Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package common contains common constants and functions needed to be accessed across ssm-setup-cli

Package common contains common constants and functions needed to be accessed across ssm-setup-cli

Package common contains common constants and functions needed to be accessed across ssm-setup-cli

Index

Constants

View Source
const (
	// GreengrassEnv denotes the greengrass environment
	GreengrassEnv SetupCLIEnvironment = "greengrass"
	// OnPremEnv denotes the onprem environment
	OnPremEnv SetupCLIEnvironment = "onprem"

	// AmazonWindowsSetupFile denotes the name of Agent Windows Setup File
	AmazonWindowsSetupFile = "AmazonSSMAgentSetup.exe"

	// AmazonSSMExecutable denotes windows executable used on Nano
	AmazonSSMExecutable = "amazon-ssm-agent.exe"

	// PackageNotInstalledExitCode denotes exitCode for package install error
	PackageNotInstalledExitCode = 1
)

Variables

This section is empty.

Functions

func GetPowershellPath

func GetPowershellPath() string

GetPowershellPath returns the path for powershell in Windows

func SetProxyConfig

func SetProxyConfig(log log.T)

SetProxyConfig sets the proxy config for the agent

Types

type AgentStatus

type AgentStatus string

AgentStatus holds agent's running status

const (
	// UndefinedStatus states that agent's state is unknown or undefined
	UndefinedStatus AgentStatus = "UndefinedStatus"
	// Running states that agent's state is in Running mode
	Running AgentStatus = "Running"
	// Stopped states that agent's state is in Stopped mode
	Stopped AgentStatus = "Stopped"
	// NotInstalled states that agent is not installed on the instance
	NotInstalled AgentStatus = "NotInstalled"
)

type IManagerHelper

type IManagerHelper interface {
	// RunCommand executes command with timeout
	RunCommand(cmd string, args ...string) (string, error)

	// RunCommandWithCustomTimeout executes command with a custom timeout
	RunCommandWithCustomTimeout(timeout time.Duration, cmd string, args ...string) (string, error)

	// ExecCommandWithOutput executes command with output and error content returned
	ExecCommandWithOutput(
		log log.T,
		cmd string,
		workingDir string,
		outputRoot string,
		stdOut string,
		stdErr string) (pId int, updExitCode updateconstants.UpdateScriptExitCode, stdoutBytes *bytes.Buffer, errorBytes *bytes.Buffer, cmdErr error)

	// IsCommandAvailable checks if command can be executed on host
	IsCommandAvailable(cmd string) bool

	// IsTimeoutError returns true if error is context timeout error
	IsTimeoutError(err error) bool

	// IsExitCodeError returns true if error is command exit code error
	IsExitCodeError(err error) bool

	// GetExitCode returns the exit code for of exit code error, defaults to -1 if error is not exit code error
	GetExitCode(err error) int
}

IManagerHelper is the interface containing functions related to command executions on the system

type ManagerHelper

type ManagerHelper struct {
	Timeout time.Duration
}

ManagerHelper implements IManagerHelper

func (*ManagerHelper) ExecCommandWithOutput

func (m *ManagerHelper) ExecCommandWithOutput(
	log log.T,
	cmd string,
	workingDir string,
	outputRoot string,
	stdOut string,
	stdErr string) (pId int, updExitCode updateconstants.UpdateScriptExitCode, stdoutBytes *bytes.Buffer, errorBytes *bytes.Buffer, cmdErr error)

ExecCommandWithOutput executes shell command and returns output and error of command execution

func (*ManagerHelper) GetExitCode

func (m *ManagerHelper) GetExitCode(err error) int

GetExitCode returns the exit code for of exit code error, defaults to -1 if error is not exit code error

func (*ManagerHelper) IsCommandAvailable

func (m *ManagerHelper) IsCommandAvailable(cmd string) bool

IsCommandAvailable checks if command can be executed on host

func (*ManagerHelper) IsExitCodeError

func (m *ManagerHelper) IsExitCodeError(err error) bool

IsExitCodeError returns true if error is command exit code error

func (*ManagerHelper) IsTimeoutError

func (m *ManagerHelper) IsTimeoutError(err error) bool

IsTimeoutError returns true if error is context timeout error

func (*ManagerHelper) RunCommand

func (m *ManagerHelper) RunCommand(cmd string, args ...string) (string, error)

RunCommand is used to execute commands with a default timeout set to 30 secs

func (*ManagerHelper) RunCommandWithCustomTimeout

func (m *ManagerHelper) RunCommandWithCustomTimeout(timout time.Duration, cmd string, args ...string) (string, error)

RunCommandWithCustomTimeout is used to execute commands with timeout accepted as argument

type SetupCLIEnvironment

type SetupCLIEnvironment string

SetupCLIEnvironment states the different environments the ssm-setup-cli can run

Directories

Path Synopsis
Package mocks contains mocks for IManagerHelper type
Package mocks contains mocks for IManagerHelper type

Jump to

Keyboard shortcuts

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