Skip to content
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

argsFile and envFile in launch.json #1944

Closed
SebastianPfliegel opened this issue Dec 29, 2017 · 12 comments · Fixed by #2462
Closed

argsFile and envFile in launch.json #1944

SebastianPfliegel opened this issue Dec 29, 2017 · 12 comments · Fixed by #2462

Comments

@SebastianPfliegel
Copy link
Contributor

SebastianPfliegel commented Dec 29, 2017

Environment data

dotnet --info output:

.NET-Befehlszeilentools (2.0.2)
 
Product Information:
 Version:            2.0.2
 Commit SHA-1 hash:  a04b4bf512
 
Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.2\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

VS Code version: 1.19.1
C# Extension version: 1.13.1

Feature request

In my launch.json I need to pass sensitive data (like passwords) as arguments (or environment variables). As the launch.json is also committed to Git it's unwise to place the arguments in there. In NodeJS it is already possible to pass a file containing all the arguments (microsoft/vscode#14523 and microsoft/vscode-node-debug2@b3e2e8f3).

@SebastianPfliegel
Copy link
Contributor Author

@gregg-miskelly: I wanted to implement this feature myself. The only thing I managed so far is modifying ./src/tools/OptionsSchema.json

Can you give me a hint on where to look for the launch.json being parsed and those values being passed to the debugger? I'm a total Java/TypeScript beginner.

@gregg-miskelly
Copy link
Contributor

Here is how I think you could implement it: VS Code will call resolveDebugConfiguration at the start of debugging. We haven't done anything this way, but I believe you could use this as an opportunity to change the options. So you could read the argsFile/envFile and place the content into the args/env options.

The underlying .NET Cored debugger that this extension launches, isn't an open source product. So if that doesn't work this feature would need to be implemented by a Microsoft employee unfortunately.

@SebastianPfliegel
Copy link
Contributor Author

So, vsdbg parses the launch.json. That would have been my next guess.

Sounds like it shouldn't been touched and vsdbg should be modified instead. And I don't mind if a Microsoft employee finishes the job ;-)

@gregg-miskelly
Copy link
Contributor

Here is the flow: VS Code reads the launch.json file, it sends the content of the active configuration to resolveDebugConfiguration, resolveDebugConfiguration makes any changes it wants to, then VS Code sends that content onto the debug adapter.

You are certainly welcome to wait -- this seems like a fairly simple and useful feature request. That said, I don't think there is anything wrong with implementing this feature in resolveDebugConfiguration, and I don't know when exactly we will get to this feature. So if you are feeling like you would really like this feature, you are more than welcome to try and implement it.

@SebastianPfliegel
Copy link
Contributor Author

My guesses turn out to be correct then.

I'll give it a try :)

@SebastianPfliegel
Copy link
Contributor Author

@gregg-miskelly, got it working :)
Needs some polishing though before creating a PR. Can't find a way to replace the variable ${workspaceFolder}.

@gregg-miskelly
Copy link
Contributor

Can't you use the value of the folder argument?

@SebastianPfliegel
Copy link
Contributor Author

You mean like: if config.envFile contains ${workspaceFolder} substitute it with the value of folder.uri.path? Is this the right approach or is there a ready-to-use function?

@gregg-miskelly
Copy link
Contributor

Yes, that was my suggestion. You could certainly try searching VSCode's source code and see if they either have some code you can borrow or an API you can call. But I don't know the answer off hand.

@SebastianPfliegel
Copy link
Contributor Author

Haven't found an API yet. Pushed PR #1951 though.

@regul4rj0hn
Copy link

Sorry to necro but why is this closed? It is still not possible to use args in combination with the envFile. I guess that it would require a 2-step replacement on launch, which doesn't seem to be implemented (or at least it is not working for me). Is that accurate?

E.g. support the following launch.json :

{
    "version": "0.2.0",
    "configurations": [
        {
          "name": "Launch",
          "type": "go",
          "request": "launch", 
          "mode": "debug",
          "host": "127.0.0.1",
          "program": "${workspaceFolder}/cmd/api",
          "envFile": "${workspaceFolder}/config/.env",
          "args": [
              "-smtp-username", "${env:SMTP_USERNAME}",
              "-smtp-password", "${env:SMTP_PASSWORD}",
              "-auth-url", "${env:AUTH_URL}",
              "-db-dsn", "${env:DB_DSN}",
          ],
          "showLog": true
        }
      ]
}

Expected Result: the args values that point to an env variable get replaced for the correct value whether they reside on the OS or the target envFile.

@gregg-miskelly
Copy link
Contributor

Its closed because @SebastianPfliegel kindly submitted a PR to fix the part that he wanted. I don't know off hand if VS Code makes the syntax you are suggesting there possible. But you are welcome to open another feature request issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants