X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm%2Fconfig%2Fhosts.go;h=823afa16c87aad2aa59aea79ff9ef34eeba2c3ae;hb=4473e968425319e6beae558643bb047a6b01c17a;hp=119968769d2f769a9d2885045b968207913a99d1;hpb=023e863fbd9c6cf5bebd18e19c05ae9e60fbbe21;p=safcm%2Fsafcm.git diff --git a/cmd/safcm/config/hosts.go b/cmd/safcm/config/hosts.go index 1199687..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" ) @@ -50,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 }