From: Simon Ruderich Date: Wed, 7 Apr 2021 17:11:45 +0000 (+0200) Subject: config: forbid duplicate host names X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=a392efcc916e5cac948eb06b03820dd333fda64f;p=safcm%2Fsafcm.git config: forbid duplicate host names --- diff --git a/cmd/safcm/config/hosts.go b/cmd/safcm/config/hosts.go index b3c4a24..823afa1 100644 --- a/cmd/safcm/config/hosts.go +++ b/cmd/safcm/config/hosts.go @@ -69,6 +69,10 @@ func LoadHosts() (*Hosts, error) { errPrefix, GroupSpecialSeparator) } + if hostMap[x.Name] != nil { + return nil, fmt.Errorf("%s host name already exists", + errPrefix) + } hostMap[x.Name] = x } diff --git a/cmd/safcm/config/hosts_test.go b/cmd/safcm/config/hosts_test.go index ecbc37e..5d3c334 100644 --- a/cmd/safcm/config/hosts_test.go +++ b/cmd/safcm/config/hosts_test.go @@ -64,6 +64,11 @@ func TestLoadHosts(t *testing.T) { nil, }, + { + "../testdata/host-invalid-duplicate", + nil, + fmt.Errorf("hosts.yaml: host \"host1.example.org\": host name already exists"), + }, { "../testdata/host-invalid-all", nil, diff --git a/cmd/safcm/testdata/host-invalid-duplicate/hosts.yaml b/cmd/safcm/testdata/host-invalid-duplicate/hosts.yaml new file mode 100644 index 0000000..d6670b0 --- /dev/null +++ b/cmd/safcm/testdata/host-invalid-duplicate/hosts.yaml @@ -0,0 +1,2 @@ +- name: host1.example.org +- name: host1.example.org