Skip to content

Commit ff73e49

Browse files
authored
Disallow dollar sign in opaque value, allow recursive expansion to be implemented in the future (#6268)
Signed-off-by: Bogdan <[email protected]> Signed-off-by: Bogdan <[email protected]>
1 parent 3875a92 commit ff73e49

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

confmap/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ has a `<scheme>` associated with it, and will provide configs for `configURI` th
1313
This format is compatible with the URI definition (see [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986)).
1414
The `<scheme>` MUST be always included in the `configURI`. The scheme for any `Provider` MUST be at least 2
1515
characters long to avoid conflicting with a driver-letter identifier as specified in
16-
[file URI syntax](https://tools.ietf.org/id/draft-kerwin-file-scheme-07.html#syntax).
16+
[file URI syntax](https://datatracker.ietf.org/doc/html/rfc8089#section-2).
1717

1818
## Converter
1919

@@ -37,6 +37,9 @@ that can be used by code that is oblivious to the usage of `Providers` and `Conv
3737
or an individual value (partial configuration) when the `configURI` is embedded into the `Conf` as a values using
3838
the syntax `${configURI}`.
3939

40+
**Limitation:** when embed a `${configURI}` the uri cannot contain dollar sign ("$") character. This is to allow the
41+
current implementation to evolve in the future to support embedded uri within uri, e.g. `${http://my.domain.com?os=${OS}}`.
42+
4043
```terminal
4144
Resolver Provider
4245
Resolve │ │

confmap/resolver.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ func (mr *Resolver) expandValue(ctx context.Context, value interface{}) (interfa
235235
if err != nil {
236236
return nil, false, err
237237
}
238+
if strings.Contains(lURI.opaqueValue, "$") {
239+
return nil, false, fmt.Errorf("the uri %q contains unsupported characters ('$')", lURI.asString())
240+
}
238241
ret, err := mr.retrieveValue(ctx, lURI)
239242
if err != nil {
240243
return nil, false, err

confmap/resolver_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,23 @@ func TestResolverExpandInvalidScheme(t *testing.T) {
474474
assert.EqualError(t, err, `invalid uri: "g_c_s:VALUE"`)
475475
}
476476

477+
func TestResolverExpandInvalidOpaqueValue(t *testing.T) {
478+
provider := newFakeProvider("input", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
479+
return NewRetrieved(map[string]interface{}{"test": []interface{}{map[string]interface{}{"test": "${test:$VALUE}"}}})
480+
})
481+
482+
testProvider := newFakeProvider("test", func(context.Context, string, WatcherFunc) (*Retrieved, error) {
483+
return NewRetrieved(errors.New("invalid value"))
484+
})
485+
486+
resolver, err := NewResolver(ResolverSettings{URIs: []string{"input:"}, Providers: makeMapProvidersMap(provider, testProvider), Converters: nil})
487+
require.NoError(t, err)
488+
resolver.enableExpand = true
489+
490+
_, err = resolver.Resolve(context.Background())
491+
assert.EqualError(t, err, `the uri "test:$VALUE" contains unsupported characters ('$')`)
492+
}
493+
477494
func makeMapProvidersMap(providers ...Provider) map[string]Provider {
478495
ret := make(map[string]Provider, len(providers))
479496
for _, provider := range providers {

0 commit comments

Comments
 (0)