From bc439f5c4aabef1cccfe40233c2e467602a55a60 Mon Sep 17 00:00:00 2001 From: Simon Ruderich Date: Sun, 4 Apr 2021 21:27:31 +0200 Subject: [PATCH] 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. --- cmd/safcm-remote/sync/commands.go | 9 +++++++-- cmd/safcm-remote/sync/commands_test.go | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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", -- 2.44.1