mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-21 23:20:24 +00:00
config: fix loading commands args from env vars
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
parent
4440c49174
commit
d1e4ee7bc8
2 changed files with 11 additions and 1 deletions
|
@ -1961,6 +1961,11 @@ func getCommandConfigsFromEnv(idx int) {
|
||||||
cfg.Env = env
|
cfg.Env = env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
args, ok := lookupStringListFromEnv(fmt.Sprintf("SFTPGO_COMMAND__COMMANDS__%v__ARGS", idx))
|
||||||
|
if ok {
|
||||||
|
cfg.Args = args
|
||||||
|
}
|
||||||
|
|
||||||
if cfg.Path != "" {
|
if cfg.Path != "" {
|
||||||
if len(globalConf.CommandConfig.Commands) > idx {
|
if len(globalConf.CommandConfig.Commands) > idx {
|
||||||
globalConf.CommandConfig.Commands[idx] = cfg
|
globalConf.CommandConfig.Commands[idx] = cfg
|
||||||
|
|
|
@ -924,13 +924,17 @@ func TestCommandsFromEnv(t *testing.T) {
|
||||||
os.Setenv("SFTPGO_COMMAND__COMMANDS__1__PATH", "cmd2")
|
os.Setenv("SFTPGO_COMMAND__COMMANDS__1__PATH", "cmd2")
|
||||||
os.Setenv("SFTPGO_COMMAND__COMMANDS__1__TIMEOUT", "20")
|
os.Setenv("SFTPGO_COMMAND__COMMANDS__1__TIMEOUT", "20")
|
||||||
os.Setenv("SFTPGO_COMMAND__COMMANDS__1__ENV", "e=f")
|
os.Setenv("SFTPGO_COMMAND__COMMANDS__1__ENV", "e=f")
|
||||||
|
os.Setenv("SFTPGO_COMMAND__COMMANDS__1__ARGS", "arg1, arg2")
|
||||||
|
|
||||||
t.Cleanup(func() {
|
t.Cleanup(func() {
|
||||||
os.Unsetenv("SFTPGO_COMMAND__TIMEOUT")
|
os.Unsetenv("SFTPGO_COMMAND__TIMEOUT")
|
||||||
os.Unsetenv("SFTPGO_COMMAND__ENV")
|
os.Unsetenv("SFTPGO_COMMAND__ENV")
|
||||||
os.Unsetenv("SFTPGO_COMMAND__COMMANDS__0__PATH")
|
os.Unsetenv("SFTPGO_COMMAND__COMMANDS__0__PATH")
|
||||||
os.Unsetenv("SFTPGO_COMMAND__COMMANDS__0__TIMEOUT")
|
os.Unsetenv("SFTPGO_COMMAND__COMMANDS__0__TIMEOUT")
|
||||||
os.Unsetenv("SFTPGO_COMMAND__COMMANDS__0__ENV")
|
os.Unsetenv("SFTPGO_COMMAND__COMMANDS__1__PATH")
|
||||||
|
os.Unsetenv("SFTPGO_COMMAND__COMMANDS__1__TIMEOUT")
|
||||||
|
os.Unsetenv("SFTPGO_COMMAND__COMMANDS__1__ENV")
|
||||||
|
os.Unsetenv("SFTPGO_COMMAND__COMMANDS__1__ARGS")
|
||||||
})
|
})
|
||||||
|
|
||||||
err = config.LoadConfig(configDir, confName)
|
err = config.LoadConfig(configDir, confName)
|
||||||
|
@ -945,6 +949,7 @@ func TestCommandsFromEnv(t *testing.T) {
|
||||||
require.Equal(t, "cmd2", commandConfig.Commands[1].Path)
|
require.Equal(t, "cmd2", commandConfig.Commands[1].Path)
|
||||||
require.Equal(t, 20, commandConfig.Commands[1].Timeout)
|
require.Equal(t, 20, commandConfig.Commands[1].Timeout)
|
||||||
require.Equal(t, []string{"e=f"}, commandConfig.Commands[1].Env)
|
require.Equal(t, []string{"e=f"}, commandConfig.Commands[1].Env)
|
||||||
|
require.Equal(t, []string{"arg1", "arg2"}, commandConfig.Commands[1].Args)
|
||||||
|
|
||||||
err = os.Remove(configFilePath)
|
err = os.Remove(configFilePath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
Loading…
Reference in a new issue