client

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSSHClient

func NewSSHClient(cfg *Config) (*ssh.Client, error)

NewSSHClient creates a new SSH client for the given host, username, and identity file.

The host can be in the format of "example.com", "user@example.com:22", or any valid combination of username, hostname, and port. If the port is not specified, it defaults to 22.

If a ~/.ssh/config file is present and contains an entry matching host, username, port or identity file, the values from the config will override the corresponding values provided by the command line arguments.

If a username is provided, the client will use password authentication. If the username is provided in both the host string and the argument, it will return an error.

If no username is provided, it will try to use an identity file for authentication.

If the identity file is provided, it will be used. Any identity file outside of ~/.ssh will not be accepted for security reasons. Otherwise, the default identity files in the .ssh directory will be tried, e.g., id_ed25519, id_rsa, and id_ecdsa.

In either case, the client will check the host key against the known_hosts file in the ~/.ssh directory.

Types

type Client

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

func New

func New(cOpts ...ClientOptions) (*Client, error)

func (*Client) Close

func (cli *Client) Close() error

func (*Client) DaemonHost

func (cli *Client) DaemonHost() string

func (*Client) DaemonVersion

func (cli *Client) DaemonVersion() string

func (*Client) Logs

func (cli *Client) Logs(ctx context.Context, id string) LogSeq

func (*Client) Shorts

func (cli *Client) Shorts(ctx context.Context) ([]container.Short, error)

type ClientOptions

type ClientOptions func(*Config)

func WithAskPassword

func WithAskPassword(ask bool) ClientOptions

func WithDockerHost

func WithDockerHost(host string) ClientOptions

func WithHost

func WithHost(host string) ClientOptions

func WithIdentityFile

func WithIdentityFile(identityFile string) ClientOptions

func WithUsername

func WithUsername(username string) ClientOptions

type Config

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

func NewConfig

func NewConfig(opts ...ClientOptions) (*Config, error)

NewSSHClient creates a new SSH client for the given optins.

Note that the host, username, port and identity file can be rewritten during ssh client construction with the value provided in the ~/.ssh/config file.

Use the method of the client to get the constructed Addr, Host, Port, Username, AskPassword, SSHDir and DockerSocket.

func (*Config) Addr

func (cfg *Config) Addr() string

func (*Config) AskPassword

func (cfg *Config) AskPassword() bool

func (*Config) DockerHost

func (cfg *Config) DockerHost() string

func (*Config) Host

func (cfg *Config) Host() string

func (*Config) OpenIdentityFile

func (cfg *Config) OpenIdentityFile() (*os.File, error)

openIdentityFile tries to open the identity file from the given filename or if filename is empty, the ~/.ssh/config is parsed and cfg.host, cfg.username and cfg.identityFile is rewritten. If ~/.ssh/config is not present, the default ones in the ~/.ssh directory are used, e.g., id_ed25519, id_rsa, and id_ecdsa.

In either case, the file must be inside the ~/.ssh directory. Any file outside of it will not be accepted for security reasons.

The caller is responsible for closing the file.

It returns an error if the file cannot be opened or if the filename is outside of the ~/.ssh directory.

func (*Config) Port

func (cfg *Config) Port() string

func (*Config) SSHDir

func (cfg *Config) SSHDir() string

func (*Config) Username

func (cfg *Config) Username() string

type LogSeq

type LogSeq = iter.Seq2[string, error]

Jump to

Keyboard shortcuts

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