X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm%2Fconfig%2Fhosts.go;h=823afa16c87aad2aa59aea79ff9ef34eeba2c3ae;hb=4473e968425319e6beae558643bb047a6b01c17a;hp=cf750cbc0024c7381142ae5852d640b60046fecc;hpb=f2f2bc47e8729548f3c10117f7f008b547c4afc5;p=safcm%2Fsafcm.git diff --git a/cmd/safcm/config/hosts.go b/cmd/safcm/config/hosts.go index cf750cb..823afa1 100644 --- a/cmd/safcm/config/hosts.go +++ b/cmd/safcm/config/hosts.go @@ -20,6 +20,7 @@ package config import ( "fmt" "os" + "strings" "gopkg.in/yaml.v2" ) @@ -31,6 +32,8 @@ type Hosts struct { type Host struct { Name string `yaml:"name"` + + SshUser string `yaml:"ssh_user"` } func LoadHosts() (*Hosts, error) { @@ -48,6 +51,28 @@ func LoadHosts() (*Hosts, error) { hostMap := make(map[string]*Host) for _, x := range hostList { + errPrefix := fmt.Sprintf("%s: host %q:", path, x.Name) + if x.Name == GroupAll { + return nil, fmt.Errorf( + "%s conflict with pre-defined group %q", + errPrefix, x.Name) + } + if strings.HasPrefix(x.Name, GroupDetectedPrefix) { + return nil, fmt.Errorf( + "%s name must not start with %q "+ + "(reserved for detected groups)", + errPrefix, GroupDetectedPrefix) + } + if strings.Contains(x.Name, GroupSpecialSeparator) { + return nil, fmt.Errorf( + "%s name must not contain %q", + errPrefix, GroupSpecialSeparator) + } + + if hostMap[x.Name] != nil { + return nil, fmt.Errorf("%s host name already exists", + errPrefix) + } hostMap[x.Name] = x }