[go: up one dir, main page]

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

Require auth for functions:secrets family of commands. #6190

Merged
merged 4 commits into from
Jul 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix bug where functions:secrets:\* family of commands did not work when Firebase CLI is authenticated via GOOGLE_APPLICATION_CREDENTIALS (#6190)
2 changes: 2 additions & 0 deletions src/commands/functions-secrets-access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { logger } from "../logger";
import { Options } from "../options";
import { needProjectId } from "../projectUtils";
import { accessSecretVersion } from "../gcp/secretManager";
import { requireAuth } from "../requireAuth";
import * as secrets from "../functions/secrets";

export const command = new Command("functions:secrets:access <KEY>[@version]")
.description(
"Access secret value given secret and its version. Defaults to accessing the latest version."
)
.before(requireAuth)
.before(secrets.ensureApi)
.action(async (key: string, options: Options) => {
const projectId = needProjectId(options);
Expand Down
2 changes: 2 additions & 0 deletions src/commands/functions-secrets-destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ import {
} from "../gcp/secretManager";
import { promptOnce } from "../prompt";
import { logBullet, logWarning } from "../utils";
import { requireAuth } from "../requireAuth";
import * as secrets from "../functions/secrets";
import * as backend from "../deploy/functions/backend";
import * as args from "../deploy/functions/args";

export const command = new Command("functions:secrets:destroy <KEY>[@version]")
.description("Destroy a secret. Defaults to destroying the latest version.")
.withForce("Destroys a secret without confirmation.")
.before(requireAuth)
.before(secrets.ensureApi)
.action(async (key: string, options: Options) => {
const projectId = needProjectId(options);
Expand Down
2 changes: 2 additions & 0 deletions src/commands/functions-secrets-get.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Table = require("cli-table");

Check warning on line 1 in src/commands/functions-secrets-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 1 in src/commands/functions-secrets-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Require statement not part of import statement

import { requireAuth } from "../requireAuth";
import { Command } from "../command";
import { logger } from "../logger";
import { Options } from "../options";
Expand All @@ -10,18 +11,19 @@

export const command = new Command("functions:secrets:get <KEY>")
.description("Get metadata for secret and its versions")
.before(requireAuth)
.before(secrets.ensureApi)
.before(requirePermissions, ["secretmanager.secrets.get"])
.action(async (key: string, options: Options) => {
const projectId = needProjectId(options);
const versions = await listSecretVersions(projectId, key);

const table = new Table({

Check warning on line 21 in src/commands/functions-secrets-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe assignment of an `any` value

Check warning on line 21 in src/commands/functions-secrets-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe construction of an any type value
head: ["Version", "State"],
style: { head: ["yellow"] },
});
for (const version of versions) {
table.push([version.versionId, version.state]);

Check warning on line 26 in src/commands/functions-secrets-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .push on an `any` value

Check warning on line 26 in src/commands/functions-secrets-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe call of an `any` typed value
}
logger.info(table.toString());

Check warning on line 28 in src/commands/functions-secrets-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe argument of type `any` assigned to a parameter of type `Error`

Check warning on line 28 in src/commands/functions-secrets-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe member access .toString on an `any` value

Check warning on line 28 in src/commands/functions-secrets-get.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unsafe call of an `any` typed value
});
5 changes: 4 additions & 1 deletion src/commands/functions-secrets-prune.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import * as args from "../deploy/functions/args";
import * as backend from "../deploy/functions/backend";
import * as secrets from "../functions/secrets";

import { Command } from "../command";
import { Options } from "../options";
import { needProjectId, needProjectNumber } from "../projectUtils";
import * as secrets from "../functions/secrets";
import { requirePermissions } from "../requirePermissions";
import { isFirebaseManaged } from "../deploymentTool";
import { logBullet, logSuccess } from "../utils";
import { promptOnce } from "../prompt";
import { destroySecretVersion } from "../gcp/secretManager";
import { requireAuth } from "../requireAuth";

export const command = new Command("functions:secrets:prune")
.withForce("Destroys unused secrets without prompt")
.description("Destroys unused secrets")
.before(requireAuth)
.before(secrets.ensureApi)
.before(requirePermissions, [
"cloudfunctions.functions.list",
Expand Down
2 changes: 2 additions & 0 deletions src/commands/functions-secrets-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import {
toSecretVersionResourceName,
} from "../gcp/secretManager";
import { check } from "../ensureApiEnabled";
import { requireAuth } from "../requireAuth";
import * as secrets from "../functions/secrets";
import * as backend from "../deploy/functions/backend";
import * as args from "../deploy/functions/args";

export const command = new Command("functions:secrets:set <KEY>")
.description("Create or update a secret for use in Cloud Functions for Firebase.")
.withForce("Automatically updates functions to use the new secret.")
.before(requireAuth)
.before(secrets.ensureApi)
.before(requirePermissions, [
"secretmanager.secrets.create",
Expand Down
2 changes: 1 addition & 1 deletion src/functions/secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@
/**
* Utility used in the "before" command annotation to enable the API.
*/
export function ensureApi(options: any): Promise<void> {

Check warning on line 79 in src/functions/secrets.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Unexpected any. Specify a different type
const projectId = needProjectId(options);
return ensureApiEnabled.ensure(projectId, "secretmanager.googleapis.com", "runtimeconfig", true);
return ensureApiEnabled.ensure(projectId, "secretmanager.googleapis.com", "secretmanager", true);
}

/**
Expand Down