common

package module
v0.0.0-...-1ee88e1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: MIT Imports: 31 Imported by: 74

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultProperties is a map of all valid common properties with corresponding default property values
	DefaultProperties = map[string]string{
		"deployed": "false",
	}

	// GlobalProperties is a map of all valid global common properties
	GlobalProperties = map[string]bool{}
)

Functions

func AppHostRoot

func AppHostRoot(appName string) string

AppHostRoot returns the app root path

func AppRoot

func AppRoot(appName string) string

AppRoot returns the app root path

func AskForDestructiveConfirmation

func AskForDestructiveConfirmation(name string, objectType string) error

AskForDestructiveConfirmation checks for confirmation on destructive actions

func CatFile

func CatFile(filename string)

CatFile cats the contents of a file (if it exists)

func CloneAppData

func CloneAppData(pluginName string, oldAppName string, newAppName string) error

CloneAppData copies the data from one app to another

func CollectReport

func CollectReport(appName string, infoFlag string, flags map[string]ReportFunc) map[string]string

CollectReport iterates over a set of report functions to collect the :report output in parallel

func CommandPropertySet

func CommandPropertySet(pluginName, appName, property, value string, properties map[string]string, globalProperties map[string]bool)

CommandPropertySet is a generic function that will set a property for a given plugin/app combination

func CommandUsage

func CommandUsage(helpHeader string, helpContent string)

CommandUsage outputs help for a command

func ContainerExists

func ContainerExists(containerID string) bool

ContainerExists checks to see if a container exists

func ContainerIsRunning

func ContainerIsRunning(containerID string) bool

ContainerIsRunning checks to see if a container is running

func ContainerRemove

func ContainerRemove(containerID string) bool

ContainerRemove runs 'docker container remove' against an existing container

func ContainerStart

func ContainerStart(containerID string) bool

ContainerStart runs 'docker container start' against an existing container

func ContainerWait

func ContainerWait(containerID string) bool

ContainerWait runs 'docker container wait' against an existing container

func ContainerWaitTilReady

func ContainerWaitTilReady(containerID string, timeout time.Duration) error

ContainerWaitTilReady will wait timeout seconds and then check if a container is running returning an error if it is not running at the end of the timeout

func Copy

func Copy(src, dst string) error

Copy copies a file/directory from src to dst. If the source is a file, it will also convert line endings to unix style

func CopyFromImage

func CopyFromImage(appName string, image string, source string, destination string) error

CopyFromImage copies a file from named image to destination

func CreateAppDataDirectory

func CreateAppDataDirectory(pluginName, appName string) error

CreateAppDataDirectory creates a data directory for the given plugin/app combination with the correct permissions

func CreateDataDirectory

func CreateDataDirectory(pluginName string) error

CreateDataDirectory creates a data directory for the given plugin/app combination with the correct permissions

func DirectoryExists

func DirectoryExists(filename string) bool

DirectoryExists returns if a path exists and is a directory

func DockerBin

func DockerBin() string

DockerBin returns a string which contains a path to the current docker binary

func DockerCleanup

func DockerCleanup(appName string, forceCleanup bool) error

DockerCleanup cleans up all exited/dead containers and removes all dangling images

func DockerContainerCreate

func DockerContainerCreate(image string, containerCreateArgs []string) (string, error)

DockerContainerCreate creates a new container and returns the container ID

func DockerFilterContainers

func DockerFilterContainers(filters []string) ([]string, error)

DockerFilterContainers returns a slice of container IDs based on the passed in filters

func DockerFilterImages

func DockerFilterImages(filters []string) ([]string, error)

DockerFilterImages returns a slice of image IDs based on the passed in filters

func DockerInspect

func DockerInspect(containerOrImageID, format string) (output string, err error)

DockerInspect runs an inspect command with a given format against a container or image ID

func DockerRemoveContainers

func DockerRemoveContainers(containerIDs []string)

DockerRemoveContainers will call `docker container rm` on the specified containers

func DokkuApps

func DokkuApps() ([]string, error)

DokkuApps returns a list of all local apps

func EnvWrap

func EnvWrap(fn func() error, environ map[string]string) error

EnvWrap wraps a func with a setenv call and resets the value at the end

func FileExists

func FileExists(filename string) bool

FileExists returns if a path exists and is a file

func FileToSlice

func FileToSlice(filename string) (lines []string, err error)

FileToSlice reads in all the lines from a file into a string slice

func GetAppContainerIDs

func GetAppContainerIDs(appName string, containerType string) ([]string, error)

GetAppContainerIDs returns a list of docker container ids for given app and optional container_type

func GetAppDataDirectory

func GetAppDataDirectory(pluginName string, appName string) string

GetAppDataDirectory returns the path to the data directory for the given plugin/app combination

func GetAppImageName

func GetAppImageName(appName, imageTag, imageRepo string) (imageName string)

GetAppImageName returns image identifier for a given app, tag tuple. validate if tag is presented

func GetAppImageRepo

func GetAppImageRepo(appName string) string

GetAppImageRepo is the central definition of a dokku image repo pattern

func GetAppRunningContainerIDs

func GetAppRunningContainerIDs(appName string, containerType string) ([]string, error)

GetAppRunningContainerIDs return a list of running docker container ids for given app and optional container_type

func GetAppScheduler

func GetAppScheduler(appName string) string

GetAppScheduler fetches the scheduler for a given application

func GetDataDirectory

func GetDataDirectory(pluginName string) string

GetDataDirectory returns the path to the data directory for the specified plugin

func GetDeployingAppImageName

func GetDeployingAppImageName(appName, imageTag, imageRepo string) (string, error)

GetDeployingAppImageName returns deploying image identifier for a given app, tag tuple. validate if tag is presented

func GetGlobalScheduler

func GetGlobalScheduler() string

GetGlobalScheduler fetchs the global scheduler

func GetRunningImageTag

func GetRunningImageTag(appName string, imageTag string) (string, error)

GetRunningImageTag retrieves current deployed image tag for a given app

func GetWorkingDir

func GetWorkingDir(appName string, image string) string

GetWorkingDir returns the working directory for a given image

func GetenvWithDefault

func GetenvWithDefault(key string, defaultValue string) (val string)

GetenvWithDefault returns env variable or defaultValue if it's not set

func IsAbsPath

func IsAbsPath(path string) bool

IsAbsPath returns 0 if input path is absolute

func IsComposeInstalled

func IsComposeInstalled() bool

func IsDeployed

func IsDeployed(appName string) bool

IsDeployed returns true if given app has a running container

func IsImageCnbBased

func IsImageCnbBased(image string) bool

IsImageCnbBased returns true if app image is based on cnb

func IsImageHerokuishBased

func IsImageHerokuishBased(image string, appName string) bool

IsImageHerokuishBased returns true if app image is based on herokuish

func IsValidAppName

func IsValidAppName(appName string) error

IsValidAppName verifies that the app name matches naming restrictions

func ListDanglingImages

func ListDanglingImages(appName string) ([]string, error)

ListDanglingImages lists all dangling image ids for a given app

func ListFilesWithPrefix

func ListFilesWithPrefix(path string, prefix string) []string

ListFilesWithPrefix lists files within a given path that have a given prefix

func Log

func Log(text string)

Log is the log formatter

func LogDebug

func LogDebug(text string)

LogDebug is the debug log formatter

func LogExclaim

func LogExclaim(text string)

LogExclaim is the log exclaim formatter

func LogFail

func LogFail(text string)

LogFail is the failure log formatter prints text to stderr and exits with status 1

func LogFailQuiet

func LogFailQuiet(text string)

LogFailQuiet is the failure log formatter (with quiet option) prints text to stderr and exits with status 1

func LogFailWithError

func LogFailWithError(err error)

LogFailWithError is the failure log formatter prints text to stderr and exits with the specified exit code

func LogFailWithErrorQuiet

func LogFailWithErrorQuiet(err error)

LogFailWithErrorQuiet is the failure log formatter (with quiet option) prints text to stderr and exits with the specified exit code The error message is not printed if DOKKU_QUIET_OUTPUT has any value

