Hi, I am new to Ktor. How can access secret values...
# ktor
h
Hi, I am new to Ktor. How can access secret values from application.conf in Ktor outside any Application extension function? I am trying to fetch values as environment.config.property("key").toString() in a seperate object outside the application module but it does not work. How to fix that? Thanks in advance
l
Secrets are typically passed as ENV (or better yet using some secrets management service e.g. Vault) like you point out. In ktor the environment object needs to be in scope in order to acess it, which is the case when you create and extension function on Application. So if you really want this mapped in application.config you need a way to pass the environment or read th file yourself. Alternatively why not just read the env directly using System.getEnv...
Oh and if you already passed the environment elsewhere you might need to get the config block before you can access the properties
h
Right, so the environment objects need go be within the Application Scope. I moved the same and passed the secret parameters from there via function parameters to object. Actually I was trying to achieve something like this and I converted it to something like this after passing the secret parameters through Application extension function. This solved the problem I think.Thanks a lot for taking the time to answer. I appreciate it.