This commit is contained in:
parent
e20141043c
commit
c3de4386ab
3
.changes/unreleased/Changed-20250210-165532.yaml
Normal file
3
.changes/unreleased/Changed-20250210-165532.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
kind: Changed
|
||||||
|
body: Hosts passed to `exec host` now checked against default SSH config files
|
||||||
|
time: 2025-02-10T16:55:32.936776556-06:00
|
12
cmd/host.go
12
cmd/host.go
@ -15,8 +15,10 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Holds command list to run
|
// Holds list of hosts to run commands on
|
||||||
var hostsList []string
|
var hostsList []string
|
||||||
|
|
||||||
|
// Holds command list to run
|
||||||
var cmdList []string
|
var cmdList []string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -48,7 +50,13 @@ func Host(cmd *cobra.Command, args []string) {
|
|||||||
for _, h := range hostsList {
|
for _, h := range hostsList {
|
||||||
_, hostFound := backyConfOpts.Hosts[h]
|
_, hostFound := backyConfOpts.Hosts[h]
|
||||||
if !hostFound {
|
if !hostFound {
|
||||||
logging.ExitWithMSG("host "+h+" not found", 1, &backyConfOpts.Logger)
|
// check if h exists in the config file
|
||||||
|
hostFoundInConfig, s := backy.CheckIfHostHasHostName(h)
|
||||||
|
if !hostFoundInConfig {
|
||||||
|
logging.ExitWithMSG("host "+h+" not found", 1, &backyConfOpts.Logger)
|
||||||
|
}
|
||||||
|
// create host with hostname and host
|
||||||
|
backyConfOpts.Hosts[h] = &backy.Host{Host: h, HostName: s}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if cmdList == nil {
|
if cmdList == nil {
|
||||||
|
@ -757,3 +757,12 @@ func (h *Host) DetectOS(opts *ConfigOpts) (string, error) {
|
|||||||
osName := string(output)
|
osName := string(output)
|
||||||
return osName, nil
|
return osName, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckIfHostHasHostName(host string) (bool, string) {
|
||||||
|
HostName, err := ssh_config.DefaultUserSettings.GetStrict(host, "HostName")
|
||||||
|
if err != nil {
|
||||||
|
return false, ""
|
||||||
|
}
|
||||||
|
println(HostName)
|
||||||
|
return HostName != "", HostName
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user