remoteflight

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PackageGetterTypeCopy        PackageGetterType    = "copy"
	PackageGetterTypeReleases    PackageGetterType    = "releases"
	PackageGetterTypeArtifactory PackageGetterType    = "artifactory"
	PackageGetterTypeRepository  PackageGetterType    = "repository"
	PackageInstallerTypeZip      PackageInstallerType = "zip"
	PackageInstallerTypeDeb      PackageInstallerType = "deb"
	PackageInstallerTypeRPM      PackageInstallerType = "rpm"
	PackageInstallerTypeYum      PackageInstallerType = "yum"
	PackageInstallerTypeApt      PackageInstallerType = "apt"
)
View Source
const DefaultFlightControlPath = "/opt/qti/bin/enos-flight-control"

DefaultFlightControlPath is the default location of our binary.

Variables

View Source
var (
	PackageInstallGetterCopy        = &PackageInstallGetter{PackageGetterTypeCopy, packageInstallGetCopy}
	PackageInstallGetterReleases    = &PackageInstallGetter{PackageGetterTypeReleases, packageInstallGetDownload}
	PackageInstallGetterArtifactory = &PackageInstallGetter{PackageGetterTypeArtifactory, packageInstallGetDownload}
	PackageInstallGetterRepository  = &PackageInstallGetter{PackageGetterTypeRepository, packageInstallGetRepository}
)

Package install gets. These are the built-in package getters.

View Source
var (
	PackageInstallInstallerZip = &PackageInstallInstaller{
		Type:    PackageInstallerTypeZip,
		Install: packageInstallZipInstall,
		CompatibleGetters: []*PackageInstallGetter{
			PackageInstallGetterCopy,
			PackageInstallGetterReleases,
			PackageInstallGetterArtifactory,
		},
	}
	PackageInstallInstallerDEB = &PackageInstallInstaller{
		Type:    PackageInstallerTypeDeb,
		Install: packageInstallDEBInstall,
		CompatibleGetters: []*PackageInstallGetter{
			PackageInstallGetterCopy,
			PackageInstallGetterReleases,
			PackageInstallGetterArtifactory,
		},
	}
	PackageInstallInstallerRPM = &PackageInstallInstaller{
		Type:    PackageInstallerTypeRPM,
		Install: packageInstallRPMInstall,
		CompatibleGetters: []*PackageInstallGetter{
			PackageInstallGetterCopy,
			PackageInstallGetterReleases,
			PackageInstallGetterArtifactory,
		},
	}
	PackageInstallInstallerYum = &PackageInstallInstaller{
		Type:    PackageInstallerTypeYum,
		Install: packageInstallYumInstall,
		CompatibleGetters: []*PackageInstallGetter{
			PackageInstallGetterRepository,
		},
	}
	PackageInstallInstallerApt = &PackageInstallInstaller{
		Type:    PackageInstallerTypeApt,
		Install: packageInstallAptInstall,
		CompatibleGetters: []*PackageInstallGetter{
			PackageInstallGetterRepository,
		},
	}
)

Package install methods. These are the built-in pacakage installers.

View Source
var (
	// ErrPackageInstallGetterUnknown means the package get has not been set.
	ErrPackageInstallGetterUnknown = errors.New("package install get is unknown")
	// ErrPackageInstallGetterUnsupported means the package get is unsupported not been set.
	ErrPackageInstallGetterUnsupported = errors.New("package install get is unsupported")
	// ErrPackageInstallInstallerUnknown means the package method has not been set.
	ErrPackageInstallInstallerUnknown = errors.New("package install method is unknown")
	// ErrPackageInstallInstallerUnsupported means the package method is unsupported.
	ErrPackageInstallInstallerUnsupported = errors.New("package install method is unsupported")
)

Functions

func CopyFile

func CopyFile(ctx context.Context, tr it.Transport, file *CopyFileRequest) error

CopyFile copies a file to the remote host. It first copies a file to a temporary directory, sets permissions, then copies to the destination directory as a superuser — retrying these operations if necessary.

func CreateDirectory

func CreateDirectory(ctx context.Context, tr it.Transport, dir *CreateDirectoryRequest) error

CreateDirectory creates the directory and sets owner permissions.

