How to access Environment secrets in java protobuf code?

Hi Team,

Could you please help us in understand, how to access the environment variables inside the code that we configure in manage secret (refer below link) in Java protobuf?

The Java standard library has System.getEnv("VARIABLE_NAME") for reading environment variables.

Note that there is a two step process to setting up the secret, first defining the secret value and name on project level, then giving a service access to it/assigning it to an environment variable name on service level. Both steps are in that documentation page but it might not be obvious.

In addition to reading the environment variable directly it would also be possible to use the “typesafe config” library which is already on the JVM SDK project class-path since it is used by the SDK itself, defining settings in an application.conf that refer to the env var and then reading the config key using the config library. Note that if you go that path it is best to load the config using ConfigFactory.load in your main and pass the read values to actions and entities as a constructor parameter, so that the config file is not parsed on each request to an action or entity start.

In the application.conf file that looks like this:

my.secret.setting = "some_default_value"
my.secret.setting = ${?VARIABLE_NAME}

Which means that it will use default if the environment variable is not set (for example locally or from tests) but use the env variable value if it is set.