how to preserve quotes when referencing a value using placeholders in a YAML file with Spring Cloud Config?

Viewed 214

I have a password ending in a colon, say abc:, that I want to store encrypted in GIT and decrypt with Spring Cloud Config. Here's the expected YAML file :

spring:
  datasource:
    password: "abc:"

Here's the encrypted YAML file :

spring:
  datasource:
    password: "{cipher}blablabla"

And here's what I receive from Spring Cloud Config after decryption :

spring:
  datasource:
    password: abc:

Which is interpreted as a key instead of a value by the YAML parser.

Is there a way to tell Spring Cloud Config that I want to surround the decrypted value in quotes or something similar ?

EDIT

My mistake, Spring Could Config server actually adds quotes when needed after decrypting the string. So the result is as expected :

spring:
  datasource:
    password: 'abc:'

The issue is that when I reference this value using a placeholder the quotes disappear in the process :

a_key:
  another_key: ${spring.datasource.password}

becomes when processed by Spring Could Config server :

a_key:
  another_key: abc:

So the question really is : how to preserve quotes when referencing a value using placeholders in a YAML file with Spring Cloud Config?

1 Answers

The only way I found so far is to leave the placeholder resolution to runtime by escaping the $ character :

a_key:
  another_key: \${spring.datasource.password}

The resulting YAML served by Spring Cloud Config server is then :

a_key:
  another_key: ${spring.datasource.password}

Link to Spring Cloud Config documentation here

Related