]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
config: permit "all" and host group in .InGroup of templates
authorSimon Ruderich <simon@ruderich.org>
Thu, 8 Apr 2021 17:02:51 +0000 (19:02 +0200)
committerSimon Ruderich <simon@ruderich.org>
Thu, 8 Apr 2021 17:02:51 +0000 (19:02 +0200)
These special groups were not handled properly.

cmd/safcm/config/files_test.go
cmd/safcm/config/permissions_test.go
cmd/safcm/config/templates.go
cmd/safcm/config/templates_test.go
cmd/safcm/config/triggers_test.go
cmd/safcm/sync_sync_test.go
cmd/safcm/testdata/project/group/files/etc/motd

index 1313fdfed18548947a6cda319b1db862d8de8dbb..82d60c9d4f086e22e6f382b1642a87ca2ab1179c 100644 (file)
@@ -126,6 +126,19 @@ This is GNU/Linux host
 {{if .InGroup "detected_freebsd"}}
 This is FreeBSD host
 {{end}}
+
+{{if .InGroup "all"}}
+all
+{{end}}
+{{if .InGroup "host1.example.org"}}
+host1.example.org
+{{end}}
+{{if .InGroup "host2"}}
+host2
+{{end}}
+{{if .InGroup "host3.example.net"}}
+host3.example.net
+{{end}}
 `),
                                },
                                "/etc/rc.local": {
index 98b82b6ba877d0aaae02959384404a4f863815a6..2f742d052d96126810a69b9adff47802640e0e35 100644 (file)
@@ -87,6 +87,19 @@ This is GNU/Linux host
 {{if .InGroup "detected_freebsd"}}
 This is FreeBSD host
 {{end}}
+
+{{if .InGroup "all"}}
+all
+{{end}}
+{{if .InGroup "host1.example.org"}}
+host1.example.org
+{{end}}
+{{if .InGroup "host2"}}
+host2
+{{end}}
+{{if .InGroup "host3.example.net"}}
+host3.example.net
+{{end}}
 `),
                                },
                                "/etc/rc.local": {
index b84b4944c017769b10624a675479be4dac6f0f25..0aad2b0b4a55d31705c64a117f90063ccd36fc2f 100644 (file)
@@ -116,7 +116,9 @@ func (t *templateArgs) IsHost(host string) bool {
 func (t *templateArgs) InGroup(group string) bool {
        // Don't permit invalid groups to detect typos; detected groups cannot
        // be checked
-       if !t.allGroups[group] &&
+       if group != GroupAll &&
+               !t.allGroups[group] &&
+               !t.allHosts[group] &&
                !strings.HasPrefix(group, GroupDetectedPrefix) {
                panic(fmt.Sprintf("group %q does not exist", group))
        }
index 36b53dc87cd3755572fea831ab4b742113afe235..fd9ecb7570e24491cfdb67b5b247c17f3ff31431 100644 (file)
@@ -97,6 +97,15 @@ func TestLoadTemplates(t *testing.T) {
 This is GNU/Linux host
 
 
+
+
+all
+
+
+host1.example.org
+
+
+
 `),
                                },
                                "/etc/rc.local": {
index 43c3a557882255e870a737ecd9c43ccc7b012368..63d702aeda97b9bfed0e1545771082a32a3b53e8 100644 (file)
@@ -90,6 +90,19 @@ This is GNU/Linux host
 {{if .InGroup "detected_freebsd"}}
 This is FreeBSD host
 {{end}}
+
+{{if .InGroup "all"}}
+all
+{{end}}
+{{if .InGroup "host1.example.org"}}
+host1.example.org
+{{end}}
+{{if .InGroup "host2"}}
+host2
+{{end}}
+{{if .InGroup "host3.example.net"}}
+host3.example.net
+{{end}}
 `),
                                },
                                "/etc/rc.local": {
index b5e8ce242b01c5e793da5702c24fb942d8bb034a..31252936e663861f18aa352766ab43479540caae 100644 (file)
@@ -93,7 +93,7 @@ func TestHostSyncReq(t *testing.T) {
                                                Mode:      0644,
                                                Uid:       -1,
                                                Gid:       -1,
-                                               Data:      []byte("Welcome to Host ONE\n\n\n\n"),
+                                               Data:      []byte("Welcome to Host ONE\n\n\n\n\n\nall\n\n\nhost1.example.org\n\n\n\n"),
                                        },
                                        "/etc/rc.local": &safcm.File{
                                                OrigGroup: "group",
@@ -191,7 +191,7 @@ func TestHostSyncReq(t *testing.T) {
                                                Mode:      0644,
                                                Uid:       -1,
                                                Gid:       -1,
-                                               Data:      []byte("Welcome to Host ONE\n\n\n\n"),
+                                               Data:      []byte("Welcome to Host ONE\n\n\n\n\n\nall\n\n\nhost1.example.org\n\n\n\n"),
                                        },
                                        "/etc/rc.local": &safcm.File{
                                                OrigGroup: "group",
index be82b961004ee5393ada2caff757679b6c9eacc2..79a9952921f979343d5cb293a93885d8e9fc8aaf 100644 (file)
@@ -9,3 +9,16 @@ This is GNU/Linux host
 {{if .InGroup "detected_freebsd"}}
 This is FreeBSD host
 {{end}}
+
+{{if .InGroup "all"}}
+all
+{{end}}
+{{if .InGroup "host1.example.org"}}
+host1.example.org
+{{end}}
+{{if .InGroup "host2"}}
+host2
+{{end}}
+{{if .InGroup "host3.example.net"}}
+host3.example.net
+{{end}}