firebase-tools 15.28.1 → 15.28.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,266 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = void 0;
4
+ const requireConfig_1 = require("../requireConfig");
5
+ const command_1 = require("../command");
6
+ const config_1 = require("../functions/kits/config");
7
+ const path_1 = require("path");
8
+ const error_1 = require("../error");
9
+ const prompt_1 = require("../prompt");
10
+ const functional_1 = require("../functional");
11
+ const posix_1 = require("path/posix");
12
+ const projectUtils_1 = require("../projectUtils");
13
+ const utils_1 = require("../utils");
14
+ const backend = require("../deploy/functions/backend");
15
+ const planner = require("../deploy/functions/release/planner");
16
+ const executor = require("../deploy/functions/release/executor");
17
+ const fabricator = require("../deploy/functions/release/fabricator");
18
+ const functionsDeployHelper_1 = require("../deploy/functions/functionsDeployHelper");
19
+ const functionsConfig = require("../functionsConfig");
20
+ const getProjectNumber_1 = require("../getProjectNumber");
21
+ const reporter = require("../deploy/functions/release/reporter");
22
+ const logger_1 = require("../logger");
23
+ exports.command = new command_1.Command("functions:kits:uninstall")
24
+ .description("uninstall a function kit or kit instance from your project")
25
+ .before(requireConfig_1.requireConfig)
26
+ .option("--kit <kitId>", "")
27
+ .option("--instance <instanceId>", "")
28
+ .action(async (options) => {
29
+ const firebaseConfig = options.config;
30
+ if (options.instance && options.kit) {
31
+ throw new error_1.FirebaseError("Cannot specify both --kit and --instance. Please specify only one.");
32
+ }
33
+ if (!options.instance && !options.kit) {
34
+ throw new error_1.FirebaseError("Must specify either --kit or --instance.");
35
+ }
36
+ if (typeof options.instance === "string") {
37
+ await handleInstance(options, firebaseConfig);
38
+ }
39
+ if (typeof options.kit === "string") {
40
+ await handleKit(options, firebaseConfig);
41
+ }
42
+ });
43
+ async function handleKit(options, config) {
44
+ const kitId = options.kit;
45
+ const kits = (0, config_1.listKitConfigs)(config.src);
46
+ const kitConfig = kits.find((k) => k.kit === kitId);
47
+ if (!kitConfig) {
48
+ throw new error_1.FirebaseError(`Kit ${kitId} not found in firebase.json. Use functions:kits:list to get all existing kit IDs.`);
49
+ }
50
+ const conservativeDeletion = nonstandardKitLayout(kitConfig);
51
+ logger_1.logger.debug(`Kit ${kitConfig.kit} uninstall mode: conservativeDeletion=${conservativeDeletion}`);
52
+ if (Object.keys(kitConfig.instances).length > 0) {
53
+ const willBlindDeleteMsg = conservativeDeletion
54
+ ? ""
55
+ : " and permanently remove their source code and configuration";
56
+ if (!(await (0, prompt_1.confirm)({
57
+ message: `Uninstall will delete all active instances of this kit${willBlindDeleteMsg}. You have the following active instances that will be deleted:
58
+ ${Object.keys(kitConfig.instances).join(",")}
59
+ Do you want to continue with uninstall (y/N)?`,
60
+ default: false,
61
+ nonInteractive: options.nonInteractive,
62
+ force: options.force,
63
+ }))) {
64
+ return;
65
+ }
66
+ }
67
+ await uninstallKit(options, config, kitConfig);
68
+ return;
69
+ }
70
+ async function handleInstance(options, config) {
71
+ const instanceId = options.instance;
72
+ const projectId = (0, projectUtils_1.needProjectId)(options);
73
+ const kits = (0, config_1.listKitConfigs)(config.src);
74
+ const kitForInstance = kits.find((k) => instanceId in k.instances);
75
+ if (typeof kitForInstance === "undefined") {
76
+ throw new error_1.FirebaseError(`Instance ID ${instanceId} not found in firebase.json`);
77
+ }
78
+ const instanceConfigDirPath = kitForInstance.instances[instanceId];
79
+ const conservativeDeletion = nonstandardKitLayout(kitForInstance);
80
+ logger_1.logger.debug(`Kit ${kitForInstance.kit} uninstall mode: conservativeDeletion=${conservativeDeletion}`);
81
+ const projectsWithConfigs = [];
82
+ const configDirContents = config.lsProjectDir(instanceConfigDirPath);
83
+ const fileNames = configDirContents.filter((f) => f.isFile()).map((f) => f.name);
84
+ for (const fileName of fileNames) {
85
+ if (!fileName.startsWith(".env.")) {
86
+ continue;
87
+ }
88
+ projectsWithConfigs.push(fileName.slice(".env.".length));
89
+ }
90
+ if (projectsWithConfigs.length > 0 && !projectsWithConfigs.includes(projectId)) {
91
+ throw new error_1.FirebaseError(`Instance at ${instanceConfigDirPath} contains no .env file for current project`);
92
+ }
93
+ if (projectsWithConfigs.length === 0 || projectsWithConfigs.length === 1) {
94
+ if (Object.keys(kitForInstance.instances).length > 1) {
95
+ await uninstallInstance(options, config, instanceId, instanceConfigDirPath, conservativeDeletion);
96
+ return;
97
+ }
98
+ const confirmMsg = `This is the last remaining instance for kit ${kitForInstance.kit}. This will delete all source and configuration code. Proceed? (y/N)`;
99
+ if (!(await (0, prompt_1.confirm)({
100
+ message: confirmMsg,
101
+ default: false,
102
+ nonInteractive: options.nonInteractive,
103
+ force: options.force,
104
+ }))) {
105
+ return;
106
+ }
107
+ await uninstallKit(options, config, kitForInstance);
108
+ return;
109
+ }
110
+ await uninstallProjectInstance(options, config, projectId, instanceId, instanceConfigDirPath);
111
+ }
112
+ async function uninstallInstance(options, config, instanceId, instanceConfigDirPath, onlyDeleteEmpty) {
113
+ const configDirContents = config.lsProjectDir(instanceConfigDirPath);
114
+ const fileNames = configDirContents.filter((f) => f.isFile()).map((f) => f.name);
115
+ for (const fileName of fileNames) {
116
+ if (!fileName.startsWith(".env.")) {
117
+ continue;
118
+ }
119
+ const projectId = fileName.replace(new RegExp("^.env."), "");
120
+ await uninstallProjectInstance(options, config, projectId, instanceId, instanceConfigDirPath);
121
+ }
122
+ if (!onlyDeleteEmpty || configDirEmpty(config, instanceConfigDirPath)) {
123
+ config.deleteProjectDir(instanceConfigDirPath);
124
+ }
125
+ let functionsConfig = config.src.functions ?? [];
126
+ if (!Array.isArray(functionsConfig)) {
127
+ functionsConfig = [functionsConfig];
128
+ }
129
+ for (const stanza of functionsConfig) {
130
+ if (typeof stanza.kit === "undefined") {
131
+ continue;
132
+ }
133
+ const instances = stanza.instances ?? {};
134
+ for (const configInstanceId of Object.keys(instances)) {
135
+ if (configInstanceId === instanceId) {
136
+ delete stanza.instances[instanceId];
137
+ }
138
+ }
139
+ }
140
+ config.set("functions", functionsConfig);
141
+ config.writeProjectFile("firebase.json", config.src);
142
+ }
143
+ async function uninstallProjectInstance(options, config, projectId, instanceId, kitInstancePath) {
144
+ const envFilePath = (0, path_1.join)(kitInstancePath, `.env.${projectId}`);
145
+ const context = {
146
+ projectId: projectId,
147
+ filters: [{ codebase: instanceId }],
148
+ };
149
+ const haveBackend = await backend.existingBackend(context);
150
+ const plan = await planner.createDeploymentPlan({
151
+ wantBackend: backend.empty(),
152
+ haveBackend: haveBackend,
153
+ codebase: "",
154
+ projectId: context.projectId,
155
+ filters: context.filters,
156
+ deleteAll: true,
157
+ });
158
+ const allEpToDelete = Object.values(plan.regionalChangesets)
159
+ .map((changes) => changes.endpointsToDelete)
160
+ .reduce(functional_1.reduceFlat, [])
161
+ .sort(backend.compareFunctions);
162
+ if (allEpToDelete.length > 0) {
163
+ const deleteList = allEpToDelete.map((func) => `\t${(0, functionsDeployHelper_1.getFunctionLabel)(func)}`).join("\n");
164
+ const confirmDeletion = await (0, prompt_1.confirm)({
165
+ message: "You are about to delete the following Cloud Functions:\n" +
166
+ deleteList +
167
+ "\n Are you sure?",
168
+ default: false,
169
+ force: options.force,
170
+ nonInteractive: options.nonInteractive,
171
+ });
172
+ if (!confirmDeletion) {
173
+ throw new error_1.FirebaseError("Command aborted.");
174
+ }
175
+ const functionExecutor = new executor.QueueExecutor({
176
+ retries: 30,
177
+ backoff: 20000,
178
+ concurrency: 40,
179
+ maxBackoff: 40000,
180
+ });
181
+ const appEngineLocation = functionsConfig.getAppEngineLocation(config);
182
+ try {
183
+ const fab = new fabricator.Fabricator({
184
+ functionExecutor,
185
+ runFunctionExecutor: functionExecutor,
186
+ appEngineLocation,
187
+ executor: new executor.QueueExecutor({}),
188
+ sources: {},
189
+ projectNumber: await (0, getProjectNumber_1.getProjectNumber)({ projectId: context.projectId }),
190
+ projectId: context.projectId,
191
+ });
192
+ const summary = await fab.applyPlan({ default: plan });
193
+ await reporter.logAndTrackDeployStats(summary);
194
+ reporter.printErrors(summary);
195
+ if (summary.results.some((r) => r.error)) {
196
+ throw new error_1.FirebaseError("Some functions deletions failed. Not modifying firebase.json.");
197
+ }
198
+ }
199
+ catch (err) {
200
+ throw new error_1.FirebaseError("Failed to delete functions", {
201
+ original: err,
202
+ exit: 1,
203
+ });
204
+ }
205
+ }
206
+ else {
207
+ logger_1.logger.info(`No deployed functions found for instance ${instanceId}. This is normal if firebase deploy was never run.`);
208
+ }
209
+ config.deleteProjectFile(envFilePath);
210
+ }
211
+ async function uninstallKit(options, config, kit) {
212
+ const conservativeDeletion = nonstandardKitLayout(kit);
213
+ for (const [instanceId, instanceConfigDir] of Object.entries(kit.instances)) {
214
+ await uninstallInstance(options, config, instanceId, instanceConfigDir, conservativeDeletion);
215
+ }
216
+ if (conservativeDeletion) {
217
+ const instanceConfigDirParents = Object.values(kit.instances).map((p) => (0, posix_1.dirname)(p));
218
+ if (instanceConfigDirParents.length > 0 &&
219
+ instanceConfigDirParents.every((p) => p === instanceConfigDirParents[0]) &&
220
+ configDirEmpty(config, instanceConfigDirParents[0])) {
221
+ config.deleteProjectDir(instanceConfigDirParents[0]);
222
+ }
223
+ }
224
+ else {
225
+ const kitRootDirs = [
226
+ (0, posix_1.dirname)(kit.source),
227
+ ...Object.values(kit.instances).map((p) => (0, posix_1.dirname)(p)),
228
+ ];
229
+ if (!kitRootDirs.every((p) => p === kitRootDirs[0])) {
230
+ throw new error_1.FirebaseError(`aborting kit uninstall: couldn't infer one kit root directory (${[...new Set(kitRootDirs)].join(", ")} in firebase.json)`);
231
+ }
232
+ config.deleteProjectDir(kitRootDirs[0]);
233
+ }
234
+ let functionsConfig = config.src.functions ?? [];
235
+ if (!Array.isArray(functionsConfig)) {
236
+ functionsConfig = [functionsConfig];
237
+ }
238
+ functionsConfig = functionsConfig.filter((fc) => fc.kit !== kit.kit);
239
+ config.set("functions", functionsConfig);
240
+ config.writeProjectFile("firebase.json", config.src);
241
+ }
242
+ function nonstandardKitLayout(kitConfig) {
243
+ if (kitConfig.sourcePackage) {
244
+ if (kitConfig.source !== `function-kits/${kitConfig.kit}/source`) {
245
+ return true;
246
+ }
247
+ for (const [instanceId, instanceConfigDirPath] of Object.entries(kitConfig.instances)) {
248
+ if (instanceConfigDirPath !== `function-kits/${kitConfig.kit}/config-${instanceId}`) {
249
+ return true;
250
+ }
251
+ }
252
+ return false;
253
+ }
254
+ return true;
255
+ }
256
+ function configDirEmpty(config, projectRelativePath) {
257
+ const contents = config.lsProjectDir(projectRelativePath).map((dirent) => dirent.name);
258
+ if (contents.length > 0) {
259
+ const digest = contents.length > 5
260
+ ? `${contents.slice(0, 5).join(",")}, ...${contents.length - 5} more`
261
+ : contents.join(",");
262
+ (0, utils_1.logLabeledWarning)("functions", `Kits instance config directory ${projectRelativePath} still contains files (${digest}); not deleting automatically`);
263
+ return false;
264
+ }
265
+ return true;
266
+ }
@@ -120,6 +120,9 @@ function load(client) {
120
120
  client.ext.list = loadCommand("ext-list");
121
121
  client.ext.uninstall = loadCommand("ext-uninstall");
122
122
  client.ext.update = loadCommand("ext-update");
123
+ if (experiments.isEnabled("extMigrationFeatures")) {
124
+ client.ext.migrate = loadCommand("ext-migrate");
125
+ }
123
126
  client.ext.sdk = {};
124
127
  client.ext.sdk.install = loadCommand("ext-sdk-install");
125
128
  client.ext.dev = {};
@@ -188,6 +191,7 @@ function load(client) {
188
191
  if (experiments.isEnabled("kits")) {
189
192
  client.functions.kits = {};
190
193
  client.functions.kits.install = loadCommand("functions-kits-install");
194
+ client.functions.kits.uninstall = loadCommand("functions-kits-uninstall");
191
195
  client.functions.kits.list = loadCommand("functions-kits-list");
192
196
  }
193
197
  client.help = loadCommand("help");
package/lib/config.js CHANGED
@@ -180,9 +180,43 @@ class Config {
180
180
  projectFileExists(p) {
181
181
  return fs.existsSync(this.path(p));
182
182
  }
183
+ projectDirExists(p) {
184
+ return this.projectFileExists(p) && fs.statSync(this.path(p)).isDirectory();
185
+ }
183
186
  deleteProjectFile(p) {
184
187
  fs.removeSync(this.path(p));
185
188
  }
189
+ deleteProjectDir(p) {
190
+ if (path.isAbsolute(p)) {
191
+ throw new error_1.FirebaseError(`Sanity: deleteProjectDir() should not be called with an absolute path.`);
192
+ }
193
+ const resolvedPath = this.path(p);
194
+ if (!fs.existsSync(resolvedPath)) {
195
+ throw new error_1.FirebaseError(`Failed to delete project directory ${p}: directory doesn't exist.`);
196
+ }
197
+ try {
198
+ fs.rmSync(resolvedPath, { recursive: true });
199
+ }
200
+ catch (err) {
201
+ throw new error_1.FirebaseError(`Failed to delete project directory ${p}: ${err}`, {
202
+ original: err instanceof Error ? err : undefined,
203
+ });
204
+ }
205
+ }
206
+ lsProjectDir(p) {
207
+ const resolvedPath = this.path(p);
208
+ if (!fs.existsSync(resolvedPath)) {
209
+ throw new error_1.FirebaseError(`Failed to list files in project directory ${p}: directory doesn't exist.`);
210
+ }
211
+ try {
212
+ return fs.readdirSync(resolvedPath, { withFileTypes: true });
213
+ }
214
+ catch (err) {
215
+ throw new error_1.FirebaseError(`Failed to list files in project directory ${p}: ${err}`, {
216
+ original: err instanceof Error ? err : undefined,
217
+ });
218
+ }
219
+ }
186
220
  async confirmWriteProjectFile(path, content, confirmByDefault) {
187
221
  const writeTo = this.path(path);
188
222
  if (!fsutils.fileExistsSync(writeTo)) {
@@ -115,7 +115,7 @@ async function upsertSchema(schema, validateOnly = false, async = false) {
115
115
  apiOrigin: (0, api_1.dataconnectOrigin)(),
116
116
  apiVersion: DATACONNECT_API_VERSION,
117
117
  operationResourceName: op.body.name,
118
- masterTimeout: 60000,
118
+ masterTimeout: 300000,
119
119
  });
120
120
  }
121
121
  async function deleteSchema(name) {
@@ -164,7 +164,7 @@ async function upsertConnector(connector) {
164
164
  apiOrigin: (0, api_1.dataconnectOrigin)(),
165
165
  apiVersion: DATACONNECT_API_VERSION,
166
166
  operationResourceName: op.body.name,
167
- masterTimeout: 60000,
167
+ masterTimeout: 300000,
168
168
  });
169
169
  return pollRes;
170
170
  }
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultServiceAccount = defaultServiceAccount;
4
4
  exports.cloudBuildEnabled = cloudBuildEnabled;
5
- exports.secretAccess = secretAccess;
5
+ exports.secretsAccessDelta = secretsAccessDelta;
6
+ exports.checkSecretAccess = checkSecretAccess;
7
+ exports.grantSecretAccess = grantSecretAccess;
6
8
  const clc = require("colorette");
7
9
  const ensureApiEnabled_1 = require("../../ensureApiEnabled");
8
10
  const error_1 = require("../../error");
@@ -70,8 +72,11 @@ async function cloudBuildEnabled(projectId) {
70
72
  async function secretsToServiceAccounts(b) {
71
73
  const secretsToSa = {};
72
74
  for (const e of backend.allEndpoints(b)) {
75
+ if (!e.secretEnvironmentVariables || e.secretEnvironmentVariables.length === 0) {
76
+ continue;
77
+ }
73
78
  const sa = e.serviceAccount || (await module.exports.defaultServiceAccount(e));
74
- for (const s of e.secretEnvironmentVariables || []) {
79
+ for (const s of e.secretEnvironmentVariables) {
75
80
  const serviceAccounts = secretsToSa[s.secret] || new Set();
76
81
  serviceAccounts.add(sa);
77
82
  secretsToSa[s.secret] = serviceAccounts;
@@ -79,20 +84,8 @@ async function secretsToServiceAccounts(b) {
79
84
  }
80
85
  return secretsToSa;
81
86
  }
82
- async function secretAccess(projectId, wantBackend, haveBackend, dryRun) {
83
- const ensureAccess = async (secret, serviceAccounts) => {
84
- (0, utils_1.logLabeledBullet)("functions", `ensuring ${clc.bold(serviceAccounts.join(", "))} access to secret ${clc.bold(secret)}.`);
85
- if (dryRun) {
86
- const check = await (0, secretManager_1.checkServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
87
- if (check.length) {
88
- (0, utils_1.logLabeledBullet)("functions", `On your next deploy, ${clc.bold(serviceAccounts.join(", "))} will be granted access to secret ${clc.bold(secret)}.`);
89
- }
90
- }
91
- else {
92
- await (0, secretManager_1.ensureServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
93
- }
94
- (0, utils_1.logLabeledSuccess)("functions", `ensured ${clc.bold(serviceAccounts.join(", "))} access to ${clc.bold(secret)}.`);
95
- };
87
+ async function secretsAccessDelta(args) {
88
+ const { wantBackend, haveBackend } = args;
96
89
  const wantSecrets = await secretsToServiceAccounts(wantBackend);
97
90
  const haveSecrets = await secretsToServiceAccounts(haveBackend);
98
91
  for (const [secret, serviceAccounts] of Object.entries(haveSecrets)) {
@@ -103,9 +96,26 @@ async function secretAccess(projectId, wantBackend, haveBackend, dryRun) {
103
96
  delete wantSecrets[secret];
104
97
  }
105
98
  }
106
- const ensure = [];
99
+ const delta = {};
107
100
  for (const [secret, serviceAccounts] of Object.entries(wantSecrets)) {
108
- ensure.push(ensureAccess(secret, Array.from(serviceAccounts)));
101
+ if (serviceAccounts.size > 0) {
102
+ delta[secret] = Array.from(serviceAccounts);
103
+ }
109
104
  }
110
- await Promise.all(ensure);
105
+ return delta;
106
+ }
107
+ async function checkSecretAccess(projectId, secretAccessDelta) {
108
+ for (const [secret, serviceAccounts] of Object.entries(secretAccessDelta)) {
109
+ (0, utils_1.logLabeledBullet)("functions", `ensuring ${clc.bold(serviceAccounts.join(", "))} access to secret ${clc.bold(secret)}.`);
110
+ const check = await (0, secretManager_1.checkServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
111
+ if (check.length) {
112
+ (0, utils_1.logLabeledBullet)("functions", `On your next deploy, ${clc.bold(serviceAccounts.join(", "))} will be granted access to secret ${clc.bold(secret)}.`);
113
+ }
114
+ }
115
+ }
116
+ async function grantSecretAccess(args) {
117
+ const { projectId, secret, serviceAccounts } = args;
118
+ (0, utils_1.logLabeledBullet)("functions", `ensuring ${clc.bold(serviceAccounts.join(", "))} access to secret ${clc.bold(secret)}.`);
119
+ await (0, secretManager_1.ensureServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
120
+ (0, utils_1.logLabeledSuccess)("functions", `ensured ${clc.bold(serviceAccounts.join(", "))} access to ${clc.bold(secret)}.`);
111
121
  }
@@ -341,7 +341,14 @@ async function prepare(context, options, payload) {
341
341
  await validate.secretsAreValid(projectId, matchingBackend);
342
342
  await (0, checkIam_1.ensureServiceAgentRoles)(projectId, projectNumber, matchingBackend, haveBackend, options.dryRun);
343
343
  await (0, checkIam_1.ensureGenkitMonitoringRoles)(projectId, projectNumber, matchingBackend, haveBackend, options.dryRun);
344
- await ensure.secretAccess(projectId, matchingBackend, haveBackend, options.dryRun);
344
+ if (options.dryRun) {
345
+ const secretAccessDelta = await ensure.secretsAccessDelta({
346
+ projectId,
347
+ wantBackend: matchingBackend,
348
+ haveBackend,
349
+ });
350
+ await ensure.checkSecretAccess(projectId, secretAccessDelta);
351
+ }
345
352
  updateEndpointTargetedStatus(wantBackends, context.filters || []);
346
353
  validate.checkFiltersIntegrity(wantBackends, context.filters);
347
354
  (0, applyHash_1.applyBackendHashToBackends)(wantBackends, context);
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Fabricator = void 0;
4
4
  const clc = require("colorette");
5
5
  const executor_1 = require("./executor");
6
+ const ensure = require("../ensure");
6
7
  const error_1 = require("../../../error");
7
8
  const sourceTokenScraper_1 = require("./sourceTokenScraper");
8
9
  const timer_1 = require("./timer");
@@ -55,6 +56,13 @@ const rethrowAs = (endpoint, op) => (err) => {
55
56
  logger_1.logger.error(err.message);
56
57
  throw new reporter.DeploymentError(endpoint, op, err);
57
58
  };
59
+ const rethrowAsUnlessNotFound = (endpoint, op) => (err) => {
60
+ if ((0, executor_1.parseErrorCode)(err) === 404) {
61
+ logger_1.logger.debug(`Ignoring 404 for ${op} on ${endpoint.id}; resource already deleted.`);
62
+ return;
63
+ }
64
+ return rethrowAs(endpoint, op)(err);
65
+ };
58
66
  class Fabricator {
59
67
  constructor(args) {
60
68
  this.executor = args.executor;
@@ -147,6 +155,14 @@ class Fabricator {
147
155
  for (const [codebase, codebasePlan] of Object.entries(plan)) {
148
156
  await this.grantNewRoles(codebasePlan, codebase);
149
157
  }
158
+ const secretAccessPromises = Object.values(plan).flatMap((codebasePlan) => Object.entries(codebasePlan.secretAccessPlan || {}).map(([secret, serviceAccounts]) => this.executor.run(() => ensure.grantSecretAccess({
159
+ projectId: this.projectId,
160
+ secret,
161
+ serviceAccounts,
162
+ }), {
163
+ retryPredicates: [executor_1.isTransientError, executor_1.isServiceAccount404],
164
+ })));
165
+ await Promise.all(secretAccessPromises);
150
166
  const allChangesets = [];
151
167
  for (const codebasePlan of Object.values(plan)) {
152
168
  allChangesets.push(...Object.values(codebasePlan.regionalChangesets));
@@ -820,17 +836,17 @@ class Fabricator {
820
836
  const jobName = scheduler.jobNameForEndpoint(endpoint, this.appEngineLocation);
821
837
  await this.executor
822
838
  .run(() => scheduler.deleteJob(jobName))
823
- .catch(rethrowAs(endpoint, "delete schedule"));
839
+ .catch(rethrowAsUnlessNotFound(endpoint, "delete schedule"));
824
840
  const topicName = scheduler.topicNameForEndpoint(endpoint);
825
841
  await this.executor
826
842
  .run(() => pubsub.deleteTopic(topicName))
827
- .catch(rethrowAs(endpoint, "delete topic"));
843
+ .catch(rethrowAsUnlessNotFound(endpoint, "delete topic"));
828
844
  }
829
845
  async deleteScheduleV2(endpoint) {
830
846
  const jobName = scheduler.jobNameForEndpoint(endpoint, endpoint.region);
831
847
  await this.executor
832
848
  .run(() => scheduler.deleteJob(jobName))
833
- .catch(rethrowAs(endpoint, "delete schedule"));
849
+ .catch(rethrowAsUnlessNotFound(endpoint, "delete schedule"));
834
850
  }
835
851
  async disableTaskQueue(endpoint) {
836
852
  const update = {
@@ -15,6 +15,7 @@ const deploymentTool_1 = require("../../../deploymentTool");
15
15
  const error_1 = require("../../../error");
16
16
  const utils = require("../../../utils");
17
17
  const backend = require("../backend");
18
+ const ensure = require("../ensure");
18
19
  const v2events = require("../../../functions/events/v2");
19
20
  function calculateChangesets(want, have, keyFn, deleteAll) {
20
21
  const toCreate = utils.groupBy(Object.keys(want)
@@ -119,6 +120,11 @@ async function createDeploymentPlan(args) {
119
120
  "default to 80 concurrent executions, but existing functions keep the " +
120
121
  "old default of 1. You can change this with the 'concurrency' option.");
121
122
  }
123
+ const secretAccessPlan = await ensure.secretsAccessDelta({
124
+ projectId: args.projectId,
125
+ wantBackend,
126
+ haveBackend,
127
+ });
122
128
  if (requiredRoles && hasWantEndpoints) {
123
129
  if (!managedSA) {
124
130
  throw new error_1.FirebaseError("managedServiceAccount is required when requiredRoles is defined.", {
@@ -128,6 +134,7 @@ async function createDeploymentPlan(args) {
128
134
  return {
129
135
  regionalChangesets,
130
136
  plannedBackend: wantBackend,
137
+ secretAccessPlan,
131
138
  rolesToAdd,
132
139
  rolesToRemove,
133
140
  serviceAccountToCreate,
@@ -138,6 +145,7 @@ async function createDeploymentPlan(args) {
138
145
  return {
139
146
  regionalChangesets,
140
147
  plannedBackend: wantBackend,
148
+ secretAccessPlan,
141
149
  serviceAccountToDelete,
142
150
  };
143
151
  }
@@ -7,15 +7,32 @@ const extensionsApi_1 = require("./extensionsApi");
7
7
  const logger_1 = require("../logger");
8
8
  const utils_1 = require("../utils");
9
9
  const extensionsHelper_1 = require("./extensionsHelper");
10
+ const experiments = require("../experiments");
10
11
  const extensionsUtils = require("./utils");
12
+ const replacementRegistry_1 = require("./replacementRegistry");
11
13
  async function listExtensions(projectId) {
12
- const instances = await (0, extensionsApi_1.listInstances)(projectId);
14
+ const showReplacements = experiments.isEnabled("extMigrationFeatures");
15
+ let instances;
16
+ let registry;
17
+ if (showReplacements) {
18
+ [instances, registry] = await Promise.all([
19
+ (0, extensionsApi_1.listInstances)(projectId),
20
+ (0, replacementRegistry_1.getReplacementsRegistry)(),
21
+ ]);
22
+ }
23
+ else {
24
+ instances = await (0, extensionsApi_1.listInstances)(projectId);
25
+ }
13
26
  if (instances.length < 1) {
14
27
  (0, utils_1.logLabeledBullet)(extensionsHelper_1.logPrefix, `there are no extensions installed on project ${clc.bold(projectId)}.`);
15
28
  return [];
16
29
  }
30
+ const head = ["Extension", "Publisher", "Instance ID", "State", "Version", "Your last update"];
31
+ if (showReplacements) {
32
+ head.push("Replacement Kit");
33
+ }
17
34
  const table = new Table({
18
- head: ["Extension", "Publisher", "Instance ID", "State", "Version", "Your last update"],
35
+ head,
19
36
  style: { head: ["yellow"] },
20
37
  });
21
38
  const sorted = instances.sort((a, b) => new Date(b.createTime).valueOf() - new Date(a.createTime).valueOf());
@@ -35,7 +52,13 @@ async function listExtensions(projectId) {
35
52
  ((instance.config.source.state || "ACTIVE") === "DELETED" ? " (UNPUBLISHED)" : "");
36
53
  const version = instance?.config?.source?.spec?.version;
37
54
  const updateTime = extensionsUtils.formatTimestamp(instance.updateTime);
38
- table.push([extension, publisher, instanceId, state, version, updateTime]);
55
+ const row = [extension, publisher, instanceId, state, version, updateTime];
56
+ let replacementPackage;
57
+ if (showReplacements && registry) {
58
+ replacementPackage = (0, replacementRegistry_1.getReplacementPackageName)(extension, registry);
59
+ row.push(replacementPackage ? clc.green(replacementPackage) : "");
60
+ }
61
+ table.push(row);
39
62
  formatted.push({
40
63
  extension,
41
64
  publisher,
@@ -43,6 +66,7 @@ async function listExtensions(projectId) {
43
66
  state,
44
67
  version,
45
68
  updateTime,
69
+ ...(showReplacements && replacementPackage ? { replacementKit: replacementPackage } : {}),
46
70
  params: instance.config.params,
47
71
  systemParams: instance.config.systemParams,
48
72
  });