func LogInfo1

func LogInfo1(text string)

LogInfo1 is the info1 header formatter

func LogInfo1Quiet

func LogInfo1Quiet(text string)

LogInfo1Quiet is the info1 header formatter (with quiet option)

func LogInfo2

func LogInfo2(text string)

LogInfo2 is the info2 header formatter

func LogInfo2Quiet

func LogInfo2Quiet(text string)

LogInfo2Quiet is the info2 header formatter (with quiet option)

func LogQuiet

func LogQuiet(text string)

LogQuiet is the log formatter (with quiet option)

func LogStderr

func LogStderr(text string)

LogStderr is the stderr log formatter

func LogVerbose

func LogVerbose(text string)

LogVerbose is the verbose log formatter prints indented text to stdout

func LogVerboseQuiet

func LogVerboseQuiet(text string)

LogVerboseQuiet is the verbose log formatter prints indented text to stdout (with quiet option)

func LogVerboseQuietContainerLogs

func LogVerboseQuietContainerLogs(containerID string)

LogVerboseQuietContainerLogs is the verbose log formatter for container logs

func LogVerboseQuietContainerLogsTail

func LogVerboseQuietContainerLogsTail(containerID string, lines int, tail bool)

LogVerboseQuietContainerLogsTail is the verbose log formatter for container logs with tail mode enabled

func LogVerboseStderr

func LogVerboseStderr(text string)

LogVerboseStderr is the verbose log formatter prints indented text to stderr

func LogVerboseStderrQuiet

func LogVerboseStderrQuiet(text string)

LogVerboseStderrQuiet is the verbose log formatter prints indented text to stderr (with quiet option)

func LogWarn

func LogWarn(text string)

LogWarn is the warning log formatter

func MigrateAppDataDirectory

func MigrateAppDataDirectory(pluginName string, oldAppName string, newAppName string) error

MigrateAppDataDirectory migrates the data directory for one app to another

func MustGetEnv

func MustGetEnv(key string) (val string)

MustGetEnv returns env variable or fails if it's not set

func ParseReportArgs

func ParseReportArgs(pluginName string, arguments []string) ([]string, string, error)

ParseReportArgs splits out flags from non-flags for input into report commands

func ParseScaleOutput

func ParseScaleOutput(b []byte) (map[string]int32, error)

ParseScaleOutput allows golang plugins to properly parse the output of ps-current-scale

func PlugnTriggerExists

func PlugnTriggerExists(triggerName string) bool

PlugnTriggerExists returns whether a plugin trigger exists (ignoring the existence of any within the 20_events plugin)

func PropertyClone

func PropertyClone(pluginName string, oldAppName string, newAppName string) error

PropertyClone clones a set of properties from one app to another

func PropertyDelete

func PropertyDelete(pluginName string, appName string, property string) error

PropertyDelete deletes a property from the plugin properties for an app

func PropertyDestroy

func PropertyDestroy(pluginName string, appName string) error

PropertyDestroy destroys the plugin properties for an app

func PropertyExists

func PropertyExists(pluginName string, appName string, property string) bool

PropertyExists returns whether a property exists or not

func PropertyGet

func PropertyGet(pluginName string, appName string, property string) string

PropertyGet returns the value for a given property

func PropertyGetAll

func PropertyGetAll(pluginName string, appName string) (map[string]string, error)

PropertyGetAll returns a map of all properties for a given app

func PropertyGetAllByPrefix

func PropertyGetAllByPrefix(pluginName string, appName string, prefix string) (map[string]string, error)

PropertyGetAllByPrefix returns a map of all properties for a given app with a specified prefix

func PropertyGetDefault

func PropertyGetDefault(pluginName, appName, property, defaultValue string) (val string)

PropertyGetDefault returns the value for a given property with a specified default value

func PropertyListAdd

func PropertyListAdd(pluginName string, appName string, property string, value string, index int) error

PropertyListAdd adds a property to a list at an optionally specified index

func PropertyListGet

