From: Simon Ruderich Date: Tue, 13 Apr 2021 06:17:09 +0000 (+0200) Subject: config: forbid ":remove" groups which conflict with hosts X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=bd6ba5af0268551d7ca59ba4bb52a72f30af3b53;p=safcm%2Fsafcm.git config: forbid ":remove" groups which conflict with hosts Defining these groups had no effect but might confuse the user. As they don't make any sense forbid them. --- diff --git a/cmd/safcm/config/groups.go b/cmd/safcm/config/groups.go index 5af3be0..386a9a7 100644 --- a/cmd/safcm/config/groups.go +++ b/cmd/safcm/config/groups.go @@ -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) diff --git a/cmd/safcm/config/groups_test.go b/cmd/safcm/config/groups_test.go index 5717607..28aa82f 100644 --- a/cmd/safcm/config/groups_test.go +++ b/cmd/safcm/config/groups_test.go @@ -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 index 0000000..0fbd8d6 --- /dev/null +++ b/cmd/safcm/testdata/group-invalid-conflict-remove/groups.yaml @@ -0,0 +1,2 @@ +host2:remove: + - host1.example.org