Documentation
¶
Index ¶
- Constants
- Variables
- func ParseSSHPublicKey(key string) (gossh.PublicKey, error)
- type SSHKeyParser
- type SshManager
- type StandardSshManager
- func (sc *StandardSshManager) DeregisterOS() error
- func (sc *StandardSshManager) ExecuteScript(scriptPath, scriptContent string, postRemove, runWithSudo bool) error
- func (sc *StandardSshManager) HostPublicKeyIsValid(maxAttempts int) error
- func (sc *StandardSshManager) IsReady() bool
- func (sc *StandardSshManager) RebootCloudInit() error
- func (sc *StandardSshManager) String() string
- func (sc *StandardSshManager) WriteFileOnRemoteMachine(path, fileContent string, fileMode os.FileMode) error
Constants ¶
const (
SSH_CONNECT_ATTEMPT_DELAY time.Duration = 30 * time.Second
)
Variables ¶
var ( ErrNoneOfConstructorArgsCanBeEmpty = errors.New("none of the arguments can be empty; neither 'hostName', 'userName', 'sshPassword', 'sshKeyPath', 'hostPublicKey'") IsPublicKeyValid = false )
Functions ¶
func ParseSSHPublicKey ¶ added in v0.1.11
ParseSSHPublicKey parses an SSH public key string in authorized_keys format and returns the parsed PublicKey. This can be used to validate the key early (e.g. during configuration) before passing it to NewStandardSshManager.
Types ¶
type SSHKeyParser ¶ added in v0.1.8
SSHKeyParser defines the interface for parsing an SSH key from a path.
func NewFileSSHKeyParser ¶ added in v0.1.8
func NewFileSSHKeyParser() SSHKeyParser
NewFileSSHKeyParser creates a new parser that reads from the filesystem.
type SshManager ¶
type SshManager interface {
IsReady() bool
ExecuteScript(scriptPath, scriptContent string, postRemove bool, runWithSudo bool) error
WriteFileOnRemoteMachine(path, fileContent string, fileMode os.FileMode) error
RebootCloudInit() error
DeregisterOS() error
HostPublicKeyIsValid(maxAttempts int) error
}
SshManager interface defines the methods for interacting with the SSH Manager.
type StandardSshManager ¶
type StandardSshManager struct {
HostName string
UserName string
SshPassword string
SshKeyPath string
Client ssh.Client
HostPublicKey gossh.PublicKey
// contains filtered or unexported fields
}
StandardSshManager struct holds configuration for SSH Manager interaction.
func NewStandardSshManager ¶
func NewStandardSshManager(hostName, userName, sshPassword, sshKeyPath string, hostPublicKey gossh.PublicKey) (*StandardSshManager, error)
NewStandardSshManager Returns new instance of Standard SSH Manager and error. The hostPublicKey parameter must be a pre-parsed gossh.PublicKey (use ParseSSHPublicKey to obtain one).
func (*StandardSshManager) DeregisterOS ¶ added in v0.1.8
func (sc *StandardSshManager) DeregisterOS() error
DeregisterOS - De-registers SLES OS using SUSEConnect
func (*StandardSshManager) ExecuteScript ¶
func (sc *StandardSshManager) ExecuteScript(scriptPath, scriptContent string, postRemove, runWithSudo bool) error
ExecuteScript Executes script defined by path and content. Executing procedure consists of few steps:
- if script path is not set (empty), then create a secure temporary subdirectory (e.g. /tmp/fsas-nodedriver) with minimal permissions and prepare the script using a random filename inside that directory (e.g. /tmp/fsas-nodedriver/username-via-ssh-256.sh)
- generate file in above location with given content and grant executable privileges to file
- execute script
- if param 'postRemove' is true then:
- remove script after execution else leave it
- delete secure directory if it is empty.
- if script path is provided, the script is written and executed at that path without directory creation or deletion.
func (*StandardSshManager) HostPublicKeyIsValid ¶ added in v1.0.0
func (sc *StandardSshManager) HostPublicKeyIsValid(maxAttempts int) error
HostPublicKeyIsValid checks if the remote host's public key complies with the given one passed as param.
func (*StandardSshManager) IsReady ¶ added in v1.0.0
func (sc *StandardSshManager) IsReady() bool
IsReady Returns true if SSH manager is initialized and connected to the host, false otherwise. Initialization is performed during HostPublicKeyIsValid() method call and is based on successful SSH connection
to the host with provided credentials and host public key
func (*StandardSshManager) RebootCloudInit ¶
func (sc *StandardSshManager) RebootCloudInit() error
RebootCloudInit() error
func (*StandardSshManager) String ¶
func (sc *StandardSshManager) String() string
func (*StandardSshManager) WriteFileOnRemoteMachine ¶
func (sc *StandardSshManager) WriteFileOnRemoteMachine(path, fileContent string, fileMode os.FileMode) error
WriteFileOnRemoteMachine Writes content to file defined in path