func DeleteFile

func DeleteFile(ctx context.Context, tr it.Transport, req *DeleteFileRequest) error

DeleteFile deletes a file on the remote host, retrying if necessary.

func TargetArchitecture

func TargetArchitecture(ctx context.Context, tr transport.Transport, req *TargetRequest) (string, error)

TargetArchitecture is a helper that determines the targets architecture.

func TargetDistro

func TargetDistro(ctx context.Context, tr transport.Transport, req *TargetRequest) (string, error)

TargetDistro is a helper that determines the targets distribution.

func TargetDistroVersion

func TargetDistroVersion(ctx context.Context, tr transport.Transport, req *TargetRequest) (string, error)

TargetDistroVersion is a helper that determines the targets distribution version.

func TargetHomeDir

func TargetHomeDir(ctx context.Context, tr transport.Transport, req *TargetRequest) (string, error)

TargetHomeDir is a helper that determines the targets HOME directory.

func TargetHostname

func TargetHostname(ctx context.Context, tr transport.Transport, req *TargetRequest) (string, error)

TargetHostname is a helper that determines the targets hostname.

func TargetPlatform

func TargetPlatform(ctx context.Context, tr transport.Transport, req *TargetRequest) (string, error)

TargetPlatform is a helper that determines the targets platform.

func TargetPlatformVersion

func TargetPlatformVersion(ctx context.Context, tr transport.Transport, req *TargetRequest) (string, error)

TargetPlatformVersion is a helper that determines the targets platform version.

func TargetProcessManager

func TargetProcessManager(ctx context.Context, tp transport.Transport, req *TargetRequest) (string, error)

TargetProcessManager is a helper that determines the targets process manager.

func WrapErrorWith

func WrapErrorWith(err error, msg ...string) error

WrapErrorWith returns a custom error message.

Types

type CopyFileRequest

type CopyFileRequest struct {
	Content     it.Copyable
	TmpDir      string
	Chmod       string
	Chown       string
	Destination string
	RetryOpts   []retry.RetrierOpt
}

CopyFileRequest copies a file to the remote host.

func NewCopyFileRequest

func NewCopyFileRequest(opts ...CopyFileRequestOpt) *CopyFileRequest

NewCopyFileRequest takes functional options and returns a new file copy request.

type CopyFileRequestOpt

type CopyFileRequestOpt func(*CopyFileRequest) *CopyFileRequest

CopyFileRequestOpt is a functional option for file copy.

func WithCopyFileChmod

func WithCopyFileChmod(chmod string) CopyFileRequestOpt

WithCopyFileChmod sets permissions.

func WithCopyFileChown

func WithCopyFileChown(chown string) CopyFileRequestOpt

WithCopyFileChown sets ownership.

func WithCopyFileContent

func WithCopyFileContent(content it.Copyable) CopyFileRequestOpt

WithCopyFileContent sets content to be copied.

func WithCopyFileDestination

func WithCopyFileDestination(destination string) CopyFileRequestOpt

WithCopyFileDestination sets file destination.

func WithCopyFileRetryOptions

func WithCopyFileRetryOptions(opts ...retry.RetrierOpt) CopyFileRequestOpt

WithCopyFileRetryOptions sets retry options for file copy operations.

func WithCopyFileTmpDir

func WithCopyFileTmpDir(dir string) CopyFileRequestOpt

WithCopyFileTmpDir sets temporary directory to use.

type CreateDirectoryRequest

type CreateDirectoryRequest struct {
	DirName  string
	DirOwner string
}

CreateDirectoryRequest creates a directory on remote host.

func NewCreateDirectoryRequest

func NewCreateDirectoryRequest(opts ...CreateDirectoryRequestOpt) *CreateDirectoryRequest

NewCreateDirectoryRequest takes functional options and returns a new directory.

type CreateDirectoryRequestOpt

type CreateDirectoryRequestOpt func(*CreateDirectoryRequest) *CreateDirectoryRequest

CreateDirectoryRequestOpt is a functional option for creating directory.

func WithDirChown

func WithDirChown(owner string) CreateDirectoryRequestOpt

WithDirChown sets directory name.

func WithDirName

func WithDirName(directory string) CreateDirectoryRequestOpt

