]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm/config/hosts.go
config: forbid host names which conflict with special groups
[safcm/safcm.git] / cmd / safcm / config / hosts.go
index 119968769d2f769a9d2885045b968207913a99d1..b3c4a24c65b1119bcf0ba8c87c72f691670c3e3c 100644 (file)
@@ -20,6 +20,7 @@ package config
 import (
        "fmt"
        "os"
+       "strings"
 
        "gopkg.in/yaml.v2"
 )
@@ -50,6 +51,24 @@ 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)
+               }
+
                hostMap[x.Name] = x
        }