Skip to content

Commit

Permalink
return error in engine:CheckHosts
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandeep Jadoonanan committed Oct 4, 2017
1 parent 2bfa471 commit 8306264
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ var StatusCmd = &cobra.Command{
hosts = removeDuplicates(hosts)

// Validate hosts.
konnect.CheckHosts(hosts)
if err := konnect.CheckHosts(hosts); err != nil {
log.Fatal(err)
}

// Check status of the resolved hosts.
fmt.Printf("Testing connections for %v\n\n", strings.Join(hosts, ", "))
Expand Down
6 changes: 3 additions & 3 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"io/ioutil"
"log"
"sort"

yaml "gopkg.in/yaml.v2"
Expand Down Expand Up @@ -41,14 +40,15 @@ func (k *Konnect) GetHosts() []string {
}

// CheckHosts - Ensure that the given host names exist.
func (k *Konnect) CheckHosts(hosts []string) {
func (k *Konnect) CheckHosts(hosts []string) error {
// If a given host does not exist
// in Konnect.Hosts, then throw an error.
for _, host := range hosts {
if _, ok := k.Hosts[host]; ok != true {
log.Fatalf("Undefined host %v", host)
return fmt.Errorf("Undefined host %v", host)
}
}
return nil
}

// LoadFromFile - Load and validate SSHProxy objects from a yaml config file.
Expand Down

0 comments on commit 8306264

Please sign in to comment.