X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm%2Fconfig%2Fgroups.go;h=5af3be09990115740b0ed7f4e9c941b185b87477;hb=4473e968425319e6beae558643bb047a6b01c17a;hp=7f7cb3f635c346663808e69e990aac020040b345;hpb=cc1ca940efef242decfa8bd4adc2e0d9cbf6a210;p=safcm%2Fsafcm.git diff --git a/cmd/safcm/config/groups.go b/cmd/safcm/config/groups.go index 7f7cb3f..5af3be0 100644 --- a/cmd/safcm/config/groups.go +++ b/cmd/safcm/config/groups.go @@ -186,3 +186,42 @@ func ResolveHostGroups(host string, sort.Strings(res) return res, nil } + +// TransitivelyDetectedGroups returns all groups which depend on "detected" +// groups, either directly or by depending on groups which transitively depend +// on "detected" groups. +func TransitivelyDetectedGroups(groups map[string][]string) []string { + work := make(map[string][]string) + for k, v := range groups { + work[k] = v + } + + // Mark all groups which contain "detected" groups as long as new + // (transitive) "detected" groups are found. + detected := make(map[string]bool) + for { + change := false + for group, members := range work { + for _, x := range members { + if !detected[x] && !strings.HasPrefix(x, + GroupDetectedPrefix) { + continue + } + detected[strings.TrimSuffix(group, + GroupRemoveSuffix)] = true + delete(work, group) + change = true + } + } + if !change { + break + } + } + + var res []string + for x := range detected { + res = append(res, x) + } + sort.Strings(res) + return res +}