vscode launch.json 排除敏感性字符
在使用vscode调试程序是,会遇到敏感信息录入到launch.json并提交的问题,尝试了使用设置envFile,但不成功,查阅了相关资料可以设置inputs
1. 安装cscode插件, Command Variable
https://marketplace.visualstudio.com/items?itemName=rioj7.command-variable
2. 配置
在项目文件夹下,新建secrets.env
VM_HOST=<ssh host>
VM_USERNAME=<ssh 登录用户名>
VM_PASSWORD=<ssh 密码>
在.gitignore中添加
*.env
使用inputs 引入变量,并调用
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Start - VM",
"type": "go",
"request": "launch",
"apiVersion": 2,
"program": "${workspaceFolder}",
"console": "integratedTerminal",
"mode": "debug",
/* "envFile": [
"${workspaceFolder}/secrets.env"
], */
"args": [
"start",
"--host", "${input:envVM_HOST}",
"--repourl", "https://gitee.com/idcf-boat-house/boathouse-calculator.git",
"--username", "${input:envVM_USERNAME}",
"--password", "${input:envVM_PASSWORD}",
"-d"
]
},
],
"inputs": [{
"id": "envVM_HOST",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/secrets.env",
"key": "VM_HOST",
}
},
{
"id": "envVM_USERNAME",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/secrets.env",
"key": "VM_USERNAME",
}
},
{
"id": "envVM_PASSWORD",
"type": "command",
"command": "extension.commandvariable.file.content",
"args": {
"fileName": "${workspaceFolder}/secrets.env",
"key": "VM_PASSWORD",
}
}
]
}
参考资料
https://code.visualstudio.com/docs/editor/variables-reference
https://stackoverflow.com/questions/63033968/how-do-i-use-custom-environment-variables-in-launch-json-in-vscode
欢迎在评论区留下你宝贵的意见,不论好坏都是我前进的动力(cnblogs 排名提升)!
如果喜欢,记得点赞、推荐、关注、收藏、转发 ... ;)