diff --git a/CHANGELOG.md b/CHANGELOG.md index 122b4e591f..8537606dd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ Canonical reference for changes, improvements, and bugfixes for Boundary. ## Next ### New and Improved - +* 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)) * config: Add support for reading worker tags off of environment variables as well as files. ([PR](https://github.com/hashicorp/boundary/pull/1758)) * config: Add support for go-sockaddr templates to Worker and Controller diff --git a/internal/cmd/config/config.go b/internal/cmd/config/config.go index 27f2673073..01abba6525 100644 --- a/internal/cmd/config/config.go +++ b/internal/cmd/config/config.go @@ -310,6 +310,13 @@ func Parse(d string) (*Config, error) { if !strutil.Printable(result.Controller.Name) { return nil, errors.New("Controller name contains non-printable characters") } + result.Controller.Description, err = parseutil.ParsePath(result.Controller.Description) + if err != nil && !errors.Is(err, parseutil.ErrNotAUrl) { + return nil, fmt.Errorf("Error parsing controller description: %w", err) + } + if !strutil.Printable(result.Controller.Description) { + return nil, errors.New("Controller description contains non-printable characters") + } if result.Controller.AuthTokenTimeToLive != "" { t, err := parseutil.ParseDurationSecond(result.Controller.AuthTokenTimeToLive) if err != nil { diff --git a/internal/cmd/config/config_test.go b/internal/cmd/config/config_test.go index 70134e18be..0a0e7ddfef 100644 --- a/internal/cmd/config/config_test.go +++ b/internal/cmd/config/config_test.go @@ -810,3 +810,57 @@ func TestController_EventingConfig(t *testing.T) { }) } } + +func TestControllerDescription(t *testing.T) { + tests := []struct { + name string + in string + envDescription string + expDescription string + expErr bool + expErrStr string + }{ + { + name: "Valid controller description from env var", + in: ` + controller { + description = "env://CONTROLLER_DESCRIPTION" + }`, + envDescription: "Test controller description", + expDescription: "Test controller description", + expErr: false, + }, { + name: "Invalid controller description from env var", + in: ` + controller { + description = "\uTest controller description" + }`, + expErr: true, + expErrStr: "At 3:22: illegal char escape", + },{ + name: "Not a URL, non-printable description", + in: ` + controller { + description = "\x00" + }`, + expErr: true, + expErrStr: "Controller description contains non-printable characters", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Setenv("CONTROLLER_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.Controller) + require.Equal(t, tt.expDescription, c.Controller.Description) + }) + } +} \ No newline at end of file diff --git a/website/content/docs/configuration/controller.mdx b/website/content/docs/configuration/controller.mdx index 690c772856..70a80e432b 100644 --- a/website/content/docs/configuration/controller.mdx +++ b/website/content/docs/configuration/controller.mdx @@ -25,7 +25,9 @@ controller { (file://) from which an name will be read; or an env var (env://) from which the name will be read. -- `description` - Specifies a friendly description of this controller. +- `description` - Specifies a friendly description of this controller. 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. - `database` - Configuration block with two valid parameters for connecting to Postgres: