]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
config: forbid ":remove" groups which conflict with hosts
authorSimon Ruderich <simon@ruderich.org>
Tue, 13 Apr 2021 06:17:09 +0000 (08:17 +0200)
committerSimon Ruderich <simon@ruderich.org>
Tue, 13 Apr 2021 06:21:12 +0000 (08:21 +0200)
Defining these groups had no effect but might confuse the user. As they
don't make any sense forbid them.

cmd/safcm/config/groups.go
cmd/safcm/config/groups_test.go
cmd/safcm/testdata/group-invalid-conflict-remove/groups.yaml [new file with mode: 0644]

index 5af3be09990115740b0ed7f4e9c941b185b87477..386a9a773468d47f9dd4d9779c5df25856e57493 100644 (file)
@@ -60,7 +60,9 @@ func LoadGroups(cfg *Config, hosts *Hosts) (map[string][]string, error) {
                                "%s conflict with pre-defined group %q",
                                errPrefix, name)
                }
-               if hosts.Map[name] != nil {
+               if hosts.Map[name] != nil ||
+                       hosts.Map[strings.TrimSuffix(name,
+                               GroupRemoveSuffix)] != nil {
                        return nil, fmt.Errorf(
                                "%s conflict with existing host",
                                errPrefix)
index 57176079bc0782ebfc0a76fb2f59bc84d0a27391..28aa82f7c9d02be4836b743e5f53528e12b2a4cc 100644 (file)
@@ -160,6 +160,13 @@ func TestLoadGroups(t *testing.T) {
                        nil,
                        fmt.Errorf("groups.yaml: group \"host2\": conflict with existing host"),
                },
+               {
+                       "../testdata/group-invalid-conflict-remove",
+                       &Config{},
+                       hosts,
+                       nil,
+                       fmt.Errorf("groups.yaml: group \"host2:remove\": conflict with existing host"),
+               },
                {
                        "../testdata/group-invalid-detected",
                        &Config{},
diff --git a/cmd/safcm/testdata/group-invalid-conflict-remove/groups.yaml b/cmd/safcm/testdata/group-invalid-conflict-remove/groups.yaml
new file mode 100644 (file)
index 0000000..0fbd8d6
--- /dev/null
@@ -0,0 +1,2 @@
+host2:remove:
+  - host1.example.org