Infisical / infisical

♾ Infisical is the open-source secret management platform: Sync secrets across your team/infrastructure, prevent secret leaks, and manage internal PKI
https://infisical.com
Other
15.18k stars 880 forks source link

Python + Inject Infisical CLI + vscode + local development + launch.json #835

Open yaronlevi opened 1 year ago

yaronlevi commented 1 year ago

Hi,

Currently, there is no way to work locally with Python (the Infisical CLI inject way), in Vscode with the launch.json. So the desired result is that I should be able to click the green PLAY button in Vscode, and the envs will be injected by Infisical CLI.

Iv'e created this issue per the request of @maidul98

Detailed information can be found in this slack thread:

https://infisical-users.slack.com/archives/C04BSBMQAQ7/p1691421014342469

Thanks!

mystmaker33 commented 1 year ago

+1!

daninge commented 1 year ago

You can create a wrapper python script (e.g. infisical_secrets_injector.py) in your project that takes the debug command generated by the launch.json file, and prepends the infisical run command so that the environment variables are in place before even the debugger itself starts up

infisical_secrets_injector.py

import subprocess, sys
sys.exit(subprocess.run(
    args=["infisical", "run", "--", "python3" ] + sys.argv[1:],
).returncode)

You can then add this script to the pythonArgs section of your launch.json

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug my app",
            "type": "python",
            "request": "launch",
            "program": "the_python_app_you_want_to_debug.py",
            "pythonArgs": ["infisical_secrets_injector.py"],
            "args": ["actual", "args", "for", "your", "app"],
            "console": "integratedTerminal",
            "justMyCode": true,
        }
    ]
}

(Kudos to Merramore's comment on this Stack Overflow post for coming up with this idea)

yaronlevi commented 1 year ago

@daninge98 Thank you for the detailed information! I'll check this later.

imrane commented 1 year ago

Here's my setup if it helps anyone - using FastAPI