From 5601f2bc5f05ca5e55443280e8bc8cbbb6b768b7 Mon Sep 17 00:00:00 2001 From: Irena Rindos Date: Wed, 8 Dec 2021 09:39:04 -0500 Subject: [PATCH] feat(config) Add env and file support to Plugins execution dir --- CHANGELOG.md | 2 + internal/cmd/config/config.go | 7 +++ internal/cmd/config/config_test.go | 52 +++++++++++++++++-- .../content/docs/configuration/plugins.mdx | 8 +-- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8537606dd8..c8773ef153 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. ## Next ### New and Improved +* config: The `execution_dir` field for plugins now supports being set from environment variables + or a file on disk.([PR](https://github.com/hashicorp/boundary/pull/1772)) * config: The `description` field for controllers now supports being set from environment variables or a file on disk ([PR](https://github.com/hashicorp/boundary/pull/1766)) diff --git a/internal/cmd/config/config.go b/internal/cmd/config/config.go index 01abba6525..63d62f767f 100644 --- a/internal/cmd/config/config.go +++ b/internal/cmd/config/config.go @@ -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 } diff --git a/internal/cmd/config/config_test.go b/internal/cmd/config/config_test.go index 0a0e7ddfef..915c7b12f0 100644 --- a/internal/cmd/config/config_test.go +++ b/internal/cmd/config/config_test.go @@ -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) }) } -} \ No newline at end of file +} + +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) + }) + } +} diff --git a/website/content/docs/configuration/plugins.mdx b/website/content/docs/configuration/plugins.mdx index 069e7acb63..c73937506d 100644 --- a/website/content/docs/configuration/plugins.mdx +++ b/website/content/docs/configuration/plugins.mdx @@ -21,6 +21,8 @@ plugins { ``` - `execution_dir` - Specifies a directory that Boundary can use to write and - execute its built-in plugins. This directory must be writeable by the Boundary - user. If not set, Boundary will attempt to create a suitable directory in the - system temporary folder. + execute its built-in plugins. This value can be a direct directory string, + can refer to a file on disk (file://) from which a directory location will be + read; or an env var (env://) from which the directory location will be read. + This directory must be writeable by the Boundary user. If not set, Boundary will + attempt to create a suitable directory in the system temporary folder.