Skip to content

Commit 8df102b

Browse files
authored
Require auth for functions:secrets family of commands. (#6190)
Need requireAuth call to properly setup credentials when developer is relying on GOOGLE_APPLICATION_CREDENTIALS. Fixes #6186
1 parent e17a4b3 commit 8df102b

File tree

7 files changed

+14
-2
lines changed

7 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fix bug where functions:secrets:\* family of commands did not work when Firebase CLI is authenticated via GOOGLE_APPLICATION_CREDENTIALS (#6190)

src/commands/functions-secrets-access.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { logger } from "../logger";
33
import { Options } from "../options";
44
import { needProjectId } from "../projectUtils";
55
import { accessSecretVersion } from "../gcp/secretManager";
6+
import { requireAuth } from "../requireAuth";
67
import * as secrets from "../functions/secrets";
78

89
export const command = new Command("functions:secrets:access <KEY>[@version]")
910
.description(
1011
"Access secret value given secret and its version. Defaults to accessing the latest version."
1112
)
13+
.before(requireAuth)
1214
.before(secrets.ensureApi)
1315
.action(async (key: string, options: Options) => {
1416
const projectId = needProjectId(options);

src/commands/functions-secrets-destroy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import {
1010
} from "../gcp/secretManager";
1111
import { promptOnce } from "../prompt";
1212
import { logBullet, logWarning } from "../utils";
13+
import { requireAuth } from "../requireAuth";
1314
import * as secrets from "../functions/secrets";
1415
import * as backend from "../deploy/functions/backend";
1516
import * as args from "../deploy/functions/args";
1617

1718
export const command = new Command("functions:secrets:destroy <KEY>[@version]")
1819
.description("Destroy a secret. Defaults to destroying the latest version.")
1920
.withForce("Destroys a secret without confirmation.")
21+
.before(requireAuth)
2022
.before(secrets.ensureApi)
2123
.action(async (key: string, options: Options) => {
2224
const projectId = needProjectId(options);

src/commands/functions-secrets-get.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const Table = require("cli-table");
22

3+
import { requireAuth } from "../requireAuth";
34
import { Command } from "../command";
45
import { logger } from "../logger";
56
import { Options } from "../options";
@@ -10,6 +11,7 @@ import * as secrets from "../functions/secrets";
1011

1112
export const command = new Command("functions:secrets:get <KEY>")
1213
.description("Get metadata for secret and its versions")
14+
.before(requireAuth)
1315
.before(secrets.ensureApi)
1416
.before(requirePermissions, ["secretmanager.secrets.get"])
1517
.action(async (key: string, options: Options) => {

src/commands/functions-secrets-prune.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
import * as args from "../deploy/functions/args";
22
import * as backend from "../deploy/functions/backend";
3+
import * as secrets from "../functions/secrets";
4+
35
import { Command } from "../command";
46
import { Options } from "../options";
57
import { needProjectId, needProjectNumber } from "../projectUtils";
6-
import * as secrets from "../functions/secrets";
78
import { requirePermissions } from "../requirePermissions";
89
import { isFirebaseManaged } from "../deploymentTool";
910
import { logBullet, logSuccess } from "../utils";
1011
import { promptOnce } from "../prompt";
1112
import { destroySecretVersion } from "../gcp/secretManager";
13+
import { requireAuth } from "../requireAuth";
1214

1315
export const command = new Command("functions:secrets:prune")
1416
.withForce("Destroys unused secrets without prompt")
1517
.description("Destroys unused secrets")
18+
.before(requireAuth)
1619
.before(secrets.ensureApi)
1720
.before(requirePermissions, [
1821
"cloudfunctions.functions.list",

src/commands/functions-secrets-set.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ import {
1717
toSecretVersionResourceName,
1818
} from "../gcp/secretManager";
1919
import { check } from "../ensureApiEnabled";
20+
import { requireAuth } from "../requireAuth";
2021
import * as secrets from "../functions/secrets";
2122
import * as backend from "../deploy/functions/backend";
2223
import * as args from "../deploy/functions/args";
2324

2425
export const command = new Command("functions:secrets:set <KEY>")
2526
.description("Create or update a secret for use in Cloud Functions for Firebase.")
2627
.withForce("Automatically updates functions to use the new secret.")
28+
.before(requireAuth)
2729
.before(secrets.ensureApi)
2830
.before(requirePermissions, [
2931
"secretmanager.secrets.create",

src/functions/secrets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function toUpperSnakeCase(key: string): string {
7878
*/
7979
export function ensureApi(options: any): Promise<void> {
8080
const projectId = needProjectId(options);
81-
return ensureApiEnabled.ensure(projectId, "secretmanager.googleapis.com", "runtimeconfig", true);
81+
return ensureApiEnabled.ensure(projectId, "secretmanager.googleapis.com", "secretmanager", true);
8282
}
8383

8484
/**

0 commit comments

Comments
 (0)