firebase-tools 15.36.1-main.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/commands/dataconnect-services-list.js +8 -2
- package/lib/dataconnect/client.js +14 -8
- package/lib/deploy/dataconnect/release.js +2 -2
- package/lib/deploy/functions/prepare.js +28 -0
- package/lib/deploy/functions/release/fabricator.js +18 -1
- package/lib/deploy/functions/runtimes/supported/index.js +10 -4
- package/lib/deploy/functions/runtimes/supported/types.js +7 -1
- package/lib/emulator/downloadableEmulatorInfo.json +24 -24
- package/lib/emulator/functionsEmulator.js +73 -1
- package/lib/gcp/cloudscheduler.js +12 -0
- package/lib/tsconfig.compile.tsbuildinfo +1 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/schema/firebase-config.json +3 -0
|
@@ -5,6 +5,7 @@ const command_1 = require("../command");
|
|
|
5
5
|
const projectUtils_1 = require("../projectUtils");
|
|
6
6
|
const names = require("../dataconnect/names");
|
|
7
7
|
const client = require("../dataconnect/client");
|
|
8
|
+
const types_1 = require("../dataconnect/types");
|
|
8
9
|
const logger_1 = require("../logger");
|
|
9
10
|
const requirePermissions_1 = require("../requirePermissions");
|
|
10
11
|
const ensureApis_1 = require("../dataconnect/ensureApis");
|
|
@@ -33,12 +34,17 @@ exports.command = new command_1.Command("dataconnect:services:list")
|
|
|
33
34
|
});
|
|
34
35
|
const jsonOutput = { services: [] };
|
|
35
36
|
for (const service of services) {
|
|
36
|
-
const
|
|
37
|
+
const getSchemaFields = ["datasources", "updateTime"];
|
|
38
|
+
const schema = (await client.getSchema(service.name, types_1.MAIN_SCHEMA_ID, getSchemaFields)) ?? {
|
|
37
39
|
name: "",
|
|
38
40
|
datasources: [{}],
|
|
39
41
|
source: { files: [] },
|
|
40
42
|
};
|
|
41
|
-
const connectors = await client.listConnectors(service.name
|
|
43
|
+
const connectors = await client.listConnectors(service.name, [
|
|
44
|
+
"connectors.name",
|
|
45
|
+
"connectors.updateTime",
|
|
46
|
+
"nextPageToken",
|
|
47
|
+
]);
|
|
42
48
|
const serviceName = names.parseServiceName(service.name);
|
|
43
49
|
const postgresDatasource = schema?.datasources.find((d) => d.postgresql);
|
|
44
50
|
const instanceName = postgresDatasource?.postgresql?.cloudSql?.instance ?? "";
|
|
@@ -29,8 +29,10 @@ async function listLocations(projectId) {
|
|
|
29
29
|
const res = await dataconnectClient().get(`/projects/${projectId}/locations`);
|
|
30
30
|
return res.body?.locations?.map((l) => l.locationId) ?? [];
|
|
31
31
|
}
|
|
32
|
-
async function getService(serviceName) {
|
|
33
|
-
const res = await dataconnectClient().get(serviceName
|
|
32
|
+
async function getService(serviceName, fields = []) {
|
|
33
|
+
const res = await dataconnectClient().get(serviceName, {
|
|
34
|
+
queryParams: fields.length ? { fields: fields.join(",") } : undefined,
|
|
35
|
+
});
|
|
34
36
|
return res.body;
|
|
35
37
|
}
|
|
36
38
|
async function listAllServices(projectId) {
|
|
@@ -71,9 +73,11 @@ async function deleteService(serviceName) {
|
|
|
71
73
|
});
|
|
72
74
|
return pollRes;
|
|
73
75
|
}
|
|
74
|
-
async function getSchema(serviceName, schemaId = types.MAIN_SCHEMA_ID) {
|
|
76
|
+
async function getSchema(serviceName, schemaId = types.MAIN_SCHEMA_ID, fields = []) {
|
|
75
77
|
try {
|
|
76
|
-
const res = await dataconnectClient().get(`${serviceName}/schemas/${schemaId}
|
|
78
|
+
const res = await dataconnectClient().get(`${serviceName}/schemas/${schemaId}`, {
|
|
79
|
+
queryParams: fields.length ? { fields: fields.join(",") } : undefined,
|
|
80
|
+
});
|
|
77
81
|
return res.body;
|
|
78
82
|
}
|
|
79
83
|
catch (err) {
|
|
@@ -90,7 +94,7 @@ async function listSchemas(serviceName, fields = []) {
|
|
|
90
94
|
queryParams: {
|
|
91
95
|
pageSize: PAGE_SIZE_MAX,
|
|
92
96
|
pageToken,
|
|
93
|
-
fields: fields.join(","),
|
|
97
|
+
...(fields.length ? { fields: fields.join(",") } : {}),
|
|
94
98
|
},
|
|
95
99
|
});
|
|
96
100
|
schemas.push(...(res.body.schemas || []));
|
|
@@ -127,8 +131,10 @@ async function deleteSchema(name) {
|
|
|
127
131
|
});
|
|
128
132
|
return;
|
|
129
133
|
}
|
|
130
|
-
async function getConnector(name) {
|
|
131
|
-
const res = await dataconnectClient().get(name
|
|
134
|
+
async function getConnector(name, fields = []) {
|
|
135
|
+
const res = await dataconnectClient().get(name, {
|
|
136
|
+
queryParams: fields.length ? { fields: fields.join(",") } : undefined,
|
|
137
|
+
});
|
|
132
138
|
return res.body;
|
|
133
139
|
}
|
|
134
140
|
async function deleteConnector(name) {
|
|
@@ -147,7 +153,7 @@ async function listConnectors(serviceName, fields = []) {
|
|
|
147
153
|
queryParams: {
|
|
148
154
|
pageSize: PAGE_SIZE_MAX,
|
|
149
155
|
pageToken,
|
|
150
|
-
fields: fields.join(","),
|
|
156
|
+
...(fields.length ? { fields: fields.join(",") } : {}),
|
|
151
157
|
},
|
|
152
158
|
});
|
|
153
159
|
connectors.push(...(res.body.connectors || []));
|
|
@@ -109,11 +109,11 @@ async function default_1(context, options) {
|
|
|
109
109
|
async function deployedConnectors(serviceInfos) {
|
|
110
110
|
let connectors = [];
|
|
111
111
|
for (const si of serviceInfos) {
|
|
112
|
-
connectors = connectors.concat(await (0, client_1.listConnectors)(si.serviceName));
|
|
112
|
+
connectors = connectors.concat(await (0, client_1.listConnectors)(si.serviceName, ["connectors.name", "nextPageToken"]));
|
|
113
113
|
}
|
|
114
114
|
return connectors;
|
|
115
115
|
}
|
|
116
116
|
async function deployedSchemas(serviceInfos) {
|
|
117
|
-
const schemasPerService = await Promise.all(serviceInfos.map((si) => (0, client_1.listSchemas)(si.serviceName)));
|
|
117
|
+
const schemasPerService = await Promise.all(serviceInfos.map((si) => (0, client_1.listSchemas)(si.serviceName, ["schemas.name", "nextPageToken"])));
|
|
118
118
|
return schemasPerService.flat();
|
|
119
119
|
}
|
|
@@ -10,6 +10,7 @@ exports.inferBlockingDetails = inferBlockingDetails;
|
|
|
10
10
|
exports.resolveCpuAndConcurrency = resolveCpuAndConcurrency;
|
|
11
11
|
exports.resolveDefaultTimeout = resolveDefaultTimeout;
|
|
12
12
|
exports.loadCodebases = loadCodebases;
|
|
13
|
+
exports.ensureScheduleRegionsSupported = ensureScheduleRegionsSupported;
|
|
13
14
|
exports.getExecutablePaths = getExecutablePaths;
|
|
14
15
|
exports.stripStaleDartBuildIgnore = stripStaleDartBuildIgnore;
|
|
15
16
|
exports.warnIfNewGenkitFunctionIsMissingSecrets = warnIfNewGenkitFunctionIsMissingSecrets;
|
|
@@ -51,6 +52,7 @@ const functional_1 = require("../../functional");
|
|
|
51
52
|
const prepare_1 = require("../extensions/prepare");
|
|
52
53
|
const prompt = require("../../prompt");
|
|
53
54
|
const iam = require("../../gcp/iam");
|
|
55
|
+
const scheduler = require("../../gcp/cloudscheduler");
|
|
54
56
|
const resourcemanager = require("../../gcp/resourceManager");
|
|
55
57
|
exports.EVENTARC_SOURCE_ENV = "EVENTARC_CLOUD_EVENT_SOURCE";
|
|
56
58
|
exports.DECLARATIVE_SECURITY_ETAG_LABEL = "firebase-declarative-security-etag";
|
|
@@ -336,6 +338,7 @@ async function prepare(context, options, payload) {
|
|
|
336
338
|
const matchingBackend = backend.matchingBackend(wantBackend, (endpoint) => {
|
|
337
339
|
return (0, functionsDeployHelper_1.endpointMatchesAnyFilter)(endpoint, context.filters);
|
|
338
340
|
});
|
|
341
|
+
await ensureScheduleRegionsSupported(projectId, matchingBackend);
|
|
339
342
|
await (0, prompts_1.promptForFailurePolicies)(options, matchingBackend, haveBackend);
|
|
340
343
|
await (0, prompts_1.promptForMinInstances)(options, matchingBackend, haveBackend);
|
|
341
344
|
await backend.checkAvailability(context, matchingBackend);
|
|
@@ -562,6 +565,31 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
|
|
|
562
565
|
}
|
|
563
566
|
return wantBuilds;
|
|
564
567
|
}
|
|
568
|
+
async function ensureScheduleRegionsSupported(projectId, want) {
|
|
569
|
+
const scheduled = backend
|
|
570
|
+
.allEndpoints(want)
|
|
571
|
+
.filter((ep) => backend.isScheduleTriggered(ep) && ep.platform === "gcfv2");
|
|
572
|
+
if (scheduled.length === 0) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
let supported;
|
|
576
|
+
try {
|
|
577
|
+
supported = await scheduler.listLocations(projectId);
|
|
578
|
+
}
|
|
579
|
+
catch (err) {
|
|
580
|
+
logger_1.logger.debug(`Failed to list Cloud Scheduler locations: ${(0, error_1.getErrMsg)(err)}`);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
if (supported.length === 0) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const unsupported = scheduled.filter((ep) => !supported.includes(ep.region));
|
|
587
|
+
if (unsupported.length > 0) {
|
|
588
|
+
const fns = unsupported.map((ep) => `${ep.id}(${ep.region})`).join(", ");
|
|
589
|
+
throw new error_1.FirebaseError(`Cloud Scheduler is not available in the region of these scheduled functions: ${fns}. ` +
|
|
590
|
+
`Deploy them to a region that supports Cloud Scheduler: ${[...supported].sort().join(", ")}.`);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
565
593
|
function warnIfDartBackendHasUnsupportedTriggers(want) {
|
|
566
594
|
const dartEndpoints = backend.allEndpoints(want).filter(triggerSupport_1.isDartEndpoint);
|
|
567
595
|
if (dartEndpoints.length === 0) {
|
|
@@ -908,7 +908,24 @@ class Fabricator {
|
|
|
908
908
|
const jobName = scheduler.jobNameForEndpoint(endpoint, endpoint.region);
|
|
909
909
|
await this.executor
|
|
910
910
|
.run(() => scheduler.deleteJob(jobName))
|
|
911
|
-
.catch(
|
|
911
|
+
.catch(async (err) => {
|
|
912
|
+
if ((0, executor_1.parseErrorCode)(err) === 400 &&
|
|
913
|
+
!(await this.schedulerSupportsRegion(endpoint.project, endpoint.region))) {
|
|
914
|
+
logger_1.logger.debug(`Cloud Scheduler does not support ${endpoint.region}; no schedule to delete for ${endpoint.id}.`);
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
return rethrowAsUnlessNotFound(endpoint, "delete schedule")(err);
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
async schedulerSupportsRegion(projectId, region) {
|
|
921
|
+
try {
|
|
922
|
+
const regions = await scheduler.listLocations(projectId);
|
|
923
|
+
return regions.length === 0 || regions.includes(region);
|
|
924
|
+
}
|
|
925
|
+
catch (err) {
|
|
926
|
+
logger_1.logger.debug(`Failed to list Cloud Scheduler locations: ${(0, error_1.getErrMsg)(err)}`);
|
|
927
|
+
return true;
|
|
928
|
+
}
|
|
912
929
|
}
|
|
913
930
|
async disableTaskQueue(endpoint) {
|
|
914
931
|
await this.executor
|
|
@@ -29,8 +29,8 @@ function isRuntime(maybe) {
|
|
|
29
29
|
function runtimeIsLanguage(runtime, language) {
|
|
30
30
|
return !!runtime && runtime.startsWith(language);
|
|
31
31
|
}
|
|
32
|
-
function latest(language, runtimes
|
|
33
|
-
const sorted = runtimes
|
|
32
|
+
function latest(language, runtimes) {
|
|
33
|
+
const sorted = (runtimes ?? Object.keys(types_1.RUNTIMES))
|
|
34
34
|
.filter((s) => runtimeIsLanguage(s, language))
|
|
35
35
|
.sort((left, right) => {
|
|
36
36
|
const leftVersion = +left.substring(language.length);
|
|
@@ -42,7 +42,8 @@ function latest(language, runtimes = Object.keys(types_1.RUNTIMES)) {
|
|
|
42
42
|
}
|
|
43
43
|
return leftVersion - rightVersion;
|
|
44
44
|
});
|
|
45
|
-
const
|
|
45
|
+
const ga = runtimes ? [] : sorted.filter((r) => types_1.RUNTIMES[r]?.status === "GA");
|
|
46
|
+
const latest = utils.last(ga.length ? ga : sorted);
|
|
46
47
|
if (!latest) {
|
|
47
48
|
throw new error_1.FirebaseError(`Internal error trying to find the latest supported runtime for ${language}`, { exit: 1 });
|
|
48
49
|
}
|
|
@@ -53,12 +54,17 @@ function isDecommissioned(runtime, now = new Date()) {
|
|
|
53
54
|
return cutoff < now;
|
|
54
55
|
}
|
|
55
56
|
function guardVersionSupport(runtime, now = new Date()) {
|
|
56
|
-
const { deprecationDate, decommissionDate } = types_1.RUNTIMES[runtime];
|
|
57
|
+
const { friendly, status, deprecationDate, decommissionDate } = types_1.RUNTIMES[runtime];
|
|
57
58
|
const decommission = new Date(decommissionDate);
|
|
58
59
|
if (now >= decommission) {
|
|
59
60
|
throw new error_1.FirebaseError(`Runtime ${types_1.RUNTIMES[runtime].friendly} was decommissioned on ${decommissionDate}. To deploy ` +
|
|
60
61
|
"you must first upgrade your runtime version.", { exit: 1 });
|
|
61
62
|
}
|
|
63
|
+
if (status === "beta") {
|
|
64
|
+
utils.logLabeledWarning("functions", `Runtime ${friendly} is in Preview. Preview runtimes may change and are not recommended ` +
|
|
65
|
+
"for production workloads. See https://cloud.google.com/functions/docs/runtime-support " +
|
|
66
|
+
"for details.");
|
|
67
|
+
}
|
|
62
68
|
const deprecation = new Date(deprecationDate);
|
|
63
69
|
if (now >= deprecation) {
|
|
64
70
|
utils.logLabeledWarning("functions", `Runtime ${types_1.RUNTIMES[runtime].friendly} was deprecated on ${deprecationDate} and will be ` +
|
|
@@ -57,7 +57,7 @@ exports.RUNTIMES = runtimes({
|
|
|
57
57
|
friendly: "Node.js 22",
|
|
58
58
|
status: "GA",
|
|
59
59
|
deprecationDate: "2027-04-30",
|
|
60
|
-
decommissionDate: "
|
|
60
|
+
decommissionDate: "2027-10-31",
|
|
61
61
|
},
|
|
62
62
|
nodejs24: {
|
|
63
63
|
friendly: "Node.js 24",
|
|
@@ -65,6 +65,12 @@ exports.RUNTIMES = runtimes({
|
|
|
65
65
|
deprecationDate: "2028-04-30",
|
|
66
66
|
decommissionDate: "2028-10-31",
|
|
67
67
|
},
|
|
68
|
+
nodejs26: {
|
|
69
|
+
friendly: "Node.js 26",
|
|
70
|
+
status: "beta",
|
|
71
|
+
deprecationDate: "2029-04-30",
|
|
72
|
+
decommissionDate: "2029-10-31",
|
|
73
|
+
},
|
|
68
74
|
python310: {
|
|
69
75
|
friendly: "Python 3.10",
|
|
70
76
|
status: "GA",
|
|
@@ -54,36 +54,36 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dataconnect": {
|
|
56
56
|
"darwin": {
|
|
57
|
-
"version": "3.4.
|
|
58
|
-
"expectedSize":
|
|
59
|
-
"expectedChecksum": "
|
|
60
|
-
"expectedChecksumSHA256": "
|
|
61
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.
|
|
62
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
57
|
+
"version": "3.4.28",
|
|
58
|
+
"expectedSize": 36296112,
|
|
59
|
+
"expectedChecksum": "85f315cee8bf94af8eedfff7c51a2a72",
|
|
60
|
+
"expectedChecksumSHA256": "d6824ee803bbd4579a6b75af38c0079a882071b017024afe2502de21867098f7",
|
|
61
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-amd64-v3.4.28",
|
|
62
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.28"
|
|
63
63
|
},
|
|
64
64
|
"darwin_arm64": {
|
|
65
|
-
"version": "3.4.
|
|
66
|
-
"expectedSize":
|
|
67
|
-
"expectedChecksum": "
|
|
68
|
-
"expectedChecksumSHA256": "
|
|
69
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.
|
|
70
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
65
|
+
"version": "3.4.28",
|
|
66
|
+
"expectedSize": 34214194,
|
|
67
|
+
"expectedChecksum": "3781a39f4acdaee1645abc7ae3f72152",
|
|
68
|
+
"expectedChecksumSHA256": "2b35d5eae39d57a8666c3771ddad7c09e7189534ecfbb1ef0891c3c6d507d733",
|
|
69
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-macos-arm64-v3.4.28",
|
|
70
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.28"
|
|
71
71
|
},
|
|
72
72
|
"win32": {
|
|
73
|
-
"version": "3.4.
|
|
74
|
-
"expectedSize":
|
|
75
|
-
"expectedChecksum": "
|
|
76
|
-
"expectedChecksumSHA256": "
|
|
77
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.
|
|
78
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
73
|
+
"version": "3.4.28",
|
|
74
|
+
"expectedSize": 36275200,
|
|
75
|
+
"expectedChecksum": "4cb3b2b72860464b92f438136da86d63",
|
|
76
|
+
"expectedChecksumSHA256": "bffb0dedacc979673130c6e5802a13cda0e98e74769a2618c06ed2683bfe1040",
|
|
77
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-windows-amd64-v3.4.28",
|
|
78
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.28.exe"
|
|
79
79
|
},
|
|
80
80
|
"linux": {
|
|
81
|
-
"version": "3.4.
|
|
82
|
-
"expectedSize":
|
|
83
|
-
"expectedChecksum": "
|
|
84
|
-
"expectedChecksumSHA256": "
|
|
85
|
-
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.
|
|
86
|
-
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.
|
|
81
|
+
"version": "3.4.28",
|
|
82
|
+
"expectedSize": 35291298,
|
|
83
|
+
"expectedChecksum": "4fa5bc3ecfadc4c246d7b72e89b5b38d",
|
|
84
|
+
"expectedChecksumSHA256": "b70a3d7fe9a0feb99710d387e7a9ab4cac9c4c7b9e687ae60d391cef959f214f",
|
|
85
|
+
"remoteUrl": "https://storage.googleapis.com/firemat-preview-drop/emulator/dataconnect-emulator-linux-amd64-v3.4.28",
|
|
86
|
+
"downloadPathRelativeToCacheDir": "dataconnect-emulator-3.4.28"
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FunctionsEmulator = exports.TCPConn = exports.IPCConn = void 0;
|
|
4
4
|
exports.createIgnoredFilter = createIgnoredFilter;
|
|
5
|
+
exports.getAllowedEmulatorUIOrigins = getAllowedEmulatorUIOrigins;
|
|
5
6
|
const fs = require("fs");
|
|
6
7
|
const path = require("path");
|
|
7
8
|
const express = require("express");
|
|
@@ -14,6 +15,7 @@ const events_1 = require("events");
|
|
|
14
15
|
const logger_1 = require("../logger");
|
|
15
16
|
const track_1 = require("../track");
|
|
16
17
|
const constants_1 = require("./constants");
|
|
18
|
+
const dns_1 = require("./dns");
|
|
17
19
|
const types_1 = require("./types");
|
|
18
20
|
const chokidar = require("chokidar");
|
|
19
21
|
const minimatch = require("minimatch");
|
|
@@ -85,6 +87,60 @@ function createIgnoredFilter(ignore) {
|
|
|
85
87
|
}
|
|
86
88
|
return ignored;
|
|
87
89
|
}
|
|
90
|
+
const LOOPBACK_AND_WILDCARD_HOSTS = [
|
|
91
|
+
"localhost",
|
|
92
|
+
dns_1.IPV4_LOOPBACK.address,
|
|
93
|
+
dns_1.IPV6_LOOPBACK.address,
|
|
94
|
+
dns_1.IPV4_UNSPECIFIED.address,
|
|
95
|
+
dns_1.IPV6_UNSPECIFIED.address,
|
|
96
|
+
];
|
|
97
|
+
function addOrigin(origins, options) {
|
|
98
|
+
const { protocol, host, port } = options;
|
|
99
|
+
const formattedHost = host.includes(":") && !host.startsWith("[") ? `[${host}]` : host;
|
|
100
|
+
const portSuffix = port !== undefined ? `:${port}` : "";
|
|
101
|
+
try {
|
|
102
|
+
origins.add(new url_1.URL(`${protocol}://${formattedHost}${portSuffix}`).origin);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function getAllowedEmulatorUIOrigins() {
|
|
108
|
+
const uiInfo = registry_1.EmulatorRegistry.getInfo(types_1.Emulators.UI);
|
|
109
|
+
if (!uiInfo) {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
const origins = new Set();
|
|
113
|
+
const specs = uiInfo.listen?.length
|
|
114
|
+
? uiInfo.listen
|
|
115
|
+
: [
|
|
116
|
+
{
|
|
117
|
+
address: uiInfo.host,
|
|
118
|
+
port: uiInfo.port,
|
|
119
|
+
family: uiInfo.host.includes(":") ? "IPv6" : "IPv4",
|
|
120
|
+
},
|
|
121
|
+
];
|
|
122
|
+
for (const spec of specs) {
|
|
123
|
+
const { address, port } = spec;
|
|
124
|
+
if (LOOPBACK_AND_WILDCARD_HOSTS.includes(address)) {
|
|
125
|
+
addOrigin(origins, { protocol: "http", host: "localhost", port });
|
|
126
|
+
addOrigin(origins, { protocol: "http", host: dns_1.IPV4_LOOPBACK.address, port });
|
|
127
|
+
addOrigin(origins, { protocol: "http", host: dns_1.IPV6_LOOPBACK.address, port });
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
addOrigin(origins, { protocol: "http", host: address, port });
|
|
131
|
+
}
|
|
132
|
+
if (process.env.WEB_HOST) {
|
|
133
|
+
addOrigin(origins, { protocol: "https", host: `${port}-${process.env.WEB_HOST}` });
|
|
134
|
+
}
|
|
135
|
+
if (process.env.CODESPACE_NAME && process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN) {
|
|
136
|
+
addOrigin(origins, {
|
|
137
|
+
protocol: "https",
|
|
138
|
+
host: `${process.env.CODESPACE_NAME}-${port}.${process.env.GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN}`,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return Array.from(origins);
|
|
143
|
+
}
|
|
88
144
|
class FunctionsEmulator {
|
|
89
145
|
static getHttpFunctionUrl(projectId, name, region, info) {
|
|
90
146
|
let url;
|
|
@@ -223,10 +279,26 @@ class FunctionsEmulator {
|
|
|
223
279
|
}
|
|
224
280
|
res.json({ status: "multicast_acknowledged" });
|
|
225
281
|
};
|
|
282
|
+
const rejectDisallowedBackendsOrigin = (req, res, next) => {
|
|
283
|
+
const origin = req.headers.origin;
|
|
284
|
+
if (origin && !getAllowedEmulatorUIOrigins().includes(origin)) {
|
|
285
|
+
res.status(403).json({
|
|
286
|
+
message: `/backends cannot be accessed by external callers.`,
|
|
287
|
+
});
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
next();
|
|
291
|
+
};
|
|
292
|
+
const listBackendsCors = cors({
|
|
293
|
+
origin: (origin, callback) => {
|
|
294
|
+
callback(null, Boolean(origin));
|
|
295
|
+
},
|
|
296
|
+
});
|
|
226
297
|
const listBackendsHandler = (req, res) => {
|
|
227
298
|
res.json({ backends: this.getBackendInfo() });
|
|
228
299
|
};
|
|
229
|
-
hub.
|
|
300
|
+
hub.options(listBackendsRoute, rejectDisallowedBackendsOrigin, listBackendsCors);
|
|
301
|
+
hub.get(listBackendsRoute, rejectDisallowedBackendsOrigin, listBackendsCors, listBackendsHandler);
|
|
230
302
|
hub.post(backgroundFunctionRoute, dataMiddleware, httpsHandler);
|
|
231
303
|
hub.post(multicastFunctionRoute, dataMiddleware, multicastHandler);
|
|
232
304
|
hub.all(httpsFunctionRoutes, dataMiddleware, httpsHandler);
|
|
@@ -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;
|