firebase-tools-with-isolate 13.7.3 → 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/lib/api.js +18 -8
- package/lib/apiv2.js +19 -13
- package/lib/apphosting/app.js +40 -59
- package/lib/apphosting/constants.js +2 -2
- package/lib/apphosting/githubConnections.js +7 -9
- package/lib/apphosting/index.js +122 -58
- package/lib/apphosting/repo.js +3 -3
- package/lib/apphosting/secrets/index.js +7 -1
- package/lib/checkValidTargetFilters.js +8 -1
- package/lib/commands/apphosting-backends-create.js +7 -6
- package/lib/commands/apphosting-backends-delete.js +24 -28
- package/lib/commands/apphosting-backends-list.js +4 -5
- package/lib/commands/apphosting-secrets-access.js +1 -1
- package/lib/commands/apphosting-secrets-grantaccess.js +11 -7
- package/lib/commands/apphosting-secrets-set.js +1 -1
- 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/index.js +11 -0
- 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/functions/checkIam.js +4 -34
- package/lib/deploy/functions/release/fabricator.js +7 -2
- package/lib/deploy/index.js +2 -0
- package/lib/downloadUtils.js +2 -2
- package/lib/emulator/constants.js +3 -0
- package/lib/emulator/controller.js +39 -12
- package/lib/emulator/dataconnectEmulator.js +95 -0
- package/lib/emulator/download.js +1 -1
- package/lib/emulator/downloadableEmulators.js +57 -8
- 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 +19 -6
- package/lib/extensions/emulator/specHelper.js +5 -39
- package/lib/frameworks/next/index.js +6 -4
- package/lib/frameworks/next/utils.js +2 -1
- package/lib/functions/python.js +4 -3
- package/lib/gcp/apphosting.js +11 -1
- 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/devConnect.js +1 -1
- package/lib/gcp/firedata.js +27 -0
- package/lib/gcp/iam.js +33 -1
- package/lib/gcp/secretManager.js +1 -1
- 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/genkit.js +53 -0
- package/lib/init/features/index.js +5 -1
- 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 +55 -4
- package/package.json +9 -3
- package/schema/connector-yaml.json +54 -0
- package/schema/dataconnect-yaml.json +72 -0
- package/schema/firebase-config.json +103 -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/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/_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/monospace/index.js +0 -82
- /package/lib/{monospace/interfaces.js → gcp/cloudsql/types.js} +0 -0
package/lib/apphosting/repo.js
CHANGED
|
@@ -50,7 +50,7 @@ function generateConnectionId() {
|
|
|
50
50
|
}
|
|
51
51
|
const ADD_CONN_CHOICE = "@ADD_CONN";
|
|
52
52
|
async function linkGitHubRepository(projectId, location) {
|
|
53
|
-
utils.logBullet(clc.bold(`${clc.yellow("===")}
|
|
53
|
+
utils.logBullet(clc.bold(`${clc.yellow("===")} Import a GitHub repository`));
|
|
54
54
|
const oauthConn = await getOrCreateOauthConnection(projectId, location);
|
|
55
55
|
const existingConns = await listAppHostingConnections(projectId);
|
|
56
56
|
if (existingConns.length === 0) {
|
|
@@ -83,7 +83,7 @@ async function createFullyInstalledConnection(projectId, location, connectionId,
|
|
|
83
83
|
});
|
|
84
84
|
while (conn.installationState.stage !== "COMPLETE") {
|
|
85
85
|
utils.logBullet("Install the Cloud Build GitHub app to enable access to GitHub repositories");
|
|
86
|
-
const targetUri = conn.installationState.actionUri
|
|
86
|
+
const targetUri = conn.installationState.actionUri;
|
|
87
87
|
utils.logBullet(targetUri);
|
|
88
88
|
await utils.openInBrowser(targetUri);
|
|
89
89
|
await (0, prompt_1.promptOnce)({
|
|
@@ -129,7 +129,7 @@ async function promptRepositoryUri(projectId, connections) {
|
|
|
129
129
|
const remoteUri = await (0, prompt_1.promptOnce)({
|
|
130
130
|
type: "autocomplete",
|
|
131
131
|
name: "remoteUri",
|
|
132
|
-
message: "Which
|
|
132
|
+
message: "Which GitHub repo do you want to deploy?",
|
|
133
133
|
source: (_, input = "") => {
|
|
134
134
|
return new Promise((resolve) => resolve([
|
|
135
135
|
new inquirer.Separator(),
|
|
@@ -5,6 +5,7 @@ const error_1 = require("../../error");
|
|
|
5
5
|
const gcsm = require("../../gcp/secretManager");
|
|
6
6
|
const gcb = require("../../gcp/cloudbuild");
|
|
7
7
|
const gce = require("../../gcp/computeEngine");
|
|
8
|
+
const apphosting = require("../../gcp/apphosting");
|
|
8
9
|
const secretManager_1 = require("../../gcp/secretManager");
|
|
9
10
|
const secretManager_2 = require("../../gcp/secretManager");
|
|
10
11
|
const utils = require("../../utils");
|
|
@@ -33,7 +34,8 @@ function serviceAccountsForBackend(projectNumber, backend) {
|
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
exports.serviceAccountsForBackend = serviceAccountsForBackend;
|
|
36
|
-
async function grantSecretAccess(projectId, secretName, accounts) {
|
|
37
|
+
async function grantSecretAccess(projectId, projectNumber, secretName, accounts) {
|
|
38
|
+
const p4saEmail = apphosting.serviceAgentEmail(projectNumber);
|
|
37
39
|
const newBindings = [
|
|
38
40
|
{
|
|
39
41
|
role: "roles/secretmanager.secretAccessor",
|
|
@@ -43,6 +45,10 @@ async function grantSecretAccess(projectId, secretName, accounts) {
|
|
|
43
45
|
role: "roles/secretmanager.viewer",
|
|
44
46
|
members: accounts.buildServiceAccounts.map((sa) => `serviceAccount:${sa}`),
|
|
45
47
|
},
|
|
48
|
+
{
|
|
49
|
+
role: "roles/secretmanager.secretVersionManager",
|
|
50
|
+
members: [`serviceAccount:${p4saEmail}`],
|
|
51
|
+
},
|
|
46
52
|
];
|
|
47
53
|
let existingBindings;
|
|
48
54
|
try {
|
|
@@ -19,7 +19,14 @@ function targetsHaveFilters(...targets) {
|
|
|
19
19
|
function targetsHaveNoFilters(...targets) {
|
|
20
20
|
return targets.some((t) => !t.includes(":"));
|
|
21
21
|
}
|
|
22
|
-
const FILTERABLE_TARGETS = new Set([
|
|
22
|
+
const FILTERABLE_TARGETS = new Set([
|
|
23
|
+
"hosting",
|
|
24
|
+
"functions",
|
|
25
|
+
"firestore",
|
|
26
|
+
"storage",
|
|
27
|
+
"database",
|
|
28
|
+
"dataconnect",
|
|
29
|
+
]);
|
|
23
30
|
async function checkValidTargetFilters(options) {
|
|
24
31
|
const only = !options.only ? [] : options.only.split(",");
|
|
25
32
|
return new Promise((resolve, reject) => {
|
|
@@ -6,19 +6,20 @@ const projectUtils_1 = require("../projectUtils");
|
|
|
6
6
|
const requireInteractive_1 = require("../requireInteractive");
|
|
7
7
|
const apphosting_1 = require("../apphosting");
|
|
8
8
|
const apphosting_2 = require("../gcp/apphosting");
|
|
9
|
+
const firedata_1 = require("../gcp/firedata");
|
|
10
|
+
const requireTosAcceptance_1 = require("../requireTosAcceptance");
|
|
9
11
|
exports.command = new command_1.Command("apphosting:backends:create")
|
|
10
12
|
.description("create a Firebase App Hosting backend")
|
|
11
|
-
.option("-a, --app <
|
|
12
|
-
.option("-l, --location <location>", "specify the
|
|
13
|
+
.option("-a, --app <webAppId>", "specify an existing Firebase web app's ID to associate your App Hosting backend with")
|
|
14
|
+
.option("-l, --location <location>", "specify the location of the backend", "")
|
|
13
15
|
.option("-s, --service-account <serviceAccount>", "specify the service account used to run the server", "")
|
|
14
|
-
.option("-w, --with-dev-connect", "use the Developer Connect flow insetad of Cloud Build Repositories (testing)", false)
|
|
15
16
|
.before(apphosting_2.ensureApiEnabled)
|
|
16
17
|
.before(requireInteractive_1.default)
|
|
18
|
+
.before((0, requireTosAcceptance_1.requireTosAcceptance)(firedata_1.APPHOSTING_TOS_ID))
|
|
17
19
|
.action(async (options) => {
|
|
18
20
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
19
|
-
const
|
|
21
|
+
const webAppId = options.app;
|
|
20
22
|
const location = options.location;
|
|
21
23
|
const serviceAccount = options.serviceAccount;
|
|
22
|
-
|
|
23
|
-
await (0, apphosting_1.doSetup)(projectId, webApp, location, serviceAccount, withDevConnect);
|
|
24
|
+
await (0, apphosting_1.doSetup)(projectId, webAppId, location, serviceAccount);
|
|
24
25
|
});
|
|
@@ -5,44 +5,29 @@ const command_1 = require("../command");
|
|
|
5
5
|
const projectUtils_1 = require("../projectUtils");
|
|
6
6
|
const error_1 = require("../error");
|
|
7
7
|
const prompt_1 = require("../prompt");
|
|
8
|
-
const constants_1 = require("../apphosting/constants");
|
|
9
8
|
const utils = require("../utils");
|
|
10
9
|
const apphosting = require("../gcp/apphosting");
|
|
11
10
|
const apphosting_backends_list_1 = require("./apphosting-backends-list");
|
|
12
11
|
const apphosting_1 = require("../apphosting");
|
|
12
|
+
const ora = require("ora");
|
|
13
13
|
exports.command = new command_1.Command("apphosting:backends:delete <backend>")
|
|
14
14
|
.description("delete a Firebase App Hosting backend")
|
|
15
|
-
.option("-l, --location <location>", "specify the
|
|
15
|
+
.option("-l, --location <location>", "specify the location of the backend", "-")
|
|
16
16
|
.withForce()
|
|
17
17
|
.before(apphosting.ensureApiEnabled)
|
|
18
18
|
.action(async (backendId, options) => {
|
|
19
19
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
20
20
|
let location = options.location;
|
|
21
|
-
if (!backendId) {
|
|
22
|
-
throw new error_1.FirebaseError("Backend id can't be empty.");
|
|
23
|
-
}
|
|
24
|
-
if (!location) {
|
|
25
|
-
const allowedLocations = (await apphosting.listLocations(projectId)).map((loc) => loc.locationId);
|
|
26
|
-
location = await (0, prompt_1.promptOnce)({
|
|
27
|
-
name: "region",
|
|
28
|
-
type: "list",
|
|
29
|
-
default: constants_1.DEFAULT_REGION,
|
|
30
|
-
message: "Please select the region of the backend you'd like to delete:",
|
|
31
|
-
choices: allowedLocations,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
21
|
let backend;
|
|
35
|
-
|
|
36
|
-
backend = await
|
|
22
|
+
if (location === "-" || location === "") {
|
|
23
|
+
backend = await (0, apphosting_1.getBackendForAmbiguousLocation)(projectId, backendId, "Please select the location of the backend you'd like to delete:");
|
|
24
|
+
location = apphosting.parseBackendName(backend.name).location;
|
|
37
25
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
original: err,
|
|
41
|
-
});
|
|
26
|
+
else {
|
|
27
|
+
backend = await getBackendForLocation(projectId, location, backendId);
|
|
42
28
|
}
|
|
43
|
-
utils.logWarning("You are about to permanently delete
|
|
44
|
-
|
|
45
|
-
(0, apphosting_backends_list_1.printBackendsTable)(backends);
|
|
29
|
+
utils.logWarning("You are about to permanently delete this backend:");
|
|
30
|
+
(0, apphosting_backends_list_1.printBackendsTable)([backend]);
|
|
46
31
|
const confirmDeletion = await (0, prompt_1.promptOnce)({
|
|
47
32
|
type: "confirm",
|
|
48
33
|
name: "force",
|
|
@@ -50,14 +35,25 @@ exports.command = new command_1.Command("apphosting:backends:delete <backend>")
|
|
|
50
35
|
message: "Are you sure?",
|
|
51
36
|
}, options);
|
|
52
37
|
if (!confirmDeletion) {
|
|
53
|
-
|
|
38
|
+
return;
|
|
54
39
|
}
|
|
40
|
+
const spinner = ora("Deleting backend...").start();
|
|
55
41
|
try {
|
|
56
42
|
await (0, apphosting_1.deleteBackendAndPoll)(projectId, location, backendId);
|
|
57
|
-
|
|
43
|
+
spinner.succeed(`Successfully deleted the backend: ${backendId}`);
|
|
58
44
|
}
|
|
59
45
|
catch (err) {
|
|
60
|
-
|
|
46
|
+
spinner.stop();
|
|
47
|
+
throw new error_1.FirebaseError(`Failed to delete backend: ${backendId}.`, { original: err });
|
|
61
48
|
}
|
|
62
|
-
return backend;
|
|
63
49
|
});
|
|
50
|
+
async function getBackendForLocation(projectId, location, backendId) {
|
|
51
|
+
try {
|
|
52
|
+
return await apphosting.getBackend(projectId, location, backendId);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
throw new error_1.FirebaseError(`No backend named "${backendId}" found in ${location}.`, {
|
|
56
|
+
original: err,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -8,7 +8,7 @@ const logger_1 = require("../logger");
|
|
|
8
8
|
const projectUtils_1 = require("../projectUtils");
|
|
9
9
|
const apphosting = require("../gcp/apphosting");
|
|
10
10
|
const Table = require("cli-table");
|
|
11
|
-
const TABLE_HEAD = ["Backend
|
|
11
|
+
const TABLE_HEAD = ["Backend", "Repository", "URL", "Location", "Updated Date"];
|
|
12
12
|
exports.command = new command_1.Command("apphosting:backends:list")
|
|
13
13
|
.description("list Firebase App Hosting backends")
|
|
14
14
|
.option("-l, --location <location>", "list backends in the specified location", "-")
|
|
@@ -33,13 +33,12 @@ function printBackendsTable(backends) {
|
|
|
33
33
|
style: { head: ["green"] },
|
|
34
34
|
});
|
|
35
35
|
for (const backend of backends) {
|
|
36
|
-
const
|
|
36
|
+
const { location, id } = apphosting.parseBackendName(backend.name);
|
|
37
37
|
table.push([
|
|
38
|
-
|
|
38
|
+
id,
|
|
39
39
|
backend.codebase?.repository?.split("/").pop() ?? "",
|
|
40
|
-
backendLocation,
|
|
41
40
|
backend.uri.startsWith("https:") ? backend.uri : "https://" + backend.uri,
|
|
42
|
-
|
|
41
|
+
location,
|
|
43
42
|
(0, utils_1.datetimeString)(new Date(backend.updateTime)),
|
|
44
43
|
]);
|
|
45
44
|
}
|
|
@@ -8,7 +8,7 @@ const secretManager_1 = require("../gcp/secretManager");
|
|
|
8
8
|
const requireAuth_1 = require("../requireAuth");
|
|
9
9
|
const secretManager = require("../gcp/secretManager");
|
|
10
10
|
const requirePermissions_1 = require("../requirePermissions");
|
|
11
|
-
exports.command = new command_1.Command("apphosting:secrets:access <secretName
|
|
11
|
+
exports.command = new command_1.Command("apphosting:secrets:access <secretName[@version]>")
|
|
12
12
|
.description("Access secret value given secret and its version. Defaults to accessing the latest version.")
|
|
13
13
|
.before(requireAuth_1.requireAuth)
|
|
14
14
|
.before(secretManager.ensureApi)
|
|
@@ -9,9 +9,10 @@ const secretManager = require("../gcp/secretManager");
|
|
|
9
9
|
const requirePermissions_1 = require("../requirePermissions");
|
|
10
10
|
const apphosting = require("../gcp/apphosting");
|
|
11
11
|
const secrets = require("../apphosting/secrets");
|
|
12
|
+
const apphosting_1 = require("../apphosting");
|
|
12
13
|
exports.command = new command_1.Command("apphosting:secrets:grantaccess <secretName>")
|
|
13
14
|
.description("grant service accounts permissions to the provided secret")
|
|
14
|
-
.option("-l, --location <location>", "backend location")
|
|
15
|
+
.option("-l, --location <location>", "backend location", "-")
|
|
15
16
|
.option("-b, --backend <backend>", "backend name")
|
|
16
17
|
.before(requireAuth_1.requireAuth)
|
|
17
18
|
.before(secretManager.ensureApi)
|
|
@@ -27,10 +28,6 @@ exports.command = new command_1.Command("apphosting:secrets:grantaccess <secretN
|
|
|
27
28
|
.action(async (secretName, options) => {
|
|
28
29
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
29
30
|
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
30
|
-
if (!options.location) {
|
|
31
|
-
throw new error_1.FirebaseError("Missing required flag --location. See firebase apphosting:secrets:grantaccess --help for more info");
|
|
32
|
-
}
|
|
33
|
-
const location = options.location;
|
|
34
31
|
if (!options.backend) {
|
|
35
32
|
throw new error_1.FirebaseError("Missing required flag --backend. See firebase apphosting:secrets:grantaccess --help for more info");
|
|
36
33
|
}
|
|
@@ -39,7 +36,14 @@ exports.command = new command_1.Command("apphosting:secrets:grantaccess <secretN
|
|
|
39
36
|
throw new error_1.FirebaseError(`Cannot find secret ${secretName}`);
|
|
40
37
|
}
|
|
41
38
|
const backendId = options.backend;
|
|
42
|
-
const
|
|
39
|
+
const location = options.location;
|
|
40
|
+
let backend;
|
|
41
|
+
if (location === "" || location === "-") {
|
|
42
|
+
backend = await (0, apphosting_1.getBackendForAmbiguousLocation)(projectId, backendId, "Please select the location of your backend:");
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
backend = await apphosting.getBackend(projectId, location, backendId);
|
|
46
|
+
}
|
|
43
47
|
const accounts = secrets.toMulti(secrets.serviceAccountsForBackend(projectNumber, backend));
|
|
44
|
-
await secrets.grantSecretAccess(projectId, secretName, accounts);
|
|
48
|
+
await secrets.grantSecretAccess(projectId, projectNumber, secretName, accounts);
|
|
45
49
|
});
|
|
@@ -50,7 +50,7 @@ exports.command = new command_1.Command("apphosting:secrets:set <secretName>")
|
|
|
50
50
|
utils.logWarning(`To use this secret in your backend, you must grant access. You can do so in the future with ${clc.bold("firebase apphosting:secrets:grantaccess")}`);
|
|
51
51
|
}
|
|
52
52
|
else {
|
|
53
|
-
await secrets.grantSecretAccess(projectId, secretName, accounts);
|
|
53
|
+
await secrets.grantSecretAccess(projectId, projectNumber, secretName, accounts);
|
|
54
54
|
}
|
|
55
55
|
await config.maybeAddSecretToYaml(secretName);
|
|
56
56
|
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const command_1 = require("../command");
|
|
6
|
+
const dataconnectEmulator_1 = require("../emulator/dataconnectEmulator");
|
|
7
|
+
const projectUtils_1 = require("../projectUtils");
|
|
8
|
+
const load_1 = require("../dataconnect/load");
|
|
9
|
+
const fileUtils_1 = require("../dataconnect/fileUtils");
|
|
10
|
+
const logger_1 = require("../logger");
|
|
11
|
+
exports.command = new command_1.Command("dataconnect:sdk:generate")
|
|
12
|
+
.description("generates typed SDKs for your Data Connect connectors")
|
|
13
|
+
.action(async (options) => {
|
|
14
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
15
|
+
const services = (0, fileUtils_1.readFirebaseJson)(options.config);
|
|
16
|
+
for (const service of services) {
|
|
17
|
+
let configDir = service.source;
|
|
18
|
+
if (!path.isAbsolute(configDir)) {
|
|
19
|
+
const cwd = options.cwd || process.cwd();
|
|
20
|
+
configDir = path.resolve(path.join(cwd), configDir);
|
|
21
|
+
}
|
|
22
|
+
const serviceInfo = await (0, load_1.load)(projectId, service.location, configDir);
|
|
23
|
+
const args = {
|
|
24
|
+
projectId,
|
|
25
|
+
configDir,
|
|
26
|
+
auto_download: true,
|
|
27
|
+
rc: options.rc,
|
|
28
|
+
locationId: service.location,
|
|
29
|
+
};
|
|
30
|
+
const dataconnectEmulator = new dataconnectEmulator_1.DataConnectEmulator(args);
|
|
31
|
+
for (const conn of serviceInfo.connectorInfo) {
|
|
32
|
+
const output = await dataconnectEmulator.generate(conn.connectorYaml.connectorId);
|
|
33
|
+
logger_1.logger.info(output);
|
|
34
|
+
logger_1.logger.info(`Generated SDKs for ${conn.connectorYaml.connectorId}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const projectUtils_1 = require("../projectUtils");
|
|
6
|
+
const names = require("../dataconnect/names");
|
|
7
|
+
const client = require("../dataconnect/client");
|
|
8
|
+
const logger_1 = require("../logger");
|
|
9
|
+
const requirePermissions_1 = require("../requirePermissions");
|
|
10
|
+
const ensureApis_1 = require("../dataconnect/ensureApis");
|
|
11
|
+
const Table = require("cli-table");
|
|
12
|
+
exports.command = new command_1.Command("dataconnect:services:list")
|
|
13
|
+
.description("list all deployed services in your Firebase project")
|
|
14
|
+
.before(requirePermissions_1.requirePermissions, [
|
|
15
|
+
"dataconnect.services.list",
|
|
16
|
+
"dataconnect.schemas.list",
|
|
17
|
+
"dataconnect.connectors.list",
|
|
18
|
+
])
|
|
19
|
+
.action(async (options) => {
|
|
20
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
21
|
+
await (0, ensureApis_1.ensureApis)(projectId);
|
|
22
|
+
const services = await client.listAllServices(projectId);
|
|
23
|
+
const table = new Table({
|
|
24
|
+
head: [
|
|
25
|
+
"Service ID",
|
|
26
|
+
"Location",
|
|
27
|
+
"Data Source",
|
|
28
|
+
"Schema Last Updated",
|
|
29
|
+
"Connector ID",
|
|
30
|
+
"Connector Last Updated",
|
|
31
|
+
],
|
|
32
|
+
style: { head: ["yellow"] },
|
|
33
|
+
});
|
|
34
|
+
const jsonOutput = { services: [] };
|
|
35
|
+
for (const service of services) {
|
|
36
|
+
let schema = {
|
|
37
|
+
name: "",
|
|
38
|
+
primaryDatasource: {},
|
|
39
|
+
source: { files: [] },
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
schema = await client.getSchema(service.name);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
logger_1.logger.debug(`Error fetching schema: ${err}`);
|
|
46
|
+
}
|
|
47
|
+
const connectors = await client.listConnectors(service.name);
|
|
48
|
+
const serviceName = names.parseServiceName(service.name);
|
|
49
|
+
const instanceName = schema?.primaryDatasource.postgresql?.cloudSql.instance ?? "";
|
|
50
|
+
const instanceId = instanceName.split("/").pop();
|
|
51
|
+
const dbId = schema?.primaryDatasource.postgresql?.database ?? "";
|
|
52
|
+
const dbName = `CloudSQL Instance: ${instanceId}\nDatabase:${dbId}`;
|
|
53
|
+
table.push([
|
|
54
|
+
serviceName.serviceId,
|
|
55
|
+
serviceName.location,
|
|
56
|
+
dbName,
|
|
57
|
+
schema?.updateTime ?? "",
|
|
58
|
+
"",
|
|
59
|
+
"",
|
|
60
|
+
]);
|
|
61
|
+
const serviceJson = {
|
|
62
|
+
serviceId: serviceName.serviceId,
|
|
63
|
+
location: serviceName.location,
|
|
64
|
+
datasource: dbName,
|
|
65
|
+
schemaUpdateTime: schema?.updateTime,
|
|
66
|
+
connectors: [],
|
|
67
|
+
};
|
|
68
|
+
for (const conn of connectors) {
|
|
69
|
+
const connectorName = names.parseConnectorName(conn.name);
|
|
70
|
+
table.push(["", "", "", "", connectorName.connectorId, conn.updateTime]);
|
|
71
|
+
serviceJson.connectors.push({
|
|
72
|
+
connectorId: connectorName.connectorId,
|
|
73
|
+
connectorLastUpdated: conn.updateTime ?? "",
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
jsonOutput.services.push(serviceJson);
|
|
77
|
+
}
|
|
78
|
+
logger_1.logger.info(table.toString());
|
|
79
|
+
return jsonOutput;
|
|
80
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const projectUtils_1 = require("../projectUtils");
|
|
6
|
+
const ensureApis_1 = require("../dataconnect/ensureApis");
|
|
7
|
+
const requirePermissions_1 = require("../requirePermissions");
|
|
8
|
+
const fileUtils_1 = require("../dataconnect/fileUtils");
|
|
9
|
+
const schemaMigration_1 = require("../dataconnect/schemaMigration");
|
|
10
|
+
const requireAuth_1 = require("../requireAuth");
|
|
11
|
+
exports.command = new command_1.Command("dataconnect:sql:diff [serviceId]")
|
|
12
|
+
.description("displays the differences between a local DataConnect schema and your CloudSQL database's current schema")
|
|
13
|
+
.before(requirePermissions_1.requirePermissions, [
|
|
14
|
+
"firebasedataconnect.services.list",
|
|
15
|
+
"firebasedataconnect.schemas.list",
|
|
16
|
+
"firebasedataconnect.schemas.update",
|
|
17
|
+
])
|
|
18
|
+
.before(requireAuth_1.requireAuth)
|
|
19
|
+
.action(async (serviceId, options) => {
|
|
20
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
21
|
+
await (0, ensureApis_1.ensureApis)(projectId);
|
|
22
|
+
const serviceInfo = await (0, fileUtils_1.pickService)(projectId, options.config, serviceId);
|
|
23
|
+
const diffs = await (0, schemaMigration_1.diffSchema)(serviceInfo.schema);
|
|
24
|
+
return { projectId, serviceId, diffs };
|
|
25
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const projectUtils_1 = require("../projectUtils");
|
|
6
|
+
const fileUtils_1 = require("../dataconnect/fileUtils");
|
|
7
|
+
const error_1 = require("../error");
|
|
8
|
+
const schemaMigration_1 = require("../dataconnect/schemaMigration");
|
|
9
|
+
const requireAuth_1 = require("../requireAuth");
|
|
10
|
+
const requirePermissions_1 = require("../requirePermissions");
|
|
11
|
+
const ensureApis_1 = require("../dataconnect/ensureApis");
|
|
12
|
+
const utils_1 = require("../utils");
|
|
13
|
+
exports.command = new command_1.Command("dataconnect:sql:migrate [serviceId]")
|
|
14
|
+
.description("migrates your CloudSQL database's schema to match your local DataConnect schema")
|
|
15
|
+
.before(requirePermissions_1.requirePermissions, [
|
|
16
|
+
"firebasedataconnect.services.list",
|
|
17
|
+
"firebasedataconnect.schemas.list",
|
|
18
|
+
"firebasedataconnect.schemas.update",
|
|
19
|
+
"cloudsql.instances.connect",
|
|
20
|
+
"cloudsql.users.create",
|
|
21
|
+
])
|
|
22
|
+
.before(requireAuth_1.requireAuth)
|
|
23
|
+
.withForce("Execute any required database changes without prompting")
|
|
24
|
+
.action(async (serviceId, options) => {
|
|
25
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
26
|
+
await (0, ensureApis_1.ensureApis)(projectId);
|
|
27
|
+
const serviceInfo = await (0, fileUtils_1.pickService)(projectId, options.config, serviceId);
|
|
28
|
+
const instanceId = serviceInfo.dataConnectYaml.schema.datasource.postgresql?.cloudSql.instanceId;
|
|
29
|
+
if (!instanceId) {
|
|
30
|
+
throw new error_1.FirebaseError("dataconnect.yaml is missing field schema.datasource.postgresql.cloudsql.instanceId");
|
|
31
|
+
}
|
|
32
|
+
const diffs = await (0, schemaMigration_1.migrateSchema)({
|
|
33
|
+
options,
|
|
34
|
+
schema: serviceInfo.schema,
|
|
35
|
+
allowNonInteractiveMigration: true,
|
|
36
|
+
validateOnly: true,
|
|
37
|
+
});
|
|
38
|
+
if (diffs.length) {
|
|
39
|
+
(0, utils_1.logLabeledSuccess)("dataconnect", `Database schema sucessfully migrated! Run 'firebase deploy' to deploy your new schema to your Data Connect service.`);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
(0, utils_1.logLabeledSuccess)("dataconnect", "Database schema is already up to date!");
|
|
43
|
+
}
|
|
44
|
+
return { projectId, serviceId, diffs };
|
|
45
|
+
});
|
package/lib/commands/deploy.js
CHANGED
|
@@ -23,6 +23,7 @@ exports.VALID_DEPLOY_TARGETS = [
|
|
|
23
23
|
"hosting",
|
|
24
24
|
"remoteconfig",
|
|
25
25
|
"extensions",
|
|
26
|
+
"dataconnect",
|
|
26
27
|
];
|
|
27
28
|
exports.TARGET_PERMISSIONS = {
|
|
28
29
|
database: ["firebasedatabase.instances.update"],
|
|
@@ -47,6 +48,29 @@ exports.TARGET_PERMISSIONS = {
|
|
|
47
48
|
"firebaserules.releases.update",
|
|
48
49
|
],
|
|
49
50
|
remoteconfig: ["cloudconfig.configs.get", "cloudconfig.configs.update"],
|
|
51
|
+
dataconnect: [
|
|
52
|
+
"cloudsql.databases.create",
|
|
53
|
+
"cloudsql.databases.update",
|
|
54
|
+
"cloudsql.instances.connect",
|
|
55
|
+
"cloudsql.instances.create",
|
|
56
|
+
"cloudsql.instances.get",
|
|
57
|
+
"cloudsql.instances.list",
|
|
58
|
+
"cloudsql.instances.update",
|
|
59
|
+
"cloudsql.users.create",
|
|
60
|
+
"firebasedataconnect.connectors.create",
|
|
61
|
+
"firebasedataconnect.connectors.delete",
|
|
62
|
+
"firebasedataconnect.connectors.list",
|
|
63
|
+
"firebasedataconnect.connectors.update",
|
|
64
|
+
"firebasedataconnect.operations.get",
|
|
65
|
+
"firebasedataconnect.services.create",
|
|
66
|
+
"firebasedataconnect.services.delete",
|
|
67
|
+
"firebasedataconnect.services.update",
|
|
68
|
+
"firebasedataconnect.services.list",
|
|
69
|
+
"firebasedataconnect.schemas.create",
|
|
70
|
+
"firebasedataconnect.schemas.delete",
|
|
71
|
+
"firebasedataconnect.schemas.list",
|
|
72
|
+
"firebasedataconnect.schemas.update",
|
|
73
|
+
],
|
|
50
74
|
};
|
|
51
75
|
exports.command = new command_1.Command("deploy")
|
|
52
76
|
.description("deploy code and assets to your Firebase project")
|
|
@@ -56,7 +80,9 @@ exports.command = new command_1.Command("deploy")
|
|
|
56
80
|
.option("--only <targets>", 'only deploy to specified, comma-separated targets (e.g. "hosting,storage"). For functions, ' +
|
|
57
81
|
'can specify filters with colons to scope function deploys to only those functions (e.g. "--only functions:func1,functions:func2"). ' +
|
|
58
82
|
"When filtering based on export groups (the exported module object keys), use dots to specify group names " +
|
|
59
|
-
'(e.g. "--only functions:group1.subgroup1,functions:group2)"'
|
|
83
|
+
'(e.g. "--only functions:group1.subgroup1,functions:group2)"' +
|
|
84
|
+
"For data connect, can specify filters with colons to deploy only a service, connector, or schema" +
|
|
85
|
+
'(e.g. "--only dataconnect:serviceId,dataconnect:serviceId:connectorId,dataconnect:serviceId:schema"). ')
|
|
60
86
|
.option("--except <targets>", 'deploy to all targets except specified (e.g. "database")')
|
|
61
87
|
.before(requireConfig_1.requireConfig)
|
|
62
88
|
.before((options) => {
|
package/lib/commands/index.js
CHANGED
|
@@ -200,6 +200,17 @@ function load(client) {
|
|
|
200
200
|
client.setup.emulators.pubsub = loadCommand("setup-emulators-pubsub");
|
|
201
201
|
client.setup.emulators.storage = loadCommand("setup-emulators-storage");
|
|
202
202
|
client.setup.emulators.ui = loadCommand("setup-emulators-ui");
|
|
203
|
+
if (experiments.isEnabled("dataconnect")) {
|
|
204
|
+
client.dataconnect = {};
|
|
205
|
+
client.setup.emulators.dataconnect = loadCommand("setup-emulators-dataconnect");
|
|
206
|
+
client.dataconnect.services = {};
|
|
207
|
+
client.dataconnect.services.list = loadCommand("dataconnect-services-list");
|
|
208
|
+
client.dataconnect.sql = {};
|
|
209
|
+
client.dataconnect.sql.diff = loadCommand("dataconnect-sql-diff");
|
|
210
|
+
client.dataconnect.sql.migrate = loadCommand("dataconnect-sql-migrate");
|
|
211
|
+
client.dataconnect.sdk = {};
|
|
212
|
+
client.dataconnect.sdk.generate = loadCommand("dataconnect-sdk-generate");
|
|
213
|
+
}
|
|
203
214
|
client.target = loadCommand("target");
|
|
204
215
|
client.target.apply = loadCommand("target-apply");
|
|
205
216
|
client.target.clear = loadCommand("target-clear");
|
package/lib/commands/init.js
CHANGED
|
@@ -69,10 +69,17 @@ const choices = [
|
|
|
69
69
|
checked: false,
|
|
70
70
|
},
|
|
71
71
|
];
|
|
72
|
-
if ((0, experiments_1.isEnabled)("
|
|
72
|
+
if ((0, experiments_1.isEnabled)("genkit")) {
|
|
73
73
|
choices.push({
|
|
74
|
-
value: "
|
|
75
|
-
name: "
|
|
74
|
+
value: "genkit",
|
|
75
|
+
name: "Genkit: Setup a new Genkit project with Firebase",
|
|
76
|
+
checked: false,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if ((0, experiments_1.isEnabled)("dataconnect")) {
|
|
80
|
+
choices.push({
|
|
81
|
+
value: "dataconnect",
|
|
82
|
+
name: "Data Connect: Set up a Firebase Data Connect service.",
|
|
76
83
|
checked: false,
|
|
77
84
|
});
|
|
78
85
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const download_1 = require("../emulator/download");
|
|
6
|
+
const types_1 = require("../emulator/types");
|
|
7
|
+
const NAME = types_1.Emulators.DATACONNECT;
|
|
8
|
+
exports.command = new command_1.Command(`setup:emulators:${NAME}`)
|
|
9
|
+
.description(`downloads the ${NAME} emulator`)
|
|
10
|
+
.action(() => {
|
|
11
|
+
return (0, download_1.downloadEmulator)(NAME);
|
|
12
|
+
});
|
package/lib/config.js
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.build = void 0;
|
|
4
|
+
const dataconnectEmulator_1 = require("../emulator/dataconnectEmulator");
|
|
5
|
+
const error_1 = require("../error");
|
|
6
|
+
const graphqlError_1 = require("./graphqlError");
|
|
7
|
+
async function build(options, configDir) {
|
|
8
|
+
const projectId = options.project ?? "demo-test";
|
|
9
|
+
const args = {
|
|
10
|
+
projectId,
|
|
11
|
+
configDir,
|
|
12
|
+
auto_download: true,
|
|
13
|
+
rc: options.rc,
|
|
14
|
+
};
|
|
15
|
+
const dataconnectEmulator = new dataconnectEmulator_1.DataConnectEmulator(args);
|
|
16
|
+
const buildResult = await dataconnectEmulator.build();
|
|
17
|
+
if (buildResult?.errors?.length) {
|
|
18
|
+
throw new error_1.FirebaseError(`There are errors in your schema and connector files:\n${buildResult.errors.map(graphqlError_1.prettify).join("\n")}`);
|
|
19
|
+
}
|
|
20
|
+
return buildResult?.metadata ?? {};
|
|
21
|
+
}
|
|
22
|
+
exports.build = build;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.grantRolesToCloudSqlServiceAccount = void 0;
|
|
4
|
+
const iam = require("../gcp/iam");
|
|
5
|
+
const resourceManager_1 = require("../gcp/resourceManager");
|
|
6
|
+
const cloudSqlAdmin = require("../gcp/cloudsql/cloudsqladmin");
|
|
7
|
+
const error_1 = require("../error");
|
|
8
|
+
async function grantRolesToCloudSqlServiceAccount(projectId, instanceId, roles) {
|
|
9
|
+
const instance = await cloudSqlAdmin.getInstance(projectId, instanceId);
|
|
10
|
+
const saEmail = instance.serviceAccountEmailAddress;
|
|
11
|
+
const policy = await (0, resourceManager_1.getIamPolicy)(projectId);
|
|
12
|
+
const requiredBindings = roles.map((r) => {
|
|
13
|
+
const binding = {
|
|
14
|
+
role: r,
|
|
15
|
+
members: [`serviceAccount:${saEmail}`],
|
|
16
|
+
};
|
|
17
|
+
return binding;
|
|
18
|
+
});
|
|
19
|
+
const updated = iam.mergeBindings(policy, requiredBindings);
|
|
20
|
+
if (updated) {
|
|
21
|
+
try {
|
|
22
|
+
await (0, resourceManager_1.setIamPolicy)(projectId, policy, "bindings");
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
iam.printManualIamConfig(requiredBindings, projectId, "dataconnect");
|
|
26
|
+
throw new error_1.FirebaseError("Unable to make required IAM policy changes.");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.grantRolesToCloudSqlServiceAccount = grantRolesToCloudSqlServiceAccount;
|