From bd6ba5af0268551d7ca59ba4bb52a72f30af3b53 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Tue, 13 Apr 2021 08:17:09 +0200 Subject: [PATCH] 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. --- cmd/safcm/config/groups.go | 4 +++- cmd/safcm/config/groups_test.go | 7 +++++++ .../testdata/group-invalid-conflict-remove/groups.yaml | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 cmd/safcm/testdata/group-invalid-conflict-remove/groups.yaml 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 -- 2.45.2