Skip to content

Commit

Permalink
Merge pull request #1766 from hashicorp/irenarindos-env-file-controll…
Browse files Browse the repository at this point in the history
…erconfig

feat(config): Add env and file support to Controller description
  • Loading branch information
irenarindos authored Dec 8, 2021
2 parents faabfc0 + 1f43ec1 commit ae4aff8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions internal/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
54 changes: 54 additions & 0 deletions internal/cmd/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
4 changes: 3 additions & 1 deletion website/content/docs/configuration/controller.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit ae4aff8

Please # to comment.