Open tomdavidson opened 4 years ago
@tomdavidson do you mean support dotenv variables in extension environment variables?
Yes, that is what I meant in step #2. If that is not the intended design, then this would be a feature request and not a bug. I attempted to clarify in #418.
@tomdavidson I think this is a feature request and I've already added the feature request
label on the issue.
I can see this could be useful, or is there another to let variables in .env
to override the variables in settings.json
?
Yes, I was thinking about the same tonight. This feature would save me so much time
+1 for this feature request (if for no other reason than stopping GitGuardian warn me about example JWT tokens that I have in test authheaders).
How do I use this feature? Can you write a example. What the content format of .env file
@jackma8ge8 like a normal .env
SECRET_TOKEN=mysecrettoken
@LeCoupa thanks {{$dotenv SECRET_TOKEN}}
I'm trying to do the same thing but it doesn't seem to resolve to dotenv variable. Will you be willing to provide sample files so I can see how the settings.json / .env / .http files link to each other?
I reckon this repo can benefit from having couple of sample implementations written... something like: https://github.com/IdentityServer/IdentityServer4/tree/main/samples
--
oops... didn't notice this is still an open issue... so I guess not supported yet?
@kent-id
Usage
{{$dotenv HOST}}
{{$dotenv TOKEN}}
{{$dotenv HOST}} works {{$dotEnv HOST}} doesnt work. The documentation is incorrect
Maybe there is a different way to accomplish what I want to do. But I would love to see this. Here is why:
I have two different API keys, one for a production environment and one for a staging environment. I don't want to commit those to the .vscode/settings.json so I add them to a .env file.
At this point I want to be able to switch which API key is being used depending on which environment is selected. So ideally I would be able to dynamically change which .env variable is used when selecting a different environment. For example:
.env:
API_KEY_PRODUCTION=ABC
API_KEY_STAGING=DEF
settings.json:
{
"rest-client.environmentVariables": {
"$shared": {},
"staging": {
"apiKey": "{{$dotenv API_KEY_STAGING}}"
},
"production": {
"apiKey": "{{$dotenv API_KEY_PRODUCTION}}"
}
}
}
I could then use {{apiKey}}
within .http
files and it would use the correct api key value regardless of which environment is selected.
Is there another way to accomplish this same functionality?
Ok, something finally clicked right after I typed that above. I'll leave this here for others who might have the same question:
The indirect variable referencing method described in the docs for processEnv
using the '%' symbol works with dotenv, too:
.env:
API_KEY_PRODUCTION=ABC
API_KEY_STAGING=DEF
settings.json
{
"rest-client.environmentVariables": {
"$shared": {},
"staging": {
"apiKey": "API_KEY_STAGING"
},
"production": {
"apiKey": "API_KEY_PRODUCTION"
}
}
}
To be clear, those values are the literal strings "API_KEY_STAGING" and "API_KEY_PRODUCTION".
Then in an .http file:
POST https://example.com/thepath HTTP/1.1
X-Api-Key: {{$dotenv %apiKey}}
This will dynamically replace %apiKey
with either the string "API_KEY_STAGING" or "API_KEY_PRODUCTION" based on the environment selected, and then dotenv
resolves to using one of those from the .env
file.
@devguydavid @jackma8ge8 @cgullcharlie You three helped me to understand that feature! I was reading the docs many times and do not understand until I found this.
(except the "%"...I know that it is needed in this construct but not why :D)
This would be a really helpful feature for AAD auth flow as well. I'd love to be able to do something like this so I can safely commit this to our repo's .vscode/settings.json
file:
{
"rest-client.environmentVariables": {
"$shared": {
"aadV2ClientId": "00000000-0000-0000-0000-000000000000",
"aadV2ClientSecret": "{{$dotenv CLIENT_SECRET}}",
"aadV2TenantId": "00000000-0000-0000-0000-000000000000"
},
"dev": {
"aadV2AppUri": "dev.example.com"
},
"prod": {
"aadV2AppUri": "example.com"
}
}
}
That would let me add a dotenv template and gitignore the real dotenv file. Otherwise the best solution I've found is to put a placeholder secret there and add comments warning users not to commit their actual secrets on accident which is error prone.
dotenv variables do not resolve when used as environment variable value.
Steps to Reproduce:
PASSWORD_PRODUCTION=TkVuZtnoeEPYr
"password": "{{$dotenv PASSWORD_PRODUCTION}}"
@password = {{$dotenv CMIX_PASSWORD_PRODUCTION}}
And, thank you, this is an awesome tool!