feat(config) Add env and file support to Plugins execution dir

This commit is contained in:
Irena Rindos committed 2021-12-08 10:48:24 -05:00
1 parent ae4aff85ca
commit 5601f2bc5f
4 files changed
+63 -6

No files matched your search

+7
View File
@@ -496,6 +496,13 @@ func Parse(d string) (*Config, error) {
return nil, fmt.Errorf(`too many "events" nodes (max 1, got %d)`, len(eventList.Items))
}
if result.Plugins.ExecutionDir != "" {
result.Plugins.ExecutionDir, err = parseutil.ParsePath(result.Plugins.ExecutionDir)
if err != nil && !errors.Is(err, parseutil.ErrNotAUrl) {
return nil, fmt.Errorf("Error parsing plugins execution dir: %w", err)
}
}
return result, nil
}
+49 -3
View File
@@ -837,13 +837,13 @@ func TestControllerDescription(t *testing.T) {
}`,
expErr: true,
expErrStr: "At 3:22: illegal char escape",
},{
}, {
name: "Not a URL, non-printable description",
in: `
controller {
description = "\x00"
}`,
expErr: true,
expErr: true,
expErrStr: "Controller description contains non-printable characters",
},
}
@@ -863,4 +863,50 @@ func TestControllerDescription(t *testing.T) {
require.Equal(t, tt.expDescription, c.Controller.Description)
})
}
}
}
func TestPluginExecutionDir(t *testing.T) {
tests := []struct {
name string
in string
envPluginExecutionDir string
expPluginExecutionDir string
expErr bool
expErrStr string
}{
{
name: "Valid plugin execution dir from env var",
in: `
plugins {
execution_dir = "env://PLUGIN_EXEC_DIR"
}`,
envPluginExecutionDir: `/var/run/boundary/plugin-exec`,
expPluginExecutionDir: `/var/run/boundary/plugin-exec`,
expErr: false,
}, {
name: "Invalid plugin execution dir from env var",
in: `
plugins {
execution_dir ="\ubad plugin directory"
}`,
expErr: true,
expErrStr: "At 3:28: illegal char escape",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("PLUGIN_EXEC_DIR", tt.envPluginExecutionDir)
p, err := Parse(tt.in)
if tt.expErr {
require.EqualError(t, err, tt.expErrStr)
require.Nil(t, p)
return
}
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.Plugins)
require.Equal(t, tt.expPluginExecutionDir, p.Plugins.ExecutionDir)
})
}
}