run

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	No = iota
	Yes
	Continue
)

Variables

View Source
var ResetColor = "\033[0m"

Functions

func AddKnownHost

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

func AsExport

func AsExport(env []string) string

Process all ENVs into a string of form Example output: export FOO="bar"; export BAR="baz";

func CalcForks added in v0.13.0

func CalcForks(batch int, forks uint32) int

func CalcFreeForks added in v0.13.0

func CalcFreeForks(batch int, tasks int, forks uint32) int

func CheckKnownHost

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

func ExecTTY

func ExecTTY(cmd string, envs []string) error

func FingerprintSHA256 added in v0.12.0

func FingerprintSHA256(b []byte) string

func GetFingerprintPubKey added in v0.12.0

func GetFingerprintPubKey(server dao.Server) (string, error)

func GetPasswordAuth added in v0.10.3

func GetPasswordAuth(server dao.Server) (ssh.AuthMethod, error)

func GetPasswordIdentitySigner added in v0.12.0

func GetPasswordIdentitySigner(server dao.Server) (ssh.Signer, error)

Password protected key

func GetSSHAgentSigners added in v0.10.3

func GetSSHAgentSigners() ([]ssh.Signer, error)

func GetSigner added in v0.12.0

func GetSigner(identityFile string) (ssh.Signer, error)

func Line added in v0.10.0

func Line(address string, key ssh.PublicKey) string

TODO: Replace this method with known_hosts Line method when issue with ip6 formats is fixed. Supported Host formats:

172.24.2.3
172.24.2.3:333 # custom port
2001:3984:3989::10
[2001:3984:3989::10]:333 # custom port

func PrefixTemplate added in v0.14.0

func PrefixTemplate(prefix string, data PrefixData) (string, error)

func PrintHeader added in v0.13.0

func PrintHeader(value string, ts dao.Text, padding bool)

func SSHToServer

func SSHToServer(server dao.Server, disableVerifyHost bool, knownHostFile string) error

