SteeltoeOSS / Steeltoe

.NET Components for Externalized Configuration, Database Connectors, Service Discovery, Logging and Distributed Tracing, Application Management, Security, and more.
https://steeltoe.io
Apache License 2.0
1.01k stars 163 forks source link

Escaped dots in Spring configuration keys are not properly translated #1359

Open bart-vmware opened 2 months ago

bart-vmware commented 2 months ago

Describe the bug

As described at https://docs.spring.io/spring-boot/reference/features/external-config.html#features.external-config.yaml.mapping-to-properties, Spring Boot supports escaping dots in configuration keys:

When binding to scalar values, keys with . in them do not need to be surrounded by []. Scalar values include enums and all types in the java.lang package except for Object. Binding a.b=c to Map<String, String> will preserve the . in the key and return a Map with the entry {"a.b"="c"}. For any other types you need to use the bracket notation if your key contains a .. For example, binding a.b=c to Map<String, Object> will return a Map with the entry {"a"={"b"="c"}} whereas [a.b]=c will return a Map with the entry {"a.b"="c"}.

Based on that, Steeltoe should translate the Spring configuration key a.b.c to a:b:c (which it already does). But also translate [a.b].c to a.b:c, which is currently not the case. And translate arrays, such as a[0].b to a:0:b (which it already does).

Because there's no way to escape colons in .NET configuration keys, there's nothing Steeltoe can do to properly translate when the Spring key contains a colon.

This affects the various Steeltoe configuration providers, such as Placeholder, SpringBoot, and Config Server. Key translation isn't correct everywhere and there's limited test coverage.

bart-vmware commented 2 months ago

Related to https://github.com/spring-cloud/spring-cloud-config/issues/1595.