Merge pull request #1766 from hashicorp/irenarindos-env-file-controllerconfig

feat(config): Add env and file support to Controller description
pull/1772/head
Irena Rindos 5 years ago committed by GitHub
commit ae4aff85ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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 {

@ -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)
})
}
}

@ -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:

Loading…
Cancel
Save