https://kotlinlang.org logo
#server
Title
# server
a

Andy Alorwu

02/15/2023, 12:20 PM
Hi, I have a question regarding the
application.conf
file when using
ktor.
I’m trying this for the first time so pardon me. I’ve created a conf file as follows:
Copy code
ktor {
  deployment {
      port = 8080
  }

  application {
      modules = [ com.example.ApplicationKt.module ]
  }
}

jwt {
 "secret" = ${m_secret}
 "issuer" = "my_issuer"
 ….
}
I would like to extract the values for the
jwt
properties into an environment file so that i don’t publish my secrets into version control. What’s the best way to do this? I tried accessing the value of
${m_secret}
from a
dev.env
file which I set as
m_secret="secret"
but that didn’t work as I run into the following error:
Could not resolve substitution to a value: ${m_secret}
. Thanks in advance.
d

Dominik Sandjaja

02/15/2023, 1:16 PM
The syntax looks correct, are you sure that the
dev.env
file is correctly used for variable substitution? Have you tried running with a direct environment variable?
g

Goetz Markgraf

02/15/2023, 2:50 PM
m_secret
is the value. I guess, you should use the key:
secret
, probably with its path:
jwt.secret
.
a

Adam Proschek

02/17/2023, 5:48 AM
I think the
.conf
file is just a text file, so I don’t think it’ll grab the actual environment variable. Those variables are used in
Security.kt
in the default project setup, so you could access the environment variables there instead.
a

Andy Alorwu

02/17/2023, 7:34 AM
Thanks for all the help. So I finally figured it out. I’m using IntelliJ and in the
Run/Debug Configurations
I had to enable the use of the
EnvFile
and attach my
dev.env
file as shown in the attached image. After that, I could pass the environment variables from my
dev.env
file.
👍 1
59 Views