GSI - Employe Self Service Mobile
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.

44 lines
2.0 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.command = void 0;
  4. const command_1 = require("../command");
  5. const projectUtils_1 = require("../projectUtils");
  6. const containerCleaner_1 = require("../deploy/functions/containerCleaner");
  7. const prompt_1 = require("../prompt");
  8. const requirePermissions_1 = require("../requirePermissions");
  9. const error_1 = require("../error");
  10. function getConfirmationMessage(paths) {
  11. let message = "You are about to delete all images in the following directories:\n\n";
  12. for (const path of paths) {
  13. message += `${path}\n`;
  14. }
  15. message += "\nAre you sure?\n";
  16. return message;
  17. }
  18. exports.command = new command_1.Command("functions:deletegcfartifacts")
  19. .description("Deletes all artifacts created by Google Cloud Functions on Google Container Registry.")
  20. .option("--regions <regions>", "Specify regions of artifacts to be deleted. " +
  21. "If omitted, artifacts from all regions will be deleted. " +
  22. "<regions> is a Google defined region list, e.g. us-central1,us-east1,europe-west2.")
  23. .before(requirePermissions_1.requirePermissions, ["storage.objects.delete"])
  24. .action(async (options) => {
  25. const projectId = (0, projectUtils_1.needProjectId)(options);
  26. const regions = options.regions ? options.regions.split(",") : undefined;
  27. const dockerHelper = {};
  28. try {
  29. const gcfPaths = await (0, containerCleaner_1.listGcfPaths)(projectId, regions, dockerHelper);
  30. const confirmDeletion = await (0, prompt_1.promptOnce)({
  31. type: "confirm",
  32. name: "force",
  33. default: false,
  34. message: getConfirmationMessage(gcfPaths),
  35. }, options);
  36. if (!confirmDeletion) {
  37. throw new error_1.FirebaseError("Command aborted.", { exit: 1 });
  38. }
  39. await (0, containerCleaner_1.deleteGcfArtifacts)(projectId, regions, dockerHelper);
  40. }
  41. catch (err) {
  42. throw new error_1.FirebaseError("Command failed.", { original: err });
  43. }
  44. });