firebase-tools-with-isolate 13.6.4 → 13.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -6
- package/lib/api.js +18 -8
- package/lib/apiv2.js +19 -13
- package/lib/apphosting/app.js +69 -0
- package/lib/apphosting/config.js +97 -0
- package/lib/{init/features/apphosting → apphosting}/constants.js +2 -2
- package/lib/apphosting/githubConnections.js +263 -0
- package/lib/apphosting/index.js +319 -0
- package/lib/{init/features/apphosting → apphosting}/repo.js +12 -12
- package/lib/apphosting/secrets/dialogs.js +170 -0
- package/lib/apphosting/secrets/index.js +103 -0
- package/lib/checkValidTargetFilters.js +8 -1
- package/lib/commands/apphosting-backends-create.js +9 -4
- package/lib/commands/apphosting-backends-delete.js +27 -30
- package/lib/commands/apphosting-backends-get.js +8 -8
- package/lib/commands/apphosting-backends-list.js +6 -7
- package/lib/commands/apphosting-secrets-access.js +24 -0
- package/lib/commands/apphosting-secrets-describe.js +29 -0
- package/lib/commands/apphosting-secrets-grantaccess.js +49 -0
- package/lib/commands/apphosting-secrets-set.js +56 -0
- package/lib/commands/dataconnect-sdk-generate.js +37 -0
- package/lib/commands/dataconnect-services-list.js +80 -0
- package/lib/commands/dataconnect-sql-diff.js +25 -0
- package/lib/commands/dataconnect-sql-migrate.js +45 -0
- package/lib/commands/deploy.js +27 -1
- package/lib/commands/firestore-databases-create.js +1 -0
- package/lib/commands/firestore-databases-restore.js +1 -0
- package/lib/commands/functions-secrets-access.js +2 -2
- package/lib/commands/functions-secrets-describe.js +14 -0
- package/lib/commands/functions-secrets-destroy.js +2 -2
- package/lib/commands/functions-secrets-get.js +3 -17
- package/lib/commands/functions-secrets-prune.js +2 -1
- package/lib/commands/functions-secrets-set.js +3 -19
- package/lib/commands/index.js +25 -6
- package/lib/commands/init.js +10 -3
- package/lib/commands/setup-emulators-dataconnect.js +12 -0
- package/lib/config.js +1 -0
- package/lib/dataconnect/build.js +22 -0
- package/lib/dataconnect/checkIam.js +30 -0
- package/lib/dataconnect/client.js +112 -0
- package/lib/dataconnect/dataplaneClient.js +16 -0
- package/lib/dataconnect/ensureApis.js +12 -0
- package/lib/dataconnect/errors.js +29 -0
- package/lib/dataconnect/fileUtils.js +92 -0
- package/lib/dataconnect/filters.js +45 -0
- package/lib/dataconnect/freeTrial.js +22 -0
- package/lib/dataconnect/graphqlError.js +12 -0
- package/lib/dataconnect/load.js +40 -0
- package/lib/dataconnect/names.js +46 -0
- package/lib/dataconnect/prompts.js +20 -0
- package/lib/dataconnect/provisionCloudSql.js +74 -0
- package/lib/dataconnect/schemaMigration.js +246 -0
- package/lib/dataconnect/types.js +22 -0
- package/lib/deploy/dataconnect/deploy.js +75 -0
- package/lib/deploy/dataconnect/index.js +9 -0
- package/lib/deploy/dataconnect/prepare.js +33 -0
- package/lib/deploy/dataconnect/release.js +65 -0
- package/lib/deploy/firestore/prepare.js +4 -2
- package/lib/deploy/functions/checkIam.js +6 -39
- package/lib/deploy/functions/containerCleaner.js +1 -15
- package/lib/deploy/functions/deploy.js +2 -2
- package/lib/deploy/functions/params.js +2 -2
- package/lib/deploy/functions/prepare.js +13 -3
- package/lib/deploy/functions/pricing.js +2 -2
- package/lib/deploy/functions/prompts.js +39 -7
- package/lib/deploy/functions/release/fabricator.js +12 -7
- package/lib/deploy/functions/release/index.js +17 -2
- package/lib/deploy/functions/release/planner.js +11 -3
- package/lib/deploy/functions/runtimes/discovery/index.js +3 -3
- package/lib/deploy/functions/runtimes/index.js +6 -43
- package/lib/deploy/functions/runtimes/node/index.js +3 -2
- package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +15 -34
- package/lib/deploy/functions/runtimes/python/index.js +10 -7
- package/lib/deploy/functions/runtimes/supported/index.js +80 -0
- package/lib/deploy/functions/runtimes/supported/types.js +74 -0
- package/lib/deploy/functions/services/index.js +4 -0
- package/lib/deploy/index.js +2 -0
- package/lib/downloadUtils.js +3 -2
- package/lib/emulator/constants.js +3 -0
- package/lib/emulator/controller.js +44 -13
- package/lib/emulator/dataconnectEmulator.js +95 -0
- package/lib/emulator/download.js +1 -1
- package/lib/emulator/downloadableEmulators.js +57 -8
- package/lib/emulator/functionsEmulator.js +2 -2
- package/lib/emulator/hub.js +5 -0
- package/lib/emulator/portUtils.js +3 -3
- package/lib/emulator/registry.js +6 -1
- package/lib/emulator/types.js +3 -0
- package/lib/experiments.js +31 -6
- package/lib/extensions/emulator/specHelper.js +9 -42
- package/lib/extensions/extensionsApi.js +2 -2
- package/lib/extensions/localHelper.js +3 -3
- package/lib/firestore/pretty-print.js +5 -0
- package/lib/frameworks/astro/index.js +1 -1
- package/lib/frameworks/flutter/index.js +2 -2
- package/lib/frameworks/next/constants.js +2 -1
- package/lib/frameworks/next/index.js +27 -15
- package/lib/frameworks/next/utils.js +33 -3
- package/lib/functional.js +2 -2
- package/lib/functions/events/v2.js +7 -1
- package/lib/functions/python.js +4 -3
- package/lib/functions/secrets.js +40 -22
- package/lib/gcp/apphosting.js +25 -3
- package/lib/gcp/cloudbuild.js +7 -3
- package/lib/gcp/cloudfunctions.js +5 -5
- package/lib/gcp/cloudfunctionsv2.js +3 -3
- package/lib/gcp/cloudscheduler.js +2 -2
- package/lib/gcp/cloudsql/cloudsqladmin.js +174 -0
- package/lib/gcp/cloudsql/connect.js +144 -0
- package/lib/gcp/cloudsql/fbToolsAuthClient.js +44 -0
- package/lib/gcp/computeEngine.js +7 -0
- package/lib/gcp/devConnect.js +25 -12
- package/lib/gcp/firedata.js +27 -0
- package/lib/gcp/iam.js +41 -1
- package/lib/gcp/secretManager.js +55 -7
- package/lib/gcp/serviceusage.js +24 -5
- package/lib/hosting/interactive.js +4 -0
- package/lib/init/features/dataconnect/index.js +166 -0
- package/lib/init/features/emulators.js +13 -1
- package/lib/init/features/functions/index.js +19 -3
- package/lib/init/features/functions/npm-dependencies.js +12 -23
- package/lib/init/features/functions/python.js +4 -3
- package/lib/init/features/genkit.js +53 -0
- package/lib/init/features/hosting/github.js +4 -5
- package/lib/init/features/index.js +6 -2
- package/lib/init/index.js +2 -0
- package/lib/init/spawn.js +23 -0
- package/lib/logger.js +22 -2
- package/lib/operation-poller.js +8 -2
- package/lib/rc.js +9 -1
- package/lib/requireAuth.js +1 -8
- package/lib/requireTosAcceptance.js +22 -0
- package/lib/utils.js +76 -8
- package/package.json +11 -5
- package/schema/connector-yaml.json +54 -0
- package/schema/dataconnect-yaml.json +72 -0
- package/schema/firebase-config.json +115 -2
- 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/init/dataconnect/connector.yaml +2 -0
- package/templates/init/dataconnect/dataconnect.yaml +10 -0
- package/templates/init/dataconnect/mutations.gql +30 -0
- package/templates/init/dataconnect/queries.gql +51 -0
- package/templates/init/dataconnect/schema.gql +28 -0
- package/templates/init/functions/javascript/_gitignore +2 -1
- package/templates/init/functions/javascript/package.lint.json +2 -2
- package/templates/init/functions/javascript/package.nolint.json +2 -2
- package/templates/init/functions/python/_gitignore +1 -0
- package/templates/init/functions/typescript/_eslintrc +1 -0
- package/templates/init/functions/typescript/_gitignore +1 -0
- package/templates/init/functions/typescript/package.lint.json +2 -2
- package/templates/init/functions/typescript/package.nolint.json +2 -2
- package/lib/init/features/apphosting/index.js +0 -229
- package/lib/monospace/index.js +0 -82
- /package/lib/{monospace/interfaces.js → gcp/cloudsql/types.js} +0 -0
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRoutesWithServerAction = exports.hasStaticAppNotFoundComponent = exports.getNextVersion = exports.getBuildId = exports.getHeadersFromMetaFiles = 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;
|
|
3
|
+
exports.whichNextConfigFile = exports.getProductionDistDirFiles = exports.getRoutesWithServerAction = exports.hasStaticAppNotFoundComponent = exports.getNextVersion = exports.getBuildId = exports.getHeadersFromMetaFiles = 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");
|
|
7
7
|
const promises_1 = require("fs/promises");
|
|
8
8
|
const glob_1 = require("glob");
|
|
9
|
+
const glob = require("glob");
|
|
9
10
|
const semver_1 = require("semver");
|
|
10
11
|
const utils_1 = require("../utils");
|
|
11
12
|
const constants_1 = require("./constants");
|
|
12
13
|
const fsutils_1 = require("../../fsutils");
|
|
14
|
+
const utils_2 = require("../../utils");
|
|
13
15
|
exports.I18N_SOURCE = /\/:nextInternalLocale(\([^\)]+\))?/;
|
|
14
16
|
function cleanEscapedChars(path) {
|
|
15
17
|
return path.replace(/\\([(){}:+?*])/g, (a, b) => b);
|
|
@@ -104,10 +106,15 @@ async function isUsingImageOptimization(projectDir, distDir) {
|
|
|
104
106
|
}
|
|
105
107
|
exports.isUsingImageOptimization = isUsingImageOptimization;
|
|
106
108
|
async function isUsingNextImageInAppDirectory(projectDir, nextDir) {
|
|
109
|
+
const nextImagePath = ["node_modules", "next", "dist", "client", "image"];
|
|
110
|
+
const nextImageString = utils_2.IS_WINDOWS
|
|
111
|
+
?
|
|
112
|
+
nextImagePath.join(path_1.sep + path_1.sep)
|
|
113
|
+
: (0, path_1.join)(...nextImagePath);
|
|
107
114
|
const files = (0, glob_1.sync)((0, path_1.join)(projectDir, nextDir, "server", "**", "*client-reference-manifest.js"));
|
|
108
115
|
for (const filepath of files) {
|
|
109
|
-
const fileContents = await (0, promises_1.readFile)(filepath);
|
|
110
|
-
if (fileContents.includes(
|
|
116
|
+
const fileContents = await (0, promises_1.readFile)(filepath, "utf-8");
|
|
117
|
+
if (fileContents.includes(nextImageString)) {
|
|
111
118
|
return true;
|
|
112
119
|
}
|
|
113
120
|
}
|
|
@@ -221,3 +228,26 @@ function getRoutesWithServerAction(serverReferenceManifest, appPathRoutesManifes
|
|
|
221
228
|
return Array.from(routesWithServerAction);
|
|
222
229
|
}
|
|
223
230
|
exports.getRoutesWithServerAction = getRoutesWithServerAction;
|
|
231
|
+
async function getProductionDistDirFiles(sourceDir, distDir) {
|
|
232
|
+
const productionDistDirFiles = await new Promise((resolve, reject) => glob("**", {
|
|
233
|
+
ignore: [(0, path_1.join)("cache", "webpack", "*-development", "**"), (0, path_1.join)("cache", "eslint", "**")],
|
|
234
|
+
cwd: (0, path_1.join)(sourceDir, distDir),
|
|
235
|
+
nodir: true,
|
|
236
|
+
absolute: false,
|
|
237
|
+
realpath: utils_2.IS_WINDOWS,
|
|
238
|
+
}, (err, matches) => {
|
|
239
|
+
if (err)
|
|
240
|
+
reject(err);
|
|
241
|
+
resolve(matches);
|
|
242
|
+
}));
|
|
243
|
+
return productionDistDirFiles;
|
|
244
|
+
}
|
|
245
|
+
exports.getProductionDistDirFiles = getProductionDistDirFiles;
|
|
246
|
+
async function whichNextConfigFile(dir) {
|
|
247
|
+
for (const file of constants_1.CONFIG_FILES) {
|
|
248
|
+
if (await (0, fs_extra_1.pathExists)((0, path_1.join)(dir, file)))
|
|
249
|
+
return file;
|
|
250
|
+
}
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
exports.whichNextConfigFile = whichNextConfigFile;
|
package/lib/functional.js
CHANGED
|
@@ -52,8 +52,8 @@ const zipIn = (other) => (elem, ndx) => {
|
|
|
52
52
|
return [elem, other[ndx]];
|
|
53
53
|
};
|
|
54
54
|
exports.zipIn = zipIn;
|
|
55
|
-
function assertExhaustive(val) {
|
|
56
|
-
throw new Error(`Never has a value (${val}).`);
|
|
55
|
+
function assertExhaustive(val, message) {
|
|
56
|
+
throw new Error(message || `Never has a value (${val}).`);
|
|
57
57
|
}
|
|
58
58
|
exports.assertExhaustive = assertExhaustive;
|
|
59
59
|
function partition(arr, predicate) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FIRESTORE_EVENTS = exports.TEST_LAB_EVENT = exports.REMOTE_CONFIG_EVENT = exports.DATABASE_EVENTS = exports.FIREBASE_ALERTS_PUBLISH_EVENT = exports.STORAGE_EVENTS = exports.PUBSUB_PUBLISH_EVENT = void 0;
|
|
3
|
+
exports.FIRESTORE_EVENT_WITH_AUTH_CONTEXT_REGEX = exports.FIRESTORE_EVENT_REGEX = exports.FIRESTORE_EVENTS = exports.TEST_LAB_EVENT = exports.REMOTE_CONFIG_EVENT = exports.DATABASE_EVENTS = exports.FIREBASE_ALERTS_PUBLISH_EVENT = exports.STORAGE_EVENTS = exports.PUBSUB_PUBLISH_EVENT = void 0;
|
|
4
4
|
exports.PUBSUB_PUBLISH_EVENT = "google.cloud.pubsub.topic.v1.messagePublished";
|
|
5
5
|
exports.STORAGE_EVENTS = [
|
|
6
6
|
"google.cloud.storage.object.v1.finalized",
|
|
@@ -22,4 +22,10 @@ exports.FIRESTORE_EVENTS = [
|
|
|
22
22
|
"google.cloud.firestore.document.v1.created",
|
|
23
23
|
"google.cloud.firestore.document.v1.updated",
|
|
24
24
|
"google.cloud.firestore.document.v1.deleted",
|
|
25
|
+
"google.cloud.firestore.document.v1.written.withAuthContext",
|
|
26
|
+
"google.cloud.firestore.document.v1.created.withAuthContext",
|
|
27
|
+
"google.cloud.firestore.document.v1.updated.withAuthContext",
|
|
28
|
+
"google.cloud.firestore.document.v1.deleted.withAuthContext",
|
|
25
29
|
];
|
|
30
|
+
exports.FIRESTORE_EVENT_REGEX = /^google\.cloud\.firestore\.document\.v1\.[^\.]*$/;
|
|
31
|
+
exports.FIRESTORE_EVENT_WITH_AUTH_CONTEXT_REGEX = /^google\.cloud\.firestore\.document\.v1\..*\.withAuthContext$/;
|
package/lib/functions/python.js
CHANGED
|
@@ -4,13 +4,14 @@ exports.runWithVirtualEnv = exports.virtualEnvCmd = exports.DEFAULT_VENV_DIR = v
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const spawn = require("cross-spawn");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
7
8
|
exports.DEFAULT_VENV_DIR = "venv";
|
|
8
9
|
function virtualEnvCmd(cwd, venvDir) {
|
|
9
|
-
const activateScriptPath =
|
|
10
|
+
const activateScriptPath = utils_1.IS_WINDOWS ? ["Scripts", "activate.bat"] : ["bin", "activate"];
|
|
10
11
|
const venvActivate = `"${path.join(cwd, venvDir, ...activateScriptPath)}"`;
|
|
11
12
|
return {
|
|
12
|
-
command:
|
|
13
|
-
args: [
|
|
13
|
+
command: utils_1.IS_WINDOWS ? venvActivate : ".",
|
|
14
|
+
args: [utils_1.IS_WINDOWS ? "" : venvActivate],
|
|
14
15
|
};
|
|
15
16
|
}
|
|
16
17
|
exports.virtualEnvCmd = virtualEnvCmd;
|
package/lib/functions/secrets.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateEndpointSecret = exports.pruneAndDestroySecrets = exports.pruneSecrets = exports.versionInUse = exports.inUse = exports.getSecretVersions = exports.of = exports.ensureSecret = exports.ensureValidKey =
|
|
3
|
+
exports.describeSecret = exports.updateEndpointSecret = exports.pruneAndDestroySecrets = exports.pruneSecrets = exports.versionInUse = exports.inUse = exports.getSecretVersions = exports.of = exports.ensureSecret = exports.ensureValidKey = void 0;
|
|
4
4
|
const utils = require("../utils");
|
|
5
5
|
const poller = require("../operation-poller");
|
|
6
6
|
const gcfV1 = require("../gcp/cloudfunctions");
|
|
7
7
|
const gcfV2 = require("../gcp/cloudfunctionsv2");
|
|
8
|
-
const ensureApiEnabled = require("../ensureApiEnabled");
|
|
9
8
|
const api_1 = require("../api");
|
|
10
9
|
const secretManager_1 = require("../gcp/secretManager");
|
|
11
10
|
const error_1 = require("../error");
|
|
@@ -14,8 +13,10 @@ const prompt_1 = require("../prompt");
|
|
|
14
13
|
const env_1 = require("./env");
|
|
15
14
|
const logger_1 = require("../logger");
|
|
16
15
|
const functional_1 = require("../functional");
|
|
16
|
+
const secretManager_2 = require("../gcp/secretManager");
|
|
17
|
+
const secretManager_3 = require("../gcp/secretManager");
|
|
17
18
|
const projectUtils_1 = require("../projectUtils");
|
|
18
|
-
const
|
|
19
|
+
const Table = require("cli-table");
|
|
19
20
|
const gcfV1PollerOptions = {
|
|
20
21
|
apiOrigin: (0, api_1.functionsOrigin)(),
|
|
21
22
|
apiVersion: "v1",
|
|
@@ -28,25 +29,12 @@ const gcfV2PollerOptions = {
|
|
|
28
29
|
masterTimeout: 25 * 60 * 1000,
|
|
29
30
|
maxBackoff: 10000,
|
|
30
31
|
};
|
|
31
|
-
function isFirebaseManaged(secret) {
|
|
32
|
-
return Object.keys(secret.labels || []).includes(FIREBASE_MANAGED);
|
|
33
|
-
}
|
|
34
|
-
exports.isFirebaseManaged = isFirebaseManaged;
|
|
35
|
-
function labels() {
|
|
36
|
-
return { [FIREBASE_MANAGED]: "true" };
|
|
37
|
-
}
|
|
38
|
-
exports.labels = labels;
|
|
39
32
|
function toUpperSnakeCase(key) {
|
|
40
33
|
return key
|
|
41
34
|
.replace(/[.-]/g, "_")
|
|
42
35
|
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
43
36
|
.toUpperCase();
|
|
44
37
|
}
|
|
45
|
-
function ensureApi(options) {
|
|
46
|
-
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
47
|
-
return ensureApiEnabled.ensure(projectId, (0, api_1.secretManagerOrigin)(), "secretmanager", true);
|
|
48
|
-
}
|
|
49
|
-
exports.ensureApi = ensureApi;
|
|
50
38
|
async function ensureValidKey(key, options) {
|
|
51
39
|
const transformedKey = toUpperSnakeCase(key);
|
|
52
40
|
if (transformedKey !== key) {
|
|
@@ -76,20 +64,36 @@ exports.ensureValidKey = ensureValidKey;
|
|
|
76
64
|
async function ensureSecret(projectId, name, options) {
|
|
77
65
|
try {
|
|
78
66
|
const secret = await (0, secretManager_1.getSecret)(projectId, name);
|
|
79
|
-
if (
|
|
67
|
+
if ((0, secretManager_1.isAppHostingManaged)(secret)) {
|
|
68
|
+
(0, utils_1.logWarning)("Your secret is managed by Firebase App Hosting. Continuing will disable automatic deletion of old versions.");
|
|
69
|
+
const stopTracking = await (0, prompt_1.promptOnce)({
|
|
70
|
+
name: "doNotTrack",
|
|
71
|
+
type: "confirm",
|
|
72
|
+
default: false,
|
|
73
|
+
message: "Do you wish to continue?",
|
|
74
|
+
}, options);
|
|
75
|
+
if (stopTracking) {
|
|
76
|
+
delete secret.labels[secretManager_2.FIREBASE_MANAGED];
|
|
77
|
+
await (0, secretManager_1.patchSecret)(secret.projectId, secret.name, secret.labels);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new Error("A secret cannot be managed by both Firebase App Hosting and Cloud Functions for Firebase");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (!(0, secretManager_2.isFunctionsManaged)(secret)) {
|
|
80
84
|
if (!options.force) {
|
|
81
|
-
(0, utils_1.logWarning)("Your secret is not managed by Firebase. " +
|
|
85
|
+
(0, utils_1.logWarning)("Your secret is not managed by Cloud Functions for Firebase. " +
|
|
82
86
|
"Firebase managed secrets are automatically pruned to reduce your monthly cost for using Secret Manager. ");
|
|
83
87
|
const confirm = await (0, prompt_1.promptOnce)({
|
|
84
88
|
name: "updateLabels",
|
|
85
89
|
type: "confirm",
|
|
86
90
|
default: true,
|
|
87
|
-
message: `Would you like to have your secret ${secret.name} managed by Firebase?`,
|
|
91
|
+
message: `Would you like to have your secret ${secret.name} managed by Cloud Functions for Firebase?`,
|
|
88
92
|
}, options);
|
|
89
93
|
if (confirm) {
|
|
90
94
|
return (0, secretManager_1.patchSecret)(projectId, secret.name, {
|
|
91
95
|
...secret.labels,
|
|
92
|
-
...labels(),
|
|
96
|
+
...(0, secretManager_3.labels)(),
|
|
93
97
|
});
|
|
94
98
|
}
|
|
95
99
|
}
|
|
@@ -101,7 +105,7 @@ async function ensureSecret(projectId, name, options) {
|
|
|
101
105
|
throw err;
|
|
102
106
|
}
|
|
103
107
|
}
|
|
104
|
-
return await (0, secretManager_1.createSecret)(projectId, name, labels());
|
|
108
|
+
return await (0, secretManager_1.createSecret)(projectId, name, (0, secretManager_3.labels)());
|
|
105
109
|
}
|
|
106
110
|
exports.ensureSecret = ensureSecret;
|
|
107
111
|
function of(endpoints) {
|
|
@@ -142,7 +146,7 @@ async function pruneSecrets(projectInfo, endpoints) {
|
|
|
142
146
|
const { projectId, projectNumber } = projectInfo;
|
|
143
147
|
const pruneKey = (name, version) => `${name}@${version}`;
|
|
144
148
|
const prunedSecrets = new Set();
|
|
145
|
-
const haveSecrets = await (0, secretManager_1.listSecrets)(projectId, `labels.${FIREBASE_MANAGED}=true`);
|
|
149
|
+
const haveSecrets = await (0, secretManager_1.listSecrets)(projectId, `labels.${secretManager_2.FIREBASE_MANAGED}=true`);
|
|
146
150
|
for (const secret of haveSecrets) {
|
|
147
151
|
const versions = await (0, secretManager_1.listSecretVersions)(projectId, secret.name, `NOT state: DESTROYED`);
|
|
148
152
|
for (const version of versions) {
|
|
@@ -252,3 +256,17 @@ async function updateEndpointSecret(projectInfo, secretVersion, endpoint) {
|
|
|
252
256
|
}
|
|
253
257
|
}
|
|
254
258
|
exports.updateEndpointSecret = updateEndpointSecret;
|
|
259
|
+
async function describeSecret(key, options) {
|
|
260
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
261
|
+
const versions = await (0, secretManager_1.listSecretVersions)(projectId, key);
|
|
262
|
+
const table = new Table({
|
|
263
|
+
head: ["Version", "State"],
|
|
264
|
+
style: { head: ["yellow"] },
|
|
265
|
+
});
|
|
266
|
+
for (const version of versions) {
|
|
267
|
+
table.push([version.versionId, version.state]);
|
|
268
|
+
}
|
|
269
|
+
logger_1.logger.info(table.toString());
|
|
270
|
+
return { secrets: versions };
|
|
271
|
+
}
|
|
272
|
+
exports.describeSecret = describeSecret;
|
package/lib/gcp/apphosting.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNextRolloutId = exports.ensureApiEnabled = exports.listLocations = exports.updateTraffic = exports.listRollouts = exports.createRollout = exports.createBuild = exports.listBuilds = exports.getBuild = exports.deleteBackend = exports.listBackends = exports.getBackend = exports.createBackend = exports.client = exports.API_VERSION = void 0;
|
|
3
|
+
exports.getNextRolloutId = exports.ensureApiEnabled = exports.listLocations = exports.updateTraffic = exports.listRollouts = exports.createRollout = exports.createBuild = exports.listBuilds = exports.getBuild = exports.deleteBackend = exports.listBackends = exports.getBackend = exports.createBackend = exports.parseBackendName = exports.serviceAgentEmail = exports.client = exports.API_VERSION = void 0;
|
|
4
4
|
const proto = require("../gcp/proto");
|
|
5
5
|
const apiv2_1 = require("../apiv2");
|
|
6
6
|
const projectUtils_1 = require("../projectUtils");
|
|
@@ -19,6 +19,16 @@ exports.client = new apiv2_1.Client({
|
|
|
19
19
|
(0, metaprogramming_1.assertImplements)();
|
|
20
20
|
(0, metaprogramming_1.assertImplements)();
|
|
21
21
|
(0, metaprogramming_1.assertImplements)();
|
|
22
|
+
const P4SA_DOMAIN = (0, api_1.apphostingP4SADomain)();
|
|
23
|
+
function serviceAgentEmail(projectNumber) {
|
|
24
|
+
return `service-${projectNumber}@${P4SA_DOMAIN}`;
|
|
25
|
+
}
|
|
26
|
+
exports.serviceAgentEmail = serviceAgentEmail;
|
|
27
|
+
function parseBackendName(backendName) {
|
|
28
|
+
const [, projectName, , location, , id] = backendName.split("/");
|
|
29
|
+
return { projectName, location, id };
|
|
30
|
+
}
|
|
31
|
+
exports.parseBackendName = parseBackendName;
|
|
22
32
|
async function createBackend(projectId, location, backendReqBoby, backendId) {
|
|
23
33
|
const res = await exports.client.post(`projects/${projectId}/locations/${location}/backends`, {
|
|
24
34
|
...backendReqBoby,
|
|
@@ -38,8 +48,20 @@ async function getBackend(projectId, location, backendId) {
|
|
|
38
48
|
exports.getBackend = getBackend;
|
|
39
49
|
async function listBackends(projectId, location) {
|
|
40
50
|
const name = `projects/${projectId}/locations/${location}/backends`;
|
|
41
|
-
|
|
42
|
-
|
|
51
|
+
let pageToken;
|
|
52
|
+
const res = {
|
|
53
|
+
backends: [],
|
|
54
|
+
unreachable: [],
|
|
55
|
+
};
|
|
56
|
+
do {
|
|
57
|
+
const queryParams = pageToken ? { pageToken } : {};
|
|
58
|
+
const int = await exports.client.get(name, { queryParams });
|
|
59
|
+
res.backends.push(...(int.body.backends || []));
|
|
60
|
+
res.unreachable?.push(...(int.body.unreachable || []));
|
|
61
|
+
pageToken = int.body.nextPageToken;
|
|
62
|
+
} while (pageToken);
|
|
63
|
+
res.unreachable = [...new Set(res.unreachable)];
|
|
64
|
+
return res;
|
|
43
65
|
}
|
|
44
66
|
exports.listBackends = listBackends;
|
|
45
67
|
async function deleteBackend(projectId, location, backendId) {
|
package/lib/gcp/cloudbuild.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getDefaultServiceAgent = exports.getDefaultServiceAccount = exports.deleteRepository = exports.getRepository = exports.createRepository = exports.fetchLinkableRepositories = exports.deleteConnection = exports.listConnections = exports.getConnection = exports.createConnection = void 0;
|
|
4
4
|
const apiv2_1 = require("../apiv2");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
const PAGE_SIZE_MAX = 100;
|
|
@@ -74,7 +74,11 @@ async function deleteRepository(projectId, location, connectionId, repositoryId)
|
|
|
74
74
|
return res.body;
|
|
75
75
|
}
|
|
76
76
|
exports.deleteRepository = deleteRepository;
|
|
77
|
-
function
|
|
77
|
+
function getDefaultServiceAccount(projectNumber) {
|
|
78
|
+
return `${projectNumber}@cloudbuild.gserviceaccount.com`;
|
|
79
|
+
}
|
|
80
|
+
exports.getDefaultServiceAccount = getDefaultServiceAccount;
|
|
81
|
+
function getDefaultServiceAgent(projectNumber) {
|
|
78
82
|
return `service-${projectNumber}@gcp-sa-cloudbuild.iam.gserviceaccount.com`;
|
|
79
83
|
}
|
|
80
|
-
exports.
|
|
84
|
+
exports.getDefaultServiceAgent = getDefaultServiceAgent;
|
|
@@ -7,7 +7,7 @@ const logger_1 = require("../logger");
|
|
|
7
7
|
const backend = require("../deploy/functions/backend");
|
|
8
8
|
const utils = require("../utils");
|
|
9
9
|
const proto = require("./proto");
|
|
10
|
-
const
|
|
10
|
+
const supported = require("../deploy/functions/runtimes/supported");
|
|
11
11
|
const projectConfig = require("../functions/projectConfig");
|
|
12
12
|
const apiv2_1 = require("../apiv2");
|
|
13
13
|
const api_1 = require("../api");
|
|
@@ -243,8 +243,8 @@ function endpointFromFunction(gcfFunction) {
|
|
|
243
243
|
uri = gcfFunction.httpsTrigger.url;
|
|
244
244
|
securityLevel = gcfFunction.httpsTrigger.securityLevel;
|
|
245
245
|
}
|
|
246
|
-
if (!
|
|
247
|
-
logger_1.logger.debug("
|
|
246
|
+
if (!supported.isRuntime(gcfFunction.runtime)) {
|
|
247
|
+
logger_1.logger.debug("GCF 1st gen function has unsupported runtime:", JSON.stringify(gcfFunction, null, 2));
|
|
248
248
|
}
|
|
249
249
|
const endpoint = {
|
|
250
250
|
platform: "gcfv1",
|
|
@@ -280,9 +280,9 @@ function functionFromEndpoint(endpoint, sourceUploadUrl) {
|
|
|
280
280
|
if (endpoint.platform !== "gcfv1") {
|
|
281
281
|
throw new error_1.FirebaseError("Trying to create a v1 CloudFunction with v2 API. This should never happen");
|
|
282
282
|
}
|
|
283
|
-
if (!
|
|
283
|
+
if (!supported.isRuntime(endpoint.runtime)) {
|
|
284
284
|
throw new error_1.FirebaseError("Failed internal assertion. Trying to deploy a new function with a deprecated runtime." +
|
|
285
|
-
" This should never happen");
|
|
285
|
+
" This should never happen", { exit: 1 });
|
|
286
286
|
}
|
|
287
287
|
const gcfFunction = {
|
|
288
288
|
name: backend.functionName(endpoint),
|
|
@@ -7,7 +7,7 @@ const api_1 = require("../api");
|
|
|
7
7
|
const logger_1 = require("../logger");
|
|
8
8
|
const v2_1 = require("../functions/events/v2");
|
|
9
9
|
const backend = require("../deploy/functions/backend");
|
|
10
|
-
const
|
|
10
|
+
const supported = require("../deploy/functions/runtimes/supported");
|
|
11
11
|
const proto = require("./proto");
|
|
12
12
|
const utils = require("../utils");
|
|
13
13
|
const projectConfig = require("../functions/projectConfig");
|
|
@@ -185,7 +185,7 @@ function functionFromEndpoint(endpoint) {
|
|
|
185
185
|
if (endpoint.platform !== "gcfv2") {
|
|
186
186
|
throw new error_1.FirebaseError("Trying to create a v2 CloudFunction with v1 API. This should never happen");
|
|
187
187
|
}
|
|
188
|
-
if (!
|
|
188
|
+
if (!supported.isRuntime(endpoint.runtime)) {
|
|
189
189
|
throw new error_1.FirebaseError("Failed internal assertion. Trying to deploy a new function with a deprecated runtime." +
|
|
190
190
|
" This should never happen");
|
|
191
191
|
}
|
|
@@ -358,7 +358,7 @@ function endpointFromFunction(gcfFunction) {
|
|
|
358
358
|
else {
|
|
359
359
|
trigger = { httpsTrigger: {} };
|
|
360
360
|
}
|
|
361
|
-
if (!
|
|
361
|
+
if (!supported.isRuntime(gcfFunction.buildConfig.runtime)) {
|
|
362
362
|
logger_1.logger.debug("GCFv2 function has a deprecated runtime:", JSON.stringify(gcfFunction, null, 2));
|
|
363
363
|
}
|
|
364
364
|
const endpoint = {
|
|
@@ -8,7 +8,7 @@ const api_1 = require("../api");
|
|
|
8
8
|
const apiv2_1 = require("../apiv2");
|
|
9
9
|
const backend = require("../deploy/functions/backend");
|
|
10
10
|
const proto = require("./proto");
|
|
11
|
-
const
|
|
11
|
+
const gce = require("../gcp/computeEngine");
|
|
12
12
|
const functional_1 = require("../functional");
|
|
13
13
|
const VERSION = "v1";
|
|
14
14
|
const DEFAULT_TIME_ZONE_V1 = "America/Los_Angeles";
|
|
@@ -129,7 +129,7 @@ function jobFromEndpoint(endpoint, location, projectNumber) {
|
|
|
129
129
|
uri: endpoint.uri,
|
|
130
130
|
httpMethod: "POST",
|
|
131
131
|
oidcToken: {
|
|
132
|
-
serviceAccountEmail: endpoint.serviceAccount ??
|
|
132
|
+
serviceAccountEmail: endpoint.serviceAccount ?? gce.getDefaultServiceAccount(projectNumber),
|
|
133
133
|
},
|
|
134
134
|
};
|
|
135
135
|
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listUsers = exports.deleteUser = exports.getUser = exports.createUser = exports.createDatabase = exports.getDatabase = exports.listDatabases = exports.updateInstanceForDataConnect = exports.createInstance = exports.getInstance = exports.listInstances = void 0;
|
|
4
|
+
const apiv2_1 = require("../../apiv2");
|
|
5
|
+
const api_1 = require("../../api");
|
|
6
|
+
const operationPoller = require("../../operation-poller");
|
|
7
|
+
const API_VERSION = "v1";
|
|
8
|
+
const client = new apiv2_1.Client({
|
|
9
|
+
urlPrefix: (0, api_1.cloudSQLAdminOrigin)(),
|
|
10
|
+
auth: true,
|
|
11
|
+
apiVersion: API_VERSION,
|
|
12
|
+
});
|
|
13
|
+
async function listInstances(projectId) {
|
|
14
|
+
const res = await client.get(`projects/${projectId}/instances`);
|
|
15
|
+
return res.body.items ?? [];
|
|
16
|
+
}
|
|
17
|
+
exports.listInstances = listInstances;
|
|
18
|
+
async function getInstance(projectId, instanceId) {
|
|
19
|
+
const res = await client.get(`projects/${projectId}/instances/${instanceId}`);
|
|
20
|
+
return res.body;
|
|
21
|
+
}
|
|
22
|
+
exports.getInstance = getInstance;
|
|
23
|
+
async function createInstance(projectId, location, instanceId, enableGoogleMlIntegration) {
|
|
24
|
+
const databaseFlags = [{ name: "cloudsql.iam_authentication", value: "on" }];
|
|
25
|
+
if (enableGoogleMlIntegration) {
|
|
26
|
+
databaseFlags.push({ name: "cloudsql.enable_google_ml_integration", value: "on" });
|
|
27
|
+
}
|
|
28
|
+
const op = await client.post(`projects/${projectId}/instances`, {
|
|
29
|
+
name: instanceId,
|
|
30
|
+
region: location,
|
|
31
|
+
databaseVersion: "POSTGRES_15",
|
|
32
|
+
settings: {
|
|
33
|
+
tier: "db-f1-micro",
|
|
34
|
+
edition: "ENTERPRISE",
|
|
35
|
+
ipConfiguration: {
|
|
36
|
+
authorizedNetworks: [],
|
|
37
|
+
},
|
|
38
|
+
enableGoogleMlIntegration,
|
|
39
|
+
databaseFlags,
|
|
40
|
+
storageAutoResize: false,
|
|
41
|
+
userLabels: { "firebase-data-connect": "ft" },
|
|
42
|
+
insightsConfig: {
|
|
43
|
+
queryInsightsEnabled: true,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const opName = `projects/${projectId}/operations/${op.body.name}`;
|
|
48
|
+
const pollRes = await operationPoller.pollOperation({
|
|
49
|
+
apiOrigin: (0, api_1.cloudSQLAdminOrigin)(),
|
|
50
|
+
apiVersion: API_VERSION,
|
|
51
|
+
operationResourceName: opName,
|
|
52
|
+
doneFn: (op) => op.status === "DONE",
|
|
53
|
+
masterTimeout: 1200000,
|
|
54
|
+
});
|
|
55
|
+
return pollRes;
|
|
56
|
+
}
|
|
57
|
+
exports.createInstance = createInstance;
|
|
58
|
+
async function updateInstanceForDataConnect(instance, enableGoogleMlIntegration) {
|
|
59
|
+
let dbFlags = setDatabaseFlag({ name: "cloudsql.iam_authentication", value: "on" }, instance.settings.databaseFlags);
|
|
60
|
+
if (enableGoogleMlIntegration) {
|
|
61
|
+
dbFlags = setDatabaseFlag({ name: "cloudsql.enable_google_ml_integration", value: "on" }, dbFlags);
|
|
62
|
+
}
|
|
63
|
+
const op = await client.patch(`projects/${instance.project}/instances/${instance.name}`, {
|
|
64
|
+
settings: {
|
|
65
|
+
ipConfiguration: {
|
|
66
|
+
ipv4Enabled: true,
|
|
67
|
+
},
|
|
68
|
+
databaseFlags: dbFlags,
|
|
69
|
+
enableGoogleMlIntegration,
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
const opName = `projects/${instance.project}/operations/${op.body.name}`;
|
|
73
|
+
const pollRes = await operationPoller.pollOperation({
|
|
74
|
+
apiOrigin: (0, api_1.cloudSQLAdminOrigin)(),
|
|
75
|
+
apiVersion: API_VERSION,
|
|
76
|
+
operationResourceName: opName,
|
|
77
|
+
doneFn: (op) => op.status === "DONE",
|
|
78
|
+
masterTimeout: 1200000,
|
|
79
|
+
});
|
|
80
|
+
return pollRes;
|
|
81
|
+
}
|
|
82
|
+
exports.updateInstanceForDataConnect = updateInstanceForDataConnect;
|
|
83
|
+
function setDatabaseFlag(flag, flags = []) {
|
|
84
|
+
const temp = flags.filter((f) => f.name !== flag.name);
|
|
85
|
+
temp.push(flag);
|
|
86
|
+
return temp;
|
|
87
|
+
}
|
|
88
|
+
async function listDatabases(projectId, instanceId) {
|
|
89
|
+
const res = await client.get(`projects/${projectId}/instances/${instanceId}/databases`);
|
|
90
|
+
return res.body.items;
|
|
91
|
+
}
|
|
92
|
+
exports.listDatabases = listDatabases;
|
|
93
|
+
async function getDatabase(projectId, instanceId, databaseId) {
|
|
94
|
+
const res = await client.get(`projects/${projectId}/instances/${instanceId}/databases/${databaseId}`);
|
|
95
|
+
return res.body;
|
|
96
|
+
}
|
|
97
|
+
exports.getDatabase = getDatabase;
|
|
98
|
+
async function createDatabase(projectId, instanceId, databaseId) {
|
|
99
|
+
const op = await client.post(`projects/${projectId}/instances/${instanceId}/databases`, {
|
|
100
|
+
project: projectId,
|
|
101
|
+
instance: instanceId,
|
|
102
|
+
name: databaseId,
|
|
103
|
+
});
|
|
104
|
+
const opName = `projects/${projectId}/operations/${op.body.name}`;
|
|
105
|
+
const pollRes = await operationPoller.pollOperation({
|
|
106
|
+
apiOrigin: (0, api_1.cloudSQLAdminOrigin)(),
|
|
107
|
+
apiVersion: API_VERSION,
|
|
108
|
+
operationResourceName: opName,
|
|
109
|
+
doneFn: (op) => op.status === "DONE",
|
|
110
|
+
});
|
|
111
|
+
return pollRes;
|
|
112
|
+
}
|
|
113
|
+
exports.createDatabase = createDatabase;
|
|
114
|
+
async function createUser(projectId, instanceId, type, username, password) {
|
|
115
|
+
const maxRetries = 3;
|
|
116
|
+
let retries = 0;
|
|
117
|
+
while (true) {
|
|
118
|
+
try {
|
|
119
|
+
const op = await client.post(`projects/${projectId}/instances/${instanceId}/users`, {
|
|
120
|
+
name: username,
|
|
121
|
+
instance: instanceId,
|
|
122
|
+
project: projectId,
|
|
123
|
+
password: password,
|
|
124
|
+
sqlserverUserDetails: {
|
|
125
|
+
disabled: false,
|
|
126
|
+
serverRoles: ["cloudsqlsuperuser"],
|
|
127
|
+
},
|
|
128
|
+
type,
|
|
129
|
+
});
|
|
130
|
+
const opName = `projects/${projectId}/operations/${op.body.name}`;
|
|
131
|
+
const pollRes = await operationPoller.pollOperation({
|
|
132
|
+
apiOrigin: (0, api_1.cloudSQLAdminOrigin)(),
|
|
133
|
+
apiVersion: API_VERSION,
|
|
134
|
+
operationResourceName: opName,
|
|
135
|
+
doneFn: (op) => op.status === "DONE",
|
|
136
|
+
});
|
|
137
|
+
return pollRes;
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
if (builtinRoleNotReady(err.message) && retries < maxRetries) {
|
|
141
|
+
retries++;
|
|
142
|
+
await new Promise((resolve) => {
|
|
143
|
+
setTimeout(resolve, 1000 * retries);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.createUser = createUser;
|
|
153
|
+
function builtinRoleNotReady(message) {
|
|
154
|
+
return message.includes("cloudsqliamuser");
|
|
155
|
+
}
|
|
156
|
+
async function getUser(projectId, instanceId, username) {
|
|
157
|
+
const res = await client.get(`projects/${projectId}/instances/${instanceId}/users/${username}`);
|
|
158
|
+
return res.body;
|
|
159
|
+
}
|
|
160
|
+
exports.getUser = getUser;
|
|
161
|
+
async function deleteUser(projectId, instanceId, username) {
|
|
162
|
+
const res = await client.delete(`projects/${projectId}/instances/${instanceId}/users`, {
|
|
163
|
+
queryParams: {
|
|
164
|
+
name: username,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
return res.body;
|
|
168
|
+
}
|
|
169
|
+
exports.deleteUser = deleteUser;
|
|
170
|
+
async function listUsers(projectId, instanceId) {
|
|
171
|
+
const res = await client.get(`projects/${projectId}/instances/${instanceId}/users`);
|
|
172
|
+
return res.body.items;
|
|
173
|
+
}
|
|
174
|
+
exports.listUsers = listUsers;
|