func PropertyListGet(pluginName string, appName string, property string) (lines []string, err error)

PropertyListGet returns a property list

func PropertyListGetByIndex

func PropertyListGetByIndex(pluginName string, appName string, property string, index int) (propertyValue string, err error)

PropertyListGetByIndex returns an entry within property list by index

func PropertyListGetByValue

func PropertyListGetByValue(pluginName string, appName string, property string, value string) (propertyValue string, err error)

PropertyListGetByValue returns an entry within property list by value

func PropertyListLength

func PropertyListLength(pluginName string, appName string, property string) (length int, err error)

PropertyListLength returns the length of a property list

func PropertyListRemove

func PropertyListRemove(pluginName string, appName string, property string, value string) error

PropertyListRemove removes a value from a property list

func PropertyListRemoveByPrefix

func PropertyListRemoveByPrefix(pluginName string, appName string, property string, prefix string) error

PropertyListRemoveByPrefix removes a value by prefix from a property list

func PropertyListSet

func PropertyListSet(pluginName string, appName string, property string, value string, index int) error

PropertyListSet sets a value within a property list at a specified index

func PropertyListWrite

func PropertyListWrite(pluginName string, appName string, property string, values []string) error

PropertyListWrite completely rewrites a list property

func PropertySetup

func PropertySetup(pluginName string) error

PropertySetup creates the plugin config root

func PropertyWrite

func PropertyWrite(pluginName string, appName string, property string, value string) error

PropertyWrite writes a value for a given application property

func ReadFirstLine

func ReadFirstLine(filename string) (text string)

ReadFirstLine gets the first line of a file that has contents and returns it if there are no contents, an empty string is returned will also return an empty string if the file does not exist

func RemoveAppDataDirectory

func RemoveAppDataDirectory(pluginName, appName string) error

RemoveAppDataDirectory removes the path to the data directory for the given plugin/app combination

func RemoveImages

func RemoveImages(imageIDs []string) error

RemoveImages removes images by ID

func ReportSingleApp

func ReportSingleApp(reportType string, appName string, infoFlag string, infoFlags map[string]string, infoFlagKeys []string, format string, trimPrefix bool, uppercaseFirstCharacter bool) error

ReportSingleApp is an internal function that displays a report for an app

func RightPad

func RightPad(str string, length int, pad string) string

RightPad right-pads the string with pad up to len runes

func RunCommandAgainstAllApps

func RunCommandAgainstAllApps(command parallelCommand, commandName string, parallelCount int) error

RunCommandAgainstAllApps runs a given parallelCommand against all apps

func RunCommandAgainstAllAppsInParallel

func RunCommandAgainstAllAppsInParallel(command parallelCommand, commandName string, parallelCount int) error

RunCommandAgainstAllAppsInParallel runs a given parallelCommand against all apps in parallel

func RunCommandAgainstAllAppsSerially

func RunCommandAgainstAllAppsSerially(command parallelCommand, commandName string) error

RunCommandAgainstAllAppsSerially runs a given parallelCommand against all apps serially

func SetPermissions

func SetPermissions(input SetPermissionInput) error

SetPermissions sets the proper owner and filemode for a given file

func SetupAppData

func SetupAppData(pluginName string) error

SetupAppData ensures each app has a data directory

func ShiftString

func ShiftString(a []string) (string, []string)

ShiftString removes the first and returns that entry as well as the rest of the list

func StripInlineComments

func StripInlineComments(text string) string

StripInlineComments removes bash-style comment from input line

func SuppressOutput

func SuppressOutput(f errfunc) error

SuppressOutput suppresses the output of a function unless there is an error

func ToBool

func ToBool(s string) bool

ToBool returns a bool value for a given string

func ToInt

func ToInt(s string, defaultValue int) int

ToInt returns an int value for a given string

func TouchFile

func TouchFile(filename string) error

TouchFile creates an empty file at the specified path

func TriggerAppList

func TriggerAppList(filtered bool) error

TriggerAppList outputs each app name to stdout on a newline

func TriggerCorePostDeploy

