firebase-tools-with-isolate 15.27.0 → 15.28.2-1
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/apphosting/backend.js +44 -10
- package/lib/apphosting/githubConnections.js +1 -1
- package/lib/apphosting/repo.js +1 -1
- package/lib/apphosting/rollout.js +1 -1
- package/lib/commands/ext-export.js +78 -17
- package/lib/commands/ext-migrate.js +36 -0
- package/lib/commands/ext-uninstall.js +35 -1
- package/lib/commands/functions-delete.js +19 -5
- package/lib/commands/functions-kits-install.js +18 -275
- package/lib/commands/functions-kits-list.js +27 -0
- package/lib/commands/functions-kits-uninstall.js +266 -0
- package/lib/commands/index.js +5 -0
- package/lib/config.js +34 -0
- package/lib/dataconnect/client.js +13 -2
- package/lib/dataconnect/schemaMigration.js +16 -5
- package/lib/deploy/extensions/secrets.js +18 -0
- package/lib/deploy/functions/ensure.js +29 -19
- package/lib/deploy/functions/functionsDeployHelper.js +39 -15
- package/lib/deploy/functions/prepare.js +51 -10
- package/lib/deploy/functions/release/fabricator.js +19 -3
- package/lib/deploy/functions/release/planner.js +8 -0
- package/lib/deploy/functions/runtimes/dart/features.js +51 -0
- package/lib/deploy/functions/runtimes/dart/index.js +60 -16
- package/lib/emulator/downloadableEmulatorInfo.json +31 -31
- package/lib/emulator/functionsEmulator.js +4 -1
- package/lib/experiments.js +6 -0
- package/lib/extensions/export.js +26 -0
- package/lib/extensions/listExtensions.js +27 -3
- package/lib/extensions/migrate.js +171 -0
- package/lib/extensions/replacementRegistry.js +65 -0
- package/lib/extensions/replacements.json +464 -0
- package/lib/fetchMOTD.js +3 -0
- package/lib/functions/env.js +11 -0
- package/lib/functions/iac/export.js +16 -1
- package/lib/functions/kits/config.js +8 -0
- package/lib/functions/kits/env.js +38 -0
- package/lib/functions/kits/index.js +19 -0
- package/lib/functions/kits/install.js +709 -0
- package/lib/gcp/secretManager.js +3 -3
- package/lib/init/features/functions/dart.js +1 -1
- package/lib/mcp/tools/core/deploy.js +2 -0
- package/lib/mcp/tools/core/login.js +59 -4
- package/lib/mcp/tools/dataconnect/compile.js +23 -2
- package/lib/mcp/tools/dataconnect/list_services.js +3 -4
- package/lib/requireTosAcceptance.js +2 -1
- package/lib/tsconfig.publish.tsbuildinfo +1 -1
- package/lib/unzip.js +12 -2
- package/package.json +6 -5
- package/schema/firebase-config.json +1 -1
- package/templates/init/functions/dart/_gitignore +1 -0
- package/templates/init/functions/typescript/index.ts +3 -3
- package/templates/init/functions/typescript/package-ongraphrequest.lint.json +3 -3
- package/templates/init/functions/typescript/package.lint.json +3 -3
- package/templates/init/functions/typescript/tsconfig.dev.json +4 -0
|
@@ -13,6 +13,7 @@ exports.getConnector = getConnector;
|
|
|
13
13
|
exports.deleteConnector = deleteConnector;
|
|
14
14
|
exports.listConnectors = listConnectors;
|
|
15
15
|
exports.upsertConnector = upsertConnector;
|
|
16
|
+
exports.executeSchemaMigration = executeSchemaMigration;
|
|
16
17
|
const api_1 = require("../api");
|
|
17
18
|
const apiv2_1 = require("../apiv2");
|
|
18
19
|
const operationPoller = require("../operation-poller");
|
|
@@ -114,7 +115,7 @@ async function upsertSchema(schema, validateOnly = false, async = false) {
|
|
|
114
115
|
apiOrigin: (0, api_1.dataconnectOrigin)(),
|
|
115
116
|
apiVersion: DATACONNECT_API_VERSION,
|
|
116
117
|
operationResourceName: op.body.name,
|
|
117
|
-
masterTimeout:
|
|
118
|
+
masterTimeout: 300000,
|
|
118
119
|
});
|
|
119
120
|
}
|
|
120
121
|
async function deleteSchema(name) {
|
|
@@ -163,7 +164,17 @@ async function upsertConnector(connector) {
|
|
|
163
164
|
apiOrigin: (0, api_1.dataconnectOrigin)(),
|
|
164
165
|
apiVersion: DATACONNECT_API_VERSION,
|
|
165
166
|
operationResourceName: op.body.name,
|
|
166
|
-
masterTimeout:
|
|
167
|
+
masterTimeout: 300000,
|
|
167
168
|
});
|
|
168
169
|
return pollRes;
|
|
169
170
|
}
|
|
171
|
+
async function executeSchemaMigration(serviceName, diffs) {
|
|
172
|
+
const client = dataconnectClient();
|
|
173
|
+
const op = await client.post(`${serviceName}/schemas/main:migrate`, { diffs });
|
|
174
|
+
await operationPoller.pollOperation({
|
|
175
|
+
apiOrigin: (0, api_1.dataconnectOrigin)(),
|
|
176
|
+
apiVersion: DATACONNECT_API_VERSION,
|
|
177
|
+
operationResourceName: op.body.name,
|
|
178
|
+
masterTimeout: 300000,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
@@ -6,7 +6,9 @@ exports.upsertSecondarySchema = upsertSecondarySchema;
|
|
|
6
6
|
exports.grantRoleToUserInSchema = grantRoleToUserInSchema;
|
|
7
7
|
exports.getIdentifiers = getIdentifiers;
|
|
8
8
|
exports.serviceNameFromSchema = serviceNameFromSchema;
|
|
9
|
+
exports.handleIncompatibleSchemaError = handleIncompatibleSchemaError;
|
|
9
10
|
exports.ensureServiceIsConnectedToCloudSql = ensureServiceIsConnectedToCloudSql;
|
|
11
|
+
const experiments = require("../experiments");
|
|
10
12
|
const clc = require("colorette");
|
|
11
13
|
const sql_formatter_1 = require("sql-formatter");
|
|
12
14
|
const types_1 = require("./types");
|
|
@@ -169,6 +171,7 @@ async function migrateSchema(args) {
|
|
|
169
171
|
databaseId,
|
|
170
172
|
instanceId,
|
|
171
173
|
schemaName,
|
|
174
|
+
schema,
|
|
172
175
|
incompatibleSchemaError: incompatible,
|
|
173
176
|
choice: migrationMode,
|
|
174
177
|
});
|
|
@@ -204,6 +207,7 @@ async function migrateSchema(args) {
|
|
|
204
207
|
databaseId,
|
|
205
208
|
instanceId,
|
|
206
209
|
schemaName,
|
|
210
|
+
schema,
|
|
207
211
|
incompatibleSchemaError: incompatible,
|
|
208
212
|
choice: migrationMode,
|
|
209
213
|
});
|
|
@@ -303,7 +307,7 @@ function suggestedCommand(serviceName, invalidConnectorNames) {
|
|
|
303
307
|
return `firebase deploy --only ${onlys}`;
|
|
304
308
|
}
|
|
305
309
|
async function handleIncompatibleSchemaError(args) {
|
|
306
|
-
const { incompatibleSchemaError, options, instanceId, databaseId, schemaName, choice } = args;
|
|
310
|
+
const { schema, incompatibleSchemaError, options, instanceId, databaseId, schemaName, choice } = args;
|
|
307
311
|
const commandsToExecute = incompatibleSchemaError.diffs.filter((d) => {
|
|
308
312
|
switch (choice) {
|
|
309
313
|
case "all":
|
|
@@ -342,10 +346,17 @@ async function handleIncompatibleSchemaError(args) {
|
|
|
342
346
|
await (0, connect_1.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, commandsToExecuteBySuperUser.map((d) => d.sql), false);
|
|
343
347
|
}
|
|
344
348
|
if (commandsToExecuteByOwner.length) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
+
if (experiments.isEnabled("fdcapimigration")) {
|
|
350
|
+
(0, utils_1.logLabeledBullet)("dataconnect", `[EXPERIMENTAL] Delegating SQL execution to FDC Backend...`);
|
|
351
|
+
const serviceName = serviceNameFromSchema(schema);
|
|
352
|
+
await (0, client_1.executeSchemaMigration)(serviceName, commandsToExecuteByOwner);
|
|
353
|
+
}
|
|
354
|
+
else {
|
|
355
|
+
await (0, connect_1.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [
|
|
356
|
+
`SET ROLE "${(0, permissions_1.firebaseowner)(databaseId, schemaName)}"`,
|
|
357
|
+
...commandsToExecuteByOwner.map((d) => d.sql),
|
|
358
|
+
], false);
|
|
359
|
+
}
|
|
349
360
|
return incompatibleSchemaError.diffs;
|
|
350
361
|
}
|
|
351
362
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handleSecretParams = handleSecretParams;
|
|
4
4
|
exports.checkSpecForSecrets = checkSpecForSecrets;
|
|
5
|
+
exports.transferSecretToKits = transferSecretToKits;
|
|
5
6
|
const clc = require("colorette");
|
|
6
7
|
const secretUtils = require("../../extensions/secretsUtils");
|
|
7
8
|
const secretManager = require("../../gcp/secretManager");
|
|
@@ -11,6 +12,7 @@ const types_1 = require("../../extensions/types");
|
|
|
11
12
|
const error_1 = require("../../error");
|
|
12
13
|
const logger_1 = require("../../logger");
|
|
13
14
|
const utils_1 = require("../../utils");
|
|
15
|
+
const secretManager_1 = require("../../gcp/secretManager");
|
|
14
16
|
async function handleSecretParams(payload, have, nonInteractive) {
|
|
15
17
|
for (const i of payload.instancesToCreate ?? []) {
|
|
16
18
|
if (await checkSpecForSecrets(i)) {
|
|
@@ -138,6 +140,22 @@ async function getSecretInfo(projectId, secretName, version) {
|
|
|
138
140
|
}
|
|
139
141
|
return secretInfo;
|
|
140
142
|
}
|
|
143
|
+
async function transferSecretToKits(projectId, secretName) {
|
|
144
|
+
const newLabels = {};
|
|
145
|
+
try {
|
|
146
|
+
const have = await secretManager.getSecret(projectId, secretName);
|
|
147
|
+
for (const [labelKey, labelValue] of Object.entries(have.labels)) {
|
|
148
|
+
if (labelKey !== secretUtils.SECRET_LABEL) {
|
|
149
|
+
newLabels[labelKey] = labelValue;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
throw new error_1.FirebaseError(`Error when retrieving current state of migrating secret ${projectId}/${secretName}: ${err instanceof Error ? err.message : String(err)}`, { original: err instanceof Error ? err : undefined });
|
|
155
|
+
}
|
|
156
|
+
newLabels[secretManager_1.FIREBASE_MANAGED] = "functions";
|
|
157
|
+
return secretManager.patchSecret(projectId, secretName, newLabels);
|
|
158
|
+
}
|
|
141
159
|
async function promptForCreateSecret(args) {
|
|
142
160
|
logger_1.logger.info(`${clc.bold(args.instanceId)}: Secret ${args.projectId}/${args.secretName} doesn't exist yet.`);
|
|
143
161
|
if (args.nonInteractive) {
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultServiceAccount = defaultServiceAccount;
|
|
4
4
|
exports.cloudBuildEnabled = cloudBuildEnabled;
|
|
5
|
-
exports.
|
|
5
|
+
exports.secretsAccessDelta = secretsAccessDelta;
|
|
6
|
+
exports.checkSecretAccess = checkSecretAccess;
|
|
7
|
+
exports.grantSecretAccess = grantSecretAccess;
|
|
6
8
|
const clc = require("colorette");
|
|
7
9
|
const ensureApiEnabled_1 = require("../../ensureApiEnabled");
|
|
8
10
|
const error_1 = require("../../error");
|
|
@@ -70,8 +72,11 @@ async function cloudBuildEnabled(projectId) {
|
|
|
70
72
|
async function secretsToServiceAccounts(b) {
|
|
71
73
|
const secretsToSa = {};
|
|
72
74
|
for (const e of backend.allEndpoints(b)) {
|
|
75
|
+
if (!e.secretEnvironmentVariables || e.secretEnvironmentVariables.length === 0) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
73
78
|
const sa = e.serviceAccount || (await module.exports.defaultServiceAccount(e));
|
|
74
|
-
for (const s of e.secretEnvironmentVariables
|
|
79
|
+
for (const s of e.secretEnvironmentVariables) {
|
|
75
80
|
const serviceAccounts = secretsToSa[s.secret] || new Set();
|
|
76
81
|
serviceAccounts.add(sa);
|
|
77
82
|
secretsToSa[s.secret] = serviceAccounts;
|
|
@@ -79,20 +84,8 @@ async function secretsToServiceAccounts(b) {
|
|
|
79
84
|
}
|
|
80
85
|
return secretsToSa;
|
|
81
86
|
}
|
|
82
|
-
async function
|
|
83
|
-
const
|
|
84
|
-
(0, utils_1.logLabeledBullet)("functions", `ensuring ${clc.bold(serviceAccounts.join(", "))} access to secret ${clc.bold(secret)}.`);
|
|
85
|
-
if (dryRun) {
|
|
86
|
-
const check = await (0, secretManager_1.checkServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
|
|
87
|
-
if (check.length) {
|
|
88
|
-
(0, utils_1.logLabeledBullet)("functions", `On your next deploy, ${clc.bold(serviceAccounts.join(", "))} will be granted access to secret ${clc.bold(secret)}.`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
await (0, secretManager_1.ensureServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
|
|
93
|
-
}
|
|
94
|
-
(0, utils_1.logLabeledSuccess)("functions", `ensured ${clc.bold(serviceAccounts.join(", "))} access to ${clc.bold(secret)}.`);
|
|
95
|
-
};
|
|
87
|
+
async function secretsAccessDelta(args) {
|
|
88
|
+
const { wantBackend, haveBackend } = args;
|
|
96
89
|
const wantSecrets = await secretsToServiceAccounts(wantBackend);
|
|
97
90
|
const haveSecrets = await secretsToServiceAccounts(haveBackend);
|
|
98
91
|
for (const [secret, serviceAccounts] of Object.entries(haveSecrets)) {
|
|
@@ -103,9 +96,26 @@ async function secretAccess(projectId, wantBackend, haveBackend, dryRun) {
|
|
|
103
96
|
delete wantSecrets[secret];
|
|
104
97
|
}
|
|
105
98
|
}
|
|
106
|
-
const
|
|
99
|
+
const delta = {};
|
|
107
100
|
for (const [secret, serviceAccounts] of Object.entries(wantSecrets)) {
|
|
108
|
-
|
|
101
|
+
if (serviceAccounts.size > 0) {
|
|
102
|
+
delta[secret] = Array.from(serviceAccounts);
|
|
103
|
+
}
|
|
109
104
|
}
|
|
110
|
-
|
|
105
|
+
return delta;
|
|
106
|
+
}
|
|
107
|
+
async function checkSecretAccess(projectId, secretAccessDelta) {
|
|
108
|
+
for (const [secret, serviceAccounts] of Object.entries(secretAccessDelta)) {
|
|
109
|
+
(0, utils_1.logLabeledBullet)("functions", `ensuring ${clc.bold(serviceAccounts.join(", "))} access to secret ${clc.bold(secret)}.`);
|
|
110
|
+
const check = await (0, secretManager_1.checkServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
|
|
111
|
+
if (check.length) {
|
|
112
|
+
(0, utils_1.logLabeledBullet)("functions", `On your next deploy, ${clc.bold(serviceAccounts.join(", "))} will be granted access to secret ${clc.bold(secret)}.`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async function grantSecretAccess(args) {
|
|
117
|
+
const { projectId, secret, serviceAccounts } = args;
|
|
118
|
+
(0, utils_1.logLabeledBullet)("functions", `ensuring ${clc.bold(serviceAccounts.join(", "))} access to secret ${clc.bold(secret)}.`);
|
|
119
|
+
await (0, secretManager_1.ensureServiceAgentRole)({ name: secret, projectId }, serviceAccounts, "roles/secretmanager.secretAccessor");
|
|
120
|
+
(0, utils_1.logLabeledSuccess)("functions", `ensured ${clc.bold(serviceAccounts.join(", "))} access to ${clc.bold(secret)}.`);
|
|
111
121
|
}
|
|
@@ -11,6 +11,8 @@ exports.targetCodebases = targetCodebases;
|
|
|
11
11
|
exports.groupEndpointsByCodebase = groupEndpointsByCodebase;
|
|
12
12
|
exports.isCodebaseFiltered = isCodebaseFiltered;
|
|
13
13
|
exports.isEndpointFiltered = isEndpointFiltered;
|
|
14
|
+
exports.parseDeleteFilters = parseDeleteFilters;
|
|
15
|
+
exports.detectCodebaseAndIdCollisions = detectCodebaseAndIdCollisions;
|
|
14
16
|
const backend = require("./backend");
|
|
15
17
|
const projectConfig_1 = require("../../functions/projectConfig");
|
|
16
18
|
const functional_1 = require("../../functional");
|
|
@@ -21,31 +23,24 @@ function endpointMatchesAnyFilter(endpoint, filters) {
|
|
|
21
23
|
return filters.some((filter) => endpointMatchesFilter(endpoint, filter));
|
|
22
24
|
}
|
|
23
25
|
function endpointMatchesFilter(endpoint, filter) {
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
+
if (filter.codebase) {
|
|
27
|
+
const endpointCodebase = endpoint.codebase || projectConfig_1.DEFAULT_CODEBASE;
|
|
28
|
+
if (endpointCodebase !== filter.codebase) {
|
|
26
29
|
return false;
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
|
-
if (!filter.idChunks) {
|
|
32
|
+
if (!filter.idChunks || filter.idChunks.length === 0) {
|
|
30
33
|
return true;
|
|
31
34
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
for (let i = 0; i < filter.idChunks.length; i += 1) {
|
|
37
|
-
if (idChunks[i] !== filter.idChunks[i]) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return true;
|
|
35
|
+
const filterPrefix = filter.idChunks.join("-");
|
|
36
|
+
return endpoint.id === filterPrefix || endpoint.id.startsWith(`${filterPrefix}-`);
|
|
42
37
|
}
|
|
43
|
-
function getCodebasesFromConfig(config) {
|
|
38
|
+
function getCodebasesFromConfig(config = []) {
|
|
44
39
|
return [
|
|
45
40
|
...new Set(config.flatMap((c) => ((0, projectConfig_1.isKitConfig)(c) ? Object.keys(c.instances) : [c.codebase]))),
|
|
46
41
|
];
|
|
47
42
|
}
|
|
48
|
-
function parseFunctionSelector(selector, config) {
|
|
43
|
+
function parseFunctionSelector(selector, config = []) {
|
|
49
44
|
const fragments = selector.split(":");
|
|
50
45
|
const target = fragments[0];
|
|
51
46
|
const codebaseNames = getCodebasesFromConfig(config);
|
|
@@ -145,3 +140,32 @@ function isCodebaseFiltered(codebase, filters) {
|
|
|
145
140
|
function isEndpointFiltered(endpoint, filters) {
|
|
146
141
|
return filters.some((filter) => endpointMatchesFilter(endpoint, filter));
|
|
147
142
|
}
|
|
143
|
+
function parseDeleteFilters(filters, activeCodebases) {
|
|
144
|
+
const liveCodebasesConfig = activeCodebases.map((codebase) => ({ source: "", codebase }));
|
|
145
|
+
return filters.flatMap((f) => {
|
|
146
|
+
const parsed = parseFunctionSelector(f, liveCodebasesConfig);
|
|
147
|
+
return parsed.map((filter) => !f.includes(":") && filter.codebase === projectConfig_1.DEFAULT_CODEBASE && filter.idChunks
|
|
148
|
+
? { idChunks: filter.idChunks }
|
|
149
|
+
: filter);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function detectCodebaseAndIdCollisions(filters, activeCodebases, allEndpoints, defaultCodebase = projectConfig_1.DEFAULT_CODEBASE) {
|
|
153
|
+
const collisions = [];
|
|
154
|
+
for (const f of filters) {
|
|
155
|
+
if (f.includes(":") || !activeCodebases.includes(f)) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const matchingEndpoints = allEndpoints.filter((ep) => ep.id === f || ep.id.startsWith(`${f}-`));
|
|
159
|
+
if (matchingEndpoints.length > 0) {
|
|
160
|
+
const ep = matchingEndpoints[0];
|
|
161
|
+
const prefix = ep.codebase || defaultCodebase;
|
|
162
|
+
collisions.push({
|
|
163
|
+
filter: f,
|
|
164
|
+
codebase: prefix,
|
|
165
|
+
functionLabel: getFunctionLabel(ep),
|
|
166
|
+
workaroundCommand: `firebase functions:delete ${prefix}:${f}`,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return collisions;
|
|
171
|
+
}
|
|
@@ -10,12 +10,13 @@ exports.inferBlockingDetails = inferBlockingDetails;
|
|
|
10
10
|
exports.resolveCpuAndConcurrency = resolveCpuAndConcurrency;
|
|
11
11
|
exports.resolveDefaultTimeout = resolveDefaultTimeout;
|
|
12
12
|
exports.loadCodebases = loadCodebases;
|
|
13
|
+
exports.getExecutablePaths = getExecutablePaths;
|
|
14
|
+
exports.stripStaleDartBuildIgnore = stripStaleDartBuildIgnore;
|
|
13
15
|
exports.warnIfNewGenkitFunctionIsMissingSecrets = warnIfNewGenkitFunctionIsMissingSecrets;
|
|
14
16
|
exports.ensureAllRequiredAPIsEnabled = ensureAllRequiredAPIsEnabled;
|
|
15
17
|
exports.partitionUserEnvs = partitionUserEnvs;
|
|
16
18
|
exports.checkKitForGen1 = checkKitForGen1;
|
|
17
19
|
const clc = require("colorette");
|
|
18
|
-
const proto = require("../../gcp/proto");
|
|
19
20
|
const backend = require("./backend");
|
|
20
21
|
const build = require("./build");
|
|
21
22
|
const experiments = require("../../experiments");
|
|
@@ -31,6 +32,8 @@ const api_1 = require("../../api");
|
|
|
31
32
|
const functionsDeployHelper_1 = require("./functionsDeployHelper");
|
|
32
33
|
const utils_1 = require("../../utils");
|
|
33
34
|
const triggerSupport_1 = require("./runtimes/dart/triggerSupport");
|
|
35
|
+
const dart_1 = require("./runtimes/dart");
|
|
36
|
+
const features_1 = require("./runtimes/dart/features");
|
|
34
37
|
const prepareFunctionsUpload_1 = require("./prepareFunctionsUpload");
|
|
35
38
|
const prompts_1 = require("./prompts");
|
|
36
39
|
const projectUtils_1 = require("../../projectUtils");
|
|
@@ -197,11 +200,9 @@ async function prepare(context, options, payload) {
|
|
|
197
200
|
projectAlias: options.projectAlias,
|
|
198
201
|
projectDir: options.config.projectDir,
|
|
199
202
|
};
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
else {
|
|
204
|
-
proto.convertIfPresent(userEnvOpt, localCfg, "configDir", (cd) => options.config.path(cd));
|
|
203
|
+
const configDir = (0, projectConfig_1.resolveConfigDir)(localCfg, codebase);
|
|
204
|
+
if (configDir) {
|
|
205
|
+
userEnvOpt.configDir = options.config.path(configDir);
|
|
205
206
|
}
|
|
206
207
|
const rawUserEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
|
|
207
208
|
const { userEnvs: userEnvs, secretRefs: secretRefs } = partitionUserEnvs(rawUserEnvs);
|
|
@@ -303,9 +304,9 @@ async function prepare(context, options, payload) {
|
|
|
303
304
|
const exportType = backend.someEndpoint(wantBackend, (e) => e.platform === "run")
|
|
304
305
|
? "tar.gz"
|
|
305
306
|
: "zip";
|
|
306
|
-
const
|
|
307
|
-
const
|
|
308
|
-
const packagedSource = await (0, prepareFunctionsUpload_1.prepareFunctionsUpload)(options.config.projectDir, sourceDir,
|
|
307
|
+
const executablePaths = await getExecutablePaths(wantBuilds[codebase].runtime, sourceDir);
|
|
308
|
+
const uploadCfg = await stripStaleDartBuildIgnore(wantBuilds[codebase].runtime, sourceDir, localCfg);
|
|
309
|
+
const packagedSource = await (0, prepareFunctionsUpload_1.prepareFunctionsUpload)(options.config.projectDir, sourceDir, uploadCfg, [...schPathSet], undefined, { exportType, executablePaths });
|
|
309
310
|
source.functionsSourceV2 = packagedSource?.pathToSource;
|
|
310
311
|
source.functionsSourceV2Hash = packagedSource?.hash;
|
|
311
312
|
}
|
|
@@ -346,7 +347,14 @@ async function prepare(context, options, payload) {
|
|
|
346
347
|
await validate.secretsAreValid(projectId, matchingBackend);
|
|
347
348
|
await (0, checkIam_1.ensureServiceAgentRoles)(projectId, projectNumber, matchingBackend, haveBackend, options.dryRun);
|
|
348
349
|
await (0, checkIam_1.ensureGenkitMonitoringRoles)(projectId, projectNumber, matchingBackend, haveBackend, options.dryRun);
|
|
349
|
-
|
|
350
|
+
if (options.dryRun) {
|
|
351
|
+
const secretAccessDelta = await ensure.secretsAccessDelta({
|
|
352
|
+
projectId,
|
|
353
|
+
wantBackend: matchingBackend,
|
|
354
|
+
haveBackend,
|
|
355
|
+
});
|
|
356
|
+
await ensure.checkSecretAccess(projectId, secretAccessDelta);
|
|
357
|
+
}
|
|
350
358
|
updateEndpointTargetedStatus(wantBackends, context.filters || []);
|
|
351
359
|
validate.checkFiltersIntegrity(wantBackends, context.filters);
|
|
352
360
|
(0, applyHash_1.applyBackendHashToBackends)(wantBackends, context);
|
|
@@ -511,12 +519,24 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
|
|
|
511
519
|
await runtimeDelegate.validate();
|
|
512
520
|
logger_1.logger.debug(`Building ${runtimeDelegate.language} source`);
|
|
513
521
|
await runtimeDelegate.build();
|
|
522
|
+
const userEnvOpt = {
|
|
523
|
+
functionsSource: sourceDir,
|
|
524
|
+
projectId: projectId,
|
|
525
|
+
projectAlias: options.projectAlias,
|
|
526
|
+
projectDir: options.config.projectDir,
|
|
527
|
+
};
|
|
528
|
+
const configDir = (0, projectConfig_1.resolveConfigDir)(codebaseConfig, codebase);
|
|
529
|
+
if (configDir) {
|
|
530
|
+
userEnvOpt.configDir = options.config.path(configDir);
|
|
531
|
+
}
|
|
532
|
+
const userEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
|
|
514
533
|
const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId, (0, projectConfig_1.isKitConfig)(codebaseConfig) ? codebase : undefined);
|
|
515
534
|
(0, utils_1.logLabeledBullet)("functions", `Loading and analyzing source code for codebase ${codebase} to determine what to deploy`);
|
|
516
535
|
const codebaseRuntimeConfig = (0, projectConfig_1.shouldUseRuntimeConfig)(codebaseConfig)
|
|
517
536
|
? runtimeConfig
|
|
518
537
|
: { firebase: firebaseConfig };
|
|
519
538
|
const discoveredBuild = await runtimeDelegate.discoverBuild(codebaseRuntimeConfig, {
|
|
539
|
+
...userEnvs,
|
|
520
540
|
...firebaseEnvs,
|
|
521
541
|
GOOGLE_CLOUD_QUOTA_PROJECT: projectId,
|
|
522
542
|
});
|
|
@@ -542,6 +562,27 @@ function warnIfDartBackendHasUnsupportedTriggers(want) {
|
|
|
542
562
|
"See https://github.com/firebase/firebase-functions-dart for current trigger support.");
|
|
543
563
|
}
|
|
544
564
|
}
|
|
565
|
+
async function getExecutablePaths(runtime, sourceDir) {
|
|
566
|
+
if (!supported.runtimeIsLanguage(runtime, "dart")) {
|
|
567
|
+
return [];
|
|
568
|
+
}
|
|
569
|
+
const features = await features_1.DartVersionFeatures.detect(sourceDir);
|
|
570
|
+
return features.isNativeAssetsAvailable ? [dart_1.DART_BUNDLE_EXECUTABLE_PATH] : [dart_1.DART_COMPILE_EXE_PATH];
|
|
571
|
+
}
|
|
572
|
+
async function stripStaleDartBuildIgnore(runtime, sourceDir, localCfg) {
|
|
573
|
+
if (!supported.runtimeIsLanguage(runtime, "dart") ||
|
|
574
|
+
!localCfg.ignore?.some((i) => i === "build" || i === "build/")) {
|
|
575
|
+
return localCfg;
|
|
576
|
+
}
|
|
577
|
+
const features = await features_1.DartVersionFeatures.detect(sourceDir);
|
|
578
|
+
if (!features.isNativeAssetsAvailable) {
|
|
579
|
+
return localCfg;
|
|
580
|
+
}
|
|
581
|
+
return {
|
|
582
|
+
...localCfg,
|
|
583
|
+
ignore: localCfg.ignore.filter((i) => i !== "build" && i !== "build/"),
|
|
584
|
+
};
|
|
585
|
+
}
|
|
545
586
|
async function warnIfNewGenkitFunctionIsMissingSecrets(have, want, options) {
|
|
546
587
|
if (options.force) {
|
|
547
588
|
return;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Fabricator = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
5
|
const executor_1 = require("./executor");
|
|
6
|
+
const ensure = require("../ensure");
|
|
6
7
|
const error_1 = require("../../../error");
|
|
7
8
|
const sourceTokenScraper_1 = require("./sourceTokenScraper");
|
|
8
9
|
const timer_1 = require("./timer");
|
|
@@ -55,6 +56,13 @@ const rethrowAs = (endpoint, op) => (err) => {
|
|
|
55
56
|
logger_1.logger.error(err.message);
|
|
56
57
|
throw new reporter.DeploymentError(endpoint, op, err);
|
|
57
58
|
};
|
|
59
|
+
const rethrowAsUnlessNotFound = (endpoint, op) => (err) => {
|
|
60
|
+
if ((0, executor_1.parseErrorCode)(err) === 404) {
|
|
61
|
+
logger_1.logger.debug(`Ignoring 404 for ${op} on ${endpoint.id}; resource already deleted.`);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
return rethrowAs(endpoint, op)(err);
|
|
65
|
+
};
|
|
58
66
|
class Fabricator {
|
|
59
67
|
constructor(args) {
|
|
60
68
|
this.executor = args.executor;
|
|
@@ -147,6 +155,14 @@ class Fabricator {
|
|
|
147
155
|
for (const [codebase, codebasePlan] of Object.entries(plan)) {
|
|
148
156
|
await this.grantNewRoles(codebasePlan, codebase);
|
|
149
157
|
}
|
|
158
|
+
const secretAccessPromises = Object.values(plan).flatMap((codebasePlan) => Object.entries(codebasePlan.secretAccessPlan || {}).map(([secret, serviceAccounts]) => this.executor.run(() => ensure.grantSecretAccess({
|
|
159
|
+
projectId: this.projectId,
|
|
160
|
+
secret,
|
|
161
|
+
serviceAccounts,
|
|
162
|
+
}), {
|
|
163
|
+
retryPredicates: [executor_1.isTransientError, executor_1.isServiceAccount404],
|
|
164
|
+
})));
|
|
165
|
+
await Promise.all(secretAccessPromises);
|
|
150
166
|
const allChangesets = [];
|
|
151
167
|
for (const codebasePlan of Object.values(plan)) {
|
|
152
168
|
allChangesets.push(...Object.values(codebasePlan.regionalChangesets));
|
|
@@ -820,17 +836,17 @@ class Fabricator {
|
|
|
820
836
|
const jobName = scheduler.jobNameForEndpoint(endpoint, this.appEngineLocation);
|
|
821
837
|
await this.executor
|
|
822
838
|
.run(() => scheduler.deleteJob(jobName))
|
|
823
|
-
.catch(
|
|
839
|
+
.catch(rethrowAsUnlessNotFound(endpoint, "delete schedule"));
|
|
824
840
|
const topicName = scheduler.topicNameForEndpoint(endpoint);
|
|
825
841
|
await this.executor
|
|
826
842
|
.run(() => pubsub.deleteTopic(topicName))
|
|
827
|
-
.catch(
|
|
843
|
+
.catch(rethrowAsUnlessNotFound(endpoint, "delete topic"));
|
|
828
844
|
}
|
|
829
845
|
async deleteScheduleV2(endpoint) {
|
|
830
846
|
const jobName = scheduler.jobNameForEndpoint(endpoint, endpoint.region);
|
|
831
847
|
await this.executor
|
|
832
848
|
.run(() => scheduler.deleteJob(jobName))
|
|
833
|
-
.catch(
|
|
849
|
+
.catch(rethrowAsUnlessNotFound(endpoint, "delete schedule"));
|
|
834
850
|
}
|
|
835
851
|
async disableTaskQueue(endpoint) {
|
|
836
852
|
const update = {
|
|
@@ -15,6 +15,7 @@ const deploymentTool_1 = require("../../../deploymentTool");
|
|
|
15
15
|
const error_1 = require("../../../error");
|
|
16
16
|
const utils = require("../../../utils");
|
|
17
17
|
const backend = require("../backend");
|
|
18
|
+
const ensure = require("../ensure");
|
|
18
19
|
const v2events = require("../../../functions/events/v2");
|
|
19
20
|
function calculateChangesets(want, have, keyFn, deleteAll) {
|
|
20
21
|
const toCreate = utils.groupBy(Object.keys(want)
|
|
@@ -119,6 +120,11 @@ async function createDeploymentPlan(args) {
|
|
|
119
120
|
"default to 80 concurrent executions, but existing functions keep the " +
|
|
120
121
|
"old default of 1. You can change this with the 'concurrency' option.");
|
|
121
122
|
}
|
|
123
|
+
const secretAccessPlan = await ensure.secretsAccessDelta({
|
|
124
|
+
projectId: args.projectId,
|
|
125
|
+
wantBackend,
|
|
126
|
+
haveBackend,
|
|
127
|
+
});
|
|
122
128
|
if (requiredRoles && hasWantEndpoints) {
|
|
123
129
|
if (!managedSA) {
|
|
124
130
|
throw new error_1.FirebaseError("managedServiceAccount is required when requiredRoles is defined.", {
|
|
@@ -128,6 +134,7 @@ async function createDeploymentPlan(args) {
|
|
|
128
134
|
return {
|
|
129
135
|
regionalChangesets,
|
|
130
136
|
plannedBackend: wantBackend,
|
|
137
|
+
secretAccessPlan,
|
|
131
138
|
rolesToAdd,
|
|
132
139
|
rolesToRemove,
|
|
133
140
|
serviceAccountToCreate,
|
|
@@ -138,6 +145,7 @@ async function createDeploymentPlan(args) {
|
|
|
138
145
|
return {
|
|
139
146
|
regionalChangesets,
|
|
140
147
|
plannedBackend: wantBackend,
|
|
148
|
+
secretAccessPlan,
|
|
141
149
|
serviceAccountToDelete,
|
|
142
150
|
};
|
|
143
151
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DartVersionFeatures = void 0;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const MIN_DART_SDK_VERSION = "3.9.0";
|
|
7
|
+
const MIN_DART_SDK_VERSION_NATIVE_ASSETS = "3.13.0";
|
|
8
|
+
class DartVersionFeatures {
|
|
9
|
+
constructor(languageVersion) {
|
|
10
|
+
this.languageVersion = languageVersion;
|
|
11
|
+
}
|
|
12
|
+
static async detect(sourceDir) {
|
|
13
|
+
return new DartVersionFeatures(await readRootLanguageVersion(sourceDir));
|
|
14
|
+
}
|
|
15
|
+
get isNativeAssetsAvailable() {
|
|
16
|
+
return this.atLeast(3, 13);
|
|
17
|
+
}
|
|
18
|
+
get minDartSdkVersion() {
|
|
19
|
+
return this.isNativeAssetsAvailable ? MIN_DART_SDK_VERSION_NATIVE_ASSETS : MIN_DART_SDK_VERSION;
|
|
20
|
+
}
|
|
21
|
+
atLeast(major, minor) {
|
|
22
|
+
if (!this.languageVersion) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const [actualMajor, actualMinor] = this.languageVersion;
|
|
26
|
+
return actualMajor > major || (actualMajor === major && actualMinor >= minor);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.DartVersionFeatures = DartVersionFeatures;
|
|
30
|
+
async function readRootLanguageVersion(sourceDir) {
|
|
31
|
+
const packageConfigPath = path.join(sourceDir, ".dart_tool", "package_config.json");
|
|
32
|
+
let raw;
|
|
33
|
+
try {
|
|
34
|
+
raw = await fs.promises.readFile(packageConfigPath, "utf8");
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(raw);
|
|
41
|
+
const root = parsed?.packages?.find((p) => p.rootUri === "../");
|
|
42
|
+
const match = root?.languageVersion ? /^(\d+)\.(\d+)$/.exec(root.languageVersion) : null;
|
|
43
|
+
if (!match) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return [Number(match[1]), Number(match[2])];
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|