WithDirName sets directory name.

type DeleteFileRequest

type DeleteFileRequest struct {
	Path      string
	RetryOpts []retry.RetrierOpt
}

DeleteFileRequest deletes a file on the remote host.

func NewDeleteFileRequest

func NewDeleteFileRequest(opts ...DeleteFileRequestOpt) *DeleteFileRequest

NewDeleteFileRequest takes functional options and returns a new file deletion request.

type DeleteFileRequestOpt

type DeleteFileRequestOpt func(*DeleteFileRequest) *DeleteFileRequest

DeleteFileRequestOpt is a functional option for file deletion.

func WithDeleteFilePath

func WithDeleteFilePath(path string) DeleteFileRequestOpt

WithDeleteFilePath sets which file to delete for file delete operations.

func WithDeleteFileRetryOptions

func WithDeleteFileRetryOptions(opts ...retry.RetrierOpt) DeleteFileRequestOpt

WithDeleteFileRetryOptions sets retry options for file delete operations.

type DownloadOpt

type DownloadOpt func(*DownloadRequest) *DownloadRequest

DownloadOpt is a functional option for an download request.

func WithDownloadRequestAuthPassword

func WithDownloadRequestAuthPassword(password string) DownloadOpt

WithDownloadRequestAuthPassword sets basic auth password.

func WithDownloadRequestAuthUser

func WithDownloadRequestAuthUser(user string) DownloadOpt

WithDownloadRequestAuthUser sets basic auth user.

func WithDownloadRequestDestination

func WithDownloadRequestDestination(dest string) DownloadOpt

WithDownloadRequestDestination sets destination path of the downloaded file.

func WithDownloadRequestFlightControlPath

func WithDownloadRequestFlightControlPath(path string) DownloadOpt

WithDownloadRequestFlightControlPath sets the location of the enos-flight-contro binary.

func WithDownloadRequestHTTPMethod

func WithDownloadRequestHTTPMethod(meth string) DownloadOpt

WithDownloadRequestHTTPMethod sets the download HTTP method.

func WithDownloadRequestMode

func WithDownloadRequestMode(mode string) DownloadOpt

WithDownloadRequestMode sets the mode for the downloaded file.

func WithDownloadRequestReplace

func WithDownloadRequestReplace(replace bool) DownloadOpt

WithDownloadRequestReplace determines if the download command should replace existing files.

func WithDownloadRequestRetryOptions

func WithDownloadRequestRetryOptions(opts ...retry.RetrierOpt) DownloadOpt

WithDownloadRequestRetryOptions sets retry options for dowload operation.

func WithDownloadRequestSHA256

func WithDownloadRequestSHA256(sha string) DownloadOpt

WithDownloadRequestSHA256 sets required SHA256 sum.

func WithDownloadRequestURL

func WithDownloadRequestURL(url string) DownloadOpt

WithDownloadRequestURL sets the download drL.

func WithDownloadRequestUseSudo

func WithDownloadRequestUseSudo(useSudo bool) DownloadOpt

WithDownloadRequestUseSudo determines if the download command should be run with sudo.

type DownloadRequest

type DownloadRequest struct {
	FlightControlPath string
	URL               string
	HTTPMethod        string
	Destination       string
	Mode              string
	SHA256            string
	Timeout           string
	AuthUser          string
	AuthPassword      string
	Sudo              bool
	Replace           bool
	RetryOpts         []retry.RetrierOpt
}

DownloadRequest performs a remote flight control download.

func NewDownloadRequest

func NewDownloadRequest(opts ...DownloadOpt) *DownloadRequest

NewDownloadRequest takes functional options and returns a new download request.

type DownloadResponse

type DownloadResponse struct{}

DownloadResponse is a flight control download response.

func Download

Download downloads a file on a remote machine with enos-flight-control, retrying if necessary.

type GetLogsResponse

type GetLogsResponse interface {
	// GetAppName gets the name of the application that the logs pertain to.
	GetAppName() string
	// GetLogFileName creates a unique log file name.
	GetLogFileName() string
	// GetLogs gets the logs that were retrieved by a log file request
	GetLogs() []byte
}

GetLogsResponse interface defining the functions required for any get logs request response.

type HostInfo

