Repository navigation
Accept VARLOCK_* aliases for _VARLOCK_* config vars (AWS Lambda) #1295
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| varlock: patch | ||
| "@varlock/nextjs-integration": patch | ||
| --- | ||
|
|
||
| Accept `VARLOCK_ENV_KEY` (and the other `_VARLOCK_*` config vars without the leading underscore) for platforms like AWS Lambda that reject env var names starting with `_` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** | ||
| * Some platforms reject env var names that start with an underscore (AWS Lambda requires | ||
| * `[a-zA-Z][a-zA-Z0-9_]+`), so the `_VARLOCK_*` config vars cannot be set there directly. | ||
| * Each one can also be set without the leading underscore (`VARLOCK_ENV_KEY` for | ||
| * `_VARLOCK_ENV_KEY`); the underscore form wins when both are set. | ||
| * | ||
| * Kept as a plain list of names (rather than importing `VARLOCK_CONFIG_ENV_VARS`) because this | ||
| * runs inside the edge-safe init bundles. A test keeps it in sync with reserved-vars.ts. | ||
| */ | ||
| export const VARLOCK_CONFIG_ENV_VAR_NAMES = [ | ||
| '_VARLOCK_ENV_KEY', | ||
| '_VARLOCK_ALLOW_PLAINTEXT_FROZEN_ENV', | ||
| '_VARLOCK_CACHE_KEY', | ||
| '_VARLOCK_REDACT_STDOUT', | ||
| '_VARLOCK_FILTER', | ||
| '_VARLOCK_THROW_ON_LOAD_ERROR', | ||
| '_VARLOCK_DYNAMIC_BUILD_ACCESS_MODE', | ||
| '_VARLOCK_USE_INJECTED_ENV', | ||
| '_VARLOCK_ALLOW_EMPTY_CONFIG', | ||
| '_VARLOCK_USE_FROZEN_ENV', | ||
| ] as const; | ||
|
|
||
| /** The underscore-free alias names themselves (`VARLOCK_ENV_KEY`, ...) */ | ||
| export const VARLOCK_CONFIG_ENV_VAR_ALIAS_NAMES: ReadonlySet<string> = new Set( | ||
| VARLOCK_CONFIG_ENV_VAR_NAMES.map((name) => name.slice(1)), | ||
| ); | ||
|
|
||
| type ConfigEnvVarName = typeof VARLOCK_CONFIG_ENV_VAR_NAMES[number]; | ||
|
|
||
| /** | ||
| * Read a `_VARLOCK_*` config var, falling back to its underscore-free alias. Use where the | ||
| * value matters even if process.env is read-only (so `applyVarlockConfigEnvAliases` could | ||
| * not copy the alias over). | ||
| */ | ||
| export function getVarlockConfigEnvVar( | ||
| name: ConfigEnvVarName, | ||
| env: Record<string, string | undefined> | undefined = (globalThis as any).process?.env, | ||
| ): string | undefined { | ||
| return env?.[name] || env?.[name.slice(1)] || undefined; | ||
| } | ||
|
|
||
| /** | ||
| * Copy each underscore-free alias (`VARLOCK_ENV_KEY`) onto its `_VARLOCK_*` name when that | ||
| * name is not already set, so every reader of the `_VARLOCK_*` name sees it. | ||
| * Mutates `env` (process.env by default). Safe to call more than once, and a no-op where | ||
| * process.env is missing or read-only (some edge runtimes). | ||
| */ | ||
| export function applyVarlockConfigEnvAliases( | ||
| env: Record<string, string | undefined> | undefined = (globalThis as any).process?.env, | ||
| ) { | ||
| if (!env) return; | ||
| for (const name of VARLOCK_CONFIG_ENV_VAR_NAMES) { | ||
| if (env[name] !== undefined && env[name] !== '') continue; | ||
| const aliasValue = env[name.slice(1)]; | ||
|
pullfrog[bot] marked this conversation as resolved.
Resolved
|
||
| if (aliasValue === undefined || aliasValue === '') continue; | ||
| try { | ||
| env[name] = aliasValue; | ||
| } catch { | ||
| // read-only process.env | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.