How to use the application loader to set application secret?


(Mohamedali10) #1

I want to update the application secret property that exist in the application.conf file from the application loader. In fact, it seems the only way that I can do to modify the applicaton.conf properties such as the application secret from a web interface.


(Marcos Pereira) #2

Hi @Mohamedali101,

Why do you need that? Can you share your current code so that we can give you some direction based on the existing code? Are you using compile-time dependency injection or runtime with Guice?

Best.


#3

We use compile-time DI and in our main app class:

override lazy val configuration: Configuration = MySecretsManager.populate(super.configuration, context.environment.mode)

Then MySecretsManager fetches the application secret from AWS ParameterStore and appends it to the configuration that Play provides (but only in production):

val extra: Map[String, String] = fetchSecrets() // Your fetching implementation goes here
playConfiguration ++ Configuration.from(extra)  // Override Play's config with our fetched secrets

(MySecretsManager is a class I wrote myself, it’s not included, you’ll need to implement your own that handles the fetching the way you want it. There are probably some more or less usable github projects out there for this type of thing…)