type HostInfo struct {
	Arch            *string
	Distro          *string
	DistroVersion   *string
	Hostname        *string
	Pid1            *string
	Platform        *string
	PlatformVersion *string
}

HostInfo represents information about the target host.

func TargetHostInfo

func TargetHostInfo(ctx context.Context, tr transport.Transport, req *TargetRequest) (*HostInfo, error)

TargetHostInfo is a helper that determines the targets host information. Any errors will be returned. NOTE: not all platforms support all host info so handle the result and error accordingly.

type InstallFlightControlOpt

type InstallFlightControlOpt func(*InstallFlightControlRequest) *InstallFlightControlRequest

InstallFlightControlOpt is a functional option for an install request.

func WithInstallFlightControlRequestPath

func WithInstallFlightControlRequestPath(path string) InstallFlightControlOpt

WithInstallFlightControlRequestPath sets the install path.

func WithInstallFlightControlRequestTargetRequest

func WithInstallFlightControlRequestTargetRequest(tr *TargetRequest) InstallFlightControlOpt

WithInstallFlightControlRequestTargetRequest sets the target request.

func WithInstallFlightControlRequestUseHomeDir

func WithInstallFlightControlRequestUseHomeDir() InstallFlightControlOpt

WithInstallFlightControlRequestUseHomeDir installs enos-flight-control into the home directory.

type InstallFlightControlRequest

type InstallFlightControlRequest struct {
	Path       string
	UseHomeDir bool
	*TargetRequest
}

InstallFlightControlRequest is a flight control install request.

func NewInstallFlightControlRequest

func NewInstallFlightControlRequest(opts ...InstallFlightControlOpt) *InstallFlightControlRequest

NewInstallFlightControlRequest takes functional options and returns a new install request.

type InstallFlightControlResponse

type InstallFlightControlResponse struct {
	Path string
}

InstallFlightControlResponse is a flight control install response.

func InstallFlightControl

InstallFlightControl installs the enos-flight-control binary on a remote host in an idempotent fashion.

type PackageGetterType added in v0.5.4

type PackageGetterType string

type PackageInstallGetter

type PackageInstallGetter struct {
	Type PackageGetterType
	Get  func(ctx context.Context, tr it.Transport, req *PackageInstallRequest) (string, error)
}

PackageInstallGetter is where the package is coming from.

type PackageInstallInstaller

type PackageInstallInstaller struct {
	Type              PackageInstallerType
	CompatibleGetters []*PackageInstallGetter
	Install           func(ctx context.Context, tr it.Transport, req *PackageInstallRequest) error
}

PackageInstallInstaller is how a package is going to be installed.

func PackageInstallInstallerForFile

func PackageInstallInstallerForFile(name string) *PackageInstallInstaller

PackageInstallInstallerForFile attempts to determine a suitable package installation method given the file name.

func (*PackageInstallInstaller) Compatible

Compatible determines if the install get artifact is compatible with the install method.

type PackageInstallRequest

type PackageInstallRequest struct {
	Installer         *PackageInstallInstaller
	Getter            *PackageInstallGetter
	FlightControlPath string
	UnzipOpts         []UnzipOpt    // Unzip options if we're getting a zip bundle
	DownloadOpts      []DownloadOpt // Download options if we're downloading the artifact
	CopyPath          string        // Where to copy from
	TempArtifactPath  string        // Intermediate location of artifact
	TempDir           string        // Base directory of temporary directory
	DestionationPath  string        // Final destination of artifact
}

PackageInstallRequest is a request to install a package on a target machine.

func NewPackageInstallRequest

func NewPackageInstallRequest(opts ...PackageInstallRequestOpt) *PackageInstallRequest

NewPackageInstallRequest takes functional options and returns a new script run req.

type PackageInstallRequestOpt

type PackageInstallRequestOpt func(*PackageInstallRequest) *PackageInstallRequest

PackageInstallRequestOpt is a functional option for running a script.

func WithPackageInstallCopyPath

func WithPackageInstallCopyPath(path string) PackageInstallRequestOpt

WithPackageInstallCopyPath sets get location of an artifact that is being copied from the local machine.

func WithPackageInstallDestination

func WithPackageInstallDestination(path string) PackageInstallRequestOpt

