firebase-tools-with-isolate 13.16.0 → 13.26.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/api.js +3 -1
- package/lib/apiv2.js +10 -3
- package/lib/appdistribution/client.js +62 -8
- package/lib/appdistribution/distribution.js +1 -1
- package/lib/apphosting/backend.js +299 -0
- package/lib/apphosting/config.js +31 -8
- package/lib/apphosting/githubConnections.js +70 -22
- package/lib/apphosting/index.js +3 -312
- package/lib/apphosting/rollout.js +138 -0
- package/lib/apphosting/secrets/index.js +70 -5
- package/lib/apphosting/utils.js +41 -0
- package/lib/apphosting/yaml.js +82 -0
- package/lib/archiveDirectory.js +1 -1
- package/lib/auth.js +31 -5
- package/lib/bin/firebase.js +2 -2
- package/lib/command.js +18 -4
- package/lib/commands/appdistribution-distribute.js +4 -4
- package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
- package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
- package/lib/commands/appdistribution-groups-list.js +55 -0
- package/lib/commands/appdistribution-testers-list.js +52 -0
- package/lib/commands/appdistribution-testers-remove.js +1 -1
- package/lib/commands/apphosting-backends-create.js +4 -4
- package/lib/commands/apphosting-backends-delete.js +7 -15
- package/lib/commands/apphosting-backends-get.js +1 -1
- package/lib/commands/apphosting-config-export.js +51 -0
- package/lib/commands/apphosting-repos-create.js +23 -0
- package/lib/commands/apphosting-rollouts-create.js +14 -15
- package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
- package/lib/commands/database-import.js +4 -2
- package/lib/commands/database-push.js +4 -2
- package/lib/commands/database-set.js +4 -2
- package/lib/commands/database-settings-get.js +1 -1
- package/lib/commands/database-settings-set.js +1 -1
- package/lib/commands/dataconnect-sdk-generate.js +4 -1
- package/lib/commands/dataconnect-services-list.js +4 -3
- package/lib/commands/dataconnect-sql-diff.js +1 -1
- package/lib/commands/dataconnect-sql-grant.js +37 -0
- package/lib/commands/dataconnect-sql-migrate.js +1 -1
- package/lib/commands/dataconnect-sql-shell.js +115 -0
- package/lib/commands/deploy.js +2 -0
- package/lib/commands/emulators-start.js +4 -1
- package/lib/commands/ext-dev-init.js +2 -2
- package/lib/commands/ext-dev-list.js +1 -1
- package/lib/commands/ext-dev-register.js +2 -2
- package/lib/commands/ext-dev-upload.js +2 -2
- package/lib/commands/ext-dev-usage.js +2 -2
- package/lib/commands/ext-info.js +3 -1
- package/lib/commands/ext-install.js +2 -2
- package/lib/commands/ext-sdk-install.js +88 -0
- package/lib/commands/ext.js +1 -0
- package/lib/commands/firestore-databases-restore.js +39 -1
- package/lib/commands/functions-secrets-access.js +2 -4
- package/lib/commands/index.js +15 -2
- package/lib/commands/init.js +25 -15
- package/lib/commands/setup-emulators-dataconnect.js +0 -13
- package/lib/commands/use.js +1 -1
- package/lib/config.js +14 -4
- package/lib/crashlytics/buildToolsJarHelper.js +2 -2
- package/lib/dataconnect/client.js +1 -1
- package/lib/dataconnect/dataplaneClient.js +12 -9
- package/lib/dataconnect/ensureApis.js +6 -1
- package/lib/dataconnect/fileUtils.js +15 -39
- package/lib/dataconnect/freeTrial.js +45 -9
- package/lib/dataconnect/load.js +3 -1
- package/lib/dataconnect/provisionCloudSql.js +39 -26
- package/lib/dataconnect/schemaMigration.js +215 -74
- package/lib/dataconnect/types.js +4 -1
- package/lib/dataconnect/webhook.js +32 -0
- package/lib/deploy/dataconnect/deploy.js +18 -15
- package/lib/deploy/dataconnect/prepare.js +41 -0
- package/lib/deploy/dataconnect/release.js +16 -7
- package/lib/deploy/extensions/deploy.js +3 -1
- package/lib/deploy/extensions/deploymentSummary.js +7 -3
- package/lib/deploy/extensions/planner.js +44 -5
- package/lib/deploy/extensions/prepare.js +45 -73
- package/lib/deploy/extensions/release.js +11 -10
- package/lib/deploy/extensions/tasks.js +32 -21
- package/lib/deploy/firestore/prepare.js +9 -0
- package/lib/deploy/firestore/release.js +3 -6
- package/lib/deploy/functions/checkIam.js +7 -2
- package/lib/deploy/functions/ensure.js +11 -3
- package/lib/deploy/functions/prepare.js +10 -2
- package/lib/deploy/functions/release/planner.js +2 -1
- package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
- package/lib/deploy/functions/runtimes/node/index.js +5 -0
- package/lib/deploy/functions/services/auth.js +34 -3
- package/lib/deploy/functions/services/index.js +2 -0
- package/lib/deploy/index.js +8 -5
- package/lib/deploy/lifecycleHooks.js +2 -1
- package/lib/emulator/apphosting/config.js +27 -0
- package/lib/emulator/apphosting/index.js +38 -0
- package/lib/emulator/apphosting/serve.js +50 -0
- package/lib/emulator/apphosting/utils.js +18 -0
- package/lib/emulator/auth/handlers.js +27 -0
- package/lib/emulator/auth/operations.js +41 -2
- package/lib/emulator/auth/state.js +2 -1
- package/lib/emulator/commandUtils.js +8 -3
- package/lib/emulator/constants.js +4 -1
- package/lib/emulator/controller.js +48 -5
- package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
- package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
- package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
- package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
- package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
- package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
- package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
- package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
- package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
- package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
- package/lib/emulator/dataconnect/pgliteServer.js +95 -0
- package/lib/emulator/dataconnectEmulator.js +58 -75
- package/lib/emulator/dataconnectToolkitController.js +44 -0
- package/lib/emulator/downloadableEmulators.js +27 -16
- package/lib/emulator/emulatorLogger.js +3 -0
- package/lib/emulator/eventarcEmulator.js +1 -1
- package/lib/emulator/extensionsEmulator.js +38 -6
- package/lib/emulator/functionsEmulator.js +85 -41
- package/lib/emulator/functionsEmulatorShared.js +2 -1
- package/lib/emulator/functionsRuntimeWorker.js +2 -1
- package/lib/emulator/hub.js +13 -9
- package/lib/emulator/hubExport.js +10 -3
- package/lib/emulator/loggingEmulator.js +2 -2
- package/lib/emulator/portUtils.js +10 -11
- package/lib/emulator/registry.js +1 -0
- package/lib/emulator/storage/persistence.js +2 -2
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/emulator/tasksEmulator.js +5 -2
- package/lib/emulator/types.js +3 -0
- package/lib/emulator/ui.js +51 -25
- package/lib/error.js +31 -1
- package/lib/experiments.js +5 -0
- package/lib/extensions/emulator/triggerHelper.js +1 -1
- package/lib/extensions/extensionsApi.js +14 -10
- package/lib/extensions/extensionsHelper.js +15 -6
- package/lib/extensions/localHelper.js +31 -0
- package/lib/extensions/runtimes/common.js +179 -39
- package/lib/extensions/runtimes/node.js +401 -0
- package/lib/extensions/types.js +25 -14
- package/lib/extensions/warnings.js +5 -2
- package/lib/firestore/api.js +2 -1
- package/lib/firestore/checkDatabaseType.js +10 -3
- package/lib/firestore/delete.js +11 -0
- package/lib/firestore/options.js +7 -0
- package/lib/frameworks/angular/index.js +15 -3
- package/lib/frameworks/constants.js +1 -1
- package/lib/frameworks/flutter/index.js +6 -6
- package/lib/frameworks/flutter/utils.js +34 -1
- package/lib/frameworks/next/index.js +10 -2
- package/lib/frameworks/next/utils.js +8 -5
- package/lib/frameworks/vite/index.js +2 -2
- package/lib/fsutils.js +13 -1
- package/lib/functions/constants.js +4 -0
- package/lib/functions/events/v1.js +9 -2
- package/lib/gcp/apphosting.js +1 -1
- package/lib/gcp/cloudmonitoring.js +3 -3
- package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
- package/lib/gcp/cloudsql/connect.js +49 -37
- package/lib/gcp/cloudsql/interactive.js +49 -0
- package/lib/gcp/cloudsql/permissions.js +165 -0
- package/lib/gcp/devConnect.js +38 -1
- package/lib/gcp/firestore.js +5 -1
- package/lib/gcp/secretManager.js +12 -5
- package/lib/getProjectNumber.js +1 -1
- package/lib/init/features/apphosting.js +15 -0
- package/lib/init/features/dataconnect/index.js +159 -120
- package/lib/init/features/dataconnect/sdk.js +77 -84
- package/lib/init/features/emulators.js +2 -15
- package/lib/init/features/firestore/index.js +20 -1
- package/lib/init/features/firestore/indexes.js +4 -4
- package/lib/init/features/genkit/index.js +444 -0
- package/lib/init/features/hosting/index.js +2 -2
- package/lib/init/features/index.js +1 -1
- package/lib/init/features/project.js +6 -6
- package/lib/init/features/storage.js +0 -2
- package/lib/init/index.js +1 -0
- package/lib/init/spawn.js +23 -2
- package/lib/logger.js +2 -2
- package/lib/management/projects.js +24 -4
- package/lib/projectUtils.js +1 -1
- package/lib/prompt.js +1 -1
- package/lib/rc.js +1 -8
- package/lib/requireAuth.js +19 -5
- package/lib/requireDatabaseInstance.js +1 -1
- package/lib/requirePermissions.js +1 -1
- package/lib/responseToError.js +5 -2
- package/lib/rulesDeploy.js +1 -1
- package/lib/templates.js +2 -2
- package/lib/utils.js +16 -11
- package/lib/vsCodeUtils.js +8 -0
- package/package.json +7 -6
- package/schema/connector-yaml.json +57 -17
- package/schema/firebase-config.json +24 -0
- package/templates/extensions/javascript/package.lint.json +2 -2
- package/templates/extensions/javascript/package.nolint.json +2 -2
- package/templates/extensions/typescript/package.lint.json +2 -2
- package/templates/extensions/typescript/package.nolint.json +2 -2
- package/templates/genkit/firebase.0.9.0.template +57 -0
- package/templates/init/apphosting/apphosting.yaml +23 -0
- package/templates/init/dataconnect/connector.yaml +0 -1
- package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
- package/templates/init/dataconnect/dataconnect.yaml +1 -1
- package/templates/init/dataconnect/queries.gql +1 -2
- package/templates/init/functions/javascript/package.lint.json +2 -2
- package/templates/init/functions/javascript/package.nolint.json +2 -2
- package/templates/init/functions/typescript/package.lint.json +2 -2
- package/templates/init/functions/typescript/package.nolint.json +2 -2
- package/lib/ensureCloudResourceLocation.js +0 -12
- package/lib/init/features/genkit.js +0 -53
|
@@ -1,11 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertFlutterCliExists = void 0;
|
|
3
|
+
exports.getPubSpec = exports.getAdditionalBuildArgs = exports.assertFlutterCliExists = void 0;
|
|
4
4
|
const cross_spawn_1 = require("cross-spawn");
|
|
5
5
|
const error_1 = require("../../error");
|
|
6
|
+
const promises_1 = require("fs/promises");
|
|
7
|
+
const fs_extra_1 = require("fs-extra");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const yaml = require("yaml");
|
|
6
10
|
function assertFlutterCliExists() {
|
|
7
11
|
const process = (0, cross_spawn_1.sync)("flutter", ["--version"], { stdio: "ignore" });
|
|
8
12
|
if (process.status !== 0)
|
|
9
13
|
throw new error_1.FirebaseError("Flutter CLI not found, follow the instructions here https://docs.flutter.dev/get-started/install before trying again.");
|
|
10
14
|
}
|
|
11
15
|
exports.assertFlutterCliExists = assertFlutterCliExists;
|
|
16
|
+
function getAdditionalBuildArgs(pubSpec) {
|
|
17
|
+
const treeShakePackages = [
|
|
18
|
+
"material_icons_named",
|
|
19
|
+
"material_symbols_icons",
|
|
20
|
+
"material_design_icons_flutter",
|
|
21
|
+
"flutter_iconpicker",
|
|
22
|
+
"font_awesome_flutter",
|
|
23
|
+
"ionicons_named",
|
|
24
|
+
];
|
|
25
|
+
const hasTreeShakePackage = treeShakePackages.some((pkg) => pubSpec.dependencies?.[pkg]);
|
|
26
|
+
const treeShakeFlags = hasTreeShakePackage ? ["--no-tree-shake-icons"] : [];
|
|
27
|
+
return [...treeShakeFlags];
|
|
28
|
+
}
|
|
29
|
+
exports.getAdditionalBuildArgs = getAdditionalBuildArgs;
|
|
30
|
+
async function getPubSpec(dir) {
|
|
31
|
+
if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "pubspec.yaml"))))
|
|
32
|
+
return {};
|
|
33
|
+
if (!(await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, "web"))))
|
|
34
|
+
return {};
|
|
35
|
+
try {
|
|
36
|
+
const pubSpecBuffer = await (0, promises_1.readFile)((0, path_1.join)(dir, "pubspec.yaml"));
|
|
37
|
+
return yaml.parse(pubSpecBuffer.toString());
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.info("Failed to read pubspec.yaml");
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.getPubSpec = getPubSpec;
|
|
@@ -25,7 +25,7 @@ const logger_1 = require("../../logger");
|
|
|
25
25
|
const env_1 = require("../../functions/env");
|
|
26
26
|
const DEFAULT_BUILD_SCRIPT = ["next build"];
|
|
27
27
|
const PUBLIC_DIR = "public";
|
|
28
|
-
exports.supportedRange = "12 -
|
|
28
|
+
exports.supportedRange = "12 - 15.0";
|
|
29
29
|
exports.name = "Next.js";
|
|
30
30
|
exports.support = "preview";
|
|
31
31
|
exports.type = 2;
|
|
@@ -123,8 +123,11 @@ async function build(dir, target, context) {
|
|
|
123
123
|
(0, utils_1.readJSON)((0, path_1.join)(dir, distDir, "server", constants_2.SERVER_REFERENCE_MANIFEST)).catch(() => undefined),
|
|
124
124
|
]);
|
|
125
125
|
if (appPathRoutesManifest) {
|
|
126
|
-
const headersFromMetaFiles = await (0, utils_2.
|
|
126
|
+
const { headers: headersFromMetaFiles, pprRoutes } = await (0, utils_2.getAppMetadataFromMetaFiles)(dir, distDir, baseUrl, appPathRoutesManifest);
|
|
127
127
|
headers.push(...headersFromMetaFiles);
|
|
128
|
+
for (const route of pprRoutes) {
|
|
129
|
+
reasonsForBackend.add(`route with PPR ${route}`);
|
|
130
|
+
}
|
|
128
131
|
if (appPathsManifest) {
|
|
129
132
|
const unrenderedServerComponents = (0, utils_2.getNonStaticServerComponents)(appPathsManifest, appPathRoutesManifest, prerenderedRoutes, dynamicRoutes);
|
|
130
133
|
const notFoundPageKey = ["/_not-found", "/_not-found/page"].find((key) => unrenderedServerComponents.has(key));
|
|
@@ -270,6 +273,7 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir, _, context) {
|
|
|
270
273
|
...prerenderManifest.routes,
|
|
271
274
|
...pagesManifestLikePrerender,
|
|
272
275
|
};
|
|
276
|
+
const { pprRoutes } = await (0, utils_2.getAppMetadataFromMetaFiles)(sourceDir, distDir, basePath, appPathRoutesManifest);
|
|
273
277
|
await Promise.all(Object.entries(routesToCopy).map(async ([path, route]) => {
|
|
274
278
|
if (route.initialRevalidateSeconds) {
|
|
275
279
|
logger_1.logger.debug(`skipping ${path} due to revalidate`);
|
|
@@ -307,6 +311,10 @@ async function ɵcodegenPublicDirectory(sourceDir, destDir, _, context) {
|
|
|
307
311
|
let defaultDestPath = isDefaultLocale && (0, path_1.join)(destDir, basePath, ...destPartsOrIndex);
|
|
308
312
|
if (!(0, fsutils_1.fileExistsSync)(sourcePath) && (0, fsutils_1.fileExistsSync)(`${sourcePath}.html`)) {
|
|
309
313
|
sourcePath += ".html";
|
|
314
|
+
if (pprRoutes.includes(path)) {
|
|
315
|
+
logger_1.logger.debug(`skipping ${path} due to ppr`);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
310
318
|
if (localizedDestPath)
|
|
311
319
|
localizedDestPath += ".html";
|
|
312
320
|
if (defaultDestPath)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.installEsbuild = exports.getGlobalEsbuildVersion = exports.findEsbuildPath = exports.whichNextConfigFile = exports.getProductionDistDirFiles = exports.getRoutesWithServerAction = exports.hasStaticAppNotFoundComponent = exports.getNextVersion = exports.getBuildId = exports.
|
|
3
|
+
exports.installEsbuild = exports.getGlobalEsbuildVersion = exports.findEsbuildPath = exports.whichNextConfigFile = exports.getProductionDistDirFiles = exports.getRoutesWithServerAction = exports.hasStaticAppNotFoundComponent = exports.getNextVersion = exports.getBuildId = exports.getAppMetadataFromMetaFiles = exports.getNonStaticServerComponents = exports.getNonStaticRoutes = exports.getMiddlewareMatcherRegexes = exports.allDependencyNames = exports.isUsingAppDirectory = exports.isUsingNextImageInAppDirectory = exports.isUsingImageOptimization = exports.isUsingMiddleware = exports.hasUnoptimizedImage = exports.usesNextImage = exports.usesAppDirRouter = exports.getNextjsRewritesToUse = exports.isHeaderSupportedByHosting = exports.isRedirectSupportedByHosting = exports.isRewriteSupportedByHosting = exports.cleanI18n = exports.cleanCustomRouteI18n = exports.cleanEscapedChars = exports.I18N_SOURCE = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const fs_extra_1 = require("fs-extra");
|
|
6
6
|
const path_1 = require("path");
|
|
@@ -170,8 +170,9 @@ function getNonStaticServerComponents(appPathsManifest, appPathRoutesManifest, p
|
|
|
170
170
|
return new Set(nonStaticServerComponents);
|
|
171
171
|
}
|
|
172
172
|
exports.getNonStaticServerComponents = getNonStaticServerComponents;
|
|
173
|
-
async function
|
|
173
|
+
async function getAppMetadataFromMetaFiles(sourceDir, distDir, basePath, appPathRoutesManifest) {
|
|
174
174
|
const headers = [];
|
|
175
|
+
const pprRoutes = [];
|
|
175
176
|
await Promise.all(Object.entries(appPathRoutesManifest).map(async ([key, source]) => {
|
|
176
177
|
if (!["route", "page"].includes((0, path_1.basename)(key)))
|
|
177
178
|
return;
|
|
@@ -186,11 +187,13 @@ async function getHeadersFromMetaFiles(sourceDir, distDir, basePath, appPathRout
|
|
|
186
187
|
source: path_1.posix.join(basePath, source),
|
|
187
188
|
headers: Object.entries(meta.headers).map(([key, value]) => ({ key, value })),
|
|
188
189
|
});
|
|
190
|
+
if (meta.postponed)
|
|
191
|
+
pprRoutes.push(source);
|
|
189
192
|
}
|
|
190
193
|
}));
|
|
191
|
-
return headers;
|
|
194
|
+
return { headers, pprRoutes };
|
|
192
195
|
}
|
|
193
|
-
exports.
|
|
196
|
+
exports.getAppMetadataFromMetaFiles = getAppMetadataFromMetaFiles;
|
|
194
197
|
async function getBuildId(distDir) {
|
|
195
198
|
const buildId = await (0, promises_1.readFile)((0, path_1.join)(distDir, "BUILD_ID"));
|
|
196
199
|
return buildId.toString();
|
|
@@ -266,7 +269,7 @@ function findEsbuildPath() {
|
|
|
266
269
|
exports.findEsbuildPath = findEsbuildPath;
|
|
267
270
|
function getGlobalEsbuildVersion(binPath) {
|
|
268
271
|
try {
|
|
269
|
-
const versionOutput = (0, child_process_1.execSync)(
|
|
272
|
+
const versionOutput = (0, child_process_1.execSync)(`"${binPath}" --version`, { encoding: "utf8" })?.trim();
|
|
270
273
|
if (!versionOutput) {
|
|
271
274
|
return null;
|
|
272
275
|
}
|
|
@@ -6,7 +6,7 @@ const cross_spawn_1 = require("cross-spawn");
|
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const fs_extra_1 = require("fs-extra");
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
-
const
|
|
9
|
+
const node_util_1 = require("node:util");
|
|
10
10
|
const prompt_1 = require("../../prompt");
|
|
11
11
|
const utils_1 = require("../utils");
|
|
12
12
|
exports.name = "Vite";
|
|
@@ -93,7 +93,7 @@ async function getDevModeHandle(dir) {
|
|
|
93
93
|
const serve = (0, cross_spawn_1.spawn)(cli, [], { cwd: dir });
|
|
94
94
|
serve.stdout.on("data", (data) => {
|
|
95
95
|
process.stdout.write(data);
|
|
96
|
-
const dataWithoutAnsiCodes =
|
|
96
|
+
const dataWithoutAnsiCodes = (0, node_util_1.stripVTControlCharacters)(data.toString());
|
|
97
97
|
const match = dataWithoutAnsiCodes.match(/(http:\/\/.+:\d+)/);
|
|
98
98
|
if (match)
|
|
99
99
|
resolve(match[1]);
|
package/lib/fsutils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readFile = exports.dirExistsSync = exports.fileExistsSync = void 0;
|
|
3
|
+
exports.listFiles = exports.readFile = exports.dirExistsSync = exports.fileExistsSync = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const error_1 = require("./error");
|
|
6
6
|
function fileExistsSync(path) {
|
|
@@ -33,3 +33,15 @@ function readFile(path) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
exports.readFile = readFile;
|
|
36
|
+
function listFiles(path) {
|
|
37
|
+
try {
|
|
38
|
+
return (0, fs_1.readdirSync)(path);
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
if (e.code === "ENOENT") {
|
|
42
|
+
throw new error_1.FirebaseError(`Directory not found: ${path}`);
|
|
43
|
+
}
|
|
44
|
+
throw e;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.listFiles = listFiles;
|
|
@@ -7,8 +7,12 @@ exports.BLOCKING_LABEL = "deployment-blocking";
|
|
|
7
7
|
exports.BLOCKING_LABEL_KEY_TO_EVENT = {
|
|
8
8
|
"before-create": "providers/cloud.auth/eventTypes/user.beforeCreate",
|
|
9
9
|
"before-sign-in": "providers/cloud.auth/eventTypes/user.beforeSignIn",
|
|
10
|
+
"before-send-email": "providers/cloud.auth/eventTypes/user.beforeSendEmail",
|
|
11
|
+
"before-send-sms": "providers/cloud.auth/eventTypes/user.beforeSendSms",
|
|
10
12
|
};
|
|
11
13
|
exports.BLOCKING_EVENT_TO_LABEL_KEY = {
|
|
12
14
|
"providers/cloud.auth/eventTypes/user.beforeCreate": "before-create",
|
|
13
15
|
"providers/cloud.auth/eventTypes/user.beforeSignIn": "before-sign-in",
|
|
16
|
+
"providers/cloud.auth/eventTypes/user.beforeSendEmail": "before-send-email",
|
|
17
|
+
"providers/cloud.auth/eventTypes/user.beforeSendSms": "before-send-sms",
|
|
14
18
|
};
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AUTH_BLOCKING_EVENTS = exports.BEFORE_SIGN_IN_EVENT = exports.BEFORE_CREATE_EVENT = void 0;
|
|
3
|
+
exports.AUTH_BLOCKING_EVENTS = exports.BEFORE_SEND_SMS_EVENT = exports.BEFORE_SEND_EMAIL_EVENT = exports.BEFORE_SIGN_IN_EVENT = exports.BEFORE_CREATE_EVENT = void 0;
|
|
4
4
|
exports.BEFORE_CREATE_EVENT = "providers/cloud.auth/eventTypes/user.beforeCreate";
|
|
5
5
|
exports.BEFORE_SIGN_IN_EVENT = "providers/cloud.auth/eventTypes/user.beforeSignIn";
|
|
6
|
-
exports.
|
|
6
|
+
exports.BEFORE_SEND_EMAIL_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendEmail";
|
|
7
|
+
exports.BEFORE_SEND_SMS_EVENT = "providers/cloud.auth/eventTypes/user.beforeSendSms";
|
|
8
|
+
exports.AUTH_BLOCKING_EVENTS = [
|
|
9
|
+
exports.BEFORE_CREATE_EVENT,
|
|
10
|
+
exports.BEFORE_SIGN_IN_EVENT,
|
|
11
|
+
exports.BEFORE_SEND_EMAIL_EVENT,
|
|
12
|
+
exports.BEFORE_SEND_SMS_EVENT,
|
|
13
|
+
];
|
package/lib/gcp/apphosting.js
CHANGED
|
@@ -9,7 +9,7 @@ const ensureApiEnabled_1 = require("../ensureApiEnabled");
|
|
|
9
9
|
const deploymentTool = require("../deploymentTool");
|
|
10
10
|
const error_1 = require("../error");
|
|
11
11
|
const metaprogramming_1 = require("../metaprogramming");
|
|
12
|
-
exports.API_VERSION = "
|
|
12
|
+
exports.API_VERSION = "v1beta";
|
|
13
13
|
exports.client = new apiv2_1.Client({
|
|
14
14
|
urlPrefix: (0, api_1.apphostingOrigin)(),
|
|
15
15
|
auth: true,
|
|
@@ -57,19 +57,19 @@ var ValueType;
|
|
|
57
57
|
ValueType["DOUBLE"] = "DOUBLE";
|
|
58
58
|
ValueType["STRING"] = "STRING";
|
|
59
59
|
})(ValueType = exports.ValueType || (exports.ValueType = {}));
|
|
60
|
-
async function queryTimeSeries(query,
|
|
60
|
+
async function queryTimeSeries(query, project) {
|
|
61
61
|
const client = new apiv2_1.Client({
|
|
62
62
|
urlPrefix: (0, api_1.cloudMonitoringOrigin)(),
|
|
63
63
|
apiVersion: exports.CLOUD_MONITORING_VERSION,
|
|
64
64
|
});
|
|
65
65
|
try {
|
|
66
|
-
const res = await client.get(`/projects/${
|
|
66
|
+
const res = await client.get(`/projects/${project}/timeSeries/`, {
|
|
67
67
|
queryParams: query,
|
|
68
68
|
});
|
|
69
69
|
return res.body.timeSeries;
|
|
70
70
|
}
|
|
71
71
|
catch (err) {
|
|
72
|
-
throw new error_1.FirebaseError(`Failed to get
|
|
72
|
+
throw new error_1.FirebaseError(`Failed to get Cloud Monitoring metric: ${err}`, {
|
|
73
73
|
status: err.status,
|
|
74
74
|
});
|
|
75
75
|
}
|
|
@@ -33,27 +33,34 @@ async function createInstance(projectId, location, instanceId, enableGoogleMlInt
|
|
|
33
33
|
if (enableGoogleMlIntegration) {
|
|
34
34
|
databaseFlags.push({ name: "cloudsql.enable_google_ml_integration", value: "on" });
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
let op;
|
|
37
|
+
try {
|
|
38
|
+
op = await client.post(`projects/${projectId}/instances`, {
|
|
39
|
+
name: instanceId,
|
|
40
|
+
region: location,
|
|
41
|
+
databaseVersion: "POSTGRES_15",
|
|
42
|
+
settings: {
|
|
43
|
+
tier: "db-f1-micro",
|
|
44
|
+
edition: "ENTERPRISE",
|
|
45
|
+
ipConfiguration: {
|
|
46
|
+
authorizedNetworks: [],
|
|
47
|
+
},
|
|
48
|
+
enableGoogleMlIntegration,
|
|
49
|
+
databaseFlags,
|
|
50
|
+
storageAutoResize: false,
|
|
51
|
+
userLabels: { "firebase-data-connect": "ft" },
|
|
52
|
+
insightsConfig: {
|
|
53
|
+
queryInsightsEnabled: true,
|
|
54
|
+
queryPlansPerMinute: 5,
|
|
55
|
+
queryStringLength: 1024,
|
|
56
|
+
},
|
|
54
57
|
},
|
|
55
|
-
}
|
|
56
|
-
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
handleAllowlistError(err, location);
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
57
64
|
if (!waitForCreation) {
|
|
58
65
|
return;
|
|
59
66
|
}
|
|
@@ -93,6 +100,11 @@ async function updateInstanceForDataConnect(instance, enableGoogleMlIntegration)
|
|
|
93
100
|
return pollRes;
|
|
94
101
|
}
|
|
95
102
|
exports.updateInstanceForDataConnect = updateInstanceForDataConnect;
|
|
103
|
+
function handleAllowlistError(err, region) {
|
|
104
|
+
if (err.message.includes("Not allowed to set system label: firebase-data-connect")) {
|
|
105
|
+
throw new error_1.FirebaseError(`Cloud SQL free trial instances are not yet available in ${region}. Please check https://firebase.google.com/docs/data-connect/ for a full list of available regions.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
96
108
|
function setDatabaseFlag(flag, flags = []) {
|
|
97
109
|
const temp = flags.filter((f) => f.name !== flag.name);
|
|
98
110
|
temp.push(flag);
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toDatabaseUser = exports.setupIAMUsers = exports.getIAMUser = exports.getDataConnectP4SA = exports.executeSqlCmdsAsSuperUser = exports.executeSqlCmdsAsIamUser = exports.execute = void 0;
|
|
4
4
|
const pg = require("pg");
|
|
5
5
|
const cloud_sql_connector_1 = require("@google-cloud/cloud-sql-connector");
|
|
6
6
|
const requireAuth_1 = require("../../requireAuth");
|
|
7
7
|
const projectUtils_1 = require("../../projectUtils");
|
|
8
|
+
const api_1 = require("../../api");
|
|
8
9
|
const cloudSqlAdminClient = require("./cloudsqladmin");
|
|
9
10
|
const utils = require("../../utils");
|
|
10
11
|
const logger_1 = require("../../logger");
|
|
11
12
|
const error_1 = require("../../error");
|
|
12
13
|
const fbToolsAuthClient_1 = require("./fbToolsAuthClient");
|
|
14
|
+
const permissions_1 = require("./permissions");
|
|
13
15
|
async function execute(sqlStatements, opts) {
|
|
14
16
|
const logFn = opts.silent ? logger_1.logger.debug : logger_1.logger.info;
|
|
15
17
|
const instance = await cloudSqlAdminClient.getInstance(opts.projectId, opts.instanceId);
|
|
@@ -87,52 +89,61 @@ async function execute(sqlStatements, opts) {
|
|
|
87
89
|
connector.close();
|
|
88
90
|
}
|
|
89
91
|
exports.execute = execute;
|
|
90
|
-
async function
|
|
92
|
+
async function executeSqlCmdsAsIamUser(options, instanceId, databaseId, cmds, silent = false) {
|
|
91
93
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
94
|
+
const { user: iamUser } = await getIAMUser(options);
|
|
95
|
+
return await execute(cmds, {
|
|
96
|
+
projectId,
|
|
97
|
+
instanceId,
|
|
98
|
+
databaseId,
|
|
99
|
+
username: iamUser,
|
|
100
|
+
silent: silent,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
exports.executeSqlCmdsAsIamUser = executeSqlCmdsAsIamUser;
|
|
104
|
+
async function executeSqlCmdsAsSuperUser(options, instanceId, databaseId, cmds, silent = false) {
|
|
105
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
106
|
+
const superuser = "firebasesuperuser";
|
|
107
|
+
const temporaryPassword = utils.generateId(20);
|
|
108
|
+
await cloudSqlAdminClient.createUser(projectId, instanceId, "BUILT_IN", superuser, temporaryPassword);
|
|
109
|
+
return await execute([`SET ROLE = cloudsqlsuperuser`, ...cmds], {
|
|
110
|
+
projectId,
|
|
111
|
+
instanceId,
|
|
112
|
+
databaseId,
|
|
113
|
+
username: superuser,
|
|
114
|
+
password: temporaryPassword,
|
|
115
|
+
silent: silent,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.executeSqlCmdsAsSuperUser = executeSqlCmdsAsSuperUser;
|
|
119
|
+
function getDataConnectP4SA(projectNumber) {
|
|
120
|
+
return `service-${projectNumber}@${(0, api_1.dataconnectP4SADomain)()}`;
|
|
121
|
+
}
|
|
122
|
+
exports.getDataConnectP4SA = getDataConnectP4SA;
|
|
123
|
+
async function getIAMUser(options) {
|
|
92
124
|
const account = await (0, requireAuth_1.requireAuth)(options);
|
|
93
125
|
if (!account) {
|
|
94
126
|
throw new error_1.FirebaseError("No account to set up! Run `firebase login` or set Application Default Credentials");
|
|
95
127
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
128
|
+
return toDatabaseUser(account);
|
|
129
|
+
}
|
|
130
|
+
exports.getIAMUser = getIAMUser;
|
|
131
|
+
async function setupIAMUsers(instanceId, databaseId, options) {
|
|
132
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
133
|
+
const { user, mode } = await getIAMUser(options);
|
|
100
134
|
await cloudSqlAdminClient.createUser(projectId, instanceId, mode, user);
|
|
135
|
+
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
136
|
+
const { user: fdcP4SAUser, mode: fdcP4SAmode } = toDatabaseUser(getDataConnectP4SA(projectNumber));
|
|
137
|
+
await cloudSqlAdminClient.createUser(projectId, instanceId, fdcP4SAmode, fdcP4SAUser);
|
|
138
|
+
await (0, permissions_1.setupSQLPermissions)(instanceId, databaseId, options, true);
|
|
101
139
|
const grants = [
|
|
102
|
-
`
|
|
103
|
-
|
|
104
|
-
begin
|
|
105
|
-
if not exists (select FROM pg_catalog.pg_roles
|
|
106
|
-
WHERE rolname = '${firebaseowner(databaseId)}') then
|
|
107
|
-
CREATE ROLE "${firebaseowner(databaseId)}" WITH ADMIN "${setupUser}";
|
|
108
|
-
end if;
|
|
109
|
-
end
|
|
110
|
-
$$
|
|
111
|
-
;`,
|
|
112
|
-
`GRANT ALL PRIVILEGES ON DATABASE "${databaseId}" TO "${firebaseowner(databaseId)}"`,
|
|
113
|
-
`GRANT cloudsqlsuperuser TO "${firebaseowner(databaseId)}"`,
|
|
114
|
-
`GRANT "${firebaseowner(databaseId)}" TO "${setupUser}"`,
|
|
115
|
-
`GRANT "${firebaseowner(databaseId)}" TO "${user}"`,
|
|
116
|
-
`ALTER SCHEMA public OWNER TO "${firebaseowner(databaseId)}"`,
|
|
117
|
-
`GRANT USAGE ON SCHEMA "public" TO PUBLIC`,
|
|
118
|
-
`GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA "public" TO PUBLIC`,
|
|
119
|
-
`GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA "public" TO PUBLIC`,
|
|
140
|
+
`GRANT "${(0, permissions_1.firebaseowner)(databaseId)}" TO "${user}"`,
|
|
141
|
+
`GRANT "${(0, permissions_1.firebasewriter)(databaseId)}" TO "${fdcP4SAUser}"`,
|
|
120
142
|
];
|
|
121
|
-
await
|
|
122
|
-
projectId,
|
|
123
|
-
instanceId,
|
|
124
|
-
databaseId,
|
|
125
|
-
username: setupUser,
|
|
126
|
-
password: temporaryPassword,
|
|
127
|
-
silent: true,
|
|
128
|
-
});
|
|
143
|
+
await executeSqlCmdsAsSuperUser(options, instanceId, databaseId, grants, true);
|
|
129
144
|
return user;
|
|
130
145
|
}
|
|
131
|
-
exports.
|
|
132
|
-
function firebaseowner(databaseId) {
|
|
133
|
-
return `firebaseowner_${databaseId}_public`;
|
|
134
|
-
}
|
|
135
|
-
exports.firebaseowner = firebaseowner;
|
|
146
|
+
exports.setupIAMUsers = setupIAMUsers;
|
|
136
147
|
function toDatabaseUser(account) {
|
|
137
148
|
let mode = "CLOUD_IAM_USER";
|
|
138
149
|
let user = account;
|
|
@@ -142,3 +153,4 @@ function toDatabaseUser(account) {
|
|
|
142
153
|
}
|
|
143
154
|
return { user, mode };
|
|
144
155
|
}
|
|
156
|
+
exports.toDatabaseUser = toDatabaseUser;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interactiveExecuteQuery = exports.confirmDangerousQuery = void 0;
|
|
4
|
+
const ora = require("ora");
|
|
5
|
+
const clc = require("colorette");
|
|
6
|
+
const logger_1 = require("../../logger");
|
|
7
|
+
const prompt_1 = require("../../prompt");
|
|
8
|
+
const Table = require("cli-table");
|
|
9
|
+
const destructiveSqlKeywords = ["DROP", "DELETE"];
|
|
10
|
+
function checkIsDestructiveSql(query) {
|
|
11
|
+
const upperCaseQuery = query.toUpperCase();
|
|
12
|
+
return destructiveSqlKeywords.some((keyword) => upperCaseQuery.includes(keyword.toUpperCase()));
|
|
13
|
+
}
|
|
14
|
+
async function confirmDangerousQuery(query) {
|
|
15
|
+
if (checkIsDestructiveSql(query)) {
|
|
16
|
+
return await (0, prompt_1.confirm)({
|
|
17
|
+
message: clc.yellow("This query may be destructive. Are you sure you want to proceed?"),
|
|
18
|
+
default: false,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
exports.confirmDangerousQuery = confirmDangerousQuery;
|
|
24
|
+
async function interactiveExecuteQuery(query, conn) {
|
|
25
|
+
const spinner = ora("Executing query...").start();
|
|
26
|
+
try {
|
|
27
|
+
const results = await conn.query(query);
|
|
28
|
+
spinner.succeed(clc.green("Query executed successfully"));
|
|
29
|
+
if (Array.isArray(results.rows) && results.rows.length > 0) {
|
|
30
|
+
const table = new Table({
|
|
31
|
+
head: Object.keys(results.rows[0]).map((key) => clc.cyan(key)),
|
|
32
|
+
style: { head: [], border: [] },
|
|
33
|
+
});
|
|
34
|
+
for (const row of results.rows) {
|
|
35
|
+
table.push(Object.values(row));
|
|
36
|
+
}
|
|
37
|
+
logger_1.logger.info(table.toString());
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (query.toUpperCase().includes("SELECT")) {
|
|
41
|
+
logger_1.logger.info(clc.yellow("No results returned"));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
spinner.fail(clc.red(`Failed executing query: ${err}`));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.interactiveExecuteQuery = interactiveExecuteQuery;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupSQLPermissions = exports.iamUserIsCSQLAdmin = exports.checkSQLRoleIsGranted = exports.fdcSqlRoleMap = exports.firebasewriter = exports.firebasereader = exports.firebaseowner = void 0;
|
|
4
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
5
|
+
const connect_1 = require("./connect");
|
|
6
|
+
const iam_1 = require("../iam");
|
|
7
|
+
const logger_1 = require("../../logger");
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const error_1 = require("../../error");
|
|
10
|
+
function firebaseowner(databaseId) {
|
|
11
|
+
return `firebaseowner_${databaseId}_public`;
|
|
12
|
+
}
|
|
13
|
+
exports.firebaseowner = firebaseowner;
|
|
14
|
+
function firebasereader(databaseId) {
|
|
15
|
+
return `firebasereader_${databaseId}_public`;
|
|
16
|
+
}
|
|
17
|
+
exports.firebasereader = firebasereader;
|
|
18
|
+
function firebasewriter(databaseId) {
|
|
19
|
+
return `firebasewriter_${databaseId}_public`;
|
|
20
|
+
}
|
|
21
|
+
exports.firebasewriter = firebasewriter;
|
|
22
|
+
exports.fdcSqlRoleMap = {
|
|
23
|
+
owner: firebaseowner,
|
|
24
|
+
writer: firebasewriter,
|
|
25
|
+
reader: firebasereader,
|
|
26
|
+
};
|
|
27
|
+
async function checkSQLRoleIsGranted(options, instanceId, databaseId, grantedRole, granteeRole) {
|
|
28
|
+
const checkCmd = `
|
|
29
|
+
DO $$
|
|
30
|
+
DECLARE
|
|
31
|
+
role_count INTEGER;
|
|
32
|
+
BEGIN
|
|
33
|
+
-- Count the number of rows matching the criteria
|
|
34
|
+
SELECT COUNT(*)
|
|
35
|
+
INTO role_count
|
|
36
|
+
FROM
|
|
37
|
+
pg_auth_members m
|
|
38
|
+
JOIN
|
|
39
|
+
pg_roles grantee ON grantee.oid = m.member
|
|
40
|
+
JOIN
|
|
41
|
+
pg_roles granted ON granted.oid = m.roleid
|
|
42
|
+
JOIN
|
|
43
|
+
pg_roles grantor ON grantor.oid = m.grantor
|
|
44
|
+
WHERE
|
|
45
|
+
granted.rolname = '${grantedRole}'
|
|
46
|
+
AND grantee.rolname = '${granteeRole}';
|
|
47
|
+
|
|
48
|
+
-- If no rows were found, raise an exception
|
|
49
|
+
IF role_count = 0 THEN
|
|
50
|
+
RAISE EXCEPTION 'Role "%", is not granted to role "%".', '${grantedRole}', '${granteeRole}';
|
|
51
|
+
END IF;
|
|
52
|
+
END $$;
|
|
53
|
+
`;
|
|
54
|
+
try {
|
|
55
|
+
await (0, connect_1.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [checkCmd], true);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (e instanceof error_1.FirebaseError && e.message.includes("not granted to role")) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
logger_1.logger.error(`Role Check Failed: ${e}`);
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.checkSQLRoleIsGranted = checkSQLRoleIsGranted;
|
|
67
|
+
async function iamUserIsCSQLAdmin(options) {
|
|
68
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
69
|
+
const requiredPermissions = [
|
|
70
|
+
"cloudsql.instances.connect",
|
|
71
|
+
"cloudsql.instances.get",
|
|
72
|
+
"cloudsql.users.create",
|
|
73
|
+
"cloudsql.users.update",
|
|
74
|
+
];
|
|
75
|
+
try {
|
|
76
|
+
const iamResult = await (0, iam_1.testIamPermissions)(projectId, requiredPermissions);
|
|
77
|
+
return iamResult.passed;
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
logger_1.logger.debug(`[iam] error while checking permissions, command may fail: ${err}`);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.iamUserIsCSQLAdmin = iamUserIsCSQLAdmin;
|
|
85
|
+
function ownerRolePermissions(databaseId, superuser, schema) {
|
|
86
|
+
const firebaseOwnerRole = firebaseowner(databaseId);
|
|
87
|
+
return [
|
|
88
|
+
`do
|
|
89
|
+
$$
|
|
90
|
+
begin
|
|
91
|
+
if not exists (select FROM pg_catalog.pg_roles
|
|
92
|
+
WHERE rolname = '${firebaseOwnerRole}') then
|
|
93
|
+
CREATE ROLE "${firebaseOwnerRole}" WITH ADMIN "${superuser}";
|
|
94
|
+
end if;
|
|
95
|
+
end
|
|
96
|
+
$$
|
|
97
|
+
;`,
|
|
98
|
+
`GRANT "${firebaseOwnerRole}" TO "cloudsqlsuperuser"`,
|
|
99
|
+
`ALTER SCHEMA "${schema}" OWNER TO "${firebaseOwnerRole}"`,
|
|
100
|
+
`GRANT USAGE ON SCHEMA "${schema}" TO "${firebaseOwnerRole}"`,
|
|
101
|
+
`GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseOwnerRole}"`,
|
|
102
|
+
`GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseOwnerRole}"`,
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
function writerRolePermissions(databaseId, superuser, schema) {
|
|
106
|
+
const firebaseWriterRole = firebasewriter(databaseId);
|
|
107
|
+
return [
|
|
108
|
+
`do
|
|
109
|
+
$$
|
|
110
|
+
begin
|
|
111
|
+
if not exists (select FROM pg_catalog.pg_roles
|
|
112
|
+
WHERE rolname = '${firebaseWriterRole}') then
|
|
113
|
+
CREATE ROLE "${firebaseWriterRole}" WITH ADMIN "${superuser}";
|
|
114
|
+
end if;
|
|
115
|
+
end
|
|
116
|
+
$$
|
|
117
|
+
;`,
|
|
118
|
+
`GRANT "${firebaseWriterRole}" TO "cloudsqlsuperuser"`,
|
|
119
|
+
`GRANT USAGE ON SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
120
|
+
`GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
121
|
+
`GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
122
|
+
`GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
123
|
+
`SET ROLE = '${firebaseowner(databaseId)}';`,
|
|
124
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON TABLES TO "${firebaseWriterRole}";`,
|
|
125
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT USAGE ON SEQUENCES TO "${firebaseWriterRole}";`,
|
|
126
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT EXECUTE ON FUNCTIONS TO "${firebaseWriterRole}"`,
|
|
127
|
+
`SET ROLE = cloudsqlsuperuser`,
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
function readerRolePermissions(databaseId, superuser, schema) {
|
|
131
|
+
const firebaseReaderRole = firebasereader(databaseId);
|
|
132
|
+
return [
|
|
133
|
+
`do
|
|
134
|
+
$$
|
|
135
|
+
begin
|
|
136
|
+
if not exists (select FROM pg_catalog.pg_roles
|
|
137
|
+
WHERE rolname = '${firebaseReaderRole}') then
|
|
138
|
+
CREATE ROLE "${firebaseReaderRole}" WITH ADMIN "${superuser}";
|
|
139
|
+
end if;
|
|
140
|
+
end
|
|
141
|
+
$$
|
|
142
|
+
;`,
|
|
143
|
+
`GRANT "${firebaseReaderRole}" TO "cloudsqlsuperuser"`,
|
|
144
|
+
`GRANT USAGE ON SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
145
|
+
`GRANT SELECT ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
146
|
+
`GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
147
|
+
`GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
148
|
+
`SET ROLE = '${firebaseowner(databaseId)}';`,
|
|
149
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT SELECT ON TABLES TO "${firebaseReaderRole}";`,
|
|
150
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT SELECT, USAGE ON SEQUENCES TO "${firebaseReaderRole}";`,
|
|
151
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT EXECUTE ON FUNCTIONS TO "${firebaseReaderRole}"`,
|
|
152
|
+
`SET ROLE = cloudsqlsuperuser`,
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
async function setupSQLPermissions(instanceId, databaseId, options, silent = false) {
|
|
156
|
+
const superuser = "firebasesuperuser";
|
|
157
|
+
const revokes = [];
|
|
158
|
+
if (await checkSQLRoleIsGranted(options, instanceId, databaseId, "cloudsqlsuperuser", firebaseowner(databaseId))) {
|
|
159
|
+
logger_1.logger.warn("Detected cloudsqlsuperuser was previously given to firebase owner, revoking to improve database security.");
|
|
160
|
+
revokes.push(`REVOKE "cloudsqlsuperuser" FROM "${firebaseowner(databaseId)}"`);
|
|
161
|
+
}
|
|
162
|
+
const sqlRoleSetupCmds = (0, lodash_1.concat)(revokes, [`CREATE SCHEMA IF NOT EXISTS "public"`], ownerRolePermissions(databaseId, superuser, "public"), writerRolePermissions(databaseId, superuser, "public"), readerRolePermissions(databaseId, superuser, "public"));
|
|
163
|
+
return (0, connect_1.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, sqlRoleSetupCmds, silent);
|
|
164
|
+
}
|
|
165
|
+
exports.setupSQLPermissions = setupSQLPermissions;
|