feat(config): Env/file support for Worker description
This commit is contained in:
1 parent
baa1d88f1f
commit
5f36057f65
4 files changed
+69
No files matched your search
@@ -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))
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user