From: Simon Ruderich Date: Sun, 4 Apr 2021 19:27:31 +0000 (+0200) Subject: sync: add SAFCM_HELPER environment variable to commands X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=bc439f5c4aabef1cccfe40233c2e467602a55a60;hp=326baeaca101fdee43b22c45a7c304a0fdea027f;p=safcm%2Fsafcm.git sync: add SAFCM_HELPER environment variable to commands Contains the absolute path to the remote helper binary. Will be useful in the future when the remote helper gets additional subcommands. --- diff --git a/cmd/safcm-remote/sync/commands.go b/cmd/safcm-remote/sync/commands.go index abc23bc..e3c48dd 100644 --- a/cmd/safcm-remote/sync/commands.go +++ b/cmd/safcm-remote/sync/commands.go @@ -79,10 +79,15 @@ func (s *Sync) syncCommand(command string, trigger string) error { } func safcmEnviroment(groups []string) []string { + exe, err := os.Executable() + if err != nil { + panic(err) // should not happen on supported systems + } + env := os.Environ() - // Provide additional environment variables so commands can check - // group membership + // Provide additional environment variables env = append(env, + fmt.Sprintf("SAFCM_HELPER=%s", exe), fmt.Sprintf("SAFCM_GROUPS=%s", strings.Join(groups, " "))) for _, x := range groups { env = append(env, fmt.Sprintf("SAFCM_GROUP_%s=%s", x, x)) diff --git a/cmd/safcm-remote/sync/commands_test.go b/cmd/safcm-remote/sync/commands_test.go index aeeea32..1b1adf7 100644 --- a/cmd/safcm-remote/sync/commands_test.go +++ b/cmd/safcm-remote/sync/commands_test.go @@ -29,7 +29,12 @@ import ( ) func TestSyncCommands(t *testing.T) { + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } env := append(os.Environ(), + "SAFCM_HELPER="+exe, "SAFCM_GROUPS=all group1 group2 host.example.org", "SAFCM_GROUP_all=all", "SAFCM_GROUP_group1=group1",