Documentation ¶
Index ¶
- Constants
- func GetKeysFromCredentialsAttribute(ctx context.Context, deploymentID, nodeName, instanceID, capabilityName string) (map[string]*PrivateKey, error)
- func GetKeysFromCredentialsDataType(creds *types.Credential) (map[string]*PrivateKey, error)
- func ReadPrivateKey(pk string) (ssh.AuthMethod, error)
- func ReadSSHPrivateKey(pk *PrivateKey) (ssh.AuthMethod, error)
- func ToPrivateKeyContent(pk string) ([]byte, error)
- type BastionHostConfig
- type Client
- type MockSSHClient
- type PrivateKey
- type SSHAgent
- func (sa *SSHAgent) AddKey(privateKey string, lifeTime uint32) error
- func (sa *SSHAgent) AddPrivateKey(privateKey *PrivateKey, lifeTime uint32) error
- func (sa *SSHAgent) GetAuthMethod() ssh.AuthMethod
- func (sa *SSHAgent) RemoveAllKeys() error
- func (sa *SSHAgent) RemoveKey(privateKey string) error
- func (sa *SSHAgent) Stop() error
- type SSHClient
- type SSHSessionWrapper
- func (sw *SSHSessionWrapper) Close() error
- func (sw *SSHSessionWrapper) RequestPty(term string, h, w int, termmodes ssh.TerminalModes) error
- func (sw *SSHSessionWrapper) RunCommand(ctx context.Context, cmd string) error
- func (sw *SSHSessionWrapper) Start(cmd string) error
- func (sw *SSHSessionWrapper) StdinPipe() (io.WriteCloser, error)
Constants ¶
const DefaultSSHPrivateKeyFilePath = "~/.ssh/yorc.pem"
DefaultSSHPrivateKeyFilePath is the default SSH private Key file path used to connect to provisioned resources
Variables ¶
This section is empty.
Functions ¶
func GetKeysFromCredentialsAttribute ¶
func GetKeysFromCredentialsAttribute(ctx context.Context, deploymentID, nodeName, instanceID, capabilityName string) (map[string]*PrivateKey, error)
GetKeysFromCredentialsAttribute returns a map of PrivateKey by analysing a given credentials attribute of a given capability
func GetKeysFromCredentialsDataType ¶
func GetKeysFromCredentialsDataType(creds *types.Credential) (map[string]*PrivateKey, error)
GetKeysFromCredentialsDataType returns a map of PrivateKey contained in a Credential datatype
func ReadPrivateKey ¶
func ReadPrivateKey(pk string) (ssh.AuthMethod, error)
ReadPrivateKey returns an authentication method relying on private/public key pairs The argument is : - either a path to the private key file, - or the content or this private key file
func ReadSSHPrivateKey ¶
func ReadSSHPrivateKey(pk *PrivateKey) (ssh.AuthMethod, error)
ReadSSHPrivateKey returns an authentication method relying on private/public key pairs
func ToPrivateKeyContent ¶
ToPrivateKeyContent allows to convert private key content or file to byte array
Types ¶
type BastionHostConfig ¶
type BastionHostConfig struct { Host string Port string User string Password string PrivateKeys map[string]*PrivateKey }
BastionHostConfig is the configuration of a bastion host that can be used for ssh connections.
type Client ¶
type Client interface { RunCommand(string) (string, error) CopyFile(source io.Reader, remotePath string, permissions string) error }
Client is interface allowing running command
type MockSSHClient ¶
type MockSSHClient struct { MockRunCommand func(string) (string, error) MockCopyFile func(source io.Reader, remotePath string, permissions string) error }
MockSSHClient allows to mock an SSH Client
func (*MockSSHClient) RunCommand ¶
func (s *MockSSHClient) RunCommand(cmd string) (string, error)
RunCommand to mock a command ran via SSH
type PrivateKey ¶
PrivateKey represent a parsed ssh Private Key. Content is always set but Path is populated only if the key content was read from a filesystem path (not provided directly)
func GetDefaultKey ¶
func GetDefaultKey() (*PrivateKey, error)
GetDefaultKey returns Yorc's default private Key
func GetPrivateKey ¶
func GetPrivateKey(pathOrContent string) (*PrivateKey, error)
GetPrivateKey returns a parsed PrivateKey
The argument is : - either a path to the private key file, - or the content or this private key file
func SelectPrivateKeyOnName ¶
func SelectPrivateKeyOnName(keys map[string]*PrivateKey, shouldHavePath bool) *PrivateKey
SelectPrivateKeyOnName select a PrivateKey when several keys are available.
This method is for backward compatibility when the ssh-agent is disable and only a single key can be used. The Selection algorithm is first to check a key named "0", then "yorc" and finally "default" if none of these are present then a random one is chosen.
If shouldHavePath parameter is true then only keys having a valid file path can be returned (that's mean that keys provided only with their content are ignored)
If there is no key or none of them matche the requirements then nil is returned
type SSHAgent ¶
type SSHAgent struct { Socket string // contains filtered or unexported fields }
SSHAgent is an SSH agent
func NewSSHAgent ¶
NewSSHAgent allows to return a new SSH Agent
func (*SSHAgent) AddPrivateKey ¶
func (sa *SSHAgent) AddPrivateKey(privateKey *PrivateKey, lifeTime uint32) error
AddPrivateKey allows to add a key into ssh-agent keys list
func (*SSHAgent) GetAuthMethod ¶
func (sa *SSHAgent) GetAuthMethod() ssh.AuthMethod
GetAuthMethod returns the auth method with all agent keys
func (*SSHAgent) RemoveAllKeys ¶
RemoveAllKeys allows to remove all keys into ssh-agent keys list
type SSHClient ¶
type SSHClient struct { Config *ssh.ClientConfig Host string Port int RetryBackoff time.Duration MaxRetries uint64 }
SSHClient is a client SSH
func (*SSHClient) CopyFile ¶
CopyFile allows to copy a reader over SSH with defined remote path and specific permissions CopyFile allows to copy a reader over SSH with defined remote path and specific permissions
func (*SSHClient) GetSessionWrapper ¶
func (client *SSHClient) GetSessionWrapper() (*SSHSessionWrapper, error)
GetSessionWrapper allows to return a session wrapper in order to handle stdout/stderr for running long synchronous commands
type SSHSessionWrapper ¶
type SSHSessionWrapper struct { Stdout io.Reader Stderr io.Reader // contains filtered or unexported fields }
SSHSessionWrapper is a wrapper with a piped SSH session
func (*SSHSessionWrapper) Close ¶
func (sw *SSHSessionWrapper) Close() error
Close closes the session
func (*SSHSessionWrapper) RequestPty ¶
func (sw *SSHSessionWrapper) RequestPty(term string, h, w int, termmodes ssh.TerminalModes) error
RequestPty requests the association of a pty with the session on the remote host.
func (*SSHSessionWrapper) RunCommand ¶
func (sw *SSHSessionWrapper) RunCommand(ctx context.Context, cmd string) error
RunCommand allows to run a specified command from a session wrapper in order to handle stdout/stderr during long synchronous commands stdout/stderr are retrieved asynchronously with SSHSessionWrapper.Stdout and SSHSessionWrapper.Stderr
func (*SSHSessionWrapper) Start ¶
func (sw *SSHSessionWrapper) Start(cmd string) error
Start runs cmd on the remote host. Typically, the remote server passes cmd to the shell for interpretation. A Session only accepts one call to Run, Start or Shell.
func (*SSHSessionWrapper) StdinPipe ¶
func (sw *SSHSessionWrapper) StdinPipe() (io.WriteCloser, error)
StdinPipe returns a pipe that will be connected to the remote command's standard input when the command starts.