feat(config): Add env and file support to Controller description
This commit is contained in:
1 parent
8c842df8a8
commit
161916f6d3
4 files changed
+67
-2
No files matched your search
+3
-1
@@ -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 go-sockaddr templates to Worker and Controller
|
||||
addresses. ([PR](https://github.com/hashicorp/boundary/pull/1731))
|
||||
* host: Plugin-based host catalogs will now schedule updates for all
|
||||
|
||||
@@ -308,6 +308,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 {
|
||||
|
||||
@@ -524,3 +524,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:
|
||||
|
||||
|
||||
Reference in new issue
Block a user