WithPackageInstallDestination sets final destination for binaries.

func WithPackageInstallDownloadOpts

func WithPackageInstallDownloadOpts(opts ...DownloadOpt) PackageInstallRequestOpt

WithPackageInstallDownloadOpts sets the package download options.

func WithPackageInstallGetter

func WithPackageInstallGetter(get *PackageInstallGetter) PackageInstallRequestOpt

WithPackageInstallGetter sets the package install get.

func WithPackageInstallInstaller

func WithPackageInstallInstaller(method *PackageInstallInstaller) PackageInstallRequestOpt

WithPackageInstallInstaller sets the package installer.

func WithPackageInstallTemporaryDirectory

func WithPackageInstallTemporaryDirectory(dir string) PackageInstallRequestOpt

WithPackageInstallTemporaryDirectory sets the temporary directory.

func WithPackageInstallUnzipOpts

func WithPackageInstallUnzipOpts(opts ...UnzipOpt) PackageInstallRequestOpt

WithPackageInstallUnzipOpts sets the package unzip options.

type PackageInstallResponse

type PackageInstallResponse struct {
	Name          string
	GetterType    PackageGetterType
	InstallerType PackageInstallerType
}

PackageInstallResponse is the response of the script run.

func PackageInstall

PackageInstall copies the script to the remote host, executes it, and cleans it up.

type PackageInstallerType added in v0.5.4

type PackageInstallerType string

type RunScriptRequest

type RunScriptRequest struct {
	Env             map[string]string
	NoCleanup       bool
	Sudo            bool
	CopyFileRequest *CopyFileRequest
}

RunScriptRequest copies a file to the remote host.

func NewRunScriptRequest

func NewRunScriptRequest(opts ...RunScriptRequestOpt) *RunScriptRequest

NewRunScriptRequest takes functional options and returns a new script run req.

type RunScriptRequestOpt

type RunScriptRequestOpt func(*RunScriptRequest) *RunScriptRequest

RunScriptRequestOpt is a functional option for running a script.

func WithRunScriptChmod

func WithRunScriptChmod(chmod string) RunScriptRequestOpt

WithRunScriptChmod sets permissions.

func WithRunScriptChown

func WithRunScriptChown(chown string) RunScriptRequestOpt

WithRunScriptChown sets ownership.

func WithRunScriptContent

func WithRunScriptContent(content it.Copyable) RunScriptRequestOpt

WithRunScriptContent sets content to be copied.

func WithRunScriptDestination

func WithRunScriptDestination(destination string) RunScriptRequestOpt

WithRunScriptDestination sets file destination.

func WithRunScriptEnv

func WithRunScriptEnv(env map[string]string) RunScriptRequestOpt

WithRunScriptEnv sets the environment variables.

func WithRunScriptNoCleanup

func WithRunScriptNoCleanup() RunScriptRequestOpt

WithRunScriptNoCleanup disable the auto cleanup.

func WithRunScriptTmpDir

func WithRunScriptTmpDir(dir string) RunScriptRequestOpt

WithRunScriptTmpDir sets temporary directory to use.

func WithRunScriptUseSudo

func WithRunScriptUseSudo() RunScriptRequestOpt

WithRunScriptUseSudo runs the script with sudo.

type RunScriptResponse

type RunScriptResponse struct {
	Stdout string
	Stderr string
}

RunScriptResponse is the response of the script run.

func RunScript

func RunScript(ctx context.Context, tr it.Transport, req *RunScriptRequest) (*RunScriptResponse, error)

RunScript copies the script to the remote host, executes it, and cleans it up.

type TargetRequest

type TargetRequest struct {
	*retry.Retrier
	RetryOpts []retry.RetrierOpt
}

TargetRequest is a Target* request.

func NewTargetRequest

func NewTargetRequest(opts ...TargetRequestOpt) *TargetRequest

NewTargetRequest takes optional arguments and returns a new instance of TargetRequest.

func (*TargetRequest) Clone

func (t *TargetRequest) Clone() *TargetRequest

Clone create a cloned copy of the target request.

type TargetRequestOpt

type TargetRequestOpt func(*TargetRequest)

TargetRequestOpt is a functional option for a new Target.

func WithTargetRequestRetryOpts

