Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions-secrets-prune.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const backend = require("../deploy/functions/backend");
  5. const command_1 = require("../command");
  6. const projectUtils_1 = require("../projectUtils");
  7. const secrets_1 = require("../functions/secrets");
  8. const requirePermissions_1 = require("../requirePermissions");
  9. const deploymentTool_1 = require("../deploymentTool");
  10. const utils_1 = require("../utils");
  11. const prompt_1 = require("../prompt");
  12. const secretManager_1 = require("../gcp/secretManager");
  13. exports.command = new command_1.Command("functions:secrets:prune")
  14. .withForce("Destroys unused secrets without prompt")
  15. .description("Destroys unused secrets")
  16. .before(requirePermissions_1.requirePermissions, [
  17. "cloudfunctions.functions.list",
  18. "secretmanager.secrets.list",
  19. "secretmanager.versions.list",
  20. "secretmanager.versions.destroy",
  21. ])
  22. .action(async (options) => {
  23. const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
  24. const projectId = (0, projectUtils_1.needProjectId)(options);
  25. (0, utils_1.logBullet)("Loading secrets...");
  26. const haveBackend = await backend.existingBackend({ projectId });
  27. const haveEndpoints = backend
  28. .allEndpoints(haveBackend)
  29. .filter((e) => (0, deploymentTool_1.isFirebaseManaged)(e.labels || []));
  30. const pruned = await (0, secrets_1.pruneSecrets)({ projectNumber, projectId }, haveEndpoints);
  31. if (pruned.length === 0) {
  32. (0, utils_1.logBullet)("All secrets are in use. Nothing to prune today.");
  33. return;
  34. }
  35. (0, utils_1.logBullet)(`Found ${pruned.length} unused active secret versions:\n\t` +
  36. pruned.map((sv) => `${sv.secret}@${sv.version}`).join("\n\t"));
  37. if (!options.force) {
  38. const confirm = await (0, prompt_1.promptOnce)({
  39. name: "destroy",
  40. type: "confirm",
  41. default: true,
  42. message: `Do you want to destroy unused secret versions?`,
  43. }, options);
  44. if (!confirm) {
  45. (0, utils_1.logBullet)("Run the following commands to destroy each unused secret version:\n\t" +
  46. pruned
  47. .map((sv) => `firebase functions:secrets:destroy ${sv.secret}@${sv.version}`)
  48. .join("\n\t"));
  49. return;
  50. }
  51. }
  52. await Promise.all(pruned.map((sv) => (0, secretManager_1.destroySecretVersion)(projectId, sv.secret, sv.version)));
  53. (0, utils_1.logSuccess)("Destroyed all unused secrets!");
  54. });