func SSHToServer(host string, user string, port uint16, bastion string, disableVerifyHost bool, knownHostFile string) error {

func VerifyHost

func VerifyHost(knownHostsFile string, mu *sync.Mutex, host string, remote net.Addr, key ssh.PublicKey) error

VerifyHost validates that the host is found in known_hosts file

Types

type Client

type Client interface {
	Connect(SSHDialFunc, bool, string, uint, *sync.Mutex) *ErrConnect
	Run(int, []string, string, string, string) error
	Wait(int) error
	Close(int) error
	Write(int, []byte) (n int, err error)
	WriteClose(int) error
	Stdin(int) io.WriteCloser
	Stderr(int) io.Reader
	Stdout(int) io.Reader
	Signal(int, os.Signal) error
	GetName() string
	Prefix() (string, string, string, uint16)
	Connected() bool
}

type ErrConnect

type ErrConnect struct {
	Name   string
	Host   string
	User   string
	Port   uint16
	Reason string
}

func ParseServers added in v0.11.0

func ParseServers(
	sshConfigFile *string,
	servers *[]dao.Server,
	runFlags *core.RunFlags,
	order string,
) ([]ErrConnect, error)

ParseServers resolves host, port, proxyjump in user ssh config

func (*ErrConnect) Error added in v0.10.3

func (e *ErrConnect) Error() string

type HeaderData added in v0.10.0

type HeaderData struct {
	Name     string
	Desc     string
	Index    int
	NumTasks int
}

func (HeaderData) Style added in v0.10.0

func (h HeaderData) Style(s any, args ...string) string

type Identity

type Identity struct {
	IdentityFile *string
	Password     *string
}

type LocalSession added in v0.13.0

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

type LocalhostClient

type LocalhostClient struct {
	Name string
	User string
	Host string
	Port uint16

	Sessions []LocalSession
}

Client is a wrapper over the SSH connection/Sessions.

func (*LocalhostClient) Close

func (c *LocalhostClient) Close(i int) error

func (*LocalhostClient) Connect

func (c *LocalhostClient) Connect(dialer SSHDialFunc, _ bool, _ string, _ uint, mu *sync.Mutex) *ErrConnect

func (*LocalhostClient) Connected added in v0.13.0

func (c *LocalhostClient) Connected() bool

func (*LocalhostClient) GetName added in v0.10.2

func (c *LocalhostClient) GetName() string

func (*LocalhostClient) Prefix

func (c *LocalhostClient) Prefix() (string, string, string, uint16)

func (*LocalhostClient) Run

func (c *LocalhostClient) Run(i int, env []string, workDir string, shell string, cmdStr string) error

func (*LocalhostClient) Signal

func (c *LocalhostClient) Signal(i int, sig os.Signal) error

func (*LocalhostClient) Stderr

func (c *LocalhostClient) Stderr(i int) io.Reader

func (*LocalhostClient) Stdin

func (c *LocalhostClient) Stdin(i int) io.WriteCloser

func (*LocalhostClient) Stdout

func (c *LocalhostClient) Stdout(i int) io.Reader

func (*LocalhostClient) Wait

func (c *LocalhostClient) Wait(i int) error

func (*LocalhostClient) Write

func (c *LocalhostClient) Write(i int, p []byte) (n int, err error)

func (*LocalhostClient) WriteClose

func (c *LocalhostClient) WriteClose(i int) error

type PrefixData added in v0.14.0

type PrefixData struct {
	Name  string
	Host  string
	User  string
	Index int
	Port  uint16
}

func (PrefixData) Style added in v0.14.0

func (h PrefixData) Style(s any, args ...string) string

type Run

type Run struct {
	LocalClients       map[string]Client
	RemoteClients      map[string]Client
	Servers            []dao.Server
	UnreachableServers []dao.Server
	Task               *dao.Task
	Config             dao.Config
}

func (*Run) CheckTaskNoColor

func (run *Run) CheckTaskNoColor()

func (*Run) CleanupClients

func (run *Run) CleanupClients()

func (*Run) ParseTask

func (run *Run) ParseTask(
	configEnv []string,
	userArgs []string,
	runFlags *core.RunFlags,
	setRunFlags *core.SetRunFlags,
) error

func (*Run) ParseTaskTarget added in v0.13.0

func (run *Run) ParseTaskTarget(
	runFlags *core.RunFlags,
	setRunFlags *core.SetRunFlags,
)

func (*Run) RunTask

func (run *Run) RunTask(
	userArgs []string,
	runFlags *core.RunFlags,
	setRunFlags *core.SetRunFlags,
) error

func (*Run) SetClients

func (run *Run) SetClients(
	task *dao.Task,
	runFlags *core.RunFlags,
	numChannels int,
	clientCh chan Client,
	errCh chan ErrConnect,
) ([]ErrConnect, error)

SetClients establishes connection to server

func (*Run) Table

func (run *Run) Table(dryRun bool) (dao.TableOutput, dao.ReportData, error)

func (*Run) Text

func (run *Run) Text(dryRun bool) (dao.ReportData, error)

type SSHClient

type SSHClient struct {
	Name         string
	User         string
	Host         string
	Port         uint16
	IdentityFile string
	Password     string
	AuthMethod   []ssh.AuthMethod

	Sessions []SSHSession
	// contains filtered or unexported fields
}

Client is a wrapper over the SSH connection/sessions.

func (*SSHClient) Close

func (c *SSHClient) Close(i int) error

Close closes the underlying SSH connection and session.

func (*SSHClient) Connect

func (c *SSHClient) Connect(
	dialer SSHDialFunc,
	disableVerifyHost bool,
	knownHostsFile string,
	defaultTimeout uint,
	mu *sync.Mutex,
) *ErrConnect

Connect creates SSH connection to a specified host.

func (*SSHClient) ConnectWith

func (c *SSHClient) ConnectWith(
	dialer SSHDialFunc,
	disableVerifyHost bool,
	knownHostsFile string,
	defaultTimeout uint,
	mu *sync.Mutex,
) *ErrConnect

ConnectWith creates a SSH connection to a specified host. It will use dialer to establish the connection.

func (*SSHClient) Connected added in v0.13.0

func (c *SSHClient) Connected() bool

func (*SSHClient) DialThrough

func (c *SSHClient) DialThrough(net, addr string, config *ssh.ClientConfig) (*ssh.Client, error)

DialThrough will create a new connection from the ssh server c is connected to. DialThrough is an SSHDialer.

func (*SSHClient) GetName added in v0.10.2

func (c *SSHClient) GetName() string

func (*SSHClient) Prefix

func (c *SSHClient) Prefix() (string, string, string, uint16)

func (*SSHClient) Run

func (c *SSHClient) Run(i int, env []string, workDir string, shell string, cmdStr string) error

Run runs a command remotely on c.host.

func (*SSHClient) Signal

func (c *SSHClient) Signal(i int, sig os.Signal) error

func (*SSHClient) Stderr

func (c *SSHClient) Stderr(i int) io.Reader

func (*SSHClient) Stdin

func (c *SSHClient) Stdin(i int) io.WriteCloser

func (*SSHClient) Stdout

func (c *SSHClient) Stdout(i int) io.Reader

func (*SSHClient) Wait

func (c *SSHClient) Wait(i int) error

Wait waits until the remote command finishes and exits. It closes the SSH session.

func (*SSHClient) Write

func (c *SSHClient) Write(i int, p []byte) (n int, err error)

func (*SSHClient) WriteClose

func (c *SSHClient) WriteClose(i int) error

type SSHDialFunc

type SSHDialFunc func(net, addr string, config *ssh.ClientConfig) (*ssh.Client, error)

SSHDialFunc can dial an ssh server and return a client

type SSHSession added in v0.13.0

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

type ServerTask added in v0.13.0

type ServerTask struct {
	Server *dao.Server
	Task   *dao.Task
	Cmd    *dao.TaskCmd
	// contains filtered or unexported fields
}

type Signers added in v0.12.0

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

type TaskContext

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

type TaskOption added in v0.13.0

type TaskOption int

func StepTaskExecute added in v0.13.0

func StepTaskExecute(task string, host string, mu *sync.Mutex) (TaskOption, error)

TODO: Prompt again when invalid answer

Jump to

Keyboard shortcuts

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