lwrunner

package
v1.50.0 Latest Latest
Warning

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

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

Documentation

Overview

A runner package that executes commands on remote hosts.

Index

Constants

View Source
const SSMInstancePolicy string = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"

Variables

This section is empty.

Functions

func AddKnownHost added in v0.2.12

func AddKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (err error)

AddKnownHost adds a host to the provided known hosts file, if no known hosts file is provided, it will fallback to default known_hosts file

func CheckKnownHost added in v0.2.12

func CheckKnownHost(host string, remote net.Addr, key ssh.PublicKey, knownFile string) (found bool, err error)

CheckKnownHost checks if a host is in known hosts file, if no known hosts file is provided, it will fallback to default known_hosts file

func DefaultIdentityFilePath added in v0.2.12

func DefaultIdentityFilePath() (string, error)

func DefaultKnownHosts added in v0.2.12

func DefaultKnownHosts() (ssh.HostKeyCallback, error)

DefaultKnownHosts returns a host key callback from default known hosts path

func DefaultKnownHostsPath added in v0.2.12

func DefaultKnownHostsPath() (string, error)

DefaultKnownHostsPath returns default user ~/.ssh/known_hosts file

func EncodePrivateKeyToPEM added in v0.43.0

func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) ([]byte, error)

Encodes private key from RSA struct to PEM formatted bytes

func GeneratePrivateKey added in v0.43.0

func GeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)

Helper function to generate a random private key. This key will stay in memory and does not persist across test runs.

func GetKeyBytes added in v0.43.0

func GetKeyBytes() ([]byte, []byte, error)

Generates SSH keys in EC2-readable format Returns public key bytes, private key bytes, error

func GetPublicKeyBytes added in v0.43.0

func GetPublicKeyBytes(key *rsa.PublicKey) ([]byte, error)

Takes an rsa.PublicKey and returns bytes suitable for writing to .pub file Returns in the format "ssh-rsa ..."

func GetSSMCommandInvocationStdErr added in v1.11.0

func GetSSMCommandInvocationStdErr(out ssm.GetCommandInvocationOutput) string

GetSSMCommandInvocationStdErr is a helper function to safely deference the SSM struct we receive from the AWS API.

func GetSSMCommandInvocationStdOut added in v1.11.0

func GetSSMCommandInvocationStdOut(out ssm.GetCommandInvocationOutput) string

GetSSMCommandInvocationStdOut is a helper function to safely deference the SSM struct we receive from the AWS API.

Types

type AWSRunner added in v0.43.0

type AWSRunner struct {
	Runner           Runner
	Region           string
	AvailabilityZone string
	InstanceID       string
	ImageName        string
}

func NewAWSRunner added in v0.43.0

func NewAWSRunner(
	amiImageId,
	userFromCLIArg,
	host,
	region,
	availabilityZone,
	instanceID string,
	filterSSH bool,
	callback ssh.HostKeyCallback,
	cfg aws.Config) (*AWSRunner, error)

func (AWSRunner) AssociateInstanceProfileWithRunner added in v1.6.0

func (run AWSRunner) AssociateInstanceProfileWithRunner(
	cfg aws.Config, instanceProfile types.InstanceProfile,
) (string, error)

AssociateInstanceProfileWithRunner associates a given instance profile with the receiving runner. First checks if there are any instance profiles already associated with the runner, and returns an error if so (since a runner can only have one instance profile associated with it). Then associates the instance profile with the runner. Returns the association ID or an error.

func (AWSRunner) DisassociateInstanceProfileFromRunner added in v1.8.0

func (run AWSRunner) DisassociateInstanceProfileFromRunner(cfg aws.Config, associationID string) error

func (AWSRunner) RunSSMCommandOnRemoteHost added in v1.6.0

func (run AWSRunner) RunSSMCommandOnRemoteHost(cfg aws.Config, operation string) (
	ssm.GetCommandInvocationOutput, error,
)

RunSSMCommandOnRemoteHost takes a shell command to install the agent on the runner the runner and executes it using SSM. `operation` must be one of the commands allowed by the SSM document. This function will not return until the command is in a terminal state, or until 2min have passed.

func (AWSRunner) SendAndUseIdentityFile added in v0.43.0

func (run AWSRunner) SendAndUseIdentityFile(cfg aws.Config) error

func (AWSRunner) SendPublicKey added in v0.43.0

func (run AWSRunner) SendPublicKey(pubBytes []byte, cfg aws.Config) error

Helper function to send a public key to a test instance. Uses EC2InstanceConnect. The AWS account used to run the tests must have EC2InstanceConnect permissions attached to its IAM role. First checks to make sure the instance is still running.

type GCPRunner added in v1.1.0

type GCPRunner struct {
	Runner           Runner
	ParentUsername   string
	ProjectID        string
	AvailabilityZone string
	InstanceID       string
}

func NewGCPRunner added in v1.1.0

func NewGCPRunner(
	host, parentUsername, projectID, availabilityZone, instanceID string, callback ssh.HostKeyCallback,
) (*GCPRunner, error)

func (GCPRunner) SendAndUseIdentityFile added in v1.1.0

func (run GCPRunner) SendAndUseIdentityFile() error

func (GCPRunner) SendPublicKey added in v1.1.0

func (run GCPRunner) SendPublicKey(pubBytes []byte) error

SendPublicKey is a helper function to send a public key to a GCP account for OSLogin authentication. The account must have the "Compute OS Login" IAM role and "Service Account User" authorization for the GCE default service account. When the SSH key is sent, it will persist in the GCP account for 10min.

type Runner added in v0.2.12

type Runner struct {
	Hostname string
	Port     int
	*ssh.ClientConfig
}

func New added in v0.2.12

func New(user, host string, callback ssh.HostKeyCallback) *Runner

func (*Runner) Address added in v0.2.12

func (run *Runner) Address() string

func (*Runner) Exec added in v0.2.12

func (run *Runner) Exec(cmd string) (stdout bytes.Buffer, stderr bytes.Buffer, err error)

Exec executes a command on the configured remote host

func (Runner) UseIdentityFile added in v0.2.12

func (run Runner) UseIdentityFile(file string) error

func (Runner) UsePassword added in v0.2.12

func (run Runner) UsePassword(secret string)

Jump to

Keyboard shortcuts

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