-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support envFile
option in launch.json
#2462
Conversation
@WardenGnaw the first commit in this PR is from @SebastianPfliegel. You are certainly welcome to review that code if you want, but I reviewed it earlier. The second commit is my work and should definitely be reviewed. |
Codecov Report
@@ Coverage Diff @@
## master #2462 +/- ##
==========================================
+ Coverage 64.23% 64.57% +0.33%
==========================================
Files 89 90 +1
Lines 4054 4104 +50
Branches 573 587 +14
==========================================
+ Hits 2604 2650 +46
+ Misses 1283 1282 -1
- Partials 167 172 +5
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly nitpicks and requests for comments.
src/configurationProvider.ts
Outdated
* Parse envFile and add to config.env | ||
*/ | ||
private parseEnvFile(envFile: string, config: vscode.DebugConfiguration): vscode.DebugConfiguration { | ||
if(envFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space after if
src/configurationProvider.ts
Outdated
} | ||
|
||
// remove envFile from config after parsing | ||
if(config.envFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space after if
public Env: { [key: string]: any }; | ||
public Warning: string|null; | ||
|
||
private constructor(env: { [key: string]: any }, warning: string|null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space around |
src/configurationProvider.ts
Outdated
private parseEnvFile(envFile: string, config: vscode.DebugConfiguration): vscode.DebugConfiguration { | ||
if(envFile) { | ||
try { | ||
const parsedFile = ParsedEnvironmentFile.CreateFromFile(envFile, config["env"]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we get a type here?
src/configurationProvider.ts
Outdated
/** | ||
* Try to add all missing attributes to the debug configuration being launched. | ||
*/ | ||
resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> { | ||
// vsdbg does the error checking | ||
|
||
// read from envFile and set config.env | ||
if(config.envFile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space after if
src/configurationProvider.ts
Outdated
|
||
return config; | ||
} | ||
|
||
/** | ||
* Try to add all missing attributes to the debug configuration being launched. | ||
*/ | ||
resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> { | ||
// vsdbg does the error checking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to above line 144 return config
and change to something like // vsdbg will error check the debug configuration fields
src/configurationProvider.ts
Outdated
const openItem: MessageItem = { title: 'Open envFile' }; | ||
let result: MessageItem = await vscode.window.showWarningMessage(message, openItem); | ||
if (result && result.title === openItem.title) { | ||
let doc = await vscode.workspace.openTextDocument(fileName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: type
} | ||
|
||
content.split("\n").forEach(line => { | ||
const r: RegExpMatchArray = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment what regex is looking for?
95c3355
to
45c2f6d
Compare
@WardenGnaw I believe I have fixed all your feedback |
This commit builds on the work of @SebastianPfliegel to finish up support for env files in launch.json. Two changes: 1. Fixes a build break in the way warnings were hooked up. I also decided to add a button to open up the env file that has the warning. 2. Moves the parser into a seperate class and adds a unit test.
45c2f6d
to
f0d5384
Compare
@gregg-miskelly Hey gregg, where can I find documentation on how to use this feature? |
@andreasblueher simply add the path to an existing UTF-8 formatted file. The default value is
When starting the debugger new environment variables will be created with the given values. This way you can hide secrets in different files from your debugger launch config. |
Thank you @SebastianPfliegel it appears for local azure function debugging it behaves differently because I couldn't get it workin, but adding a "local.settings.json" to my repo allowed me to store the env variables and access them from my code. |
@gregg-miskelly - Question: Does the parser do command substitution or support multi-line quoted sections? I am trying to use the feature for my secrets and neither the quoted multiline nor the Just to make this clearer, this is what I'm trying to do:
... or ...
|
Specifically mirroring the version used in the Ruby Gem... https://github.com/bkeepers/dotenv#command-substitution |
@armchairdeity if someone didn't improve my and @gregg-miskelly's code then it's not possible to do so. Maybe I'll find the time to look into that. |
I did take a brief look at the code... it's not terribly complicated, I just don't have time this week. I will try to look at it soon and if I can, contribute. Meanwhile I just embedded Thanks for responding! I don't mind helping achieve the features I ask for... I'll see what I can do to help out! :) |
Adds a new option for launch.json - envFile: it will read environment variables from the given UTF8 file. This way environment variables can be passed to the debugger and launch.json stays clean of sensitive data (like passwords).
This resolves #1944