func TriggerCorePostDeploy(appName string) error

TriggerCorePostDeploy associates the container with a specified network

func TriggerInstall

func TriggerInstall() error

TriggerInstall runs the install step for the common plugin

func TriggerPostAppCloneSetup

func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error

TriggerPostAppCloneSetup copies common files

func TriggerPostAppRenameSetup

func TriggerPostAppRenameSetup(oldAppName string, newAppName string) error

TriggerPostAppRenameSetup renames common files

func TriggerPostDelete

func TriggerPostDelete(appName string) error

TriggerPostDelete destroys the common property for a given app container

func UcFirst

func UcFirst(str string) string

UcFirst uppercases the first character in a string

func UnfilteredDokkuApps

func UnfilteredDokkuApps() ([]string, error)

UnfilteredDokkuApps returns an unfiltered list of all local apps

func VarArgs

func VarArgs(arguments []string, skip int) []string

VarArgs skips a number of incoming arguments, returning what is left over

func VerifyAppName

func VerifyAppName(appName string) error

VerifyAppName checks if an app conforming to either the old or new naming conventions exists

func VerifyImage

func VerifyImage(image string) bool

VerifyImage returns true if docker image exists in local repo

func WriteBytesToFile

func WriteBytesToFile(input WriteBytesToFileInput) error

WriteBytesToFile writes a byte array to a file

func WriteSliceToFile

func WriteSliceToFile(input WriteSliceToFileInput) error

WriteSliceToFile writes a slice of strings to a file

func WriteStringToFile

func WriteStringToFile(input WriteStringToFileInput) error

WriteStringToFile writes a string to a file

Types

type AppDoesNotExist

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

AppDoesNotExist wraps error to include the app name and is used to distinguish between a normal error and an error where the app is missing

func (*AppDoesNotExist) Error

func (err *AppDoesNotExist) Error() string

Error returns a standard non-existent app error

func (*AppDoesNotExist) ExitCode

func (err *AppDoesNotExist) ExitCode() int

ExitCode returns an exit code to use in case this error bubbles up into an os.Exit() call

type ErrWithExitCode

type ErrWithExitCode interface {
	ExitCode() int
}

ErrWithExitCode wraps error and exposes an ExitCode method

type ExecCommandInput

type ExecCommandInput struct {
	// Command is the command to execute
	Command string

	// Args are the arguments to pass to the command
	Args []string

	// DisableStdioBuffer disables the stdio buffer
	DisableStdioBuffer bool

	// Env is the environment variables to pass to the command
	Env map[string]string

	// Stdin is the stdin of the command
	Stdin io.Reader

	// StreamStdio prints stdout and stderr directly to os.Stdout/err as
	// the command runs
	StreamStdio bool

	// StreamStdout prints stdout directly to os.Stdout as the command runs.
	StreamStdout bool

	// StreamStderr prints stderr directly to os.Stderr as the command runs.
	StreamStderr bool

	// StdoutWriter is the writer to write stdout to
	StdoutWriter io.Writer

	// StderrWriter is the writer to write stderr to
	StderrWriter io.Writer

	// Sudo runs the command with sudo -n -u root
	Sudo bool
}

ExecCommandInput is the input for the ExecCommand function

type ExecCommandResponse

type ExecCommandResponse struct {
	// Stdout is the stdout of the command
	Stdout string

	// Stderr is the stderr of the command
	Stderr string

	// ExitCode is the exit code of the command
	ExitCode int

	// Cancelled is whether the command was cancelled
	Cancelled bool
}

ExecCommandResponse is the response for the ExecCommand function

func CallExecCommand

func CallExecCommand(input ExecCommandInput) (ExecCommandResponse, error)

CallExecCommand executes a command on the local host

func CallExecCommandWithContext

func CallExecCommandWithContext(ctx context.Context, input ExecCommandInput) (ExecCommandResponse, error)

CallExecCommandWithContext executes a command on the local host with the given context

func CallPlugnTrigger

func CallPlugnTrigger(input PlugnTriggerInput) (ExecCommandResponse, error)

