Skip to content
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

Add fix to support passing in JSON as string via command line arguments #280

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gcp-cloud-run/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-extend/gcp-cloud-run",
"version": "10.1.1",
"version": "10.1.2",
"homepage": "https://github.com/TriPSs/nx-extend/blob/master/packages/gcp-cloud-run/README.md",
"bugs": {
"url": "https://github.com/tripss/nx-extend/issues"
Expand Down
34 changes: 25 additions & 9 deletions packages/gcp-cloud-run/src/utils/get-valid-secrets.ts
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[]
}
2 changes: 1 addition & 1 deletion packages/gcp-functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-extend/gcp-functions",
"version": "13.1.4",
"version": "13.1.5",
"homepage": "https://github.com/TriPSs/nx-extend/blob/master/packages/gcp-functions/README.md",
"bugs": {
"url": "https://github.com/tripss/nx-extend/issues"
Expand Down
12 changes: 10 additions & 2 deletions packages/gcp-functions/src/utils/get-valid-secrets.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
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 (!Array.isArray(secrets)) {
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]}`)
}

Expand Down
Loading