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
Secrets: update guidance and parsing for local multiline env vars #1890
Conversation
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
Preview url: https://benefits-1890--cal-itp-previews.netlify.app |
6b1e3e5
to
f8bc1e0
Compare
Preview url: https://benefits-1890--cal-itp-previews.netlify.app |
f8bc1e0
to
29c84b6
Compare
Preview url: https://benefits-1890--cal-itp-previews.netlify.app |
🤔 Cypress tests are passing locally for me using the exact same steps as the workflow... ?? EDIT: I had an outdated Docker image, hence the addition in the secrets helper of the unescaping of newlines. |
Docker, bash, etc. support multiline environment variables, by simply wrapping the value in single quotes with newlines, e.g. in an .env file: multi_line_value='first line second line third line' Resulting in the expected: $ echo "$multi_line_value" first line second line third line Due to a quirk in VS Code's Python extension, multiline values are not parsed, see https://code.visualstudio.com/docs/python/environments#_environment-variables > ... Multiline values aren't supported ... And more ongoing discussion at microsoft/vscode-python#18307 When running locally in e.g. Debug mode, and secrets are read dynamically from the environment, Python loses the multiline value and we end up with: >> value = os.environ.get("multi_line_value") >> print(value) first line This changes the samples and docs so literal newlines are added to the value of the environment variable in an .env file: multi_line_value='first line\nsecond line\nthird line' But the initial value read by Python contains _escaped_ newline characters: first line\\nsecond line\\nthird line Hence unescaping so that local secrets contain the actual newline character: first line\nsecond line\nthird line
29c84b6
to
a7084bb
Compare
Preview url: https://benefits-1890--cal-itp-previews.netlify.app |
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.
This looks good to me 👍
Docker, bash, etc. support multiline environment variables, by simply wrapping the value in single quotes with newlines, e.g. in an .env file:
Resulting in the expected:
Due to a quirk in VS Code's Python extension, multiline values are not parsed, see https://code.visualstudio.com/docs/python/environments#_environment-variables
And more ongoing discussion at microsoft/vscode-python#18307
When running locally in e.g. Debug mode, and secrets are read dynamically from the environment, Python loses the multiline value and we end up with:
This changes the samples and docs so literal newlines are added to the value of the environment variable in an .env file:
But the initial value read by Python contains escaped newline characters:
first line\\nsecond line\\nthird line
Hence unescaping in the secrets helper, so that local secrets contain the actual newline character:
first line\nsecond line\nthird line