CallPlugnTrigger executes a trigger via plugn

func CallPlugnTriggerWithContext

func CallPlugnTriggerWithContext(ctx context.Context, input PlugnTriggerInput) (ExecCommandResponse, error)

CallPlugnTriggerWithContext executes a trigger via plugn with the given context

func (ExecCommandResponse) StderrBytes

func (ecr ExecCommandResponse) StderrBytes() []byte

StderrBytes returns the trimmed stderr of the command as bytes

func (ExecCommandResponse) StderrContents

func (ecr ExecCommandResponse) StderrContents() string

StderrContents returns the trimmed stderr of the command

func (ExecCommandResponse) StdoutBytes

func (ecr ExecCommandResponse) StdoutBytes() []byte

StdoutBytes returns the trimmed stdout of the command as bytes

func (ExecCommandResponse) StdoutContents

func (ecr ExecCommandResponse) StdoutContents() string

StdoutContents returns the trimmed stdout of the command

type PlugnTriggerInput

type PlugnTriggerInput struct {
	// Args are the arguments to pass to the trigger
	Args []string

	// DisableStdioBuffer disables the stdio buffer
	DisableStdioBuffer bool

	// Env is the environment variables to pass to the trigger
	Env map[string]string

	// Stdin is the stdin of the command
	Stdin io.Reader

	// StreamStdio determines whether to stream the stdio of the trigger
	StreamStdio bool

	// StreamStdout prints stdout directly to os.Stdout as the command runs.
	StreamStdout bool

	// StreamStderr prints stderr directly to os.Stderr as the command runs.
	StreamStderr bool

	// Trigger is the trigger to execute
	Trigger string
}

PlugnTriggerInput is the input for CallPlugnTrigger

type ReportFunc

type ReportFunc func(string) string

ReportFunc is a type that declares functions useful for :report subcommands

type SetPermissionInput

type SetPermissionInput struct {
	Filename  string
	GroupName string
	Mode      os.FileMode
	Username  string
}

SetPermissionsInput is the input struct for SetPermissions

type SftpCopyInput

type SftpCopyInput struct {
	// AllowUknownHosts allows connecting to hosts with unknown host keys
	AllowUknownHosts bool

	// DestinationPath is the path to copy the file to
	DestinationPath string

	// RemoteHost is the remote host to connect to
	RemoteHost string

	// SourcePath is the path to the file to copy
	SourcePath string
}

SftpCopyInput is the input for CallSftpCopy

type SftpCopyResult

type SftpCopyResult struct {
	ExitErr   error
	Cancelled bool
}

SftpCopyResult is the result of executing an SftpCopyTask

func CallSftpCopy

func CallSftpCopy(input SftpCopyInput) (SftpCopyResult, error)

CallSftpCopy copies a file to a remote host via sftp

func CallSftpCopyWithContext

func CallSftpCopyWithContext(ctx context.Context, input SftpCopyInput) (SftpCopyResult, error)

CallSftpCopyWithContext copies a file to a remote host via sftp with the given context

type SftpCopyTask

type SftpCopyTask struct {
	// SourcePath is the path to the file to copy
	SourcePath string

	// DestinationPath is the path to copy the file to
	DestinationPath string

	// Shell run the command in a bash shell.
	// Note that the system must have `bash` installed in the PATH or in /bin/bash
	Shell bool

	// Stdin connect a reader to stdin for the command
	// being executed.
	Stdin io.Reader

	// PrintCommand prints the command before executing
	PrintCommand bool

	// AllowUknownHosts allows connecting to hosts with unknown host keys
	AllowUknownHosts bool

	// Hostname is the hostname to connect to
	Hostname string

	// Port is the port to connect to
	Port uint

	// Username is the username to connect with
	Username string

	// Password is the password to connect with
	Password string

	// SshKeyPath is the path to the ssh key to use
	SshKeyPath string
}

func (SftpCopyTask) Execute

func (task SftpCopyTask) Execute(ctx context.Context) (SftpCopyResult, error)

Execute runs the task

type SshCommandInput

