diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc53169dd..654daf286b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. ### New and Improved +* config: The `description` field for workers now supports being set + from environment variables or a file on disk + ([PR](https://github.com/hashicorp/boundary/pull/1783)) * config: The `max_open_connections` field for the database field in controllers now supports being set from environment variables or a file on disk ([PR](https://github.com/hashicorp/boundary/pull/1776)) diff --git a/internal/cmd/config/config.go b/internal/cmd/config/config.go index 4c2c6c0cbb..cfc80d7c12 100644 --- a/internal/cmd/config/config.go +++ b/internal/cmd/config/config.go @@ -376,6 +376,14 @@ func Parse(d string) (*Config, error) { return nil, errors.New("Worker name contains non-printable characters") } + result.Worker.Description, err = parseutil.ParsePath(result.Worker.Description) + if err != nil && !errors.Is(err, parseutil.ErrNotAUrl) { + return nil, fmt.Errorf("Error parsing worker description: %w", err) + } + if !strutil.Printable(result.Worker.Description) { + return nil, errors.New("Worker description contains non-printable characters") + } + if result.Worker.TagsRaw != nil { switch t := result.Worker.TagsRaw.(type) { // We allow `tags` to be a simple string containing a URL with schema. diff --git a/internal/cmd/config/config_test.go b/internal/cmd/config/config_test.go index b4bdef63c9..28595d44ed 100644 --- a/internal/cmd/config/config_test.go +++ b/internal/cmd/config/config_test.go @@ -1007,6 +1007,61 @@ func TestControllerDescription(t *testing.T) { } } +func TestWorkerDescription(t *testing.T) { + tests := []struct { + name string + in string + envDescription string + expDescription string + expErr bool + expErrStr string + }{ + { + name: "Valid worker description from env var", + in: ` + worker { + description = "env://WORKER_DESCRIPTION" + }`, + envDescription: "Test worker description", + expDescription: "Test worker description", + expErr: false, + }, { + name: "Invalid worker description", + in: ` + worker { + description = "\uTest worker description" + }`, + expErr: true, + expErrStr: "At 3:22: illegal char escape", + }, { + name: "Not a URL, non-printable description", + in: ` + worker { + description = "\x00" + }`, + expErr: true, + expErrStr: "Worker description contains non-printable characters", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Setenv("WORKER_DESCRIPTION", tt.envDescription) + c, err := Parse(tt.in) + if tt.expErr { + require.EqualError(t, err, tt.expErrStr) + require.Nil(t, c) + return + } + + require.NoError(t, err) + require.NotNil(t, c) + require.NotNil(t, c.Worker) + require.Equal(t, tt.expDescription, c.Worker.Description) + }) + } +} + func TestPluginExecutionDir(t *testing.T) { tests := []struct { name string diff --git a/website/content/docs/configuration/worker.mdx b/website/content/docs/configuration/worker.mdx index eec61e3a76..72e1be5a76 100644 --- a/website/content/docs/configuration/worker.mdx +++ b/website/content/docs/configuration/worker.mdx @@ -23,6 +23,9 @@ worker { the name will be read. - `description` - Specifies a friendly description of this worker. + This value can be a direct description string, can refer to a file on disk + (file://) from which a description will be read; or an env var (env://) from + which the description will be read. - `public_addr` - Specifies the public host or IP address (and optionally port) at which the worker can be reached _by clients for proxying_. This defaults to