firebase-tools 11.4.0 → 11.5.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/README.md +8 -15
- package/lib/accountImporter.js +1 -1
- package/lib/auth.js +3 -4
- package/lib/bin/firebase.js +4 -4
- package/lib/command.js +3 -3
- package/lib/commands/apps-android-sha-create.js +1 -1
- package/lib/commands/apps-android-sha-delete.js +1 -1
- package/lib/commands/apps-create.js +1 -1
- package/lib/commands/apps-list.js +1 -1
- package/lib/commands/auth-export.js +1 -1
- package/lib/commands/auth-import.js +1 -1
- package/lib/commands/database-instances-list.js +1 -1
- package/lib/commands/database-push.js +1 -1
- package/lib/commands/database-remove.js +1 -1
- package/lib/commands/database-set.js +1 -1
- package/lib/commands/database-update.js +1 -1
- package/lib/commands/emulators-start.js +1 -1
- package/lib/commands/ext-dev-deprecate.js +1 -1
- package/lib/commands/ext-dev-emulators-exec.js +1 -1
- package/lib/commands/ext-dev-emulators-start.js +1 -1
- package/lib/commands/ext-dev-extension-delete.js +1 -1
- package/lib/commands/ext-dev-list.js +1 -1
- package/lib/commands/ext-dev-publish.js +1 -1
- package/lib/commands/ext-dev-register.js +1 -1
- package/lib/commands/ext-dev-undeprecate.js +1 -1
- package/lib/commands/ext-dev-unpublish.js +1 -1
- package/lib/commands/ext-dev-usage.js +1 -1
- package/lib/commands/ext-info.js +1 -1
- package/lib/commands/ext-install.js +2 -2
- package/lib/commands/ext-update.js +1 -1
- package/lib/commands/ext.js +1 -1
- package/lib/commands/firestore-delete.js +2 -2
- package/lib/commands/firestore-indexes-list.js +3 -3
- package/lib/commands/functions-config-clone.js +1 -1
- package/lib/commands/functions-config-export.js +1 -1
- package/lib/commands/functions-config-set.js +1 -1
- package/lib/commands/functions-config-unset.js +1 -1
- package/lib/commands/functions-delete.js +1 -1
- package/lib/commands/functions-secrets-set.js +1 -1
- package/lib/commands/help.js +1 -1
- package/lib/commands/hosting-channel-create.js +5 -5
- package/lib/commands/hosting-channel-delete.js +3 -3
- package/lib/commands/hosting-channel-deploy.js +6 -6
- package/lib/commands/hosting-channel-list.js +2 -2
- package/lib/commands/hosting-channel-open.js +2 -2
- package/lib/commands/hosting-clone.js +13 -8
- package/lib/commands/hosting-disable.js +1 -1
- package/lib/commands/hosting-sites-create.js +4 -4
- package/lib/commands/hosting-sites-delete.js +4 -4
- package/lib/commands/hosting-sites-list.js +2 -2
- package/lib/commands/init.js +5 -5
- package/lib/commands/login-add.js +1 -1
- package/lib/commands/login-ci.js +4 -2
- package/lib/commands/login-list.js +1 -1
- package/lib/commands/login-use.js +1 -1
- package/lib/commands/login.js +1 -1
- package/lib/commands/logout.js +1 -1
- package/lib/commands/open.js +3 -3
- package/lib/commands/projects-list.js +2 -2
- package/lib/commands/serve.js +1 -1
- package/lib/commands/target-apply.js +1 -1
- package/lib/commands/target-clear.js +1 -1
- package/lib/commands/target-remove.js +1 -1
- package/lib/commands/target.js +1 -1
- package/lib/commands/use.js +7 -7
- package/lib/config.js +1 -1
- package/lib/deploy/database/prepare.js +3 -3
- package/lib/deploy/database/release.js +3 -3
- package/lib/deploy/extensions/deploymentSummary.js +1 -1
- package/lib/deploy/extensions/errors.js +1 -1
- package/lib/deploy/extensions/secrets.js +1 -1
- package/lib/deploy/extensions/tasks.js +2 -2
- package/lib/deploy/firestore/deploy.js +2 -2
- package/lib/deploy/firestore/prepare.js +2 -2
- package/lib/deploy/functions/backend.js +7 -5
- package/lib/deploy/functions/build.js +110 -95
- package/lib/deploy/functions/checkIam.js +3 -3
- package/lib/deploy/functions/containerCleaner.js +2 -2
- package/lib/deploy/functions/deploy.js +2 -2
- package/lib/deploy/functions/ensure.js +2 -2
- package/lib/deploy/functions/params.js +5 -2
- package/lib/deploy/functions/prepare.js +4 -4
- package/lib/deploy/functions/prepareFunctionsUpload.js +2 -2
- package/lib/deploy/functions/pricing.js +3 -2
- package/lib/deploy/functions/prompts.js +2 -2
- package/lib/deploy/functions/release/fabricator.js +10 -9
- package/lib/deploy/functions/release/index.js +1 -1
- package/lib/deploy/functions/release/reporter.js +1 -1
- package/lib/deploy/functions/runtimes/discovery/parsing.js +19 -8
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +112 -107
- package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +1 -1
- package/lib/deploy/functions/runtimes/node/parseTriggers.js +54 -26
- package/lib/deploy/functions/runtimes/node/versioning.js +4 -4
- package/lib/deploy/functions/services/storage.js +6 -0
- package/lib/deploy/functions/validate.js +1 -1
- package/lib/deploy/hosting/convertConfig.js +13 -2
- package/lib/deploy/hosting/deploy.js +11 -10
- package/lib/deploy/hosting/uploader.js +2 -2
- package/lib/deploy/hosting/validate.js +2 -2
- package/lib/deploy/index.js +7 -7
- package/lib/deploy/lifecycleHooks.js +5 -2
- package/lib/deploy/storage/prepare.js +5 -3
- package/lib/deploy/storage/release.js +7 -6
- package/lib/emulator/commandUtils.js +1 -1
- package/lib/emulator/controller.js +1 -1
- package/lib/emulator/databaseEmulator.js +1 -1
- package/lib/emulator/downloadableEmulators.js +1 -1
- package/lib/emulator/emulatorLogger.js +1 -1
- package/lib/emulator/extensionsEmulator.js +2 -2
- package/lib/emulator/firestoreEmulator.js +1 -1
- package/lib/emulator/functionsEmulator.js +22 -10
- package/lib/emulator/functionsEmulatorShared.js +6 -11
- package/lib/emulator/loggingEmulator.js +2 -2
- package/lib/emulator/storage/apis/firebase.js +13 -1
- package/lib/emulator/storage/apis/gcloud.js +15 -8
- package/lib/emulator/storage/files.js +26 -24
- package/lib/emulator/storage/metadata.js +6 -6
- package/lib/emulator/storage/multipart.js +4 -3
- package/lib/emulator/storage/persistence.js +26 -12
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/emulator/storage/rules/utils.js +4 -2
- package/lib/emulator/types.js +1 -0
- package/lib/ensureApiEnabled.js +7 -7
- package/lib/extensions/askUserForConsent.js +1 -1
- package/lib/extensions/askUserForEventsConfig.js +1 -1
- package/lib/extensions/askUserForParam.js +1 -1
- package/lib/extensions/changelog.js +2 -2
- package/lib/extensions/checkProjectBilling.js +2 -2
- package/lib/extensions/displayExtensionInfo.js +2 -102
- package/lib/extensions/emulator/triggerHelper.js +2 -2
- package/lib/extensions/extensionsApi.js +1 -1
- package/lib/extensions/extensionsHelper.js +1 -1
- package/lib/extensions/listExtensions.js +1 -1
- package/lib/extensions/manifest.js +1 -1
- package/lib/extensions/metricsUtils.js +1 -1
- package/lib/extensions/paramHelper.js +1 -1
- package/lib/extensions/updateHelper.js +3 -9
- package/lib/extensions/warnings.js +2 -2
- package/lib/fetchMOTD.js +1 -1
- package/lib/firestore/delete.js +1 -1
- package/lib/firestore/indexes.js +2 -2
- package/lib/firestore/validator.js +1 -1
- package/lib/functional.js +16 -1
- package/lib/functions/env.js +3 -3
- package/lib/functions/runtimeConfigExport.js +1 -1
- package/lib/functionsConfig.js +1 -1
- package/lib/functionsConfigClone.js +1 -1
- package/lib/functionsShellCommandAction.js +1 -1
- package/lib/gcp/cloudfunctions.js +24 -11
- package/lib/gcp/cloudfunctionsv2.js +48 -24
- package/lib/gcp/cloudscheduler.js +58 -22
- package/lib/gcp/cloudtasks.js +21 -4
- package/lib/gcp/proto.js +18 -6
- package/lib/gcp/resourceManager.js +25 -3
- package/lib/gcp/serviceusage.js +2 -2
- package/lib/handlePreviewToggles.js +4 -4
- package/lib/hosting/implicitInit.js +1 -1
- package/lib/hosting/normalizedHostingConfigs.js +3 -3
- package/lib/index.js +3 -3
- package/lib/init/features/database.js +1 -1
- package/lib/init/features/emulators.js +1 -1
- package/lib/init/features/firestore/index.js +2 -2
- package/lib/init/features/firestore/indexes.js +1 -1
- package/lib/init/features/firestore/rules.js +1 -1
- package/lib/init/features/functions/golang.js +1 -1
- package/lib/init/features/functions/index.js +8 -1
- package/lib/init/features/hosting/github.js +9 -9
- package/lib/init/features/hosting/index.js +1 -1
- package/lib/init/features/project.js +1 -1
- package/lib/init/features/remoteconfig.js +1 -1
- package/lib/init/features/storage.js +1 -1
- package/lib/init/index.js +1 -1
- package/lib/logError.js +3 -3
- package/lib/management/projects.js +1 -1
- package/lib/parseBoltRules.js +1 -1
- package/lib/previews.js +1 -1
- package/lib/profileReport.js +2 -2
- package/lib/projectUtils.js +1 -1
- package/lib/rc.js +1 -1
- package/lib/requireAuth.js +5 -1
- package/lib/requireDatabaseInstance.js +2 -2
- package/lib/requirePermissions.js +2 -2
- package/lib/rulesDeploy.js +49 -13
- package/lib/serve/hosting.js +2 -1
- package/lib/utils.js +10 -10
- package/npm-shrinkwrap.json +26 -295
- package/package.json +8 -5
- package/templates/hosting/init.js +6 -2
package/lib/functions/env.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadFirebaseEnvs = exports.loadUserEnvs = exports.writeUserEnvs = exports.hasUserEnvs = exports.parseStrict = exports.validateKey = exports.KeyValidationError = exports.parse = void 0;
|
|
4
|
-
const clc = require("
|
|
4
|
+
const clc = require("colorette");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const path = require("path");
|
|
7
7
|
const error_1 = require("../error");
|
|
@@ -173,7 +173,7 @@ function writeUserEnvs(toWrite, envOpts) {
|
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
175
|
const mostSpecificEnv = path.join(functionsSource, envFiles[envFiles.length - 1]);
|
|
176
|
-
(0, utils_1.logBullet)(clc.cyan.bold("functions: ") + `Writing new parameter values to disk: ${mostSpecificEnv}`);
|
|
176
|
+
(0, utils_1.logBullet)(clc.cyan(clc.bold("functions: ")) + `Writing new parameter values to disk: ${mostSpecificEnv}`);
|
|
177
177
|
for (const k of Object.keys(toWrite)) {
|
|
178
178
|
fs.appendFileSync(mostSpecificEnv, formatUserEnvForWrite(k, toWrite[k]));
|
|
179
179
|
}
|
|
@@ -219,7 +219,7 @@ function loadUserEnvs({ functionsSource, projectId, projectAlias, isEmulator, })
|
|
|
219
219
|
});
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
(0, utils_1.logBullet)(clc.cyan.bold("functions: ") + `Loaded environment variables from ${envFiles.join(", ")}.`);
|
|
222
|
+
(0, utils_1.logBullet)(clc.cyan(clc.bold("functions: ")) + `Loaded environment variables from ${envFiles.join(", ")}.`);
|
|
223
223
|
return envs;
|
|
224
224
|
}
|
|
225
225
|
exports.loadUserEnvs = loadUserEnvs;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateDotenvFilename = exports.toDotenvFormat = exports.hydrateEnvs = exports.configToEnv = exports.convertKey = exports.hydrateConfigs = exports.getProjectInfos = void 0;
|
|
4
|
-
const clc = require("
|
|
4
|
+
const clc = require("colorette");
|
|
5
5
|
const env = require("./env");
|
|
6
6
|
const functionsConfig = require("../functionsConfig");
|
|
7
7
|
const error_1 = require("../error");
|
package/lib/functionsConfig.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseUnsetArgs = exports.parseSetArgs = exports.materializeAll = exports.materializeConfig = exports.setVariablesRecursive = exports.getFirebaseConfig = exports.getAppEngineLocation = exports.idsToVarName = exports.varNameToIds = exports.ensureApi = exports.RESERVED_NAMESPACES = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
|
-
const clc = require("
|
|
5
|
+
const clc = require("colorette");
|
|
6
6
|
const api_1 = require("./api");
|
|
7
7
|
const apiv2_1 = require("./apiv2");
|
|
8
8
|
const ensureApiEnabled_1 = require("./ensureApiEnabled");
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.functionsConfigClone = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
|
-
const clc = require("
|
|
5
|
+
const clc = require("colorette");
|
|
6
6
|
const error_1 = require("./error");
|
|
7
7
|
const functionsConfig = require("./functionsConfig");
|
|
8
8
|
const runtimeconfig = require("./gcp/runtimeconfig");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.actionFunction = void 0;
|
|
4
|
-
const clc = require("
|
|
4
|
+
const clc = require("colorette");
|
|
5
5
|
const repl = require("repl");
|
|
6
6
|
const _ = require("lodash");
|
|
7
7
|
const request = require("request");
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.functionFromEndpoint = exports.endpointFromFunction = exports.listAllFunctions = exports.listFunctions = exports.deleteFunction = exports.updateFunction = exports.setInvokerUpdate = exports.setInvokerCreate = exports.getIamPolicy = exports.setIamPolicy = exports.createFunction = exports.generateUploadUrl = exports.BLOCKING_LABEL = exports.CODEBASE_LABEL = exports.API_VERSION = void 0;
|
|
4
|
-
const clc = require("
|
|
4
|
+
const clc = require("colorette");
|
|
5
5
|
const error_1 = require("../error");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
7
7
|
const backend = require("../deploy/functions/backend");
|
|
@@ -26,10 +26,10 @@ const BLOCKING_EVENT_TO_LABEL_KEY = {
|
|
|
26
26
|
function functionsOpLogReject(funcName, type, err) {
|
|
27
27
|
var _a, _b;
|
|
28
28
|
if (((_b = (_a = err === null || err === void 0 ? void 0 : err.context) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.statusCode) === 429) {
|
|
29
|
-
utils.logWarning(`${clc.bold.yellow("functions:")} got "Quota Exceeded" error while trying to ${type} ${funcName}. Waiting to retry...`);
|
|
29
|
+
utils.logWarning(`${clc.bold(clc.yellow("functions:"))} got "Quota Exceeded" error while trying to ${type} ${funcName}. Waiting to retry...`);
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
|
-
utils.logWarning(clc.bold.yellow("functions:") + " failed to " + type + " function " + funcName);
|
|
32
|
+
utils.logWarning(clc.bold(clc.yellow("functions:")) + " failed to " + type + " function " + funcName);
|
|
33
33
|
}
|
|
34
34
|
throw new error_1.FirebaseError(`Failed to ${type} function ${funcName}`, {
|
|
35
35
|
original: err,
|
|
@@ -255,18 +255,20 @@ function endpointFromFunction(gcfFunction) {
|
|
|
255
255
|
if (securityLevel) {
|
|
256
256
|
endpoint.securityLevel = securityLevel;
|
|
257
257
|
}
|
|
258
|
-
proto.copyIfPresent(endpoint, gcfFunction, "
|
|
259
|
-
proto.renameIfPresent(endpoint, gcfFunction, "
|
|
258
|
+
proto.copyIfPresent(endpoint, gcfFunction, "minInstances", "maxInstances", "ingressSettings", "labels", "environmentVariables", "secretEnvironmentVariables", "sourceUploadUrl");
|
|
259
|
+
proto.renameIfPresent(endpoint, gcfFunction, "serviceAccount", "serviceAccountEmail");
|
|
260
|
+
proto.convertIfPresent(endpoint, gcfFunction, "availableMemoryMb", (raw) => raw);
|
|
261
|
+
proto.convertIfPresent(endpoint, gcfFunction, "timeoutSeconds", "timeout", (dur) => dur === null ? null : proto.secondsFromDuration(dur));
|
|
260
262
|
if (gcfFunction.vpcConnector) {
|
|
261
263
|
endpoint.vpc = { connector: gcfFunction.vpcConnector };
|
|
262
|
-
proto.
|
|
264
|
+
proto.convertIfPresent(endpoint.vpc, gcfFunction, "egressSettings", "vpcConnectorEgressSettings", (raw) => raw);
|
|
263
265
|
}
|
|
264
266
|
endpoint.codebase = ((_g = gcfFunction.labels) === null || _g === void 0 ? void 0 : _g[exports.CODEBASE_LABEL]) || projectConfig.DEFAULT_CODEBASE;
|
|
265
267
|
return endpoint;
|
|
266
268
|
}
|
|
267
269
|
exports.endpointFromFunction = endpointFromFunction;
|
|
268
270
|
function functionFromEndpoint(endpoint, sourceUploadUrl) {
|
|
269
|
-
var _a;
|
|
271
|
+
var _a, _b;
|
|
270
272
|
if (endpoint.platform !== "gcfv1") {
|
|
271
273
|
throw new error_1.FirebaseError("Trying to create a v1 CloudFunction with v2 API. This should never happen");
|
|
272
274
|
}
|
|
@@ -281,8 +283,13 @@ function functionFromEndpoint(endpoint, sourceUploadUrl) {
|
|
|
281
283
|
runtime: endpoint.runtime,
|
|
282
284
|
dockerRegistry: "ARTIFACT_REGISTRY",
|
|
283
285
|
};
|
|
284
|
-
|
|
286
|
+
if (typeof endpoint.labels !== "undefined") {
|
|
287
|
+
gcfFunction.labels = Object.assign({}, endpoint.labels);
|
|
288
|
+
}
|
|
285
289
|
if (backend.isEventTriggered(endpoint)) {
|
|
290
|
+
if (!((_a = endpoint.eventTrigger.eventFilters) === null || _a === void 0 ? void 0 : _a.resource)) {
|
|
291
|
+
throw new error_1.FirebaseError("Cannot create v1 function from an eventTrigger without a resource");
|
|
292
|
+
}
|
|
286
293
|
gcfFunction.eventTrigger = {
|
|
287
294
|
eventType: endpoint.eventTrigger.eventType,
|
|
288
295
|
resource: endpoint.eventTrigger.eventFilters.resource,
|
|
@@ -316,18 +323,24 @@ function functionFromEndpoint(endpoint, sourceUploadUrl) {
|
|
|
316
323
|
gcfFunction.httpsTrigger.securityLevel = endpoint.securityLevel;
|
|
317
324
|
}
|
|
318
325
|
}
|
|
319
|
-
proto.copyIfPresent(gcfFunction, endpoint, "
|
|
320
|
-
proto.renameIfPresent(gcfFunction, endpoint, "
|
|
326
|
+
proto.copyIfPresent(gcfFunction, endpoint, "minInstances", "maxInstances", "ingressSettings", "environmentVariables", "secretEnvironmentVariables");
|
|
327
|
+
proto.renameIfPresent(gcfFunction, endpoint, "serviceAccountEmail", "serviceAccount");
|
|
328
|
+
proto.convertIfPresent(gcfFunction, endpoint, "availableMemoryMb", (mem) => mem);
|
|
329
|
+
proto.convertIfPresent(gcfFunction, endpoint, "timeout", "timeoutSeconds", (sec) => sec ? proto.durationFromSeconds(sec) : null);
|
|
321
330
|
if (endpoint.vpc) {
|
|
322
331
|
proto.renameIfPresent(gcfFunction, endpoint.vpc, "vpcConnector", "connector");
|
|
323
332
|
proto.renameIfPresent(gcfFunction, endpoint.vpc, "vpcConnectorEgressSettings", "egressSettings");
|
|
324
333
|
}
|
|
334
|
+
else if (endpoint.vpc === null) {
|
|
335
|
+
gcfFunction.vpcConnector = null;
|
|
336
|
+
gcfFunction.vpcConnectorEgressSettings = null;
|
|
337
|
+
}
|
|
325
338
|
const codebase = endpoint.codebase || projectConfig.DEFAULT_CODEBASE;
|
|
326
339
|
if (codebase !== projectConfig.DEFAULT_CODEBASE) {
|
|
327
340
|
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [exports.CODEBASE_LABEL]: codebase });
|
|
328
341
|
}
|
|
329
342
|
else {
|
|
330
|
-
(
|
|
343
|
+
(_b = gcfFunction.labels) === null || _b === void 0 ? true : delete _b[exports.CODEBASE_LABEL];
|
|
331
344
|
}
|
|
332
345
|
return gcfFunction;
|
|
333
346
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.endpointFromFunction = exports.functionFromEndpoint = exports.deleteFunction = exports.updateFunction = exports.listAllFunctions = exports.listFunctions = exports.getFunction = exports.createFunction = exports.generateUploadUrl = exports.mebibytes = exports.BLOCKING_LABEL = exports.CODEBASE_LABEL = exports.API_VERSION = void 0;
|
|
4
|
-
const clc = require("
|
|
4
|
+
const clc = require("colorette");
|
|
5
5
|
const apiv2_1 = require("../apiv2");
|
|
6
6
|
const error_1 = require("../error");
|
|
7
7
|
const api_1 = require("../api");
|
|
@@ -59,15 +59,15 @@ function mebibytes(memory) {
|
|
|
59
59
|
exports.mebibytes = mebibytes;
|
|
60
60
|
function functionsOpLogReject(funcName, type, err) {
|
|
61
61
|
var _a, _b;
|
|
62
|
-
utils.logWarning(clc.bold.yellow("functions:") + ` ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
62
|
+
utils.logWarning(clc.bold(clc.yellow("functions:")) + ` ${err === null || err === void 0 ? void 0 : err.message}`);
|
|
63
63
|
if (((_b = (_a = err === null || err === void 0 ? void 0 : err.context) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.statusCode) === 429) {
|
|
64
|
-
utils.logWarning(`${clc.bold.yellow("functions:")} got "Quota Exceeded" error while trying to ${type} ${funcName}. Waiting to retry...`);
|
|
64
|
+
utils.logWarning(`${clc.bold(clc.yellow("functions:"))} got "Quota Exceeded" error while trying to ${type} ${funcName}. Waiting to retry...`);
|
|
65
65
|
}
|
|
66
66
|
else if (err === null || err === void 0 ? void 0 : err.message.includes("If you recently started to use Eventarc, it may take a few minutes before all necessary permissions are propagated to the Service Agent")) {
|
|
67
|
-
utils.logWarning(`${clc.bold.yellow("functions:")} since this is your first time using functions v2, we need a little bit longer to finish setting everything up, please retry the deployment in a few minutes.`);
|
|
67
|
+
utils.logWarning(`${clc.bold(clc.yellow("functions:"))} since this is your first time using functions v2, we need a little bit longer to finish setting everything up, please retry the deployment in a few minutes.`);
|
|
68
68
|
}
|
|
69
69
|
else {
|
|
70
|
-
utils.logWarning(clc.bold.yellow("functions:") + " failed to " + type + " function " + funcName);
|
|
70
|
+
utils.logWarning(clc.bold(clc.yellow("functions:")) + " failed to " + type + " function " + funcName);
|
|
71
71
|
}
|
|
72
72
|
throw new error_1.FirebaseError(`Failed to ${type} function ${funcName}`, {
|
|
73
73
|
original: err,
|
|
@@ -161,7 +161,7 @@ async function deleteFunction(cloudFunction) {
|
|
|
161
161
|
}
|
|
162
162
|
exports.deleteFunction = deleteFunction;
|
|
163
163
|
function functionFromEndpoint(endpoint, source) {
|
|
164
|
-
var _a;
|
|
164
|
+
var _a, _b;
|
|
165
165
|
if (endpoint.platform !== "gcfv2") {
|
|
166
166
|
throw new error_1.FirebaseError("Trying to create a v2 CloudFunction with v1 API. This should never happen");
|
|
167
167
|
}
|
|
@@ -182,7 +182,8 @@ function functionFromEndpoint(endpoint, source) {
|
|
|
182
182
|
serviceConfig: {},
|
|
183
183
|
};
|
|
184
184
|
proto.copyIfPresent(gcfFunction, endpoint, "labels");
|
|
185
|
-
proto.copyIfPresent(gcfFunction.serviceConfig, endpoint, "environmentVariables", "secretEnvironmentVariables", "
|
|
185
|
+
proto.copyIfPresent(gcfFunction.serviceConfig, endpoint, "environmentVariables", "secretEnvironmentVariables", "ingressSettings", "timeoutSeconds");
|
|
186
|
+
proto.renameIfPresent(gcfFunction.serviceConfig, endpoint, "serviceAccountEmail", "serviceAccount");
|
|
186
187
|
const mem = endpoint.availableMemoryMb || backend.DEFAULT_MEMORY;
|
|
187
188
|
gcfFunction.serviceConfig.availableMemory = mem > 1024 ? `${mem / 1024}Gi` : `${mem}Mi`;
|
|
188
189
|
proto.renameIfPresent(gcfFunction.serviceConfig, endpoint, "minInstanceCount", "minInstances");
|
|
@@ -191,11 +192,19 @@ function functionFromEndpoint(endpoint, source) {
|
|
|
191
192
|
proto.renameIfPresent(gcfFunction.serviceConfig, endpoint.vpc, "vpcConnector", "connector");
|
|
192
193
|
proto.renameIfPresent(gcfFunction.serviceConfig, endpoint.vpc, "vpcConnectorEgressSettings", "egressSettings");
|
|
193
194
|
}
|
|
195
|
+
else if (endpoint.vpc === null) {
|
|
196
|
+
gcfFunction.serviceConfig.vpcConnector = null;
|
|
197
|
+
gcfFunction.serviceConfig.vpcConnectorEgressSettings = null;
|
|
198
|
+
}
|
|
194
199
|
if (backend.isEventTriggered(endpoint)) {
|
|
195
200
|
gcfFunction.eventTrigger = {
|
|
196
201
|
eventType: endpoint.eventTrigger.eventType,
|
|
197
202
|
};
|
|
198
203
|
if (gcfFunction.eventTrigger.eventType === v2_1.PUBSUB_PUBLISH_EVENT) {
|
|
204
|
+
if (!((_a = endpoint.eventTrigger.eventFilters) === null || _a === void 0 ? void 0 : _a.topic)) {
|
|
205
|
+
throw new error_1.FirebaseError("Error: Pub/Sub event trigger is missing topic: " +
|
|
206
|
+
JSON.stringify(endpoint.eventTrigger, null, 2));
|
|
207
|
+
}
|
|
199
208
|
gcfFunction.eventTrigger.pubsubTopic = endpoint.eventTrigger.eventFilters.topic;
|
|
200
209
|
gcfFunction.eventTrigger.eventFilters = [];
|
|
201
210
|
for (const [attribute, value] of Object.entries(endpoint.eventTrigger.eventFilters)) {
|
|
@@ -206,7 +215,7 @@ function functionFromEndpoint(endpoint, source) {
|
|
|
206
215
|
}
|
|
207
216
|
else {
|
|
208
217
|
gcfFunction.eventTrigger.eventFilters = [];
|
|
209
|
-
for (const [attribute, value] of Object.entries(endpoint.eventTrigger.eventFilters)) {
|
|
218
|
+
for (const [attribute, value] of Object.entries(endpoint.eventTrigger.eventFilters || {})) {
|
|
210
219
|
gcfFunction.eventTrigger.eventFilters.push({ attribute, value });
|
|
211
220
|
}
|
|
212
221
|
for (const [attribute, value] of Object.entries(endpoint.eventTrigger.eventFilterPathPatterns || {})) {
|
|
@@ -241,7 +250,7 @@ function functionFromEndpoint(endpoint, source) {
|
|
|
241
250
|
gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { [exports.CODEBASE_LABEL]: codebase });
|
|
242
251
|
}
|
|
243
252
|
else {
|
|
244
|
-
(
|
|
253
|
+
(_b = gcfFunction.labels) === null || _b === void 0 ? true : delete _b[exports.CODEBASE_LABEL];
|
|
245
254
|
}
|
|
246
255
|
return gcfFunction;
|
|
247
256
|
}
|
|
@@ -273,29 +282,33 @@ function endpointFromFunction(gcfFunction) {
|
|
|
273
282
|
};
|
|
274
283
|
}
|
|
275
284
|
else if (gcfFunction.eventTrigger) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
eventType: gcfFunction.eventTrigger.eventType,
|
|
279
|
-
eventFilters: {},
|
|
280
|
-
retry: false,
|
|
281
|
-
},
|
|
282
|
-
};
|
|
285
|
+
const eventFilters = {};
|
|
286
|
+
const eventFilterPathPatterns = {};
|
|
283
287
|
if (gcfFunction.eventTrigger.pubsubTopic) {
|
|
284
|
-
|
|
288
|
+
eventFilters.topic = gcfFunction.eventTrigger.pubsubTopic;
|
|
285
289
|
}
|
|
286
290
|
else {
|
|
287
291
|
for (const eventFilter of gcfFunction.eventTrigger.eventFilters || []) {
|
|
288
292
|
if (eventFilter.operator === "match-path-pattern") {
|
|
289
|
-
|
|
290
|
-
trigger.eventTrigger.eventFilterPathPatterns = {};
|
|
291
|
-
}
|
|
292
|
-
trigger.eventTrigger.eventFilterPathPatterns[eventFilter.attribute] = eventFilter.value;
|
|
293
|
+
eventFilterPathPatterns[eventFilter.attribute] = eventFilter.value;
|
|
293
294
|
}
|
|
294
295
|
else {
|
|
295
|
-
|
|
296
|
+
eventFilters[eventFilter.attribute] = eventFilter.value;
|
|
296
297
|
}
|
|
297
298
|
}
|
|
298
299
|
}
|
|
300
|
+
trigger = {
|
|
301
|
+
eventTrigger: {
|
|
302
|
+
eventType: gcfFunction.eventTrigger.eventType,
|
|
303
|
+
retry: false,
|
|
304
|
+
},
|
|
305
|
+
};
|
|
306
|
+
if (Object.keys(eventFilters).length) {
|
|
307
|
+
trigger.eventTrigger.eventFilters = eventFilters;
|
|
308
|
+
}
|
|
309
|
+
if (Object.keys(eventFilterPathPatterns).length) {
|
|
310
|
+
trigger.eventTrigger.eventFilterPathPatterns = eventFilterPathPatterns;
|
|
311
|
+
}
|
|
299
312
|
proto.copyIfPresent(trigger.eventTrigger, gcfFunction.eventTrigger, "channel");
|
|
300
313
|
proto.renameIfPresent(trigger.eventTrigger, gcfFunction.eventTrigger, "region", "triggerRegion");
|
|
301
314
|
}
|
|
@@ -308,8 +321,19 @@ function endpointFromFunction(gcfFunction) {
|
|
|
308
321
|
const endpoint = Object.assign(Object.assign({ platform: "gcfv2", id,
|
|
309
322
|
project,
|
|
310
323
|
region }, trigger), { entryPoint: gcfFunction.buildConfig.entryPoint, runtime: gcfFunction.buildConfig.runtime, uri: gcfFunction.serviceConfig.uri });
|
|
311
|
-
proto.copyIfPresent(endpoint, gcfFunction.serviceConfig, "
|
|
312
|
-
proto.renameIfPresent(endpoint, gcfFunction.serviceConfig, "
|
|
324
|
+
proto.copyIfPresent(endpoint, gcfFunction.serviceConfig, "ingressSettings", "environmentVariables", "secretEnvironmentVariables", "timeoutSeconds");
|
|
325
|
+
proto.renameIfPresent(endpoint, gcfFunction.serviceConfig, "serviceAccount", "serviceAccountEmail");
|
|
326
|
+
proto.convertIfPresent(endpoint, gcfFunction.serviceConfig, "availableMemoryMb", "availableMemory", (prod) => {
|
|
327
|
+
if (prod === null) {
|
|
328
|
+
logger_1.logger.debug("Prod should always return a valid memory amount");
|
|
329
|
+
return prod;
|
|
330
|
+
}
|
|
331
|
+
const mem = mebibytes(prod);
|
|
332
|
+
if (!backend.isValidMemoryOption(mem)) {
|
|
333
|
+
logger_1.logger.warn("Converting a function to an endpoint with an invalid memory option", mem);
|
|
334
|
+
}
|
|
335
|
+
return mem;
|
|
336
|
+
});
|
|
313
337
|
proto.renameIfPresent(endpoint, gcfFunction.serviceConfig, "minInstances", "minInstanceCount");
|
|
314
338
|
proto.renameIfPresent(endpoint, gcfFunction.serviceConfig, "maxInstances", "maxInstanceCount");
|
|
315
339
|
proto.copyIfPresent(endpoint, gcfFunction, "labels");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.jobFromEndpoint = exports.createOrReplaceJob = exports.updateJob = exports.getJob = exports.deleteJob = exports.createJob =
|
|
3
|
+
exports.jobFromEndpoint = exports.topicNameForEndpoint = exports.jobNameForEndpoint = exports.createOrReplaceJob = exports.updateJob = exports.getJob = exports.deleteJob = exports.createJob = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
const error_1 = require("../error");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
@@ -9,15 +9,8 @@ const apiv2_1 = require("../apiv2");
|
|
|
9
9
|
const backend = require("../deploy/functions/backend");
|
|
10
10
|
const proto = require("./proto");
|
|
11
11
|
const functional_1 = require("../functional");
|
|
12
|
-
const VERSION = "
|
|
12
|
+
const VERSION = "v1";
|
|
13
13
|
const DEFAULT_TIME_ZONE = "America/Los_Angeles";
|
|
14
|
-
function assertValidJob(job) {
|
|
15
|
-
proto.assertOneOf("Scheduler Job", job, "target", "httpTarget", "pubsubTarget");
|
|
16
|
-
if (job.httpTarget) {
|
|
17
|
-
proto.assertOneOf("Scheduler Job", job.httpTarget, "httpTarget.authorizationHeader", "oauthToken", "odicToken");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
exports.assertValidJob = assertValidJob;
|
|
21
14
|
const apiClient = new apiv2_1.Client({ urlPrefix: api_1.cloudschedulerOrigin, apiVersion: VERSION });
|
|
22
15
|
function createJob(job) {
|
|
23
16
|
const strippedName = job.name.substring(0, job.name.lastIndexOf("/"));
|
|
@@ -35,7 +28,12 @@ function getJob(name) {
|
|
|
35
28
|
}
|
|
36
29
|
exports.getJob = getJob;
|
|
37
30
|
function updateJob(job) {
|
|
38
|
-
|
|
31
|
+
const fieldMasks = proto.fieldMasks(job, "pubsubTarget");
|
|
32
|
+
return apiClient.patch(`/${job.name}`, Object.assign({ timeZone: DEFAULT_TIME_ZONE }, job), {
|
|
33
|
+
queryParams: {
|
|
34
|
+
updateMask: fieldMasks.join(","),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
39
37
|
}
|
|
40
38
|
exports.updateJob = updateJob;
|
|
41
39
|
async function createOrReplaceJob(job) {
|
|
@@ -60,7 +58,7 @@ async function createOrReplaceJob(job) {
|
|
|
60
58
|
if (!job.timeZone) {
|
|
61
59
|
job.timeZone = DEFAULT_TIME_ZONE;
|
|
62
60
|
}
|
|
63
|
-
if (
|
|
61
|
+
if (!needUpdate(existingJob.body, job)) {
|
|
64
62
|
logger_1.logger.debug(`scheduler job ${jobName} is up to date, no changes required`);
|
|
65
63
|
return;
|
|
66
64
|
}
|
|
@@ -69,21 +67,45 @@ async function createOrReplaceJob(job) {
|
|
|
69
67
|
return updatedJob;
|
|
70
68
|
}
|
|
71
69
|
exports.createOrReplaceJob = createOrReplaceJob;
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
function needUpdate(existingJob, newJob) {
|
|
71
|
+
if (!existingJob) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
if (!newJob) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
if (existingJob.schedule !== newJob.schedule) {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
if (existingJob.timeZone !== newJob.timeZone) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (newJob.retryConfig) {
|
|
84
|
+
if (!existingJob.retryConfig) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
if (!_.isMatch(existingJob.retryConfig, newJob.retryConfig)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
function jobNameForEndpoint(endpoint, appEngineLocation) {
|
|
94
|
+
const id = backend.scheduleIdForFunction(endpoint);
|
|
95
|
+
return `projects/${endpoint.project}/locations/${appEngineLocation}/jobs/${id}`;
|
|
96
|
+
}
|
|
97
|
+
exports.jobNameForEndpoint = jobNameForEndpoint;
|
|
98
|
+
function topicNameForEndpoint(endpoint) {
|
|
99
|
+
const id = backend.scheduleIdForFunction(endpoint);
|
|
100
|
+
return `projects/${endpoint.project}/topics/${id}`;
|
|
78
101
|
}
|
|
102
|
+
exports.topicNameForEndpoint = topicNameForEndpoint;
|
|
79
103
|
function jobFromEndpoint(endpoint, appEngineLocation) {
|
|
80
104
|
const job = {};
|
|
81
105
|
if (endpoint.platform === "gcfv1") {
|
|
82
|
-
|
|
83
|
-
const region = appEngineLocation;
|
|
84
|
-
job.name = `projects/${endpoint.project}/locations/${region}/jobs/${id}`;
|
|
106
|
+
job.name = jobNameForEndpoint(endpoint, appEngineLocation);
|
|
85
107
|
job.pubsubTarget = {
|
|
86
|
-
topicName:
|
|
108
|
+
topicName: topicNameForEndpoint(endpoint),
|
|
87
109
|
attributes: {
|
|
88
110
|
scheduled: "true",
|
|
89
111
|
},
|
|
@@ -95,7 +117,21 @@ function jobFromEndpoint(endpoint, appEngineLocation) {
|
|
|
95
117
|
else {
|
|
96
118
|
(0, functional_1.assertExhaustive)(endpoint.platform);
|
|
97
119
|
}
|
|
98
|
-
|
|
120
|
+
if (!endpoint.scheduleTrigger.schedule) {
|
|
121
|
+
throw new error_1.FirebaseError("Cannot create a scheduler job without a schedule:" + JSON.stringify(endpoint));
|
|
122
|
+
}
|
|
123
|
+
job.schedule = endpoint.scheduleTrigger.schedule;
|
|
124
|
+
job.timeZone = endpoint.scheduleTrigger.timeZone || DEFAULT_TIME_ZONE;
|
|
125
|
+
if (endpoint.scheduleTrigger.retryConfig) {
|
|
126
|
+
job.retryConfig = {};
|
|
127
|
+
proto.copyIfPresent(job.retryConfig, endpoint.scheduleTrigger.retryConfig, "maxDoublings", "retryCount");
|
|
128
|
+
proto.convertIfPresent(job.retryConfig, endpoint.scheduleTrigger.retryConfig, "maxBackoffDuration", "maxBackoffSeconds", (0, functional_1.nullsafeVisitor)(proto.durationFromSeconds));
|
|
129
|
+
proto.convertIfPresent(job.retryConfig, endpoint.scheduleTrigger.retryConfig, "minBackoffDuration", "minBackoffSeconds", (0, functional_1.nullsafeVisitor)(proto.durationFromSeconds));
|
|
130
|
+
proto.convertIfPresent(job.retryConfig, endpoint.scheduleTrigger.retryConfig, "maxRetryDuration", "maxRetrySeconds", (0, functional_1.nullsafeVisitor)(proto.durationFromSeconds));
|
|
131
|
+
if (!Object.keys(job.retryConfig).length) {
|
|
132
|
+
delete job.retryConfig;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
99
135
|
return job;
|
|
100
136
|
}
|
|
101
137
|
exports.jobFromEndpoint = jobFromEndpoint;
|
package/lib/gcp/cloudtasks.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.queueFromEndpoint = exports.queueNameForEndpoint = exports.setEnqueuer = exports.getIamPolicy = exports.setIamPolicy = exports.deleteQueue = exports.purgeQueue = exports.upsertQueue = exports.updateQueue = exports.getQueue = exports.createQueue = exports.DEFAULT_SETTINGS = void 0;
|
|
3
|
+
exports.triggerFromQueue = exports.queueFromEndpoint = exports.queueNameForEndpoint = exports.setEnqueuer = exports.getIamPolicy = exports.setIamPolicy = exports.deleteQueue = exports.purgeQueue = exports.upsertQueue = exports.updateQueue = exports.getQueue = exports.createQueue = exports.DEFAULT_SETTINGS = void 0;
|
|
4
4
|
const proto = require("./proto");
|
|
5
5
|
const apiv2_1 = require("../apiv2");
|
|
6
6
|
const api_1 = require("../api");
|
|
7
|
+
const functional_1 = require("../functional");
|
|
7
8
|
const API_VERSION = "v2";
|
|
8
9
|
const client = new apiv2_1.Client({
|
|
9
10
|
urlPrefix: api_1.cloudTasksOrigin,
|
|
@@ -136,10 +137,26 @@ function queueFromEndpoint(endpoint) {
|
|
|
136
137
|
}
|
|
137
138
|
if (endpoint.taskQueueTrigger.retryConfig) {
|
|
138
139
|
proto.copyIfPresent(queue.retryConfig, endpoint.taskQueueTrigger.retryConfig, "maxAttempts", "maxDoublings");
|
|
139
|
-
proto.
|
|
140
|
-
proto.
|
|
141
|
-
proto.
|
|
140
|
+
proto.convertIfPresent(queue.retryConfig, endpoint.taskQueueTrigger.retryConfig, "maxRetryDuration", "maxRetrySeconds", (0, functional_1.nullsafeVisitor)(proto.durationFromSeconds));
|
|
141
|
+
proto.convertIfPresent(queue.retryConfig, endpoint.taskQueueTrigger.retryConfig, "maxBackoff", "maxBackoffSeconds", (0, functional_1.nullsafeVisitor)(proto.durationFromSeconds));
|
|
142
|
+
proto.convertIfPresent(queue.retryConfig, endpoint.taskQueueTrigger.retryConfig, "minBackoff", "minBackoffSeconds", (0, functional_1.nullsafeVisitor)(proto.durationFromSeconds));
|
|
142
143
|
}
|
|
143
144
|
return queue;
|
|
144
145
|
}
|
|
145
146
|
exports.queueFromEndpoint = queueFromEndpoint;
|
|
147
|
+
function triggerFromQueue(queue) {
|
|
148
|
+
const taskQueueTrigger = {};
|
|
149
|
+
if (queue.rateLimits) {
|
|
150
|
+
taskQueueTrigger.rateLimits = {};
|
|
151
|
+
proto.copyIfPresent(taskQueueTrigger.rateLimits, queue.rateLimits, "maxConcurrentDispatches", "maxDispatchesPerSecond");
|
|
152
|
+
}
|
|
153
|
+
if (queue.retryConfig) {
|
|
154
|
+
taskQueueTrigger.retryConfig = {};
|
|
155
|
+
proto.copyIfPresent(taskQueueTrigger.retryConfig, queue.retryConfig, "maxAttempts", "maxDoublings");
|
|
156
|
+
proto.convertIfPresent(taskQueueTrigger.retryConfig, queue.retryConfig, "maxRetrySeconds", "maxRetryDuration", (0, functional_1.nullsafeVisitor)(proto.secondsFromDuration));
|
|
157
|
+
proto.convertIfPresent(taskQueueTrigger.retryConfig, queue.retryConfig, "maxBackoffSeconds", "maxBackoff", (0, functional_1.nullsafeVisitor)(proto.secondsFromDuration));
|
|
158
|
+
proto.convertIfPresent(taskQueueTrigger.retryConfig, queue.retryConfig, "minBackoffSeconds", "minBackoff", (0, functional_1.nullsafeVisitor)(proto.secondsFromDuration));
|
|
159
|
+
}
|
|
160
|
+
return taskQueueTrigger;
|
|
161
|
+
}
|
|
162
|
+
exports.triggerFromQueue = triggerFromQueue;
|
package/lib/gcp/proto.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatServiceAccount = exports.getInvokerMembers = exports.fieldMasks = exports.renameIfPresent = exports.copyIfPresent = exports.assertOneOf = exports.durationFromSeconds = exports.secondsFromDuration = void 0;
|
|
3
|
+
exports.formatServiceAccount = exports.getInvokerMembers = exports.fieldMasks = exports.renameIfPresent = exports.convertIfPresent = exports.copyIfPresent = exports.assertOneOf = exports.durationFromSeconds = exports.secondsFromDuration = void 0;
|
|
4
4
|
const error_1 = require("../error");
|
|
5
5
|
function secondsFromDuration(d) {
|
|
6
6
|
return +d.slice(0, d.length - 1);
|
|
@@ -32,13 +32,25 @@ function copyIfPresent(dest, src, ...fields) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
exports.copyIfPresent = copyIfPresent;
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
function convertIfPresent(...args) {
|
|
36
|
+
if (args.length === 4) {
|
|
37
|
+
const [dest, src, key, converter] = args;
|
|
38
|
+
if (Object.prototype.hasOwnProperty.call(src, key)) {
|
|
39
|
+
dest[key] = converter(src[key]);
|
|
40
|
+
}
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const [dest, src, destKey, srcKey, converter] = args;
|
|
44
|
+
if (Object.prototype.hasOwnProperty.call(src, srcKey)) {
|
|
45
|
+
dest[destKey] = converter(src[srcKey]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.convertIfPresent = convertIfPresent;
|
|
49
|
+
function renameIfPresent(dest, src, destKey, srcKey) {
|
|
50
|
+
if (!Object.prototype.hasOwnProperty.call(src, srcKey)) {
|
|
39
51
|
return;
|
|
40
52
|
}
|
|
41
|
-
dest[
|
|
53
|
+
dest[destKey] = src[srcKey];
|
|
42
54
|
}
|
|
43
55
|
exports.renameIfPresent = renameIfPresent;
|
|
44
56
|
function fieldMasks(object, ...doNotRecurseIn) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addServiceAccountToRoles = exports.setIamPolicy = exports.getIamPolicy = exports.firebaseRoles = void 0;
|
|
3
|
+
exports.serviceAccountHasRoles = exports.addServiceAccountToRoles = exports.setIamPolicy = exports.getIamPolicy = exports.firebaseRoles = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
const apiv2_1 = require("../apiv2");
|
|
@@ -26,9 +26,11 @@ async function setIamPolicy(projectIdOrNumber, newPolicy, updateMask = "") {
|
|
|
26
26
|
return response.body;
|
|
27
27
|
}
|
|
28
28
|
exports.setIamPolicy = setIamPolicy;
|
|
29
|
-
async function addServiceAccountToRoles(projectId, serviceAccountName, roles) {
|
|
29
|
+
async function addServiceAccountToRoles(projectId, serviceAccountName, roles, skipAccountLookup = false) {
|
|
30
30
|
const [{ name: fullServiceAccountName }, projectPolicy] = await Promise.all([
|
|
31
|
-
|
|
31
|
+
skipAccountLookup
|
|
32
|
+
? Promise.resolve({ name: serviceAccountName })
|
|
33
|
+
: (0, iam_1.getServiceAccount)(projectId, serviceAccountName),
|
|
32
34
|
getIamPolicy(projectId),
|
|
33
35
|
]);
|
|
34
36
|
const newMemberName = `serviceAccount:${fullServiceAccountName.split("/").pop()}`;
|
|
@@ -49,3 +51,23 @@ async function addServiceAccountToRoles(projectId, serviceAccountName, roles) {
|
|
|
49
51
|
return setIamPolicy(projectId, projectPolicy, "bindings");
|
|
50
52
|
}
|
|
51
53
|
exports.addServiceAccountToRoles = addServiceAccountToRoles;
|
|
54
|
+
async function serviceAccountHasRoles(projectId, serviceAccountName, roles, skipAccountLookup = false) {
|
|
55
|
+
const [{ name: fullServiceAccountName }, projectPolicy] = await Promise.all([
|
|
56
|
+
skipAccountLookup
|
|
57
|
+
? Promise.resolve({ name: serviceAccountName })
|
|
58
|
+
: (0, iam_1.getServiceAccount)(projectId, serviceAccountName),
|
|
59
|
+
getIamPolicy(projectId),
|
|
60
|
+
]);
|
|
61
|
+
const memberName = `serviceAccount:${fullServiceAccountName.split("/").pop()}`;
|
|
62
|
+
for (const roleName of roles) {
|
|
63
|
+
const binding = projectPolicy.bindings.find((b) => b.role === roleName);
|
|
64
|
+
if (!binding) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if (!binding.members.includes(memberName)) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
exports.serviceAccountHasRoles = serviceAccountHasRoles;
|
package/lib/gcp/serviceusage.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateServiceIdentity = void 0;
|
|
4
|
-
const
|
|
4
|
+
const colorette_1 = require("colorette");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
const apiv2_1 = require("../apiv2");
|
|
7
7
|
const error_1 = require("../error");
|
|
@@ -11,7 +11,7 @@ const apiClient = new apiv2_1.Client({
|
|
|
11
11
|
apiVersion: "v1beta1",
|
|
12
12
|
});
|
|
13
13
|
async function generateServiceIdentity(projectNumber, service, prefix) {
|
|
14
|
-
utils.logLabeledBullet(prefix, `generating the service identity for ${(0,
|
|
14
|
+
utils.logLabeledBullet(prefix, `generating the service identity for ${(0, colorette_1.bold)(service)}...`);
|
|
15
15
|
try {
|
|
16
16
|
return await apiClient.post(`projects/${projectNumber}/services/${service}:generateServiceIdentity`);
|
|
17
17
|
}
|
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlePreviewToggles = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
-
const
|
|
5
|
+
const colorette_1 = require("colorette");
|
|
6
6
|
const configstore_1 = require("./configstore");
|
|
7
7
|
const previews_1 = require("./previews");
|
|
8
8
|
function _errorOut(name) {
|
|
9
|
-
console.log(
|
|
9
|
+
console.log((0, colorette_1.bold)((0, colorette_1.red)("Error:")), "Did not recognize preview feature", (0, colorette_1.bold)(name || ""));
|
|
10
10
|
process.exit(1);
|
|
11
11
|
}
|
|
12
12
|
function handlePreviewToggles(args) {
|
|
13
13
|
const isValidPreview = (0, lodash_1.has)(previews_1.previews, args[1]);
|
|
14
14
|
if (args[0] === "--open-sesame") {
|
|
15
15
|
if (isValidPreview) {
|
|
16
|
-
console.log("Enabling preview feature", (0,
|
|
16
|
+
console.log("Enabling preview feature", (0, colorette_1.bold)(args[1]) + "...");
|
|
17
17
|
previews_1.previews[args[1]] = true;
|
|
18
18
|
configstore_1.configstore.set("previews", previews_1.previews);
|
|
19
19
|
console.log("Preview feature enabled!");
|
|
@@ -23,7 +23,7 @@ function handlePreviewToggles(args) {
|
|
|
23
23
|
}
|
|
24
24
|
else if (args[0] === "--close-sesame") {
|
|
25
25
|
if (isValidPreview) {
|
|
26
|
-
console.log("Disabling preview feature", (0,
|
|
26
|
+
console.log("Disabling preview feature", (0, colorette_1.bold)(args[1]));
|
|
27
27
|
(0, lodash_1.unset)(previews_1.previews, args[1]);
|
|
28
28
|
configstore_1.configstore.set("previews", previews_1.previews);
|
|
29
29
|
return process.exit(0);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.implicitInit = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
|
-
const clc = require("
|
|
5
|
+
const clc = require("colorette");
|
|
6
6
|
const fs = require("fs");
|
|
7
7
|
const fetchWebSetup_1 = require("../fetchWebSetup");
|
|
8
8
|
const utils = require("../utils");
|