]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm/sync_info.go
safcm: strip invalid characters from detected os/arch groups
[safcm/safcm.git] / cmd / safcm / sync_info.go
index b0a85ee507f4603b2966eb0b7b6e8b6f74dba12a..5ba6ac83c903df14afc3c0a99396ec70dd453bb4 100644 (file)
@@ -45,19 +45,24 @@ func (s *Sync) hostInfo(conn *rpc.Conn) ([]string, error) {
        return hostInfoRespToGroups(resp), nil
 }
 
-// Keep in sync with config/groups.go:groupNameRegexp
+// Keep in sync with cmd/safcm/config/groups.go:groupNameRegexp
 var infoGroupDetectedRegexp = regexp.MustCompile(`[^a-z0-9_-]+`)
 
 func hostInfoRespToGroups(resp safcm.MsgInfoResp) []string {
        groups := []string{
-               config.GroupDetectedPrefix + "_" + resp.Goos,
-               config.GroupDetectedPrefix + "_" + resp.Goarch,
+               hostInfoDetectedGroupName(resp.Goos),
+               hostInfoDetectedGroupName(resp.Goarch),
        }
        for _, x := range resp.Output {
+               groups = append(groups, hostInfoDetectedGroupName(x))
+       }
+       return groups
+}
+
+func hostInfoDetectedGroupName(x string) string {
                x = strings.TrimSpace(x)
                x = strings.ToLower(x)
                x = infoGroupDetectedRegexp.ReplaceAllString(x, "_")
-               groups = append(groups, config.GroupDetectedPrefix+"_"+x)
-       }
-       return groups
+       x = config.GroupDetectedPrefix + "_" + x
+       return x
 }