func WithTargetRequestRetryOpts(opts ...retry.RetrierOpt) TargetRequestOpt

WithTargetRequestRetryOpts allows the caller to define retry options.

type UnzipOpt

type UnzipOpt func(*UnzipRequest) *UnzipRequest

UnzipOpt is a functional option for an unzip request.

func WithUnzipRequestCreateDestinationDir

func WithUnzipRequestCreateDestinationDir(create bool) UnzipOpt

WithUnzipRequestCreateDestinationDir determines if the destination directory should be created.

func WithUnzipRequestDestinationDir

func WithUnzipRequestDestinationDir(dir string) UnzipOpt

WithUnzipRequestDestinationDir sets the unzip directory.

func WithUnzipRequestDestinationDirMode

func WithUnzipRequestDestinationDirMode(mode string) UnzipOpt

WithUnzipRequestDestinationDirMode sets the mode for destination directory if it is created.

func WithUnzipRequestFileMode

func WithUnzipRequestFileMode(mode string) UnzipOpt

WithUnzipRequestFileMode sets the mode for files that are expanded.

func WithUnzipRequestFlightControlPath

func WithUnzipRequestFlightControlPath(path string) UnzipOpt

WithUnzipRequestFlightControlPath sets the location of the enos-flight-contro binary.

func WithUnzipRequestReplace

func WithUnzipRequestReplace(replace bool) UnzipOpt

WithUnzipRequestReplace determines if the unzip command should overwrite the destination file if it exists.

func WithUnzipRequestSourcePath

func WithUnzipRequestSourcePath(path string) UnzipOpt

WithUnzipRequestSourcePath sets the zip archive source path.

func WithUnzipRequestUseSudo

func WithUnzipRequestUseSudo(useSudo bool) UnzipOpt

WithUnzipRequestUseSudo determines if the unzip command should be run with sudo.

type UnzipRequest

type UnzipRequest struct {
	FlightControlPath          string
	SourcePath                 string
	DestinationDirectory       string
	FileMode                   string
	DestinationDirectoryMode   string
	Sudo                       bool
	CreateDestinationDirectory bool
	Replace                    bool
}

UnzipRequest performs a remote flight control unzip.

func NewUnzipRequest

func NewUnzipRequest(opts ...UnzipOpt) *UnzipRequest

NewUnzipRequest takes functional options and returns a new unzip request.

type UnzipResponse

type UnzipResponse struct{}

UnzipResponse is a flight control unzip response.

func Unzip

Unzip unzips an archive on a remote machine with enos-flight-control.

type User

type User struct {
	Name    *string
	HomeDir *string
	Shell   *string
	GID     *string
	UID     *string
}

User is a system user.

func CreateOrUpdateUser

func CreateOrUpdateUser(ctx context.Context, tr it.Transport, want *User) (*User, error)

CreateOrUpdateUser takes an wanted user specification and creates or updates a user to the specification.

func CreateUser

func CreateUser(ctx context.Context, tr it.Transport, user *User) (*User, error)

CreateUser takes a context, transport, and user and creates the user on the remote machine.

func FindUser

func FindUser(ctx context.Context, tr it.Transport, name string) (*User, error)

FindUser attempts to find details about a user on a remote machine. Currently we try to use tools that most-likely exist on most macOS and linux distro's.

func NewUser

func NewUser(opts ...UserOpt) *User

NewUser takes functional options and returns a new user.

func (*User) HasSameSetProperties

func (u *User) HasSameSetProperties(other *User) bool

HasSameSetProperties takes a user specification and verifies that the current user has the same set properties. The zero values will not be considered.

type UserOpt

type UserOpt func(*User) *User

UserOpt is a functional option for an user request.

func WithUserGID

func WithUserGID(gid string) UserOpt

WithUserGID sets the user gid.

func WithUserHomeDir

func WithUserHomeDir(dir string) UserOpt

WithUserHomeDir sets the home dir.

func WithUserName

func WithUserName(name string) UserOpt

WithUserName sets the user name.

func WithUserShell

func WithUserShell(shell string) UserOpt

WithUserShell sets the user shell.

func WithUserUID

func WithUserUID(uid string) UserOpt

WithUserUID sets the user uid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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