added modular packages

This commit is contained in:
2022-11-22 15:09:39 -06:00
parent 62be691fea
commit 6304866953
9 changed files with 181 additions and 126 deletions

33
pkg/ssh/ssh.go Normal file
View File

@ -0,0 +1,33 @@
package ssh
import (
"errors"
"github.com/kevinburke/ssh_config"
)
type SshConfig struct {
PrivateKey string
Port uint
HostName string
User string
}
func GetSSHConfig(host string) (SshConfig, error) {
var config SshConfig
hostName := ssh_config.Get(host, "HostName")
if hostName == "" {
return SshConfig{}, errors.New("hostname not found")
}
config.HostName = hostName
privKey, err := ssh_config.GetStrict(host, "IdentityFile")
if err != nil {
return SshConfig{}, err
}
config.PrivateKey = privKey
User := ssh_config.Get(host, "User")
if User == "" {
return SshConfig{}, errors.New("user not found")
}
return config, nil
}