firebase-tools 10.4.2 → 10.7.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/bin/firebase.js +1 -1
- package/lib/command.js +4 -4
- package/lib/commands/deploy.js +1 -1
- package/lib/commands/emulators-start.js +13 -3
- package/lib/commands/ext-configure.js +15 -5
- package/lib/commands/ext-dev-emulators-start.js +5 -1
- package/lib/commands/ext-export.js +6 -5
- package/lib/commands/ext-install.js +28 -44
- package/lib/commands/ext-update.js +9 -1
- package/lib/commands/functions-delete.js +2 -5
- package/lib/commands/functions-secrets-destroy.js +23 -3
- package/lib/commands/functions-secrets-prune.js +15 -12
- package/lib/commands/functions-secrets-set.js +51 -4
- package/lib/commands/hosting-channel-deploy.js +2 -2
- package/lib/deploy/database/deploy.js +4 -0
- package/lib/deploy/database/index.js +1 -0
- package/lib/deploy/extensions/deploy.js +4 -4
- package/lib/deploy/extensions/deploymentSummary.js +8 -5
- package/lib/deploy/extensions/planner.js +36 -9
- package/lib/deploy/extensions/prepare.js +1 -1
- package/lib/deploy/extensions/secrets.js +2 -2
- package/lib/deploy/extensions/tasks.js +60 -21
- package/lib/deploy/functions/backend.js +17 -6
- package/lib/deploy/functions/build.js +162 -0
- package/lib/deploy/functions/checkIam.js +6 -5
- package/lib/deploy/functions/deploy.js +14 -15
- package/lib/deploy/functions/ensure.js +4 -4
- package/lib/deploy/functions/functionsDeployHelper.js +54 -23
- package/lib/deploy/functions/prepare.js +92 -39
- package/lib/deploy/functions/prepareFunctionsUpload.js +16 -21
- package/lib/deploy/functions/pricing.js +6 -3
- package/lib/deploy/functions/prompts.js +1 -7
- package/lib/deploy/functions/release/fabricator.js +44 -5
- package/lib/deploy/functions/release/index.js +31 -6
- package/lib/deploy/functions/release/planner.js +10 -8
- package/lib/deploy/functions/release/reporter.js +14 -11
- package/lib/deploy/functions/runtimes/discovery/parsing.js +12 -6
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +61 -13
- package/lib/deploy/functions/runtimes/node/index.js +1 -1
- package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +3 -3
- package/lib/deploy/functions/runtimes/node/parseTriggers.js +29 -24
- package/lib/deploy/functions/runtimes/node/versioning.js +2 -2
- package/lib/deploy/functions/services/auth.js +95 -0
- package/lib/deploy/functions/services/index.js +41 -21
- package/lib/deploy/functions/services/storage.js +1 -6
- package/lib/deploy/functions/validate.js +8 -5
- package/lib/deploy/hosting/args.js +2 -0
- package/lib/deploy/hosting/convertConfig.js +37 -8
- package/lib/deploy/hosting/deploy.js +3 -3
- package/lib/deploy/hosting/prepare.js +2 -2
- package/lib/deploy/hosting/release.js +6 -2
- package/lib/deploy/index.js +82 -93
- package/lib/deploy/remoteconfig/deploy.js +4 -0
- package/lib/deploy/remoteconfig/index.js +3 -1
- package/lib/emulator/auth/operations.js +26 -20
- package/lib/emulator/auth/state.js +79 -43
- package/lib/emulator/auth/utils.js +3 -25
- package/lib/emulator/commandUtils.js +72 -2
- package/lib/emulator/controller.js +14 -5
- package/lib/emulator/downloadableEmulators.js +47 -24
- package/lib/emulator/extensions/postinstall.js +41 -0
- package/lib/emulator/extensions/validation.js +2 -2
- package/lib/emulator/extensionsEmulator.js +85 -21
- package/lib/emulator/functionsEmulator.js +79 -7
- package/lib/emulator/functionsEmulatorShared.js +36 -21
- package/lib/emulator/registry.js +34 -12
- package/lib/emulator/shared/request.js +19 -0
- package/lib/emulator/storage/apis/firebase.js +32 -35
- package/lib/emulator/storage/apis/gcloud.js +84 -66
- package/lib/emulator/storage/files.js +56 -52
- package/lib/emulator/storage/index.js +23 -3
- package/lib/emulator/storage/metadata.js +18 -8
- package/lib/emulator/storage/rules/manager.js +7 -17
- package/lib/emulator/storage/rules/utils.js +11 -3
- package/lib/emulator/storage/server.js +38 -12
- package/lib/ensureApiEnabled.js +8 -4
- package/lib/extensions/askUserForParam.js +14 -11
- package/lib/extensions/changelog.js +1 -1
- package/lib/extensions/emulator/optionsHelper.js +9 -10
- package/lib/extensions/emulator/specHelper.js +7 -1
- package/lib/extensions/emulator/triggerHelper.js +11 -14
- package/lib/extensions/extensionsApi.js +2 -1
- package/lib/extensions/extensionsHelper.js +30 -24
- package/lib/extensions/manifest.js +28 -8
- package/lib/extensions/paramHelper.js +19 -13
- package/lib/extensions/provisioningHelper.js +2 -2
- package/lib/extensions/warnings.js +3 -3
- package/lib/functions/env.js +10 -2
- package/lib/functions/events/index.js +7 -0
- package/lib/functions/events/v1.js +6 -0
- package/lib/functions/projectConfig.js +24 -3
- package/lib/functions/runtimeConfigExport.js +10 -6
- package/lib/functions/secrets.js +99 -6
- package/lib/gcp/cloudfunctions.js +37 -18
- package/lib/gcp/cloudfunctionsv2.js +41 -25
- package/lib/gcp/cloudtasks.js +5 -3
- package/lib/gcp/identityPlatform.js +44 -0
- package/lib/gcp/secretManager.js +2 -2
- package/lib/metaprogramming.js +2 -0
- package/lib/previews.js +1 -1
- package/lib/serve/hosting.js +25 -12
- package/lib/serve/index.js +6 -0
- package/lib/track.js +15 -21
- package/lib/utils.js +30 -1
- package/npm-shrinkwrap.json +44 -2
- package/package.json +4 -1
- package/schema/firebase-config.json +6 -0
- package/lib/emulator/storage/list.js +0 -18
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveVersion = exports.want = exports.have = exports.getExtension = exports.getExtensionVersion = void 0;
|
|
3
|
+
exports.resolveVersion = exports.want = exports.have = exports.getExtensionSpec = exports.getExtension = exports.getExtensionVersion = void 0;
|
|
4
4
|
const semver = require("semver");
|
|
5
5
|
const extensionsApi = require("../../extensions/extensionsApi");
|
|
6
6
|
const refs = require("../../extensions/refs");
|
|
@@ -8,6 +8,7 @@ const error_1 = require("../../error");
|
|
|
8
8
|
const extensionsHelper_1 = require("../../extensions/extensionsHelper");
|
|
9
9
|
const logger_1 = require("../../logger");
|
|
10
10
|
const manifest_1 = require("../../extensions/manifest");
|
|
11
|
+
const specHelper_1 = require("../../extensions/emulator/specHelper");
|
|
11
12
|
async function getExtensionVersion(i) {
|
|
12
13
|
if (!i.extensionVersion) {
|
|
13
14
|
if (!i.ref) {
|
|
@@ -20,7 +21,7 @@ async function getExtensionVersion(i) {
|
|
|
20
21
|
exports.getExtensionVersion = getExtensionVersion;
|
|
21
22
|
async function getExtension(i) {
|
|
22
23
|
if (!i.ref) {
|
|
23
|
-
throw new error_1.FirebaseError(`Can't get
|
|
24
|
+
throw new error_1.FirebaseError(`Can't get Extension for ${i.instanceId} because it has no ref`);
|
|
24
25
|
}
|
|
25
26
|
if (!i.extension) {
|
|
26
27
|
i.extension = await extensionsApi.getExtension(refs.toExtensionRef(i.ref));
|
|
@@ -28,6 +29,23 @@ async function getExtension(i) {
|
|
|
28
29
|
return i.extension;
|
|
29
30
|
}
|
|
30
31
|
exports.getExtension = getExtension;
|
|
32
|
+
async function getExtensionSpec(i) {
|
|
33
|
+
if (!i.extensionSpec) {
|
|
34
|
+
if (i.ref) {
|
|
35
|
+
const extensionVersion = await getExtensionVersion(i);
|
|
36
|
+
i.extensionSpec = extensionVersion.spec;
|
|
37
|
+
}
|
|
38
|
+
else if (i.localPath) {
|
|
39
|
+
i.extensionSpec = await (0, specHelper_1.readExtensionYaml)(i.localPath);
|
|
40
|
+
i.extensionSpec.postinstallContent = await (0, specHelper_1.readPostinstall)(i.localPath);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw new error_1.FirebaseError("InstanceSpec had no ref or localPath, unable to get extensionSpec");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return i.extensionSpec;
|
|
47
|
+
}
|
|
48
|
+
exports.getExtensionSpec = getExtensionSpec;
|
|
31
49
|
async function have(projectId) {
|
|
32
50
|
const instances = await extensionsApi.listInstances(projectId);
|
|
33
51
|
return instances.map((i) => {
|
|
@@ -50,8 +68,6 @@ async function want(args) {
|
|
|
50
68
|
for (const e of Object.entries(args.extensions)) {
|
|
51
69
|
try {
|
|
52
70
|
const instanceId = e[0];
|
|
53
|
-
const ref = refs.parse(e[1]);
|
|
54
|
-
ref.version = await resolveVersion(ref);
|
|
55
71
|
const params = (0, manifest_1.readInstanceParam)({
|
|
56
72
|
projectDir: args.projectDir,
|
|
57
73
|
instanceId,
|
|
@@ -62,11 +78,22 @@ async function want(args) {
|
|
|
62
78
|
});
|
|
63
79
|
const autoPopulatedParams = await (0, extensionsHelper_1.getFirebaseProjectParams)(args.projectId, args.emulatorMode);
|
|
64
80
|
const subbedParams = (0, extensionsHelper_1.substituteParams)(params, autoPopulatedParams);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
if ((0, extensionsHelper_1.isLocalPath)(e[1])) {
|
|
82
|
+
instanceSpecs.push({
|
|
83
|
+
instanceId,
|
|
84
|
+
localPath: e[1],
|
|
85
|
+
params: subbedParams,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const ref = refs.parse(e[1]);
|
|
90
|
+
ref.version = await resolveVersion(ref);
|
|
91
|
+
instanceSpecs.push({
|
|
92
|
+
instanceId,
|
|
93
|
+
ref,
|
|
94
|
+
params: subbedParams,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
70
97
|
}
|
|
71
98
|
catch (err) {
|
|
72
99
|
logger_1.logger.debug(`Got error reading extensions entry ${e}: ${err}`);
|
|
@@ -28,7 +28,7 @@ async function prepare(context, options, payload) {
|
|
|
28
28
|
projectDir: options.config.projectDir,
|
|
29
29
|
extensions: options.config.get("extensions"),
|
|
30
30
|
});
|
|
31
|
-
const usingSecrets = await Promise.all((_a = context.
|
|
31
|
+
const usingSecrets = await Promise.all((_a = context.want) === null || _a === void 0 ? void 0 : _a.map(secrets_1.checkSpecForSecrets));
|
|
32
32
|
if (usingSecrets.some((i) => i)) {
|
|
33
33
|
await (0, secretsUtils_1.ensureSecretManagerApiEnabled)(options);
|
|
34
34
|
}
|
|
@@ -29,8 +29,8 @@ async function handleSecretParams(payload, have, nonInteractive) {
|
|
|
29
29
|
}
|
|
30
30
|
exports.handleSecretParams = handleSecretParams;
|
|
31
31
|
async function checkSpecForSecrets(i) {
|
|
32
|
-
const
|
|
33
|
-
return secretUtils.usesSecrets(
|
|
32
|
+
const extensionSpec = await (0, planner_1.getExtensionSpec)(i);
|
|
33
|
+
return secretUtils.usesSecrets(extensionSpec);
|
|
34
34
|
}
|
|
35
35
|
exports.checkSpecForSecrets = checkSpecForSecrets;
|
|
36
36
|
const secretsInSpec = (spec) => {
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteExtensionInstanceTask = exports.configureExtensionInstanceTask = exports.updateExtensionInstanceTask = exports.createExtensionInstanceTask = exports.extensionsDeploymentHandler = void 0;
|
|
4
4
|
const clc = require("cli-color");
|
|
5
|
+
const error_1 = require("../../error");
|
|
5
6
|
const extensionsApi = require("../../extensions/extensionsApi");
|
|
7
|
+
const extensionsHelper_1 = require("../../extensions/extensionsHelper");
|
|
6
8
|
const refs = require("../../extensions/refs");
|
|
7
9
|
const utils = require("../../utils");
|
|
8
10
|
const isRetryable = (err) => err.status === 429 || err.status === 409;
|
|
@@ -25,13 +27,28 @@ function extensionsDeploymentHandler(errorHandler) {
|
|
|
25
27
|
exports.extensionsDeploymentHandler = extensionsDeploymentHandler;
|
|
26
28
|
function createExtensionInstanceTask(projectId, instanceSpec, validateOnly = false) {
|
|
27
29
|
const run = async () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
if (instanceSpec.ref) {
|
|
31
|
+
await extensionsApi.createInstance({
|
|
32
|
+
projectId,
|
|
33
|
+
instanceId: instanceSpec.instanceId,
|
|
34
|
+
params: instanceSpec.params,
|
|
35
|
+
extensionVersionRef: refs.toExtensionVersionRef(instanceSpec.ref),
|
|
36
|
+
validateOnly,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else if (instanceSpec.localPath) {
|
|
40
|
+
const extensionSource = await (0, extensionsHelper_1.createSourceFromLocation)(projectId, instanceSpec.localPath);
|
|
41
|
+
await extensionsApi.createInstance({
|
|
42
|
+
projectId,
|
|
43
|
+
instanceId: instanceSpec.instanceId,
|
|
44
|
+
params: instanceSpec.params,
|
|
45
|
+
extensionSource,
|
|
46
|
+
validateOnly,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
throw new error_1.FirebaseError(`Tried to create extension instance ${instanceSpec.instanceId} without a ref or a local path. This should never happen.`);
|
|
51
|
+
}
|
|
35
52
|
printSuccess(instanceSpec.instanceId, "create", validateOnly);
|
|
36
53
|
return;
|
|
37
54
|
};
|
|
@@ -44,13 +61,27 @@ function createExtensionInstanceTask(projectId, instanceSpec, validateOnly = fal
|
|
|
44
61
|
exports.createExtensionInstanceTask = createExtensionInstanceTask;
|
|
45
62
|
function updateExtensionInstanceTask(projectId, instanceSpec, validateOnly = false) {
|
|
46
63
|
const run = async () => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
if (instanceSpec.ref) {
|
|
65
|
+
await extensionsApi.updateInstanceFromRegistry({
|
|
66
|
+
projectId,
|
|
67
|
+
instanceId: instanceSpec.instanceId,
|
|
68
|
+
extRef: refs.toExtensionVersionRef(instanceSpec.ref),
|
|
69
|
+
params: instanceSpec.params,
|
|
70
|
+
validateOnly,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
else if (instanceSpec.localPath) {
|
|
74
|
+
const extensionSource = await (0, extensionsHelper_1.createSourceFromLocation)(projectId, instanceSpec.localPath);
|
|
75
|
+
await extensionsApi.updateInstance({
|
|
76
|
+
projectId,
|
|
77
|
+
instanceId: instanceSpec.instanceId,
|
|
78
|
+
extensionSource,
|
|
79
|
+
validateOnly,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw new error_1.FirebaseError(`Tried to update extension instance ${instanceSpec.instanceId} without a ref or a local path. This should never happen.`);
|
|
84
|
+
}
|
|
54
85
|
printSuccess(instanceSpec.instanceId, "update", validateOnly);
|
|
55
86
|
return;
|
|
56
87
|
};
|
|
@@ -63,12 +94,20 @@ function updateExtensionInstanceTask(projectId, instanceSpec, validateOnly = fal
|
|
|
63
94
|
exports.updateExtensionInstanceTask = updateExtensionInstanceTask;
|
|
64
95
|
function configureExtensionInstanceTask(projectId, instanceSpec, validateOnly = false) {
|
|
65
96
|
const run = async () => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
97
|
+
if (instanceSpec.ref) {
|
|
98
|
+
await extensionsApi.configureInstance({
|
|
99
|
+
projectId,
|
|
100
|
+
instanceId: instanceSpec.instanceId,
|
|
101
|
+
params: instanceSpec.params,
|
|
102
|
+
validateOnly,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else if (instanceSpec.localPath) {
|
|
106
|
+
throw new error_1.FirebaseError(`Tried to configure extension instance ${instanceSpec.instanceId} from a local path. This should never happen.`);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
throw new error_1.FirebaseError(`Tried to configure extension instance ${instanceSpec.instanceId} without a ref or a local path. This should never happen.`);
|
|
110
|
+
}
|
|
72
111
|
printSuccess(instanceSpec.instanceId, "configure", validateOnly);
|
|
73
112
|
return;
|
|
74
113
|
};
|
|
@@ -81,7 +120,7 @@ function configureExtensionInstanceTask(projectId, instanceSpec, validateOnly =
|
|
|
81
120
|
exports.configureExtensionInstanceTask = configureExtensionInstanceTask;
|
|
82
121
|
function deleteExtensionInstanceTask(projectId, instanceSpec) {
|
|
83
122
|
const run = async () => {
|
|
84
|
-
|
|
123
|
+
await extensionsApi.deleteInstance(projectId, instanceSpec.instanceId);
|
|
85
124
|
printSuccess(instanceSpec.instanceId, "delete", false);
|
|
86
125
|
return;
|
|
87
126
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compareFunctions = exports.
|
|
3
|
+
exports.compareFunctions = exports.missingEndpoint = exports.hasEndpoint = exports.regionalEndpoints = exports.matchingBackend = exports.findEndpoint = exports.someEndpoint = exports.allEndpoints = exports.checkAvailability = exports.existingBackend = exports.scheduleIdForFunction = exports.functionName = exports.isEmptyBackend = exports.of = exports.empty = exports.isBlockingTriggered = exports.isTaskQueueTriggered = exports.isScheduleTriggered = exports.isEventTriggered = exports.isCallableTriggered = exports.isHttpsTriggered = exports.AllFunctionsPlatforms = exports.secretVersionName = exports.SCHEDULED_FUNCTION_LABEL = exports.MIN_MEMORY_FOR_CONCURRENCY = exports.DEFAULT_MEMORY = exports.memoryOptionDisplayName = exports.AllMemoryOptions = exports.AllIngressSettings = exports.AllVpcEgressSettings = exports.endpointTriggerType = void 0;
|
|
4
4
|
const gcf = require("../../gcp/cloudfunctions");
|
|
5
5
|
const gcfV2 = require("../../gcp/cloudfunctionsv2");
|
|
6
6
|
const utils = require("../../utils");
|
|
@@ -22,11 +22,21 @@ function endpointTriggerType(endpoint) {
|
|
|
22
22
|
else if (isTaskQueueTriggered(endpoint)) {
|
|
23
23
|
return "taskQueue";
|
|
24
24
|
}
|
|
25
|
+
else if (isBlockingTriggered(endpoint)) {
|
|
26
|
+
return endpoint.blockingTrigger.eventType;
|
|
27
|
+
}
|
|
25
28
|
else {
|
|
26
29
|
throw new Error("Unexpected trigger type for endpoint " + JSON.stringify(endpoint));
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
32
|
exports.endpointTriggerType = endpointTriggerType;
|
|
33
|
+
exports.AllVpcEgressSettings = ["PRIVATE_RANGES_ONLY", "ALL_TRAFFIC"];
|
|
34
|
+
exports.AllIngressSettings = [
|
|
35
|
+
"ALLOW_ALL",
|
|
36
|
+
"ALLOW_INTERNAL_ONLY",
|
|
37
|
+
"ALLOW_INTERNAL_AND_GCLB",
|
|
38
|
+
];
|
|
39
|
+
exports.AllMemoryOptions = [128, 256, 512, 1024, 2048, 4096, 8192];
|
|
30
40
|
function memoryOptionDisplayName(option) {
|
|
31
41
|
return {
|
|
32
42
|
128: "128MB",
|
|
@@ -47,6 +57,7 @@ function secretVersionName(s) {
|
|
|
47
57
|
return `projects/${s.projectId}/secrets/${s.secret}/versions/${(_a = s.version) !== null && _a !== void 0 ? _a : "latest"}`;
|
|
48
58
|
}
|
|
49
59
|
exports.secretVersionName = secretVersionName;
|
|
60
|
+
exports.AllFunctionsPlatforms = ["gcfv1", "gcfv2"];
|
|
50
61
|
function isHttpsTriggered(triggered) {
|
|
51
62
|
return {}.hasOwnProperty.call(triggered, "httpsTrigger");
|
|
52
63
|
}
|
|
@@ -67,6 +78,10 @@ function isTaskQueueTriggered(triggered) {
|
|
|
67
78
|
return {}.hasOwnProperty.call(triggered, "taskQueueTrigger");
|
|
68
79
|
}
|
|
69
80
|
exports.isTaskQueueTriggered = isTaskQueueTriggered;
|
|
81
|
+
function isBlockingTriggered(triggered) {
|
|
82
|
+
return {}.hasOwnProperty.call(triggered, "blockingTrigger");
|
|
83
|
+
}
|
|
84
|
+
exports.isBlockingTriggered = isBlockingTriggered;
|
|
70
85
|
function empty() {
|
|
71
86
|
return {
|
|
72
87
|
requiredAPIs: [],
|
|
@@ -207,7 +222,7 @@ function findEndpoint(backend, predicate) {
|
|
|
207
222
|
}
|
|
208
223
|
exports.findEndpoint = findEndpoint;
|
|
209
224
|
function matchingBackend(backend, predicate) {
|
|
210
|
-
const filtered = Object.assign({},
|
|
225
|
+
const filtered = Object.assign(Object.assign({}, backend), { endpoints: {} });
|
|
211
226
|
for (const endpoint of allEndpoints(backend)) {
|
|
212
227
|
if (!predicate(endpoint)) {
|
|
213
228
|
continue;
|
|
@@ -230,10 +245,6 @@ const missingEndpoint = (backend) => (endpoint) => {
|
|
|
230
245
|
return !(0, exports.hasEndpoint)(backend)(endpoint);
|
|
231
246
|
};
|
|
232
247
|
exports.missingEndpoint = missingEndpoint;
|
|
233
|
-
function findEventFilter(endpoint, attribute) {
|
|
234
|
-
return endpoint.eventTrigger.eventFilters.find((ef) => ef.attribute === attribute);
|
|
235
|
-
}
|
|
236
|
-
exports.findEventFilter = findEventFilter;
|
|
237
248
|
function compareFunctions(left, right) {
|
|
238
249
|
if (left.platform !== right.platform) {
|
|
239
250
|
return right.platform < left.platform ? -1 : 1;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveBackend = void 0;
|
|
4
|
+
const backend = require("./backend");
|
|
5
|
+
const proto = require("../../gcp/proto");
|
|
6
|
+
const api = require("../../.../../api");
|
|
7
|
+
const error_1 = require("../../error");
|
|
8
|
+
const functional_1 = require("../../functional");
|
|
9
|
+
function resolveInt(from) {
|
|
10
|
+
if (from == null) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
else if (typeof from === "string") {
|
|
14
|
+
throw new error_1.FirebaseError("CEL evaluation of expression '" + from + "' not yet supported");
|
|
15
|
+
}
|
|
16
|
+
return from;
|
|
17
|
+
}
|
|
18
|
+
function resolveString(from) {
|
|
19
|
+
if (from == null) {
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
else if (from.includes("{{") && from.includes("}}")) {
|
|
23
|
+
throw new error_1.FirebaseError("CEL evaluation of expression '" + from + "' not yet supported");
|
|
24
|
+
}
|
|
25
|
+
return from;
|
|
26
|
+
}
|
|
27
|
+
function resolveBoolean(from) {
|
|
28
|
+
if (from == null) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
else if (typeof from === "string") {
|
|
32
|
+
throw new error_1.FirebaseError("CEL evaluation of expression '" + from + "' not yet supported");
|
|
33
|
+
}
|
|
34
|
+
return from;
|
|
35
|
+
}
|
|
36
|
+
function isMemoryOption(value) {
|
|
37
|
+
return value == null || [128, 256, 512, 1024, 2048, 4096, 8192].includes(value);
|
|
38
|
+
}
|
|
39
|
+
function resolveBackend(build) {
|
|
40
|
+
const bkEndpoints = [];
|
|
41
|
+
for (const endpointId of Object.keys(build.endpoints)) {
|
|
42
|
+
const endpoint = build.endpoints[endpointId];
|
|
43
|
+
let regions = endpoint.region;
|
|
44
|
+
if (typeof regions === "undefined") {
|
|
45
|
+
regions = [api.functionsDefaultRegion];
|
|
46
|
+
}
|
|
47
|
+
for (const region of regions) {
|
|
48
|
+
const trigger = discoverTrigger(endpoint);
|
|
49
|
+
if (typeof endpoint.platform === "undefined") {
|
|
50
|
+
throw new error_1.FirebaseError("platform can't be undefined");
|
|
51
|
+
}
|
|
52
|
+
if (!isMemoryOption(endpoint.availableMemoryMb)) {
|
|
53
|
+
throw new error_1.FirebaseError("available memory must be a supported value, if present");
|
|
54
|
+
}
|
|
55
|
+
let timeout;
|
|
56
|
+
if (endpoint.timeoutSeconds) {
|
|
57
|
+
timeout = resolveInt(endpoint.timeoutSeconds);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
timeout = 60;
|
|
61
|
+
}
|
|
62
|
+
const bkEndpoint = Object.assign({ id: endpointId, project: "", region: region, entryPoint: endpoint.entryPoint, platform: endpoint.platform, runtime: "", labels: endpoint.labels, environmentVariables: endpoint.environmentVariables, secretEnvironmentVariables: undefined, availableMemoryMb: endpoint.availableMemoryMb, timeoutSeconds: timeout }, trigger);
|
|
63
|
+
proto.renameIfPresent(bkEndpoint, endpoint, "maxInstances", "maxInstances", resolveInt);
|
|
64
|
+
proto.renameIfPresent(bkEndpoint, endpoint, "minInstances", "minInstances", resolveInt);
|
|
65
|
+
proto.renameIfPresent(bkEndpoint, endpoint, "concurrency", "concurrency", resolveInt);
|
|
66
|
+
proto.copyIfPresent(bkEndpoint, endpoint, "ingressSettings");
|
|
67
|
+
if (endpoint.vpc) {
|
|
68
|
+
bkEndpoint.vpc = {
|
|
69
|
+
connector: resolveString(endpoint.vpc.connector),
|
|
70
|
+
egressSettings: endpoint.vpc.egressSettings,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (endpoint.serviceAccount) {
|
|
74
|
+
bkEndpoint.serviceAccountEmail = endpoint.serviceAccount;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
bkEndpoint.serviceAccountEmail = "default";
|
|
78
|
+
}
|
|
79
|
+
bkEndpoints.push(bkEndpoint);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const bkend = backend.of(...bkEndpoints);
|
|
83
|
+
bkend.requiredAPIs = build.requiredAPIs;
|
|
84
|
+
return bkend;
|
|
85
|
+
}
|
|
86
|
+
exports.resolveBackend = resolveBackend;
|
|
87
|
+
function discoverTrigger(endpoint) {
|
|
88
|
+
let trigger;
|
|
89
|
+
if ("httpsTrigger" in endpoint) {
|
|
90
|
+
const bkHttps = {};
|
|
91
|
+
if (endpoint.httpsTrigger.invoker) {
|
|
92
|
+
bkHttps.invoker = [endpoint.httpsTrigger.invoker];
|
|
93
|
+
}
|
|
94
|
+
trigger = { httpsTrigger: bkHttps };
|
|
95
|
+
}
|
|
96
|
+
else if ("callableTrigger" in endpoint) {
|
|
97
|
+
trigger = { callableTrigger: {} };
|
|
98
|
+
}
|
|
99
|
+
else if ("blockingTrigger" in endpoint) {
|
|
100
|
+
throw new error_1.FirebaseError("blocking triggers not supported");
|
|
101
|
+
}
|
|
102
|
+
else if ("eventTrigger" in endpoint) {
|
|
103
|
+
const bkEventFilters = {};
|
|
104
|
+
for (const key in endpoint.eventTrigger.eventFilters) {
|
|
105
|
+
if (typeof key === "string") {
|
|
106
|
+
bkEventFilters[key] = resolveString(endpoint.eventTrigger.eventFilters[key]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const bkEvent = {
|
|
110
|
+
eventType: endpoint.eventTrigger.eventType,
|
|
111
|
+
eventFilters: bkEventFilters,
|
|
112
|
+
retry: resolveBoolean(endpoint.eventTrigger.retry),
|
|
113
|
+
};
|
|
114
|
+
if (endpoint.eventTrigger.serviceAccount) {
|
|
115
|
+
bkEvent.serviceAccountEmail = endpoint.eventTrigger.serviceAccount;
|
|
116
|
+
}
|
|
117
|
+
if (endpoint.eventTrigger.region) {
|
|
118
|
+
bkEvent.region = resolveString(endpoint.eventTrigger.region);
|
|
119
|
+
}
|
|
120
|
+
trigger = { eventTrigger: bkEvent };
|
|
121
|
+
}
|
|
122
|
+
else if ("scheduleTrigger" in endpoint) {
|
|
123
|
+
const bkSchedule = {
|
|
124
|
+
schedule: resolveString(endpoint.scheduleTrigger.schedule),
|
|
125
|
+
timeZone: resolveString(endpoint.scheduleTrigger.timeZone),
|
|
126
|
+
};
|
|
127
|
+
proto.renameIfPresent(bkSchedule, endpoint.scheduleTrigger, "retryConfig", "retryConfig", resolveInt);
|
|
128
|
+
trigger = { scheduleTrigger: bkSchedule };
|
|
129
|
+
}
|
|
130
|
+
else if ("taskQueueTrigger" in endpoint) {
|
|
131
|
+
const bkTaskQueue = {};
|
|
132
|
+
if (endpoint.taskQueueTrigger.rateLimits) {
|
|
133
|
+
const bkRateLimits = {};
|
|
134
|
+
proto.renameIfPresent(bkRateLimits, endpoint.taskQueueTrigger.rateLimits, "maxConcurrentDispatches", "maxConcurrentDispatches", resolveInt);
|
|
135
|
+
proto.renameIfPresent(bkRateLimits, endpoint.taskQueueTrigger.rateLimits, "maxDispatchesPerSecond", "maxDispatchesPerSecond", resolveInt);
|
|
136
|
+
bkTaskQueue.rateLimits = bkRateLimits;
|
|
137
|
+
}
|
|
138
|
+
if (endpoint.taskQueueTrigger.retryConfig) {
|
|
139
|
+
const bkRetryConfig = {};
|
|
140
|
+
proto.renameIfPresent(bkRetryConfig, endpoint.taskQueueTrigger.retryConfig, "maxAttempts", "maxAttempts", resolveInt);
|
|
141
|
+
proto.renameIfPresent(bkRetryConfig, endpoint.taskQueueTrigger.retryConfig, "maxBackoffSeconds", "maxBackoffSeconds", (from) => {
|
|
142
|
+
return proto.durationFromSeconds(resolveInt(from));
|
|
143
|
+
});
|
|
144
|
+
proto.renameIfPresent(bkRetryConfig, endpoint.taskQueueTrigger.retryConfig, "minBackoffSeconds", "minBackoffSeconds", (from) => {
|
|
145
|
+
return proto.durationFromSeconds(resolveInt(from));
|
|
146
|
+
});
|
|
147
|
+
proto.renameIfPresent(bkRetryConfig, endpoint.taskQueueTrigger.retryConfig, "maxRetrySeconds", "maxRetryDurationSeconds", (from) => {
|
|
148
|
+
return proto.durationFromSeconds(resolveInt(from));
|
|
149
|
+
});
|
|
150
|
+
proto.renameIfPresent(bkRetryConfig, endpoint.taskQueueTrigger.retryConfig, "maxDoublings", "maxDoublings", resolveInt);
|
|
151
|
+
bkTaskQueue.retryConfig = bkRetryConfig;
|
|
152
|
+
}
|
|
153
|
+
if (endpoint.taskQueueTrigger.invoker) {
|
|
154
|
+
bkTaskQueue.invoker = endpoint.taskQueueTrigger.invoker.map((sa) => resolveString(sa));
|
|
155
|
+
}
|
|
156
|
+
trigger = { taskQueueTrigger: bkTaskQueue };
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
(0, functional_1.assertExhaustive)(endpoint);
|
|
160
|
+
}
|
|
161
|
+
return trigger;
|
|
162
|
+
}
|
|
@@ -7,7 +7,7 @@ const functionsDeployHelper_1 = require("./functionsDeployHelper");
|
|
|
7
7
|
const error_1 = require("../../error");
|
|
8
8
|
const iam = require("../../gcp/iam");
|
|
9
9
|
const backend = require("./backend");
|
|
10
|
-
const
|
|
10
|
+
const track_1 = require("../../track");
|
|
11
11
|
const utils = require("../../utils");
|
|
12
12
|
const resourceManager_1 = require("../../gcp/resourceManager");
|
|
13
13
|
const services_1 = require("./services");
|
|
@@ -35,11 +35,12 @@ async function checkServiceAccountIam(projectId) {
|
|
|
35
35
|
}
|
|
36
36
|
exports.checkServiceAccountIam = checkServiceAccountIam;
|
|
37
37
|
async function checkHttpIam(context, options, payload) {
|
|
38
|
-
const
|
|
38
|
+
const filters = context.filters || (0, functionsDeployHelper_1.getEndpointFilters)(options);
|
|
39
|
+
const wantBackend = payload.functions.wantBackend;
|
|
39
40
|
const httpEndpoints = backend
|
|
40
|
-
.allEndpoints(
|
|
41
|
+
.allEndpoints(wantBackend)
|
|
41
42
|
.filter(backend.isHttpsTriggered)
|
|
42
|
-
.filter((f) => (0, functionsDeployHelper_1.
|
|
43
|
+
.filter((f) => (0, functionsDeployHelper_1.endpointMatchesAnyFilter)(f, filters));
|
|
43
44
|
const existing = await backend.existingBackend(context);
|
|
44
45
|
const newHttpsEndpoints = httpEndpoints.filter(backend.missingEndpoint(existing));
|
|
45
46
|
if (newHttpsEndpoints.length === 0) {
|
|
@@ -56,7 +57,7 @@ async function checkHttpIam(context, options, payload) {
|
|
|
56
57
|
return;
|
|
57
58
|
}
|
|
58
59
|
if (!passed) {
|
|
59
|
-
void track("Error (User)", "deploy:functions:http_create_missing_iam");
|
|
60
|
+
void (0, track_1.track)("Error (User)", "deploy:functions:http_create_missing_iam");
|
|
60
61
|
throw new error_1.FirebaseError(`Missing required permission on project ${(0, cli_color_1.bold)(context.projectId)} to deploy new HTTPS functions. The permission ${(0, cli_color_1.bold)(PERMISSION)} is required to deploy the following functions:\n\n- ` +
|
|
61
62
|
newHttpsEndpoints.map((func) => func.id).join("\n- ") +
|
|
62
63
|
`\n\nTo address this error, please ask a project Owner to assign your account the "Cloud Functions Admin" role at the following URL:\n\nhttps://console.cloud.google.com/iam-admin/iam?project=${context.projectId}`);
|
|
@@ -13,10 +13,10 @@ const backend = require("./backend");
|
|
|
13
13
|
(0, tmp_1.setGracefulCleanup)();
|
|
14
14
|
async function uploadSourceV1(context, region) {
|
|
15
15
|
const uploadUrl = await gcf.generateUploadUrl(context.projectId, region);
|
|
16
|
-
context.sourceUrl = uploadUrl;
|
|
16
|
+
context.source.sourceUrl = uploadUrl;
|
|
17
17
|
const uploadOpts = {
|
|
18
|
-
file: context.functionsSourceV1,
|
|
19
|
-
stream: fs.createReadStream(context.functionsSourceV1),
|
|
18
|
+
file: context.source.functionsSourceV1,
|
|
19
|
+
stream: fs.createReadStream(context.source.functionsSourceV1),
|
|
20
20
|
};
|
|
21
21
|
await gcs.upload(uploadOpts, uploadUrl, {
|
|
22
22
|
"x-goog-content-length-range": "0,104857600",
|
|
@@ -25,31 +25,30 @@ async function uploadSourceV1(context, region) {
|
|
|
25
25
|
async function uploadSourceV2(context, region) {
|
|
26
26
|
const res = await gcfv2.generateUploadUrl(context.projectId, region);
|
|
27
27
|
const uploadOpts = {
|
|
28
|
-
file: context.functionsSourceV2,
|
|
29
|
-
stream: fs.createReadStream(context.functionsSourceV2),
|
|
28
|
+
file: context.source.functionsSourceV2,
|
|
29
|
+
stream: fs.createReadStream(context.source.functionsSourceV2),
|
|
30
30
|
};
|
|
31
31
|
await gcs.upload(uploadOpts, res.uploadUrl);
|
|
32
|
-
context.storage =
|
|
32
|
+
context.source.storage = res.storageSource;
|
|
33
33
|
}
|
|
34
34
|
async function deploy(context, options, payload) {
|
|
35
|
+
var _a, _b, _c, _d;
|
|
35
36
|
if (!context.config) {
|
|
36
37
|
return;
|
|
37
38
|
}
|
|
38
|
-
if (!context.functionsSourceV1 && !context.functionsSourceV2) {
|
|
39
|
+
if (!((_a = context.source) === null || _a === void 0 ? void 0 : _a.functionsSourceV1) && !((_b = context.source) === null || _b === void 0 ? void 0 : _b.functionsSourceV2)) {
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
41
42
|
await (0, checkIam_1.checkHttpIam)(context, options, payload);
|
|
42
43
|
try {
|
|
43
|
-
const want = payload.functions.
|
|
44
|
+
const want = payload.functions.wantBackend;
|
|
44
45
|
const uploads = [];
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
uploads.push(uploadSourceV1(context,
|
|
46
|
+
const byPlatform = (0, utils_1.groupBy)(backend.allEndpoints(want), (e) => e.platform);
|
|
47
|
+
if (((_c = byPlatform.gcfv1) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
48
|
+
uploads.push(uploadSourceV1(context, byPlatform.gcfv1[0].region));
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
uploads.push(uploadSourceV2(context, region));
|
|
52
|
-
}
|
|
50
|
+
if (((_d = byPlatform.gcfv2) === null || _d === void 0 ? void 0 : _d.length) > 0) {
|
|
51
|
+
uploads.push(uploadSourceV2(context, byPlatform.gcfv2[0].region));
|
|
53
52
|
}
|
|
54
53
|
await Promise.all(uploads);
|
|
55
54
|
const source = context.config.source;
|
|
@@ -9,7 +9,7 @@ const secretManager_1 = require("../../gcp/secretManager");
|
|
|
9
9
|
const previews_1 = require("../../previews");
|
|
10
10
|
const projects_1 = require("../../management/projects");
|
|
11
11
|
const functional_1 = require("../../functional");
|
|
12
|
-
const
|
|
12
|
+
const track_1 = require("../../track");
|
|
13
13
|
const backend = require("./backend");
|
|
14
14
|
const ensureApiEnabled = require("../../ensureApiEnabled");
|
|
15
15
|
const FAQ_URL = "https://firebase.google.com/support/faq#functions-runtime";
|
|
@@ -26,9 +26,9 @@ async function defaultServiceAccount(e) {
|
|
|
26
26
|
}
|
|
27
27
|
exports.defaultServiceAccount = defaultServiceAccount;
|
|
28
28
|
function nodeBillingError(projectId) {
|
|
29
|
-
void track("functions_runtime_notices", "nodejs10_billing_error");
|
|
29
|
+
void (0, track_1.track)("functions_runtime_notices", "nodejs10_billing_error");
|
|
30
30
|
return new error_1.FirebaseError(`Cloud Functions deployment requires the pay-as-you-go (Blaze) billing plan. To upgrade your project, visit the following URL:
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
https://console.firebase.google.com/project/${projectId}/usage/details
|
|
33
33
|
|
|
34
34
|
For additional information about this requirement, see Firebase FAQs:
|
|
@@ -36,7 +36,7 @@ For additional information about this requirement, see Firebase FAQs:
|
|
|
36
36
|
${FAQ_URL}`, { exit: 1 });
|
|
37
37
|
}
|
|
38
38
|
function nodePermissionError(projectId) {
|
|
39
|
-
void track("functions_runtime_notices", "nodejs10_permission_error");
|
|
39
|
+
void (0, track_1.track)("functions_runtime_notices", "nodejs10_permission_error");
|
|
40
40
|
return new error_1.FirebaseError(`Cloud Functions deployment requires the Cloud Build API to be enabled. The current credentials do not have permission to enable APIs for project ${clc.bold(projectId)}.
|
|
41
41
|
|
|
42
42
|
Please ask a project owner to visit the following URL to enable Cloud Build:
|