X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm%2Fsync_info.go;h=fd480063629a67e5f1c1c8d103ee1b19107fae88;hb=2d8cd51379f293fe2047c1347b52f8dc7ac3f78d;hp=b0a85ee507f4603b2966eb0b7b6e8b6f74dba12a;hpb=f2f2bc47e8729548f3c10117f7f008b547c4afc5;p=safcm%2Fsafcm.git diff --git a/cmd/safcm/sync_info.go b/cmd/safcm/sync_info.go index b0a85ee..fd48006 100644 --- a/cmd/safcm/sync_info.go +++ b/cmd/safcm/sync_info.go @@ -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 { - x = strings.TrimSpace(x) - x = strings.ToLower(x) - x = infoGroupDetectedRegexp.ReplaceAllString(x, "_") - groups = append(groups, config.GroupDetectedPrefix+"_"+x) + groups = append(groups, hostInfoDetectedGroupName(x)) } return groups } + +func hostInfoDetectedGroupName(x string) string { + x = strings.TrimSpace(x) + x = strings.ToLower(x) + x = infoGroupDetectedRegexp.ReplaceAllString(x, "_") + x = config.GroupDetectedPrefix + "_" + x + return x +}