ashald / EnvFile

EnvFile 3.x is a plugin for JetBrains IDEs that allows you to set environment variables for your run configurations from one or multiple files.
MIT License
533 stars 125 forks source link

Why the command line used to extract information for the export isn't executed? #192

Closed acarlstein closed 1 year ago

acarlstein commented 1 year ago

Summary

First, thank you for taking a look into the current issue I created. Much appreciated.

I need some environment variables, which are required for the Spring Boot app to run, which values are obtained from the Secret Manager in GCP.

Description

Normally, if I do the following, it works:

1) I create a file with the exports (i.e.: .envs):

export EVENTHUB_ACCESS_KEY=$(gcloud secrets versions access 1 --secret eventhub-eastus-account-key)

2) I run the command `source .envs'

3) I run the command env and I can see that the gcloud command was executed.

EVENTHUB_ACCESS_KEY=access+key+would+extracted+and+shown+here=

However, this isn't the case with IntelliJ and EnvFile.

In IntelliJ, If I add the export here:

image

image

Then, the gcloud command isn't executed.

In EnvFile, If I add the following to the .env file, per the instructions, and set this as:

image

or

image

Then, it does the same thing.

Acceptance Criteria

I would like to be able to add the line below, into the .env file, and have the gcloud command executed:

EVENTHUB_ACCESS_KEY=$(gcloud secrets versions access 1 --secret eventhub-eastus-account-key)

So, when I run the Spring Boot in IntelliJ, I can see the environment variable (or see the values via adding a breakpoint) with this code example:

fun main(args: Array<String>) {
    val log = LoggerFactory.getLogger(GCloudEnvironmentTestApplication::class.java)
    log.debug("ENVS")
    val env = System.getenv()
    env.forEach { (k, v) -> log.debug("$k:$v") }
    runApplication<GCloudEnvironmentTestApplication>(*args)
}
ashald commented 1 year ago

If you look carefully, you'd notice that UI shows curly braces and you use round braces. :) That is to say that EnvFile emulates bash-like interpolation, but does not actually execute commands within $(...). That being said, as of last release when you specify a file, you can mark it as executable and this way EnvFile will run it and interpret stdout as .env or JSON/YAML depending on your settings. You can create a file that would execute gcloud and output the env vars, and run that file with EnvFile to get them into your run configuration.