firebase-tools 13.11.0 → 13.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dataconnect/client.js +3 -19
- package/lib/dataconnect/provisionCloudSql.js +13 -7
- package/lib/deploy/dataconnect/deploy.js +1 -0
- package/lib/emulator/controller.js +1 -1
- package/lib/emulator/dataconnectEmulator.js +14 -3
- package/lib/gcp/cloudsql/cloudsqladmin.js +13 -2
- package/lib/init/features/dataconnect/index.js +17 -10
- package/package.json +1 -1
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.upsertConnector = exports.listConnectors = exports.deleteConnector = exports.getConnector = exports.upsertSchema = exports.getSchema = exports.deleteService = exports.createService = exports.
|
|
3
|
+
exports.upsertConnector = exports.listConnectors = exports.deleteConnector = exports.getConnector = exports.upsertSchema = exports.getSchema = exports.deleteService = exports.createService = exports.listAllServices = exports.listLocations = void 0;
|
|
4
4
|
const api_1 = require("../api");
|
|
5
5
|
const apiv2_1 = require("../apiv2");
|
|
6
6
|
const operationPoller = require("../operation-poller");
|
|
7
7
|
const types = require("./types");
|
|
8
|
-
const logger_1 = require("../logger");
|
|
9
8
|
const DATACONNECT_API_VERSION = "v1alpha";
|
|
10
9
|
const dataconnectClient = () => new apiv2_1.Client({
|
|
11
10
|
urlPrefix: (0, api_1.dataconnectOrigin)(),
|
|
@@ -19,26 +18,11 @@ async function listLocations(projectId) {
|
|
|
19
18
|
}
|
|
20
19
|
exports.listLocations = listLocations;
|
|
21
20
|
async function listAllServices(projectId) {
|
|
22
|
-
const locations = await listLocations(projectId);
|
|
23
|
-
let services = [];
|
|
24
|
-
await Promise.all(locations.map(async (l) => {
|
|
25
|
-
try {
|
|
26
|
-
const locationServices = await listServices(projectId, l);
|
|
27
|
-
services = services.concat(locationServices);
|
|
28
|
-
}
|
|
29
|
-
catch (err) {
|
|
30
|
-
logger_1.logger.debug(`Unable to listServices in ${l}: ${err}`);
|
|
31
|
-
}
|
|
32
|
-
}));
|
|
33
|
-
return services;
|
|
34
|
-
}
|
|
35
|
-
exports.listAllServices = listAllServices;
|
|
36
|
-
async function listServices(projectId, locationId) {
|
|
37
21
|
var _a;
|
|
38
|
-
const res = await dataconnectClient().get(`/projects/${projectId}/locations
|
|
22
|
+
const res = await dataconnectClient().get(`/projects/${projectId}/locations/-/services`);
|
|
39
23
|
return (_a = res.body.services) !== null && _a !== void 0 ? _a : [];
|
|
40
24
|
}
|
|
41
|
-
exports.
|
|
25
|
+
exports.listAllServices = listAllServices;
|
|
42
26
|
async function createService(projectId, locationId, serviceId) {
|
|
43
27
|
const op = await dataconnectClient().post(`/projects/${projectId}/locations/${locationId}/services`, {
|
|
44
28
|
name: `projects/${projectId}/locations/${locationId}/services/${serviceId}`,
|
|
@@ -9,8 +9,8 @@ const GOOGLE_ML_INTEGRATION_ROLE = "roles/aiplatform.user";
|
|
|
9
9
|
const freeTrial_1 = require("./freeTrial");
|
|
10
10
|
const error_1 = require("../error");
|
|
11
11
|
async function provisionCloudSql(args) {
|
|
12
|
-
let connectionName;
|
|
13
|
-
const { projectId, locationId, instanceId, databaseId, enableGoogleMlIntegration, silent } = args;
|
|
12
|
+
let connectionName = "";
|
|
13
|
+
const { projectId, locationId, instanceId, databaseId, enableGoogleMlIntegration, waitForCreation, silent, } = args;
|
|
14
14
|
try {
|
|
15
15
|
const existingInstance = await cloudSqlAdminClient.getInstance(projectId, instanceId);
|
|
16
16
|
silent || utils.logLabeledBullet("dataconnect", `Found existing instance ${instanceId}.`);
|
|
@@ -35,11 +35,17 @@ async function provisionCloudSql(args) {
|
|
|
35
35
|
throw new error_1.FirebaseError("Free trial unavailable.");
|
|
36
36
|
}
|
|
37
37
|
silent ||
|
|
38
|
-
utils.logLabeledBullet("dataconnect", `CloudSQL instance '${instanceId}' not found, creating it
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
utils.logLabeledBullet("dataconnect", `CloudSQL instance '${instanceId}' not found, creating it.` +
|
|
39
|
+
`\nThis instance is provided under the terms of the Data Connect free trial ${(0, freeTrial_1.freeTrialTermsLink)()}` +
|
|
40
|
+
`\nMonitor the progress at ${cloudSqlAdminClient.instanceConsoleLink(projectId, instanceId)}`);
|
|
41
|
+
const newInstance = await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.createInstance(projectId, locationId, instanceId, enableGoogleMlIntegration, waitForCreation), "Creating your instance...");
|
|
42
|
+
if (newInstance) {
|
|
43
|
+
silent || utils.logLabeledBullet("dataconnect", "Instance created");
|
|
44
|
+
connectionName = (newInstance === null || newInstance === void 0 ? void 0 : newInstance.connectionName) || "";
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
silent || utils.logLabeledBullet("dataconnect", "Instance creation process started");
|
|
48
|
+
}
|
|
43
49
|
}
|
|
44
50
|
try {
|
|
45
51
|
await cloudSqlAdminClient.getDatabase(projectId, instanceId, databaseId);
|
|
@@ -540,7 +540,7 @@ async function startAll(options, showUI = true, runningTestScript = false) {
|
|
|
540
540
|
});
|
|
541
541
|
await startEmulator(dataConnectEmulator);
|
|
542
542
|
if (!utils.isVSCodeExtension()) {
|
|
543
|
-
dataConnectEmulator.connectToPostgres();
|
|
543
|
+
await dataConnectEmulator.connectToPostgres();
|
|
544
544
|
}
|
|
545
545
|
}
|
|
546
546
|
if (listenForEmulator.storage) {
|
|
@@ -118,11 +118,22 @@ class DataConnectEmulator {
|
|
|
118
118
|
exports.DataConnectEmulator = DataConnectEmulator;
|
|
119
119
|
class DataConnectEmulatorClient {
|
|
120
120
|
constructor() {
|
|
121
|
-
this.client =
|
|
121
|
+
this.client = undefined;
|
|
122
122
|
}
|
|
123
123
|
async configureEmulator(body) {
|
|
124
|
-
|
|
125
|
-
|
|
124
|
+
if (!this.client) {
|
|
125
|
+
this.client = registry_1.EmulatorRegistry.client(types_1.Emulators.DATACONNECT);
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
const res = await this.client.post("emulator/configure", body);
|
|
129
|
+
return res;
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
if (err.status === 500) {
|
|
133
|
+
throw new error_1.FirebaseError(`Data Connect emulator: ${err.context.body.message}`);
|
|
134
|
+
}
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
126
137
|
}
|
|
127
138
|
}
|
|
128
139
|
exports.DataConnectEmulatorClient = DataConnectEmulatorClient;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
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;
|
|
3
|
+
exports.listUsers = exports.deleteUser = exports.getUser = exports.createUser = exports.createDatabase = exports.getDatabase = exports.listDatabases = exports.updateInstanceForDataConnect = exports.createInstance = exports.instanceConsoleLink = exports.getInstance = exports.listInstances = void 0;
|
|
4
4
|
const apiv2_1 = require("../../apiv2");
|
|
5
5
|
const api_1 = require("../../api");
|
|
6
6
|
const operationPoller = require("../../operation-poller");
|
|
7
|
+
const error_1 = require("../../error");
|
|
7
8
|
const API_VERSION = "v1";
|
|
8
9
|
const client = new apiv2_1.Client({
|
|
9
10
|
urlPrefix: (0, api_1.cloudSQLAdminOrigin)(),
|
|
@@ -18,10 +19,17 @@ async function listInstances(projectId) {
|
|
|
18
19
|
exports.listInstances = listInstances;
|
|
19
20
|
async function getInstance(projectId, instanceId) {
|
|
20
21
|
const res = await client.get(`projects/${projectId}/instances/${instanceId}`);
|
|
22
|
+
if (res.body.state === "FAILED") {
|
|
23
|
+
throw new error_1.FirebaseError(`Cloud SQL instance ${instanceId} is in a failed state.\nGo to ${instanceConsoleLink(projectId, instanceId)} to repair or delete it.`);
|
|
24
|
+
}
|
|
21
25
|
return res.body;
|
|
22
26
|
}
|
|
23
27
|
exports.getInstance = getInstance;
|
|
24
|
-
|
|
28
|
+
function instanceConsoleLink(projectId, instanceId) {
|
|
29
|
+
return `https://console.cloud.google.com/sql/instances/${instanceId}/overview?project=${projectId}`;
|
|
30
|
+
}
|
|
31
|
+
exports.instanceConsoleLink = instanceConsoleLink;
|
|
32
|
+
async function createInstance(projectId, location, instanceId, enableGoogleMlIntegration, waitForCreation) {
|
|
25
33
|
const databaseFlags = [{ name: "cloudsql.iam_authentication", value: "on" }];
|
|
26
34
|
if (enableGoogleMlIntegration) {
|
|
27
35
|
databaseFlags.push({ name: "cloudsql.enable_google_ml_integration", value: "on" });
|
|
@@ -47,6 +55,9 @@ async function createInstance(projectId, location, instanceId, enableGoogleMlInt
|
|
|
47
55
|
},
|
|
48
56
|
},
|
|
49
57
|
});
|
|
58
|
+
if (!waitForCreation) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
50
61
|
const opName = `projects/${projectId}/operations/${op.body.name}`;
|
|
51
62
|
const pollRes = await operationPoller.pollOperation({
|
|
52
63
|
apiOrigin: (0, api_1.cloudSQLAdminOrigin)(),
|
|
@@ -11,6 +11,7 @@ const ensureApis_1 = require("../../../dataconnect/ensureApis");
|
|
|
11
11
|
const client_1 = require("../../../dataconnect/client");
|
|
12
12
|
const emulators_1 = require("../emulators");
|
|
13
13
|
const names_1 = require("../../../dataconnect/names");
|
|
14
|
+
const logger_1 = require("../../../logger");
|
|
14
15
|
const TEMPLATE_ROOT = (0, path_1.resolve)(__dirname, "../../../../templates/init/dataconnect/");
|
|
15
16
|
const DATACONNECT_YAML_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "dataconnect.yaml"), "utf8");
|
|
16
17
|
const CONNECTOR_YAML_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "connector.yaml"), "utf8");
|
|
@@ -63,6 +64,7 @@ async function doSetup(setup, config) {
|
|
|
63
64
|
instanceId: info.cloudSqlInstanceId,
|
|
64
65
|
databaseId: info.cloudSqlDatabase,
|
|
65
66
|
enableGoogleMlIntegration: false,
|
|
67
|
+
waitForCreation: false,
|
|
66
68
|
});
|
|
67
69
|
}
|
|
68
70
|
}
|
|
@@ -195,17 +197,22 @@ async function promptForDatabase(setup, config, info) {
|
|
|
195
197
|
config.set("dataconnect.location", info.locationId);
|
|
196
198
|
}
|
|
197
199
|
if (!info.isNewInstance && setup.projectId) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
choices.push({ name: "Create a new database", value: "" });
|
|
203
|
-
if (dbs.length) {
|
|
204
|
-
info.cloudSqlDatabase = await (0, prompt_1.promptOnce)({
|
|
205
|
-
message: `Which database in ${info.cloudSqlInstanceId} would you like to use?`,
|
|
206
|
-
type: "list",
|
|
207
|
-
choices,
|
|
200
|
+
try {
|
|
201
|
+
const dbs = await cloudsql.listDatabases(setup.projectId, info.cloudSqlInstanceId);
|
|
202
|
+
const choices = dbs.map((d) => {
|
|
203
|
+
return { name: d.name, value: d.name };
|
|
208
204
|
});
|
|
205
|
+
choices.push({ name: "Create a new database", value: "" });
|
|
206
|
+
if (dbs.length) {
|
|
207
|
+
info.cloudSqlDatabase = await (0, prompt_1.promptOnce)({
|
|
208
|
+
message: `Which database in ${info.cloudSqlInstanceId} would you like to use?`,
|
|
209
|
+
type: "list",
|
|
210
|
+
choices,
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
logger_1.logger.debug(`[dataconnect] Cannot list databases during init: ${err}`);
|
|
209
216
|
}
|
|
210
217
|
}
|
|
211
218
|
if (info.cloudSqlDatabase === "") {
|