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.

export.js 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.displayExportInfo = exports.setSecretParamsToLatest = exports.parameterizeProject = void 0;
  4. const planner_1 = require("../deploy/extensions/planner");
  5. const deploymentSummary_1 = require("../deploy/extensions/deploymentSummary");
  6. const logger_1 = require("../logger");
  7. const secretManager_1 = require("../gcp/secretManager");
  8. const secretsUtils_1 = require("./secretsUtils");
  9. function parameterizeProject(projectId, projectNumber, spec) {
  10. const newParams = {};
  11. for (const [key, val] of Object.entries(spec.params)) {
  12. const p1 = val.replace(projectId, "${param:PROJECT_ID}");
  13. const p2 = p1.replace(projectNumber, "${param:PROJECT_NUMBER}");
  14. newParams[key] = p2;
  15. }
  16. const newSpec = Object.assign({}, spec);
  17. newSpec.params = newParams;
  18. return newSpec;
  19. }
  20. exports.parameterizeProject = parameterizeProject;
  21. async function setSecretParamsToLatest(spec) {
  22. const newParams = Object.assign({}, spec.params);
  23. const extensionVersion = await (0, planner_1.getExtensionVersion)(spec);
  24. const activeSecrets = (0, secretsUtils_1.getActiveSecrets)(extensionVersion.spec, newParams);
  25. for (const [key, val] of Object.entries(newParams)) {
  26. if (activeSecrets.includes(val)) {
  27. const parsed = (0, secretManager_1.parseSecretVersionResourceName)(val);
  28. parsed.versionId = "latest";
  29. newParams[key] = (0, secretManager_1.toSecretVersionResourceName)(parsed);
  30. }
  31. }
  32. return Object.assign(Object.assign({}, spec), { params: newParams });
  33. }
  34. exports.setSecretParamsToLatest = setSecretParamsToLatest;
  35. function displayExportInfo(withRef, withoutRef) {
  36. logger_1.logger.info("The following Extension instances will be saved locally:");
  37. logger_1.logger.info("");
  38. displaySpecs(withRef);
  39. if (withoutRef.length) {
  40. logger_1.logger.info(`Your project also has the following instances installed from local sources. These will not be saved to firebase.json:`);
  41. for (const spec of withoutRef) {
  42. logger_1.logger.info(spec.instanceId);
  43. }
  44. }
  45. }
  46. exports.displayExportInfo = displayExportInfo;
  47. function displaySpecs(specs) {
  48. var _a;
  49. for (let i = 0; i < specs.length; i++) {
  50. const spec = specs[i];
  51. logger_1.logger.info(`${i + 1}. ${(0, deploymentSummary_1.humanReadable)(spec)}`);
  52. logger_1.logger.info(`Configuration will be written to 'extensions/${spec.instanceId}.env'`);
  53. for (const p of Object.entries(spec.params)) {
  54. logger_1.logger.info(`\t${p[0]}=${p[1]}`);
  55. }
  56. if ((_a = spec.allowedEventTypes) === null || _a === void 0 ? void 0 : _a.length) {
  57. logger_1.logger.info(`\tALLOWED_EVENTS=${spec.allowedEventTypes}`);
  58. }
  59. if (spec.eventarcChannel) {
  60. logger_1.logger.info(`\tEVENTARC_CHANNEL=${spec.eventarcChannel}`);
  61. }
  62. logger_1.logger.info("");
  63. }
  64. }