forked from toolshed/abra
feat: provision docker installation
This commit is contained in:
45
pkg/ssh/ssh.go
Normal file
45
pkg/ssh/ssh.go
Normal file
@ -0,0 +1,45 @@
|
||||
package ssh
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/kevinburke/ssh_config"
|
||||
)
|
||||
|
||||
// HostConfig is a SSH host config.
|
||||
type HostConfig struct {
|
||||
Host string
|
||||
IdentityFile string
|
||||
Port string
|
||||
User string
|
||||
}
|
||||
|
||||
// GetHostConfig retrieves a ~/.ssh/config config for a host.
|
||||
func GetHostConfig(hostname string, hasIdentityFile bool) (HostConfig, error) {
|
||||
var hostConfig HostConfig
|
||||
|
||||
var host, user, port, idf string
|
||||
|
||||
if host = ssh_config.Get(hostname, "Hostname"); host == "" {
|
||||
return hostConfig, fmt.Errorf("SSH hostname missing for %s from SSH config", hostname)
|
||||
}
|
||||
|
||||
if user = ssh_config.Get(hostname, "User"); user == "" {
|
||||
return hostConfig, fmt.Errorf("SSH user missing for %s from SSH config", hostname)
|
||||
}
|
||||
|
||||
if port = ssh_config.Get(hostname, "Port"); port == "" {
|
||||
return hostConfig, fmt.Errorf("SSH port missing for %s from SSH config", hostname)
|
||||
}
|
||||
|
||||
if idf = ssh_config.Get(hostname, "IdentityFile"); idf == "" && hasIdentityFile {
|
||||
return hostConfig, fmt.Errorf("SSH identity file missing for %s from SSH config", hostname)
|
||||
}
|
||||
|
||||
hostConfig.Host = host
|
||||
hostConfig.IdentityFile = idf
|
||||
hostConfig.Port = port
|
||||
hostConfig.User = user
|
||||
|
||||
return hostConfig, nil
|
||||
}
|
Reference in New Issue
Block a user