Skip to content

PropertySource to read a property's value from file #20842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
skuzzle opened this issue Apr 5, 2020 · 4 comments
Closed

PropertySource to read a property's value from file #20842

skuzzle opened this issue Apr 5, 2020 · 4 comments
Labels
status: duplicate A duplicate of another issue

Comments

@skuzzle
Copy link

skuzzle commented Apr 5, 2020

I want to use docker-swarm secrets in my Dockerized Spring-Boot application. These secrets are mounted as special files into the docker container: the secret text is accessible by reading the file at /run/secrets/<secret_name>. This is deemed best-practice in secret handling regarding containers (as opposed to injecting the secret text as environment variable, which isn't even supported by docker-swarm).

It would be great if Spring-Boot offered a way to set a property's value from the content of a file so I can write something like this:

spring.data.mongodb.password=${fileContent./var/run/secrets/mongo_db_password}

This would be similar to how RandomValuePropertySource works. Looking at its source it should be straight forward to provide a PropertySource implementation for reading file content. However, I wasn't able to properly inject my custom PropertySource into the Spring-Boot application start up process.

I also wonder if there might be already some spring magic that would allow to set a property's value from file?

If this is a valid feature request, I'd be happy to help out with a pull request and a PropertySource implementation thats handled similar to the RandomValuePropertySource. Otherwise it would be great to provide some information on how I could properly inject my PropertySource into the start up process.

@bclozel
Copy link
Member

bclozel commented Apr 5, 2020

Could be a duplicate of spring-projects/spring-framework#21961 or #19990.

@wilkinsona
Copy link
Member

However, I wasn't able to properly inject my custom PropertySource into the Spring-Boot application start up process.

You can do this using an EnvironmentPostProcessor registered in META-INF/spring.factories.

I agree with @bclozel that this is a duplicate of #19990 or spring-projects/spring-framework#21961.

@wilkinsona wilkinsona added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 6, 2020
@skuzzle
Copy link
Author

skuzzle commented Apr 6, 2020

I'm sorry for raising the duplicate.

I actually tried using the EnvironmentPostProcessor but just now I found an embarassing copy/ paste failure which prevented it from functioning properly (I registered the new RandomPropertySource() instead of my custom implementation ...)
So, this works for me and I happily look forward to having an official solution in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants