Skip to content

Commit

Permalink
Partially handle case of not found tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Oct 27, 2023
1 parent bd13e11 commit 1620ff3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
6 changes: 4 additions & 2 deletions cmd/revad/pkg/config/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ func applyTemplateString(l Lookuper, p setter, v reflect.Value) error {
return err
}
if val == nil {
val = ""
// key was not found, just keep it but stop further parsing
break
}

new, err := replaceTemplate(s, tmpl, val)
Expand Down Expand Up @@ -175,7 +176,8 @@ func applyTemplateInterface(l Lookuper, p setter, v reflect.Value) error {
return err
}
if val == nil {
val = ""
// key was not found, just keep it but stop further parsing
break
}

new, err := replaceTemplate(s, tmpl, val)
Expand Down
18 changes: 10 additions & 8 deletions cmd/revad/pkg/config/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ func TestApplyTemplate(t *testing.T) {
Config: map[string]any{
"drivers": map[string]any{
"sql": map[string]any{
"db_username": "{{ vars.db_username }}",
"db_password": "{{ vars.db_password }}",
"key": "value",
"port": "{{ vars.port }}",
"db_username": "{{ vars.db_username }}",
"db_password": "{{ vars.db_password }}",
"key": "value",
"port": "{{ vars.port }}",
"user_and_token": "{{ vars.db_username }} and {{.Token}}",
},
},
},
Expand All @@ -125,10 +126,11 @@ func TestApplyTemplate(t *testing.T) {
assert.ErrorIs(t, err, nil)
assert.Equal(t, "localhost:1901", cfg2.Shared.GatewaySVC)
assert.Equal(t, map[string]any{
"db_username": "root",
"db_password": "secretpassword",
"key": "value",
"port": 1000,
"db_username": "root",
"db_password": "secretpassword",
"key": "value",
"port": 1000,
"user_and_token": "root and {{.Token}}",
}, cfg2.GRPC.Services["authregistry"][0].Config["drivers"].(map[string]any)["sql"])
assert.Equal(t, map[string]any{
"db_host": "http://localhost:1000",
Expand Down

0 comments on commit 1620ff3

Please sign in to comment.