From 251f0eeea75aab4456ef49fcf6dbc48261f3160d Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Wed, 11 May 2022 12:40:17 -0700 Subject: [PATCH 1/4] Correctly copy over secret environment variables --- .../functions/runtimes/discovery/v1alpha1.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/deploy/functions/runtimes/discovery/v1alpha1.ts b/src/deploy/functions/runtimes/discovery/v1alpha1.ts index 681e7e72ad6..fdb739e60e2 100644 --- a/src/deploy/functions/runtimes/discovery/v1alpha1.ts +++ b/src/deploy/functions/runtimes/discovery/v1alpha1.ts @@ -250,16 +250,15 @@ function parseEndpoints( "secretEnvironmentVariables", "secretEnvironmentVariables", (senvs: ManifestEndpoint["secretEnvironmentVariables"]) => { - if (senvs && senvs.length > 0) { - ep.secretEnvironmentVariables = []; - for (const { key, secret } of senvs) { - ep.secretEnvironmentVariables.push({ - key, - secret: secret || key, // if secret is undefined, assume env var key == secret name - projectId: project, - }); - } + const secretEnvironmentVariables: backend.SecretEnvVar[] = []; + for (const { key, secret } of senvs!) { + secretEnvironmentVariables.push({ + key, + secret: secret || key, // if secret is undefined, assume env var key == secret name + projectId: project, + }); } + return secretEnvironmentVariables; } ); allParsed.push(parsed); From bc1927ab44b51afffb85e1c994f7055518e4dfd4 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Wed, 11 May 2022 12:41:23 -0700 Subject: [PATCH 2/4] Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e69de29bb2d..f236082c310 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -0,0 +1 @@ +- Fixes bug where secret environment variables were not set on functions (#4543) \ No newline at end of file From 0275aafa1de76c9ad5628fff16322ea4cb43ad0b Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Wed, 11 May 2022 12:49:29 -0700 Subject: [PATCH 3/4] Run formatter --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f236082c310..6050b89fbf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1 +1 @@ -- Fixes bug where secret environment variables were not set on functions (#4543) \ No newline at end of file +- Fixes bug where secret environment variables were not set on functions (#4543) From 2ac7c88c3be8731e10113563cee877fd180c6393 Mon Sep 17 00:00:00 2001 From: Thomas Bouldin Date: Wed, 11 May 2022 13:04:37 -0700 Subject: [PATCH 4/4] Add unit tests --- .../functions/runtimes/discovery/v1alpha1.ts | 14 +++++++++++--- .../runtimes/discovery/v1alpha1.spec.ts | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/deploy/functions/runtimes/discovery/v1alpha1.ts b/src/deploy/functions/runtimes/discovery/v1alpha1.ts index fdb739e60e2..5324acce314 100644 --- a/src/deploy/functions/runtimes/discovery/v1alpha1.ts +++ b/src/deploy/functions/runtimes/discovery/v1alpha1.ts @@ -13,7 +13,14 @@ const CHANNEL_NAME_REGEX = new RegExp( "(?[A-Za-z\\d\\-_]+)" ); -export type ManifestEndpoint = backend.ServiceConfiguration & +export interface ManifestSecretEnv { + key: string; + secret?: string; + projectId: string; +} + +type Base = Omit; +export type ManifestEndpoint = Base & backend.Triggered & Partial & Partial & @@ -24,6 +31,7 @@ export type ManifestEndpoint = backend.ServiceConfiguration & region?: string[]; entryPoint: string; platform?: backend.FunctionsPlatform; + secretEnvironmentVariables?: Array; }; export interface Manifest { @@ -249,9 +257,9 @@ function parseEndpoints( ep, "secretEnvironmentVariables", "secretEnvironmentVariables", - (senvs: ManifestEndpoint["secretEnvironmentVariables"]) => { + (senvs: Array) => { const secretEnvironmentVariables: backend.SecretEnvVar[] = []; - for (const { key, secret } of senvs!) { + for (const { key, secret } of senvs) { secretEnvironmentVariables.push({ key, secret: secret || key, // if secret is undefined, assume env var key == secret name diff --git a/src/test/deploy/functions/runtimes/discovery/v1alpha1.spec.ts b/src/test/deploy/functions/runtimes/discovery/v1alpha1.spec.ts index 8bea601adf9..c2569c80273 100644 --- a/src/test/deploy/functions/runtimes/discovery/v1alpha1.spec.ts +++ b/src/test/deploy/functions/runtimes/discovery/v1alpha1.spec.ts @@ -294,7 +294,10 @@ describe("backendFromV1Alpha1", () => { }); // Parser errors; describe("allows valid backends", () => { - const DEFAULTED_ENDPOINT: Omit = { + const DEFAULTED_ENDPOINT: Omit< + backend.Endpoint, + "httpsTrigger" | "secretEnvironmentVariables" + > = { ...MIN_ENDPOINT, platform: "gcfv2", id: "id", @@ -551,6 +554,13 @@ describe("backendFromV1Alpha1", () => { }, ingressSettings: "ALLOW_INTERNAL_ONLY", serviceAccountEmail: "sa@", + secretEnvironmentVariables: [ + { + key: "SECRET", + secret: "SECRET", + projectId: "project", + }, + ], }; const yaml: v1alpha1.Manifest = { @@ -560,6 +570,13 @@ describe("backendFromV1Alpha1", () => { ...MIN_ENDPOINT, httpsTrigger: {}, ...fields, + secretEnvironmentVariables: [ + { + key: "SECRET", + // Missing "secret" + projectId: "project", + }, + ], }, }, };