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.

133 lines
6.6 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.prepare = void 0;
  4. const planner = require("./planner");
  5. const deploymentSummary = require("./deploymentSummary");
  6. const prompt = require("../../prompt");
  7. const refs = require("../../extensions/refs");
  8. const projectUtils_1 = require("../../projectUtils");
  9. const logger_1 = require("../../logger");
  10. const error_1 = require("../../error");
  11. const requirePermissions_1 = require("../../requirePermissions");
  12. const extensionsHelper_1 = require("../../extensions/extensionsHelper");
  13. const secretsUtils_1 = require("../../extensions/secretsUtils");
  14. const secrets_1 = require("./secrets");
  15. const warnings_1 = require("../../extensions/warnings");
  16. const etags_1 = require("../../extensions/etags");
  17. const v2FunctionHelper_1 = require("./v2FunctionHelper");
  18. async function prepare(context, options, payload) {
  19. var _a, _b;
  20. const projectId = (0, projectUtils_1.needProjectId)(options);
  21. const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
  22. const aliases = (0, projectUtils_1.getAliases)(options, projectId);
  23. await (0, extensionsHelper_1.ensureExtensionsApiEnabled)(options);
  24. await (0, requirePermissions_1.requirePermissions)(options, ["firebaseextensions.instances.list"]);
  25. context.have = await planner.have(projectId);
  26. context.want = await planner.want({
  27. projectId,
  28. projectNumber,
  29. aliases,
  30. projectDir: options.config.projectDir,
  31. extensions: options.config.get("extensions"),
  32. });
  33. const etagsChanged = (0, etags_1.detectEtagChanges)(options.rc, projectId, context.have);
  34. if (etagsChanged.length) {
  35. (0, warnings_1.outOfBandChangesWarning)(etagsChanged);
  36. if (!options.force && options.nonInteractive) {
  37. throw new error_1.FirebaseError("Pass the --force flag to overwrite out of band changes in non-interactive mode");
  38. }
  39. else if (!options.force &&
  40. !options.nonInteractive &&
  41. !(await prompt.promptOnce({
  42. type: "confirm",
  43. message: `Do you wish to continue deploying these extension instances?`,
  44. default: false,
  45. }))) {
  46. throw new error_1.FirebaseError("Deployment cancelled");
  47. }
  48. }
  49. const usingSecrets = await Promise.all((_a = context.want) === null || _a === void 0 ? void 0 : _a.map(secrets_1.checkSpecForSecrets));
  50. if (usingSecrets.some((i) => i)) {
  51. await (0, secretsUtils_1.ensureSecretManagerApiEnabled)(options);
  52. }
  53. const usingV2Functions = await Promise.all((_b = context.want) === null || _b === void 0 ? void 0 : _b.map(v2FunctionHelper_1.checkSpecForV2Functions));
  54. if (usingV2Functions) {
  55. await (0, v2FunctionHelper_1.ensureNecessaryV2ApisAndRoles)(options);
  56. }
  57. payload.instancesToCreate = context.want.filter((i) => { var _a; return !((_a = context.have) === null || _a === void 0 ? void 0 : _a.some(matchesInstanceId(i))); });
  58. payload.instancesToConfigure = context.want.filter((i) => { var _a; return (_a = context.have) === null || _a === void 0 ? void 0 : _a.some(isConfigure(i)); });
  59. payload.instancesToUpdate = context.want.filter((i) => { var _a; return (_a = context.have) === null || _a === void 0 ? void 0 : _a.some(isUpdate(i)); });
  60. payload.instancesToDelete = context.have.filter((i) => { var _a; return !((_a = context.want) === null || _a === void 0 ? void 0 : _a.some(matchesInstanceId(i))); });
  61. if (await (0, warnings_1.displayWarningsForDeploy)(payload.instancesToCreate)) {
  62. if (!options.force && options.nonInteractive) {
  63. throw new error_1.FirebaseError("Pass the --force flag to acknowledge these terms in non-interactive mode");
  64. }
  65. else if (!options.force &&
  66. !options.nonInteractive &&
  67. !(await prompt.promptOnce({
  68. type: "confirm",
  69. message: `Do you wish to continue deploying these extension instances?`,
  70. default: true,
  71. }))) {
  72. throw new error_1.FirebaseError("Deployment cancelled");
  73. }
  74. }
  75. if (await (0, warnings_1.displayWarningsForDeploy)(payload.instancesToCreate)) {
  76. if (!options.force && options.nonInteractive) {
  77. throw new error_1.FirebaseError("Pass the --force flag to acknowledge these terms in non-interactive mode");
  78. }
  79. else if (!options.force &&
  80. !options.nonInteractive &&
  81. !(await prompt.promptOnce({
  82. type: "confirm",
  83. message: `Do you wish to continue deploying these extensions?`,
  84. default: true,
  85. }))) {
  86. throw new error_1.FirebaseError("Deployment cancelled");
  87. }
  88. }
  89. const permissionsNeeded = [];
  90. if (payload.instancesToCreate.length) {
  91. permissionsNeeded.push("firebaseextensions.instances.create");
  92. logger_1.logger.info(deploymentSummary.createsSummary(payload.instancesToCreate));
  93. }
  94. if (payload.instancesToUpdate.length) {
  95. permissionsNeeded.push("firebaseextensions.instances.update");
  96. logger_1.logger.info(deploymentSummary.updatesSummary(payload.instancesToUpdate, context.have));
  97. }
  98. if (payload.instancesToConfigure.length) {
  99. permissionsNeeded.push("firebaseextensions.instances.update");
  100. logger_1.logger.info(deploymentSummary.configuresSummary(payload.instancesToConfigure));
  101. }
  102. if (payload.instancesToDelete.length) {
  103. logger_1.logger.info(deploymentSummary.deletesSummary(payload.instancesToDelete));
  104. if (!options.force && options.nonInteractive) {
  105. throw new error_1.FirebaseError("Pass the --force flag to use this command in non-interactive mode");
  106. }
  107. else if (!options.force &&
  108. !options.nonInteractive &&
  109. !(await prompt.promptOnce({
  110. type: "confirm",
  111. message: `Would you like to delete ${payload.instancesToDelete
  112. .map((i) => i.instanceId)
  113. .join(", ")}?`,
  114. default: false,
  115. }))) {
  116. payload.instancesToDelete = [];
  117. }
  118. else {
  119. permissionsNeeded.push("firebaseextensions.instances.delete");
  120. }
  121. }
  122. await (0, requirePermissions_1.requirePermissions)(options, permissionsNeeded);
  123. }
  124. exports.prepare = prepare;
  125. const matchesInstanceId = (dep) => (test) => {
  126. return dep.instanceId === test.instanceId;
  127. };
  128. const isUpdate = (dep) => (test) => {
  129. return dep.instanceId === test.instanceId && !refs.equal(dep.ref, test.ref);
  130. };
  131. const isConfigure = (dep) => (test) => {
  132. return dep.instanceId === test.instanceId && refs.equal(dep.ref, test.ref);
  133. };