33 lines
606 B
Go
33 lines
606 B
Go
package ssh
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/Neur0toxine/sshpoke/pkg/smarttypes"
|
|
"github.com/kevinburke/ssh_config"
|
|
)
|
|
|
|
type hostConfig struct {
|
|
cfg *ssh_config.Config
|
|
host string
|
|
}
|
|
|
|
func (c *hostConfig) Get(key string) (string, error) {
|
|
val, err := c.cfg.Get(c.host, key)
|
|
return strings.TrimSpace(val), err
|
|
}
|
|
|
|
func parseSSHConfig(filePath smarttypes.Path) (*ssh_config.Config, error) {
|
|
fileName, err := filePath.File()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
file, err := os.ReadFile(fileName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ssh_config.Decode(bytes.NewReader(file))
|
|
}
|