type SshCommandInput struct {
	// Command is the command to execute. This can be the path to an executable
	// or the executable with arguments.
	//
	// Any arguments must be given via Args
	Command string

	// Args are the arguments to pass to the command.
	Args []string

	// DisableStdioBuffer disables the stdio buffer
	DisableStdioBuffer bool

	// Env is a list of environment variables to add to the current environment
	Env map[string]string

	// AllowUknownHosts allows connecting to hosts with unknown host keys
	AllowUknownHosts bool

	// RemoteHost is the remote host to connect to
	RemoteHost string

	// Stdin is the stdin of the command
	Stdin io.Reader

	// StreamStdio prints stdout and stderr directly to os.Stdout/err as
	// the command runs.
	StreamStdio bool

	// StreamStdout prints stdout directly to os.Stdout as the command runs.
	StreamStdout bool

	// StreamStderr prints stderr directly to os.Stderr as the command runs.
	StreamStderr bool

	// Sudo runs the command with sudo -n -u root
	Sudo bool
}

SshCommandInput is the input for CallSshCommand

type SshResult

type SshResult struct {
	Stdout    string
	Stderr    string
	ExitCode  int
	Cancelled bool
}

SshResult is the result of executing a command on a remote host via ssh

func CallSshCommand

func CallSshCommand(input SshCommandInput) (SshResult, error)

CallSshCommand executes a command on a remote host via ssh

func CallSshCommandWithContext

func CallSshCommandWithContext(ctx context.Context, input SshCommandInput) (SshResult, error)

CallSshCommand executes a command on a remote host via ssh with the given context

type SshTask

type SshTask struct {
	// Command is the command to execute. This can be the path to an executable
	// or the executable with arguments.
	//
	// Any arguments must be given via Args
	Command string

	// Args are the arguments to pass to the command.
	Args []string

	// Shell run the command in a bash shell.
	// Note that the system must have `bash` installed in the PATH or in /bin/bash
	Shell bool

	// Env is a list of environment variables to add to the current environment
	Env []string

	// Stdin connect a reader to stdin for the command
	// being executed.
	Stdin io.Reader

	// PrintCommand prints the command before executing
	PrintCommand bool
	// StreamStdio prints stdout and stderr directly to os.Stdout/err as
	// the command runs.
	StreamStdio bool

	// DisableStdioBuffer prevents any output from being saved in the
	// TaskResult, which is useful for when the result is very large, or
	// when you want to stream the output to another writer exclusively.
	DisableStdioBuffer bool

	// StdoutWriter when set will receive a copy of stdout from the command
	StdOutWriter io.Writer

	// StderrWriter when set will receive a copy of stderr from the command
	StdErrWriter io.Writer

	// AllowUknownHosts allows connecting to hosts with unknown host keys
	AllowUknownHosts bool

	// Hostname is the hostname to connect to
	Hostname string

	// Port is the port to connect to
	Port uint

	// Username is the username to connect with
	Username string

	// Password is the password to connect with
	Password string

	// SshKeyPath is the path to the ssh key to use
	SshKeyPath string

	// Sudo runs the command with sudo -n -u root
	Sudo bool
}

SshTask is a task for executing a command on a remote host via ssh

func (SshTask) Execute

func (task SshTask) Execute(ctx context.Context) (SshResult, error)

Execute runs the task

type WriteBytesToFileInput

type WriteBytesToFileInput struct {
	Bytes     []byte
	Filename  string
	GroupName string
	Mode      os.FileMode
	Username  string
}

WriteBytesToFileInput writes a byte array to a file

type WriteSliceToFileInput

type WriteSliceToFileInput struct {
	Filename  string
	GroupName string
	Lines     []string
	Mode      os.FileMode
	Username  string
}

WriteSliceToFile writes a slice of strings to a file

type WriteStringToFileInput

type WriteStringToFileInput struct {
	Content   string
	Filename  string
	GroupName string
	Mode      os.FileMode
	Username  string
}

WriteStringToFile writes a string to a file

Directories

Path Synopsis
src

Jump to

Keyboard shortcuts

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