-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fix to support passing in JSON as string via command line argumen…
…ts (#280) When running a command like the one below, the secrets are parsed as if they're an array/object. This should resolve that ```bash nx deploy "some-function" ... "--secrets" "[ENV_FILE=some-env]" ```
- Loading branch information
Showing
4 changed files
with
37 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,21 +1,37 @@ | ||
import { logger } from '@nx/devkit' | ||
|
||
export function getValidSecrets(secrets?: string[] | Record<string, string>): string[] { | ||
export function getValidSecrets( | ||
secrets?: string | string[] | Record<string, string> | ||
): string[] { | ||
if (!secrets) { | ||
return [] | ||
} | ||
|
||
if (typeof secrets === 'string') { | ||
try { | ||
secrets = JSON.parse(secrets) | ||
} catch { | ||
throw new Error('Invalid JSON passed to secrets argument') | ||
} | ||
} | ||
|
||
if (!Array.isArray(secrets)) { | ||
secrets = Object.keys(secrets).map((secret) => `${secret}=${secrets[secret]}`) | ||
secrets = Object.keys(secrets).map( | ||
(secret) => `${secret}=${secrets[secret]}` | ||
) | ||
} | ||
|
||
return secrets.map((secret) => { | ||
if (secret.includes('=') && secret.includes(':')) { | ||
return secret | ||
} | ||
return secrets | ||
.map((secret) => { | ||
if (secret.includes('=') && secret.includes(':')) { | ||
return secret | ||
} | ||
|
||
logger.warn(`"${secret}" is not a valid secret! It should be in the following format "ENV_VAR_NAME=SECRET:VERSION"`) | ||
logger.warn( | ||
`"${secret}" is not a valid secret! It should be in the following format "ENV_VAR_NAME=SECRET:VERSION"` | ||
) | ||
|
||
return false | ||
}).filter(Boolean) as string[] | ||
return false | ||
}) | ||
.filter(Boolean) as string[] | ||
} |
This file contains 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 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