firebase-tools-with-isolate 15.35.0 → 15.37.0
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.
- package/lib/accountExporter.js +1 -1
- package/lib/accountImporter.js +7 -6
- package/lib/apiv2.js +0 -1
- package/lib/appcheck/debugTokens.js +293 -0
- package/lib/appcheck/localConfig.js +191 -0
- package/lib/appdistribution/options-parser-util.js +1 -1
- package/lib/apphosting/githubConnections.js +1 -1
- package/lib/apptesting/parseTestFiles.js +1 -1
- package/lib/auth.js +9 -3
- package/lib/bin/progressiveHelp.js +1 -1
- package/lib/command.js +1 -2
- package/lib/commands/appcheck-debugtokens-create.js +60 -35
- package/lib/commands/appcheck-debugtokens-delete.js +21 -7
- package/lib/commands/appcheck-debugtokens-list.js +37 -8
- package/lib/commands/appcheck-debugtokens-prune.js +59 -0
- package/lib/commands/crashlytics-events-get.js +48 -0
- package/lib/commands/crashlytics-events-list.js +70 -0
- package/lib/commands/crashlytics-heapdumps-enable.js +3 -4
- package/lib/commands/crashlytics-heapdumps-status.js +5 -3
- package/lib/commands/crashlytics-issues-get.js +61 -0
- package/lib/commands/crashlytics-reports-get.js +179 -0
- package/lib/commands/crashlytics-reports-list.js +42 -0
- package/lib/commands/dataconnect-services-list.js +8 -2
- package/lib/commands/deploy.js +1 -3
- package/lib/commands/ext-dev-init.js +1 -1
- package/lib/commands/hosting-channel-create.js +1 -3
- package/lib/commands/hosting-channel-delete.js +1 -3
- package/lib/commands/hosting-channel-deploy.js +1 -3
- package/lib/commands/hosting-channel-list.js +1 -3
- package/lib/commands/hosting-channel-open.js +5 -4
- package/lib/commands/hosting-clone.js +3 -5
- package/lib/commands/hosting-disable.js +2 -2
- package/lib/commands/hosting-sites-create.js +1 -3
- package/lib/commands/hosting-sites-delete.js +1 -3
- package/lib/commands/hosting-sites-get.js +1 -3
- package/lib/commands/hosting-sites-list.js +1 -3
- package/lib/commands/index.js +11 -0
- package/lib/commands/open.js +3 -1
- package/lib/commands/serve.js +1 -1
- package/lib/commands/use.js +1 -1
- package/lib/config.js +1 -1
- package/lib/crashlytics/commandUtils.js +194 -0
- package/lib/crashlytics/events.js +122 -1
- package/lib/crashlytics/filters.js +12 -6
- package/lib/crashlytics/profilingManager.js +77 -50
- package/lib/crashlytics/reports.js +5 -1
- package/lib/crashlytics/utils.js +14 -0
- package/lib/database/import.js +5 -4
- package/lib/dataconnect/client.js +14 -8
- package/lib/dataconnect/names.js +3 -3
- package/lib/dataconnect/schemaMigration.js +1 -1
- package/lib/deploy/dataconnect/release.js +2 -2
- package/lib/deploy/firestore/prepare.js +21 -3
- package/lib/deploy/functions/backend.js +0 -10
- package/lib/deploy/functions/cel.js +2 -2
- package/lib/deploy/functions/deploy.js +2 -1
- package/lib/deploy/functions/prepare.js +28 -0
- package/lib/deploy/functions/release/fabricator.js +27 -3
- package/lib/deploy/functions/release/planner.js +3 -0
- package/lib/deploy/functions/release/reporter.js +0 -26
- package/lib/deploy/functions/runtimes/discovery/index.js +4 -1
- package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +1 -1
- package/lib/deploy/functions/runtimes/supported/index.js +10 -4
- package/lib/deploy/functions/runtimes/supported/types.js +7 -1
- package/lib/deploy/functions/services/index.js +13 -11
- package/lib/deploy/hosting/prepare.js +1 -3
- package/lib/deploy/lifecycleHooks.js +1 -1
- package/lib/emulator/auth/operations.js +2 -2
- package/lib/emulator/auth/server.js +4 -2
- package/lib/emulator/auth/widget_ui.js +1 -1
- package/lib/emulator/commandUtils.js +4 -1
- package/lib/emulator/databaseEmulator.js +16 -11
- package/lib/emulator/dataconnect/pgliteServer.js +30 -24
- package/lib/emulator/downloadableEmulatorInfo.json +31 -31
- package/lib/emulator/downloadableEmulators.js +2 -2
- package/lib/emulator/extensions/postinstall.js +6 -6
- package/lib/emulator/firestoreEmulator.js +21 -15
- package/lib/emulator/functionsEmulator.js +84 -8
- package/lib/emulator/functionsEmulatorRuntime.js +9 -4
- package/lib/emulator/hub.js +12 -8
- package/lib/emulator/shared/express.js +30 -0
- package/lib/emulator/storage/apis/firebase.js +11 -10
- package/lib/emulator/storage/apis/gcloud.js +21 -20
- package/lib/emulator/storage/files.js +1 -1
- package/lib/emulator/storage/rules/manager.js +15 -12
- package/lib/emulator/storage/server.js +10 -5
- package/lib/experiments.js +5 -0
- package/lib/extensions/extensionsHelper.js +2 -2
- package/lib/extensions/listExtensions.js +1 -1
- package/lib/extensions/paramHelper.js +1 -1
- package/lib/extensions/provisioningHelper.js +1 -6
- package/lib/firestore/delete.js +2 -3
- package/lib/firestore/util.js +3 -3
- package/lib/frameworks/angular/utils.js +1 -1
- package/lib/frameworks/next/constants.js +17 -14
- package/lib/frameworks/next/index.js +25 -3
- package/lib/frameworks/next/utils.js +7 -9
- package/lib/functions/kits/install.js +221 -316
- package/lib/functions/kits/sources/directory.js +32 -0
- package/lib/functions/kits/sources/npm.js +55 -5
- package/lib/functionsConfig.js +0 -4
- package/lib/functionsShellCommandAction.js +1 -1
- package/lib/gcp/cloudbilling.js +2 -2
- package/lib/gcp/cloudbuild.js +0 -77
- package/lib/gcp/cloudfunctionsv2.js +0 -6
- package/lib/gcp/cloudscheduler.js +12 -0
- package/lib/gcp/cloudtasks.js +0 -4
- package/lib/gcp/devConnect.js +2 -8
- package/lib/gcp/iam.js +15 -1
- package/lib/gcp/resourceManager.js +1 -14
- package/lib/gcp/storage.js +87 -4
- package/lib/hosting/api.js +79 -7
- package/lib/hosting/implicitInit.js +1 -1
- package/lib/hosting/proxy.js +5 -2
- package/lib/init/features/firestore/rules.js +1 -1
- package/lib/init/features/functions/index.js +2 -2
- package/lib/init/features/functions/npm-dependencies.js +1 -1
- package/lib/init/features/hosting/github.js +6 -4
- package/lib/init/features/hosting/index.js +4 -0
- package/lib/init/features/storage/rules.js +1 -1
- package/lib/localFunction.js +3 -3
- package/lib/management/database.js +1 -1
- package/lib/mcp/apps/init/mcp-app.js +5 -2
- package/lib/mcp/apps/update_environment/mcp-app.js +1 -1
- package/lib/mcp/index.js +14 -4
- package/lib/mcp/prompts/apptesting/run_test.js +3 -3
- package/lib/mcp/prompts/core/deploy.js +3 -3
- package/lib/mcp/resources/guides/init_ai.js +10 -10
- package/lib/mcp/tools/crashlytics/events.js +18 -93
- package/lib/mcp/tools/crashlytics/index.js +2 -0
- package/lib/mcp/tools/crashlytics/reports.js +3 -3
- package/lib/mcp/tools/crashlytics/setup.js +392 -0
- package/lib/mcp/util/dataconnect/converter.js +1 -1
- package/lib/profileReport.js +1 -1
- package/lib/profiler.js +1 -1
- package/lib/rulesDeploy.js +0 -1
- package/lib/throttler/throttler.js +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/utils.js +5 -11
- package/package.json +16 -14
- package/schema/firebase-config.json +3 -0
- package/lib/functions/kits/sources/index.js +0 -19
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateAndResolveDirectoryKit = validateAndResolveDirectoryKit;
|
|
4
4
|
exports.buildAndInstallDirectoryKit = buildAndInstallDirectoryKit;
|
|
5
|
+
exports.createDirectoryAdapter = createDirectoryAdapter;
|
|
5
6
|
const path = require("path");
|
|
6
7
|
const fs = require("fs-extra");
|
|
7
8
|
const error_1 = require("../../../error");
|
|
8
9
|
const spawn_1 = require("../../../init/spawn");
|
|
9
10
|
const utils_1 = require("../../../utils");
|
|
11
|
+
const projectConfig_1 = require("../../projectConfig");
|
|
12
|
+
const types_1 = require("./types");
|
|
10
13
|
async function validateAndResolveDirectoryKit(projectDir, rawDir) {
|
|
11
14
|
const absDirectoryPath = (0, utils_1.resolveWithin)(projectDir, rawDir, `Directory '${rawDir}' is outside of project directory. Function kit directory must be inside the project directory.`);
|
|
12
15
|
if (!(await fs.pathExists(absDirectoryPath))) {
|
|
@@ -57,3 +60,32 @@ async function buildAndInstallDirectoryKit(absSourcePath, hasBuildScript) {
|
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
}
|
|
63
|
+
function createDirectoryAdapter(config, directory) {
|
|
64
|
+
const absDir = path.isAbsolute(directory)
|
|
65
|
+
? directory
|
|
66
|
+
: path.resolve(config.projectDir, directory);
|
|
67
|
+
let validated;
|
|
68
|
+
return {
|
|
69
|
+
defaultKitId: (0, types_1.sanitizeToKitId)(path.basename(absDir)) || "kit",
|
|
70
|
+
findExistingKit(existingFunctions) {
|
|
71
|
+
return existingFunctions.find((c) => (0, projectConfig_1.isKitConfig)(c) &&
|
|
72
|
+
!c.sourcePackage &&
|
|
73
|
+
path.resolve(config.projectDir, c.source) === absDir);
|
|
74
|
+
},
|
|
75
|
+
async validateAndConfirm() {
|
|
76
|
+
validated = await validateAndResolveDirectoryKit(config.projectDir, directory);
|
|
77
|
+
},
|
|
78
|
+
async prepareSource() {
|
|
79
|
+
if (!validated) {
|
|
80
|
+
validated = await validateAndResolveDirectoryKit(config.projectDir, directory);
|
|
81
|
+
}
|
|
82
|
+
await buildAndInstallDirectoryKit(validated.absDirectoryPath, validated.hasBuildScript);
|
|
83
|
+
return {
|
|
84
|
+
sourcePath: validated.relSourcePath,
|
|
85
|
+
...(validated.hasBuildScript
|
|
86
|
+
? { predeploy: ['npm --prefix "$RESOURCE_DIR" run build'] }
|
|
87
|
+
: {}),
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -14,6 +14,7 @@ exports.scaffoldKitFiles = scaffoldKitFiles;
|
|
|
14
14
|
exports.resolveSdkSpecifierToSave = resolveSdkSpecifierToSave;
|
|
15
15
|
exports.getKitPackagesToSave = getKitPackagesToSave;
|
|
16
16
|
exports.buildAndInstallKit = buildAndInstallKit;
|
|
17
|
+
exports.createNpmPackageAdapter = createNpmPackageAdapter;
|
|
17
18
|
const path = require("path");
|
|
18
19
|
const clc = require("colorette");
|
|
19
20
|
const fs = require("fs-extra");
|
|
@@ -25,6 +26,7 @@ const prompt_1 = require("../../../prompt");
|
|
|
25
26
|
const templates_1 = require("../../../templates");
|
|
26
27
|
const utils_1 = require("../../../utils");
|
|
27
28
|
const supported = require("../../../deploy/functions/runtimes/supported");
|
|
29
|
+
const projectConfig_1 = require("../../projectConfig");
|
|
28
30
|
const types_1 = require("./types");
|
|
29
31
|
exports.TEMPLATES = {
|
|
30
32
|
installation: "init/functions/typescript/index-kit.ts",
|
|
@@ -164,18 +166,16 @@ async function writeKitIndexTs(options) {
|
|
|
164
166
|
await config.askWriteProjectFile(relIndexTsPath, indexContent);
|
|
165
167
|
}
|
|
166
168
|
}
|
|
167
|
-
async function scaffoldKitFiles(
|
|
169
|
+
async function scaffoldKitFiles(options) {
|
|
170
|
+
const { config, kitId, packageName, templateType = exports.DEFAULT_TEMPLATE } = options;
|
|
168
171
|
const sourcePath = path.join(types_1.FUNCTION_KITS_DIR, kitId, "source");
|
|
169
|
-
const configDirPath = path.join(types_1.FUNCTION_KITS_DIR, kitId, `config-${instanceId}`);
|
|
170
172
|
const absSourcePath = config.path(sourcePath);
|
|
171
|
-
const absConfigDirPath = config.path(configDirPath);
|
|
172
173
|
await fs.ensureDir(absSourcePath);
|
|
173
|
-
await fs.ensureDir(absConfigDirPath);
|
|
174
174
|
await writeKitPackageJson(config, sourcePath, kitId);
|
|
175
175
|
await config.askWriteProjectFile(path.join(sourcePath, "tsconfig.json"), (0, templates_1.readTemplateSync)("init/functions/typescript/tsconfig.json"));
|
|
176
176
|
await config.askWriteProjectFile(path.join(sourcePath, ".gitignore"), (0, templates_1.readTemplateSync)("init/functions/typescript/_gitignore"));
|
|
177
177
|
await writeKitIndexTs({ config, sourcePath, packageName, templateType });
|
|
178
|
-
return { sourcePath,
|
|
178
|
+
return { sourcePath, absSourcePath };
|
|
179
179
|
}
|
|
180
180
|
function resolveSdkSpecifierToSave(packageName, declaredVer, installedVer) {
|
|
181
181
|
const cleanVer = semver.clean(declaredVer);
|
|
@@ -272,3 +272,53 @@ async function buildAndInstallKit(absSourcePath, rawPkgName, isThirdParty) {
|
|
|
272
272
|
throw new error_1.FirebaseError(`TypeScript build failed: ${(0, error_1.getErrMsg)(err)}`);
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
|
+
function createNpmPackageAdapter(options) {
|
|
276
|
+
validateNpmPackageName(options.package);
|
|
277
|
+
const { packageName } = parseNpmPackageSpecifier(options.package);
|
|
278
|
+
const templateType = options.template || exports.DEFAULT_TEMPLATE;
|
|
279
|
+
if (!(templateType in exports.TEMPLATES)) {
|
|
280
|
+
const validTemplates = Object.keys(exports.TEMPLATES)
|
|
281
|
+
.map((t) => `'${t}'`)
|
|
282
|
+
.join(" or ");
|
|
283
|
+
throw new error_1.FirebaseError(`Invalid template '${templateType}'. Template must be ${validTemplates}.`);
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
defaultKitId: sanitizePackageNameToKitName(packageName) || "kit",
|
|
287
|
+
findExistingKit(existingFunctions) {
|
|
288
|
+
return existingFunctions.find((c) => (0, projectConfig_1.isKitConfig)(c) && c.sourcePackage?.name === packageName);
|
|
289
|
+
},
|
|
290
|
+
async validateAndConfirm() {
|
|
291
|
+
await validateNpmPackageExists(options.package);
|
|
292
|
+
await promptSecurityConfirmation({
|
|
293
|
+
rawPkgName: options.package,
|
|
294
|
+
packageName,
|
|
295
|
+
nonInteractive: options.nonInteractive,
|
|
296
|
+
force: options.force,
|
|
297
|
+
});
|
|
298
|
+
},
|
|
299
|
+
async prepareSource(kitId) {
|
|
300
|
+
const absKitDir = options.config.path(path.join(types_1.FUNCTION_KITS_DIR, kitId));
|
|
301
|
+
try {
|
|
302
|
+
const { sourcePath, absSourcePath } = await scaffoldKitFiles({
|
|
303
|
+
config: options.config,
|
|
304
|
+
kitId,
|
|
305
|
+
packageName,
|
|
306
|
+
templateType,
|
|
307
|
+
});
|
|
308
|
+
await buildAndInstallKit(absSourcePath, options.package, isThirdPartyPackage(packageName));
|
|
309
|
+
return {
|
|
310
|
+
sourcePath,
|
|
311
|
+
sourcePackage: { name: packageName },
|
|
312
|
+
predeploy: ['npm --prefix "$RESOURCE_DIR" run build'],
|
|
313
|
+
createdPaths: [absKitDir],
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
await fs.remove(absKitDir).catch((cleanupErr) => {
|
|
318
|
+
logger_1.logger.debug(`Failed to clean up kit directory '${absKitDir}': ${(0, error_1.getErrMsg)(cleanupErr)}`);
|
|
319
|
+
});
|
|
320
|
+
throw err;
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
}
|
package/lib/functionsConfig.js
CHANGED
|
@@ -6,7 +6,6 @@ exports.logFunctionsConfigDeprecationWarning = logFunctionsConfigDeprecationWarn
|
|
|
6
6
|
exports.ensureLegacyRuntimeConfigCommandsEnabled = ensureLegacyRuntimeConfigCommandsEnabled;
|
|
7
7
|
exports.ensureApi = ensureApi;
|
|
8
8
|
exports.varNameToIds = varNameToIds;
|
|
9
|
-
exports.idsToVarName = idsToVarName;
|
|
10
9
|
exports.getAppEngineLocation = getAppEngineLocation;
|
|
11
10
|
exports.getFirebaseConfig = getFirebaseConfig;
|
|
12
11
|
exports.setVariablesRecursive = setVariablesRecursive;
|
|
@@ -89,9 +88,6 @@ function varNameToIds(varName) {
|
|
|
89
88
|
variable: varName.match(new RegExp("/variables/(.+)"))[1],
|
|
90
89
|
};
|
|
91
90
|
}
|
|
92
|
-
function idsToVarName(projectId, configId, varId) {
|
|
93
|
-
return ["projects", projectId, "configs", configId, "variables", varId].join("/");
|
|
94
|
-
}
|
|
95
91
|
function getAppEngineLocation(config) {
|
|
96
92
|
let appEngineLocation = config.locationId;
|
|
97
93
|
if (appEngineLocation && appEngineLocation.match(/[^\d]$/)) {
|
|
@@ -103,7 +103,7 @@ const actionFunction = async (options) => {
|
|
|
103
103
|
replServer.on("reset", initializeContext);
|
|
104
104
|
return new Promise((resolve) => {
|
|
105
105
|
replServer.on("exit", () => {
|
|
106
|
-
|
|
106
|
+
serveFunctions.stop().then(resolve).catch(resolve);
|
|
107
107
|
});
|
|
108
108
|
});
|
|
109
109
|
});
|
package/lib/gcp/cloudbilling.js
CHANGED
|
@@ -86,10 +86,10 @@ function logBillingStatus(enabled, projectId, featureName) {
|
|
|
86
86
|
async function openBillingAccount(projectId, url, open, featureName = "Extensions") {
|
|
87
87
|
if (open) {
|
|
88
88
|
try {
|
|
89
|
-
opn(url);
|
|
89
|
+
await opn(url);
|
|
90
90
|
}
|
|
91
91
|
catch (err) {
|
|
92
|
-
logger_1.logger.debug(
|
|
92
|
+
logger_1.logger.debug(`Unable to open billing URL: ${(0, error_1.getErrStack)(err)}`);
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
const target = featureName === "Extensions" ? "your extension" : featureName.toLowerCase();
|
package/lib/gcp/cloudbuild.js
CHANGED
|
@@ -1,83 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createConnection = createConnection;
|
|
4
|
-
exports.getConnection = getConnection;
|
|
5
|
-
exports.listConnections = listConnections;
|
|
6
|
-
exports.deleteConnection = deleteConnection;
|
|
7
|
-
exports.fetchLinkableRepositories = fetchLinkableRepositories;
|
|
8
|
-
exports.createRepository = createRepository;
|
|
9
|
-
exports.getRepository = getRepository;
|
|
10
|
-
exports.deleteRepository = deleteRepository;
|
|
11
3
|
exports.getDefaultServiceAccount = getDefaultServiceAccount;
|
|
12
|
-
exports.getDefaultServiceAgent = getDefaultServiceAgent;
|
|
13
|
-
const apiv2_1 = require("../apiv2");
|
|
14
|
-
const api_1 = require("../api");
|
|
15
|
-
const PAGE_SIZE_MAX = 100;
|
|
16
|
-
const client = new apiv2_1.Client({
|
|
17
|
-
urlPrefix: (0, api_1.cloudbuildOrigin)(),
|
|
18
|
-
auth: true,
|
|
19
|
-
apiVersion: "v2",
|
|
20
|
-
});
|
|
21
|
-
async function createConnection(projectId, location, connectionId, githubConfig = {}) {
|
|
22
|
-
const res = await client.post(`projects/${projectId}/locations/${location}/connections`, { githubConfig }, { queryParams: { connectionId } });
|
|
23
|
-
return res.body;
|
|
24
|
-
}
|
|
25
|
-
async function getConnection(projectId, location, connectionId) {
|
|
26
|
-
const name = `projects/${projectId}/locations/${location}/connections/${connectionId}`;
|
|
27
|
-
const res = await client.get(name);
|
|
28
|
-
return res.body;
|
|
29
|
-
}
|
|
30
|
-
async function listConnections(projectId, location) {
|
|
31
|
-
const conns = [];
|
|
32
|
-
const getNextPage = async (pageToken = "") => {
|
|
33
|
-
const res = await client.get(`/projects/${projectId}/locations/${location}/connections`, {
|
|
34
|
-
queryParams: {
|
|
35
|
-
pageSize: PAGE_SIZE_MAX,
|
|
36
|
-
pageToken,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
if (Array.isArray(res.body.connections)) {
|
|
40
|
-
conns.push(...res.body.connections);
|
|
41
|
-
}
|
|
42
|
-
if (res.body.nextPageToken) {
|
|
43
|
-
await getNextPage(res.body.nextPageToken);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
await getNextPage();
|
|
47
|
-
return conns;
|
|
48
|
-
}
|
|
49
|
-
async function deleteConnection(projectId, location, connectionId) {
|
|
50
|
-
const name = `projects/${projectId}/locations/${location}/connections/${connectionId}`;
|
|
51
|
-
const res = await client.delete(name);
|
|
52
|
-
return res.body;
|
|
53
|
-
}
|
|
54
|
-
async function fetchLinkableRepositories(projectId, location, connectionId, pageToken = "", pageSize = 1000) {
|
|
55
|
-
const name = `projects/${projectId}/locations/${location}/connections/${connectionId}:fetchLinkableRepositories`;
|
|
56
|
-
const res = await client.get(name, {
|
|
57
|
-
queryParams: {
|
|
58
|
-
pageSize,
|
|
59
|
-
pageToken,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
return res.body;
|
|
63
|
-
}
|
|
64
|
-
async function createRepository(projectId, location, connectionId, repositoryId, remoteUri) {
|
|
65
|
-
const res = await client.post(`projects/${projectId}/locations/${location}/connections/${connectionId}/repositories`, { remoteUri }, { queryParams: { repositoryId } });
|
|
66
|
-
return res.body;
|
|
67
|
-
}
|
|
68
|
-
async function getRepository(projectId, location, connectionId, repositoryId) {
|
|
69
|
-
const name = `projects/${projectId}/locations/${location}/connections/${connectionId}/repositories/${repositoryId}`;
|
|
70
|
-
const res = await client.get(name);
|
|
71
|
-
return res.body;
|
|
72
|
-
}
|
|
73
|
-
async function deleteRepository(projectId, location, connectionId, repositoryId) {
|
|
74
|
-
const name = `projects/${projectId}/locations/${location}/connections/${connectionId}/repositories/${repositoryId}`;
|
|
75
|
-
const res = await client.delete(name);
|
|
76
|
-
return res.body;
|
|
77
|
-
}
|
|
78
4
|
function getDefaultServiceAccount(projectNumber) {
|
|
79
5
|
return `${projectNumber}@cloudbuild.gserviceaccount.com`;
|
|
80
6
|
}
|
|
81
|
-
function getDefaultServiceAgent(projectNumber) {
|
|
82
|
-
return `service-${projectNumber}@gcp-sa-cloudbuild.iam.gserviceaccount.com`;
|
|
83
|
-
}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.API_VERSION = void 0;
|
|
4
4
|
exports.generateUploadUrl = generateUploadUrl;
|
|
5
5
|
exports.createFunction = createFunction;
|
|
6
|
-
exports.getFunction = getFunction;
|
|
7
6
|
exports.listAllFunctions = listAllFunctions;
|
|
8
7
|
exports.updateFunction = updateFunction;
|
|
9
8
|
exports.deleteFunction = deleteFunction;
|
|
@@ -92,11 +91,6 @@ async function createFunction(cloudFunction) {
|
|
|
92
91
|
throw functionsOpLogReject(cloudFunction, "create", err);
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
|
-
async function getFunction(projectId, location, functionId) {
|
|
96
|
-
const name = `projects/${projectId}/locations/${location}/functions/${functionId}`;
|
|
97
|
-
const res = await client.get(name);
|
|
98
|
-
return res.body;
|
|
99
|
-
}
|
|
100
94
|
async function listAllFunctions(projectId) {
|
|
101
95
|
return await listFunctionsInternal(projectId, "-");
|
|
102
96
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteJob = deleteJob;
|
|
4
4
|
exports.getJob = getJob;
|
|
5
|
+
exports.listLocations = listLocations;
|
|
5
6
|
exports.createOrReplaceJob = createOrReplaceJob;
|
|
6
7
|
exports.jobNameForEndpoint = jobNameForEndpoint;
|
|
7
8
|
exports.topicNameForEndpoint = topicNameForEndpoint;
|
|
@@ -35,6 +36,17 @@ function getJob(name) {
|
|
|
35
36
|
resolveOnHTTPError: true,
|
|
36
37
|
});
|
|
37
38
|
}
|
|
39
|
+
async function listLocations(projectId) {
|
|
40
|
+
const locations = [];
|
|
41
|
+
let pageToken;
|
|
42
|
+
do {
|
|
43
|
+
const queryParams = pageToken ? { pageToken } : {};
|
|
44
|
+
const res = await apiClient.get(`/projects/${projectId}/locations`, { queryParams });
|
|
45
|
+
locations.push(...(res.body?.locations?.map((l) => l.locationId) ?? []));
|
|
46
|
+
pageToken = res.body?.nextPageToken;
|
|
47
|
+
} while (pageToken);
|
|
48
|
+
return locations;
|
|
49
|
+
}
|
|
38
50
|
function updateJob(job) {
|
|
39
51
|
let fieldMasks;
|
|
40
52
|
let json;
|
package/lib/gcp/cloudtasks.js
CHANGED
|
@@ -7,7 +7,6 @@ exports.updateQueue = updateQueue;
|
|
|
7
7
|
exports.upsertQueue = upsertQueue;
|
|
8
8
|
exports.disableQueue = disableQueue;
|
|
9
9
|
exports.purgeQueue = purgeQueue;
|
|
10
|
-
exports.deleteQueue = deleteQueue;
|
|
11
10
|
exports.enqueueTask = enqueueTask;
|
|
12
11
|
exports.setIamPolicy = setIamPolicy;
|
|
13
12
|
exports.getIamPolicy = getIamPolicy;
|
|
@@ -89,9 +88,6 @@ async function disableQueue(name) {
|
|
|
89
88
|
async function purgeQueue(name) {
|
|
90
89
|
await client.post(`${name}:purge`);
|
|
91
90
|
}
|
|
92
|
-
async function deleteQueue(name) {
|
|
93
|
-
await client.delete(name);
|
|
94
|
-
}
|
|
95
91
|
async function enqueueTask(queueName, task) {
|
|
96
92
|
await client.post(`${queueName}/tasks`, { task });
|
|
97
93
|
}
|
package/lib/gcp/devConnect.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.client = void 0;
|
|
4
4
|
exports.createConnection = createConnection;
|
|
5
|
-
exports.deleteConnection = deleteConnection;
|
|
6
5
|
exports.getConnection = getConnection;
|
|
7
6
|
exports.listAllConnections = listAllConnections;
|
|
8
7
|
exports.listAllLinkableGitRepositories = listAllLinkableGitRepositories;
|
|
@@ -39,11 +38,6 @@ async function createConnection(projectId, location, connectionId, githubConfig
|
|
|
39
38
|
}, { queryParams: { connectionId } });
|
|
40
39
|
return res.body;
|
|
41
40
|
}
|
|
42
|
-
async function deleteConnection(projectId, location, connectionId) {
|
|
43
|
-
const name = `projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}`;
|
|
44
|
-
const res = await exports.client.delete(name, { queryParams: { force: "true" } });
|
|
45
|
-
return res.body;
|
|
46
|
-
}
|
|
47
41
|
async function getConnection(projectId, location, connectionId) {
|
|
48
42
|
const name = `projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}`;
|
|
49
43
|
const res = await exports.client.get(name);
|
|
@@ -146,8 +140,8 @@ async function generateP4SA(projectNumber) {
|
|
|
146
140
|
await (0, serviceusage_1.generateServiceIdentityAndPoll)(projectNumber, new URL(devConnectOrigin).hostname, "apphosting");
|
|
147
141
|
}
|
|
148
142
|
function extractGitRepositoryLinkComponents(path) {
|
|
149
|
-
const connectionMatch = /connections\/([
|
|
150
|
-
const repositoryMatch = /gitRepositoryLinks\/([
|
|
143
|
+
const connectionMatch = /connections\/([^/]+)/.exec(path);
|
|
144
|
+
const repositoryMatch = /gitRepositoryLinks\/([^/]+)/.exec(path);
|
|
151
145
|
const connection = connectionMatch ? connectionMatch[1] : null;
|
|
152
146
|
const gitRepoLink = repositoryMatch ? repositoryMatch[1] : null;
|
|
153
147
|
return { connection, gitRepoLink };
|
package/lib/gcp/iam.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.listServiceAccountKeys = listServiceAccountKeys;
|
|
|
8
8
|
exports.getRole = getRole;
|
|
9
9
|
exports.testResourceIamPermissions = testResourceIamPermissions;
|
|
10
10
|
exports.testIamPermissions = testIamPermissions;
|
|
11
|
+
exports.isRetryableIamError = isRetryableIamError;
|
|
11
12
|
exports.mergeBindings = mergeBindings;
|
|
12
13
|
exports.printManualIamConfig = printManualIamConfig;
|
|
13
14
|
exports.getRoleName = getRoleName;
|
|
@@ -88,10 +89,23 @@ async function testResourceIamPermissions(origin, apiVersion, resourceName, perm
|
|
|
88
89
|
async function testIamPermissions(projectId, permissions) {
|
|
89
90
|
return testResourceIamPermissions((0, api_1.resourceManagerOrigin)(), "v1", `projects/${projectId}`, permissions, `${projectId}`);
|
|
90
91
|
}
|
|
92
|
+
function isRetryableIamError(err) {
|
|
93
|
+
const status = (0, error_1.getErrStatus)(err);
|
|
94
|
+
if (status === 409) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
const msg = (0, error_1.getErrMsg)(err).toLowerCase();
|
|
98
|
+
const hasSa = msg.includes("service account") || msg.includes("serviceaccount");
|
|
99
|
+
if (status === 400 && hasSa && msg.includes("does not exist")) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
91
104
|
function mergeBindings(policy, requiredBindings) {
|
|
92
105
|
let updated = false;
|
|
106
|
+
policy.bindings = policy.bindings || [];
|
|
93
107
|
for (const requiredBinding of requiredBindings) {
|
|
94
|
-
const match = policy.bindings.find((b) => b.role === requiredBinding.role);
|
|
108
|
+
const match = policy.bindings.find((b) => b.role === requiredBinding.role && !b.condition && !requiredBinding.condition);
|
|
95
109
|
if (!match) {
|
|
96
110
|
updated = true;
|
|
97
111
|
policy.bindings.push(requiredBinding);
|
|
@@ -9,7 +9,6 @@ exports.removeServiceAccountRoles = removeServiceAccountRoles;
|
|
|
9
9
|
exports.getServiceAccountRoles = getServiceAccountRoles;
|
|
10
10
|
const api_1 = require("../api");
|
|
11
11
|
const apiv2_1 = require("../apiv2");
|
|
12
|
-
const error_1 = require("../error");
|
|
13
12
|
const utils = require("../utils");
|
|
14
13
|
const iam_1 = require("./iam");
|
|
15
14
|
const API_VERSION = "v1";
|
|
@@ -33,18 +32,6 @@ async function setIamPolicy(projectIdOrNumber, newPolicy, updateMask = "") {
|
|
|
33
32
|
});
|
|
34
33
|
return response.body;
|
|
35
34
|
}
|
|
36
|
-
function isRetryableIamError(err) {
|
|
37
|
-
const status = (0, error_1.getErrStatus)(err);
|
|
38
|
-
if (status === 409) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
const msg = (0, error_1.getErrMsg)(err).toLowerCase();
|
|
42
|
-
const hasSa = msg.includes("service account") || msg.includes("serviceaccount");
|
|
43
|
-
if (status === 400 && hasSa && msg.includes("does not exist")) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
35
|
async function addServiceAccountToRoles(projectId, serviceAccountName, roles, skipAccountLookup = false) {
|
|
49
36
|
const { name: fullServiceAccountName } = skipAccountLookup
|
|
50
37
|
? { name: serviceAccountName }
|
|
@@ -63,7 +50,7 @@ async function addServiceAccountToRoles(projectId, serviceAccountName, roles, sk
|
|
|
63
50
|
retries: 7,
|
|
64
51
|
delay: 1000,
|
|
65
52
|
maxDelay: 5000,
|
|
66
|
-
retryPredicate: isRetryableIamError,
|
|
53
|
+
retryPredicate: iam_1.isRetryableIamError,
|
|
67
54
|
});
|
|
68
55
|
}
|
|
69
56
|
async function serviceAccountHasRoles(projectId, serviceAccountName, roles, skipAccountLookup = false) {
|
package/lib/gcp/storage.js
CHANGED
|
@@ -14,6 +14,9 @@ exports.upsertBucket = upsertBucket;
|
|
|
14
14
|
exports.listBuckets = listBuckets;
|
|
15
15
|
exports.getServiceAccount = getServiceAccount;
|
|
16
16
|
exports.getDownloadUrl = getDownloadUrl;
|
|
17
|
+
exports.getBucketIamPolicy = getBucketIamPolicy;
|
|
18
|
+
exports.setBucketIamPolicy = setBucketIamPolicy;
|
|
19
|
+
exports.addServiceAccountToBucketRoles = addServiceAccountToBucketRoles;
|
|
17
20
|
const path = require("path");
|
|
18
21
|
const clc = require("colorette");
|
|
19
22
|
const crypto_1 = require("crypto");
|
|
@@ -24,6 +27,11 @@ const logger_1 = require("../logger");
|
|
|
24
27
|
const ensureApiEnabled_1 = require("../ensureApiEnabled");
|
|
25
28
|
const utils = require("../utils");
|
|
26
29
|
const proto_1 = require("./proto");
|
|
30
|
+
const iam_1 = require("./iam");
|
|
31
|
+
const BUCKET_IAM_POLICY_VERSION = "3";
|
|
32
|
+
const IAM_RETRY_COUNT = 7;
|
|
33
|
+
const IAM_RETRY_INITIAL_DELAY_MS = 1000;
|
|
34
|
+
const IAM_RETRY_MAX_DELAY_MS = 5000;
|
|
27
35
|
var ContentType;
|
|
28
36
|
(function (ContentType) {
|
|
29
37
|
ContentType["ZIP"] = "ZIP";
|
|
@@ -126,11 +134,27 @@ async function getBucket(bucketName) {
|
|
|
126
134
|
});
|
|
127
135
|
}
|
|
128
136
|
}
|
|
137
|
+
function extractApiErrorMessage(err) {
|
|
138
|
+
if (!(0, error_1.isObject)(err) || !(0, error_1.isObject)(err.context) || !(0, error_1.isObject)(err.context.body)) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
const apiError = err.context.body.error;
|
|
142
|
+
if (typeof apiError === "string" && apiError.trim()) {
|
|
143
|
+
return apiError.trim();
|
|
144
|
+
}
|
|
145
|
+
if ((0, error_1.isObject)(apiError) &&
|
|
146
|
+
typeof apiError.message === "string" &&
|
|
147
|
+
apiError.message.trim() &&
|
|
148
|
+
apiError.message !== "Unknown Error") {
|
|
149
|
+
return apiError.message.trim();
|
|
150
|
+
}
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
129
153
|
async function createBucket(projectId, req, projectPrivate) {
|
|
130
154
|
const queryParams = {
|
|
131
155
|
project: projectId,
|
|
132
156
|
};
|
|
133
|
-
if (projectPrivate) {
|
|
157
|
+
if (projectPrivate && !req.iamConfiguration?.uniformBucketLevelAccess?.enabled) {
|
|
134
158
|
queryParams["predefinedAcl"] = "projectPrivate";
|
|
135
159
|
queryParams["predefinedDefaultObjectAcl"] = "projectPrivate";
|
|
136
160
|
}
|
|
@@ -140,9 +164,14 @@ async function createBucket(projectId, req, projectPrivate) {
|
|
|
140
164
|
return result.body;
|
|
141
165
|
}
|
|
142
166
|
catch (err) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
167
|
+
const error = (0, error_1.getError)(err);
|
|
168
|
+
logger_1.logger.debug(error);
|
|
169
|
+
const detail = extractApiErrorMessage(err) || error.message;
|
|
170
|
+
throw new error_1.FirebaseError(detail
|
|
171
|
+
? `Failed to create the storage bucket: ${detail}`
|
|
172
|
+
: "Failed to create the storage bucket", {
|
|
173
|
+
original: error,
|
|
174
|
+
status: (0, error_1.getErrStatus)(err),
|
|
146
175
|
});
|
|
147
176
|
}
|
|
148
177
|
}
|
|
@@ -270,3 +299,57 @@ async function getDownloadUrl(bucketName, objectPath, emulatorUrl) {
|
|
|
270
299
|
});
|
|
271
300
|
}
|
|
272
301
|
}
|
|
302
|
+
async function getBucketIamPolicy(bucketName) {
|
|
303
|
+
try {
|
|
304
|
+
const localAPIClient = new apiv2_1.Client({ urlPrefix: (0, api_1.storageOrigin)() });
|
|
305
|
+
const response = await localAPIClient.get(`/storage/v1/b/${bucketName}/iam`, {
|
|
306
|
+
queryParams: { optionsRequestedPolicyVersion: BUCKET_IAM_POLICY_VERSION },
|
|
307
|
+
});
|
|
308
|
+
return response.body;
|
|
309
|
+
}
|
|
310
|
+
catch (err) {
|
|
311
|
+
const error = (0, error_1.getError)(err);
|
|
312
|
+
logger_1.logger.debug(error);
|
|
313
|
+
throw new error_1.FirebaseError("Failed to get the storage bucket IAM policy", {
|
|
314
|
+
original: error,
|
|
315
|
+
status: (0, error_1.getErrStatus)(err),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
async function setBucketIamPolicy(bucketName, policy) {
|
|
320
|
+
try {
|
|
321
|
+
const localAPIClient = new apiv2_1.Client({ urlPrefix: (0, api_1.storageOrigin)() });
|
|
322
|
+
const response = await localAPIClient.put(`/storage/v1/b/${bucketName}/iam`, policy);
|
|
323
|
+
return response.body;
|
|
324
|
+
}
|
|
325
|
+
catch (err) {
|
|
326
|
+
const error = (0, error_1.getError)(err);
|
|
327
|
+
logger_1.logger.debug(error);
|
|
328
|
+
throw new error_1.FirebaseError("Failed to set the storage bucket IAM policy", {
|
|
329
|
+
original: error,
|
|
330
|
+
status: (0, error_1.getErrStatus)(err),
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
async function addServiceAccountToBucketRoles(bucketName, serviceAccountEmail, roles) {
|
|
335
|
+
const email = serviceAccountEmail.split("/").pop() || serviceAccountEmail;
|
|
336
|
+
const memberName = `serviceAccount:${email}`;
|
|
337
|
+
return await utils.retryWithBackoff(async () => {
|
|
338
|
+
const policy = await dynamicDispatch.getBucketIamPolicy(bucketName);
|
|
339
|
+
policy.bindings = policy.bindings || [];
|
|
340
|
+
const requiredBindings = roles.map((role) => ({
|
|
341
|
+
role,
|
|
342
|
+
members: [memberName],
|
|
343
|
+
}));
|
|
344
|
+
const updated = (0, iam_1.mergeBindings)(policy, requiredBindings);
|
|
345
|
+
if (!updated) {
|
|
346
|
+
return policy;
|
|
347
|
+
}
|
|
348
|
+
return await dynamicDispatch.setBucketIamPolicy(bucketName, policy);
|
|
349
|
+
}, {
|
|
350
|
+
retries: IAM_RETRY_COUNT,
|
|
351
|
+
delay: IAM_RETRY_INITIAL_DELAY_MS,
|
|
352
|
+
maxDelay: IAM_RETRY_MAX_DELAY_MS,
|
|
353
|
+
retryPredicate: iam_1.isRetryableIamError,
|
|
354
|
+
});
|
|
355
|
+
}
|