feat: provision docker installation

This commit is contained in:
2021-10-24 23:15:38 +02:00
parent 1396f15c78
commit 9a0e12258a
4 changed files with 164 additions and 8 deletions

45
pkg/ssh/ssh.go Normal file
View 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
}