No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions-delete.js 4.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const clc = require("colorette");
  5. const functionsConfig = require("../functionsConfig");
  6. const command_1 = require("../command");
  7. const error_1 = require("../error");
  8. const projectUtils_1 = require("../projectUtils");
  9. const prompt_1 = require("../prompt");
  10. const functional_1 = require("../functional");
  11. const requirePermissions_1 = require("../requirePermissions");
  12. const helper = require("../deploy/functions/functionsDeployHelper");
  13. const utils = require("../utils");
  14. const backend = require("../deploy/functions/backend");
  15. const planner = require("../deploy/functions/release/planner");
  16. const fabricator = require("../deploy/functions/release/fabricator");
  17. const executor = require("../deploy/functions/release/executor");
  18. const reporter = require("../deploy/functions/release/reporter");
  19. const containerCleaner = require("../deploy/functions/containerCleaner");
  20. const getProjectNumber_1 = require("../getProjectNumber");
  21. exports.command = new command_1.Command("functions:delete [filters...]")
  22. .description("delete one or more Cloud Functions by name or group name.")
  23. .option("--region <region>", "Specify region of the function to be deleted. " +
  24. "If omitted, functions from all regions whose names match the filters will be deleted. ")
  25. .withForce()
  26. .before(requirePermissions_1.requirePermissions, ["cloudfunctions.functions.list", "cloudfunctions.functions.delete"])
  27. .action(async (filters, options) => {
  28. if (!filters.length) {
  29. return utils.reject("Must supply at least function or group name.");
  30. }
  31. const context = {
  32. projectId: (0, projectUtils_1.needProjectId)(options),
  33. filters: filters.map((f) => ({ idChunks: f.split(/[-.]/) })),
  34. };
  35. const [config, existingBackend] = await Promise.all([
  36. functionsConfig.getFirebaseConfig(options),
  37. backend.existingBackend(context),
  38. ]);
  39. await backend.checkAvailability(context, backend.empty());
  40. const appEngineLocation = functionsConfig.getAppEngineLocation(config);
  41. if (options.region) {
  42. existingBackend.endpoints = { [options.region]: existingBackend.endpoints[options.region] };
  43. }
  44. const plan = planner.createDeploymentPlan({
  45. wantBackend: backend.empty(),
  46. haveBackend: existingBackend,
  47. codebase: "",
  48. filters: context.filters,
  49. deleteAll: true,
  50. });
  51. const allEpToDelete = Object.values(plan)
  52. .map((changes) => changes.endpointsToDelete)
  53. .reduce(functional_1.reduceFlat, [])
  54. .sort(backend.compareFunctions);
  55. if (allEpToDelete.length === 0) {
  56. throw new error_1.FirebaseError(`The specified filters do not match any existing functions in project ${clc.bold(context.projectId)}.`);
  57. }
  58. const deleteList = allEpToDelete.map((func) => `\t${helper.getFunctionLabel(func)}`).join("\n");
  59. const confirmDeletion = await (0, prompt_1.promptOnce)({
  60. type: "confirm",
  61. name: "force",
  62. default: false,
  63. message: "You are about to delete the following Cloud Functions:\n" +
  64. deleteList +
  65. "\n Are you sure?",
  66. }, options);
  67. if (!confirmDeletion) {
  68. throw new error_1.FirebaseError("Command aborted.");
  69. }
  70. const functionExecutor = new executor.QueueExecutor({
  71. retries: 30,
  72. backoff: 20000,
  73. concurrency: 40,
  74. maxBackoff: 40000,
  75. });
  76. try {
  77. const fab = new fabricator.Fabricator({
  78. functionExecutor,
  79. appEngineLocation,
  80. executor: new executor.QueueExecutor({}),
  81. sources: {},
  82. projectNumber: options.projectNumber || (await (0, getProjectNumber_1.getProjectNumber)({ projectId: context.projectId })),
  83. });
  84. const summary = await fab.applyPlan(plan);
  85. await reporter.logAndTrackDeployStats(summary);
  86. reporter.printErrors(summary);
  87. }
  88. catch (err) {
  89. throw new error_1.FirebaseError("Failed to delete functions", {
  90. original: err,
  91. exit: 1,
  92. });
  93. }
  94. await containerCleaner.cleanupBuildImages([], allEpToDelete);
  95. });