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
|
@@ -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;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.firebaseowner = exports.setupIAMUser = exports.execute = void 0;
|
|
4
|
+
const pg = require("pg");
|
|
5
|
+
const cloud_sql_connector_1 = require("@google-cloud/cloud-sql-connector");
|
|
6
|
+
const requireAuth_1 = require("../../requireAuth");
|
|
7
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
8
|
+
const cloudSqlAdminClient = require("./cloudsqladmin");
|
|
9
|
+
const utils = require("../../utils");
|
|
10
|
+
const logger_1 = require("../../logger");
|
|
11
|
+
const error_1 = require("../../error");
|
|
12
|
+
const fbToolsAuthClient_1 = require("./fbToolsAuthClient");
|
|
13
|
+
async function execute(sqlStatements, opts) {
|
|
14
|
+
const logFn = opts.silent ? logger_1.logger.debug : logger_1.logger.info;
|
|
15
|
+
const instance = await cloudSqlAdminClient.getInstance(opts.projectId, opts.instanceId);
|
|
16
|
+
const user = await cloudSqlAdminClient.getUser(opts.projectId, opts.instanceId, opts.username);
|
|
17
|
+
const connectionName = instance.connectionName;
|
|
18
|
+
if (!connectionName) {
|
|
19
|
+
throw new error_1.FirebaseError(`Could not get instance conection string for ${opts.instanceId}:${opts.databaseId}`);
|
|
20
|
+
}
|
|
21
|
+
let connector;
|
|
22
|
+
let pool;
|
|
23
|
+
switch (user.type) {
|
|
24
|
+
case "CLOUD_IAM_USER": {
|
|
25
|
+
connector = new cloud_sql_connector_1.Connector({
|
|
26
|
+
auth: new fbToolsAuthClient_1.FBToolsAuthClient(),
|
|
27
|
+
});
|
|
28
|
+
const clientOpts = await connector.getOptions({
|
|
29
|
+
instanceConnectionName: connectionName,
|
|
30
|
+
ipType: cloud_sql_connector_1.IpAddressTypes.PUBLIC,
|
|
31
|
+
authType: cloud_sql_connector_1.AuthTypes.IAM,
|
|
32
|
+
});
|
|
33
|
+
pool = new pg.Pool({
|
|
34
|
+
...clientOpts,
|
|
35
|
+
user: opts.username,
|
|
36
|
+
database: opts.databaseId,
|
|
37
|
+
max: 1,
|
|
38
|
+
});
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
case "CLOUD_IAM_SERVICE_ACCOUNT": {
|
|
42
|
+
connector = new cloud_sql_connector_1.Connector();
|
|
43
|
+
const clientOpts = await connector.getOptions({
|
|
44
|
+
instanceConnectionName: connectionName,
|
|
45
|
+
ipType: cloud_sql_connector_1.IpAddressTypes.PUBLIC,
|
|
46
|
+
authType: cloud_sql_connector_1.AuthTypes.IAM,
|
|
47
|
+
});
|
|
48
|
+
pool = new pg.Pool({
|
|
49
|
+
...clientOpts,
|
|
50
|
+
user: opts.username,
|
|
51
|
+
database: opts.databaseId,
|
|
52
|
+
max: 1,
|
|
53
|
+
});
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
default: {
|
|
57
|
+
if (!opts.password) {
|
|
58
|
+
throw new error_1.FirebaseError(`Cannot connect as BUILT_IN user without a password.`);
|
|
59
|
+
}
|
|
60
|
+
connector = new cloud_sql_connector_1.Connector({
|
|
61
|
+
auth: new fbToolsAuthClient_1.FBToolsAuthClient(),
|
|
62
|
+
});
|
|
63
|
+
const clientOpts = await connector.getOptions({
|
|
64
|
+
instanceConnectionName: connectionName,
|
|
65
|
+
ipType: cloud_sql_connector_1.IpAddressTypes.PUBLIC,
|
|
66
|
+
});
|
|
67
|
+
pool = new pg.Pool({
|
|
68
|
+
...clientOpts,
|
|
69
|
+
user: opts.username,
|
|
70
|
+
password: opts.password,
|
|
71
|
+
database: opts.databaseId,
|
|
72
|
+
max: 1,
|
|
73
|
+
});
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const s of sqlStatements) {
|
|
78
|
+
logFn(`Executing: '${s}' as ${opts.username}`);
|
|
79
|
+
try {
|
|
80
|
+
await pool.query(s);
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
throw new error_1.FirebaseError(`Error executing ${err}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
await pool.end();
|
|
87
|
+
connector.close();
|
|
88
|
+
}
|
|
89
|
+
exports.execute = execute;
|
|
90
|
+
async function setupIAMUser(instanceId, databaseId, options) {
|
|
91
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
92
|
+
const account = await (0, requireAuth_1.requireAuth)(options);
|
|
93
|
+
if (!account) {
|
|
94
|
+
throw new error_1.FirebaseError("No account to set up! Run `firebase login` or set Application Default Credentials");
|
|
95
|
+
}
|
|
96
|
+
const setupUser = "firebasesuperuser";
|
|
97
|
+
const temporaryPassword = utils.generateId(20);
|
|
98
|
+
await cloudSqlAdminClient.createUser(projectId, instanceId, "BUILT_IN", setupUser, temporaryPassword);
|
|
99
|
+
const { user, mode } = toDatabaseUser(account);
|
|
100
|
+
await cloudSqlAdminClient.createUser(projectId, instanceId, mode, user);
|
|
101
|
+
const grants = [
|
|
102
|
+
`do
|
|
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`,
|
|
120
|
+
];
|
|
121
|
+
await execute(grants, {
|
|
122
|
+
projectId,
|
|
123
|
+
instanceId,
|
|
124
|
+
databaseId,
|
|
125
|
+
username: setupUser,
|
|
126
|
+
password: temporaryPassword,
|
|
127
|
+
silent: true,
|
|
128
|
+
});
|
|
129
|
+
return user;
|
|
130
|
+
}
|
|
131
|
+
exports.setupIAMUser = setupIAMUser;
|
|
132
|
+
function firebaseowner(databaseId) {
|
|
133
|
+
return `firebaseowner_${databaseId}_public`;
|
|
134
|
+
}
|
|
135
|
+
exports.firebaseowner = firebaseowner;
|
|
136
|
+
function toDatabaseUser(account) {
|
|
137
|
+
let mode = "CLOUD_IAM_USER";
|
|
138
|
+
let user = account;
|
|
139
|
+
if (account.endsWith(".gserviceaccount.com")) {
|
|
140
|
+
user = account.replace(".gserviceaccount.com", "");
|
|
141
|
+
mode = "CLOUD_IAM_SERVICE_ACCOUNT";
|
|
142
|
+
}
|
|
143
|
+
return { user, mode };
|
|
144
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FBToolsAuthClient = void 0;
|
|
4
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
5
|
+
const apiv2 = require("../../apiv2");
|
|
6
|
+
const error_1 = require("../../error");
|
|
7
|
+
class FBToolsAuthClient extends google_auth_library_1.AuthClient {
|
|
8
|
+
async request(opts) {
|
|
9
|
+
if (!opts.url) {
|
|
10
|
+
throw new error_1.FirebaseError("opts.url was undefined");
|
|
11
|
+
}
|
|
12
|
+
const url = new URL(opts.url);
|
|
13
|
+
const client = new apiv2.Client({
|
|
14
|
+
urlPrefix: url.origin,
|
|
15
|
+
auth: true,
|
|
16
|
+
});
|
|
17
|
+
const res = await client.request({
|
|
18
|
+
method: opts.method ?? "POST",
|
|
19
|
+
path: url.pathname,
|
|
20
|
+
queryParams: opts.params,
|
|
21
|
+
body: opts.data,
|
|
22
|
+
responseType: opts.responseType,
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
config: opts,
|
|
26
|
+
status: res.status,
|
|
27
|
+
statusText: res.response.statusText,
|
|
28
|
+
data: res.body,
|
|
29
|
+
headers: res.response.headers,
|
|
30
|
+
request: {},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async getAccessToken() {
|
|
34
|
+
return { token: await apiv2.getAccessToken() };
|
|
35
|
+
}
|
|
36
|
+
async getRequestHeaders() {
|
|
37
|
+
const token = await this.getAccessToken();
|
|
38
|
+
return {
|
|
39
|
+
...apiv2.STANDARD_HEADERS,
|
|
40
|
+
Authorization: `Bearer ${token.token}`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.FBToolsAuthClient = FBToolsAuthClient;
|
package/lib/gcp/devConnect.js
CHANGED
|
@@ -87,7 +87,7 @@ async function getGitRepositoryLink(projectId, location, connectionId, gitReposi
|
|
|
87
87
|
}
|
|
88
88
|
exports.getGitRepositoryLink = getGitRepositoryLink;
|
|
89
89
|
function serviceAgentEmail(projectNumber) {
|
|
90
|
-
return `service-${projectNumber}@${(0, api_1.
|
|
90
|
+
return `service-${projectNumber}@${(0, api_1.developerConnectP4SADomain)()}`;
|
|
91
91
|
}
|
|
92
92
|
exports.serviceAgentEmail = serviceAgentEmail;
|
|
93
93
|
async function generateP4SA(projectNumber) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isProductTosAccepted = exports.getAcceptanceStatus = exports.getTosStatus = exports.DATA_CONNECT_TOS_ID = exports.APP_CHECK_TOS_ID = exports.APPHOSTING_TOS_ID = void 0;
|
|
4
|
+
const apiv2_1 = require("../apiv2");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const client = new apiv2_1.Client({ urlPrefix: (0, api_1.firedataOrigin)(), auth: true, apiVersion: "v1" });
|
|
8
|
+
exports.APPHOSTING_TOS_ID = "APP_HOSTING_TOS";
|
|
9
|
+
exports.APP_CHECK_TOS_ID = "APP_CHECK";
|
|
10
|
+
exports.DATA_CONNECT_TOS_ID = "FIREBASE_DATA_CONNECT";
|
|
11
|
+
async function getTosStatus() {
|
|
12
|
+
const res = await client.get("accessmanagement/tos:getStatus");
|
|
13
|
+
return res.body;
|
|
14
|
+
}
|
|
15
|
+
exports.getTosStatus = getTosStatus;
|
|
16
|
+
function getAcceptanceStatus(response, tosId) {
|
|
17
|
+
const perServiceStatus = response.perServiceStatus.find((tosStatus) => tosStatus.tosId === tosId);
|
|
18
|
+
if (perServiceStatus === undefined) {
|
|
19
|
+
throw new error_1.FirebaseError(`Missing terms of service status for product: ${tosId}`);
|
|
20
|
+
}
|
|
21
|
+
return perServiceStatus.serviceStatus.status;
|
|
22
|
+
}
|
|
23
|
+
exports.getAcceptanceStatus = getAcceptanceStatus;
|
|
24
|
+
function isProductTosAccepted(response, tosId) {
|
|
25
|
+
return getAcceptanceStatus(response, tosId) === "ACCEPTED";
|
|
26
|
+
}
|
|
27
|
+
exports.isProductTosAccepted = isProductTosAccepted;
|
package/lib/gcp/iam.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.testIamPermissions = exports.testResourceIamPermissions = exports.getRole = exports.listServiceAccountKeys = exports.deleteServiceAccount = exports.createServiceAccountKey = exports.getServiceAccount = exports.createServiceAccount = exports.getDefaultComputeEngineServiceAgent = exports.getDefaultCloudBuildServiceAgent = void 0;
|
|
3
|
+
exports.printManualIamConfig = exports.mergeBindings = exports.testIamPermissions = exports.testResourceIamPermissions = exports.getRole = exports.listServiceAccountKeys = exports.deleteServiceAccount = exports.createServiceAccountKey = exports.getServiceAccount = exports.createServiceAccount = exports.getDefaultComputeEngineServiceAgent = exports.getDefaultCloudBuildServiceAgent = void 0;
|
|
4
4
|
const api_1 = require("../api");
|
|
5
5
|
const logger_1 = require("../logger");
|
|
6
6
|
const apiv2_1 = require("../apiv2");
|
|
7
|
+
const utils = require("../utils");
|
|
7
8
|
const apiClient = new apiv2_1.Client({ urlPrefix: (0, api_1.iamOrigin)(), apiVersion: "v1" });
|
|
8
9
|
function getDefaultCloudBuildServiceAgent(projectNumber) {
|
|
9
10
|
return `${projectNumber}@cloudbuild.gserviceaccount.com`;
|
|
@@ -82,3 +83,34 @@ async function testIamPermissions(projectId, permissions) {
|
|
|
82
83
|
return testResourceIamPermissions((0, api_1.resourceManagerOrigin)(), "v1", `projects/${projectId}`, permissions, `projects/${projectId}`);
|
|
83
84
|
}
|
|
84
85
|
exports.testIamPermissions = testIamPermissions;
|
|
86
|
+
function mergeBindings(policy, requiredBindings) {
|
|
87
|
+
let updated = false;
|
|
88
|
+
for (const requiredBinding of requiredBindings) {
|
|
89
|
+
const match = policy.bindings.find((b) => b.role === requiredBinding.role);
|
|
90
|
+
if (!match) {
|
|
91
|
+
updated = true;
|
|
92
|
+
policy.bindings.push(requiredBinding);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
for (const requiredMember of requiredBinding.members) {
|
|
96
|
+
if (!match.members.find((m) => m === requiredMember)) {
|
|
97
|
+
updated = true;
|
|
98
|
+
match.members.push(requiredMember);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return updated;
|
|
103
|
+
}
|
|
104
|
+
exports.mergeBindings = mergeBindings;
|
|
105
|
+
function printManualIamConfig(requiredBindings, projectId, prefix) {
|
|
106
|
+
utils.logLabeledBullet(prefix, "Failed to verify the project has the correct IAM bindings for a successful deployment.", "warn");
|
|
107
|
+
utils.logLabeledBullet(prefix, "You can either re-run this command as a project owner or manually run the following set of `gcloud` commands:", "warn");
|
|
108
|
+
for (const binding of requiredBindings) {
|
|
109
|
+
for (const member of binding.members) {
|
|
110
|
+
utils.logLabeledBullet(prefix, `\`gcloud projects add-iam-policy-binding ${projectId} ` +
|
|
111
|
+
`--member=${member} ` +
|
|
112
|
+
`--role=${binding.role}\``, "warn");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.printManualIamConfig = printManualIamConfig;
|
package/lib/gcp/secretManager.js
CHANGED
|
@@ -53,7 +53,7 @@ async function getSecretMetadata(projectId, secretName, version) {
|
|
|
53
53
|
const secretInfo = {};
|
|
54
54
|
try {
|
|
55
55
|
secretInfo.secret = await getSecret(projectId, secretName);
|
|
56
|
-
secretInfo.secretVersion = getSecretVersion(projectId, secretName, version);
|
|
56
|
+
secretInfo.secretVersion = await getSecretVersion(projectId, secretName, version);
|
|
57
57
|
}
|
|
58
58
|
catch (err) {
|
|
59
59
|
if (err.status !== 404) {
|
|
@@ -43,6 +43,7 @@ async function interactiveCreateHostingSite(siteId, appId, options) {
|
|
|
43
43
|
if (options.nonInteractive) {
|
|
44
44
|
throw err;
|
|
45
45
|
}
|
|
46
|
+
id = "";
|
|
46
47
|
suggestion = getSuggestionFromError(err);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
@@ -71,5 +72,8 @@ function getSuggestionFromError(err) {
|
|
|
71
72
|
return match[1];
|
|
72
73
|
}
|
|
73
74
|
}
|
|
75
|
+
else {
|
|
76
|
+
(0, utils_1.logWarning)(err.message);
|
|
77
|
+
}
|
|
74
78
|
return;
|
|
75
79
|
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.doSetup = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const prompt_1 = require("../../../prompt");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const provisionCloudSql_1 = require("../../../dataconnect/provisionCloudSql");
|
|
8
|
+
const freeTrial_1 = require("../../../dataconnect/freeTrial");
|
|
9
|
+
const cloudsql = require("../../../gcp/cloudsql/cloudsqladmin");
|
|
10
|
+
const ensureApis_1 = require("../../../dataconnect/ensureApis");
|
|
11
|
+
const client_1 = require("../../../dataconnect/client");
|
|
12
|
+
const emulators_1 = require("../emulators");
|
|
13
|
+
const TEMPLATE_ROOT = (0, path_1.resolve)(__dirname, "../../../../templates/init/dataconnect/");
|
|
14
|
+
const DATACONNECT_YAML_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "dataconnect.yaml"), "utf8");
|
|
15
|
+
const CONNECTOR_YAML_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "connector.yaml"), "utf8");
|
|
16
|
+
const SCHEMA_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "schema.gql"), "utf8");
|
|
17
|
+
const QUERIES_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "queries.gql"), "utf8");
|
|
18
|
+
const MUTATIONS_TEMPLATE = (0, fs_1.readFileSync)((0, path_1.join)(TEMPLATE_ROOT, "mutations.gql"), "utf8");
|
|
19
|
+
async function doSetup(setup, config) {
|
|
20
|
+
if (setup.projectId) {
|
|
21
|
+
await (0, ensureApis_1.ensureApis)(setup.projectId);
|
|
22
|
+
}
|
|
23
|
+
const serviceId = await (0, prompt_1.promptOnce)({
|
|
24
|
+
message: "What ID would you like to use for this service?",
|
|
25
|
+
type: "input",
|
|
26
|
+
default: "dataconnect",
|
|
27
|
+
});
|
|
28
|
+
const connectorId = await (0, prompt_1.promptOnce)({
|
|
29
|
+
message: "What ID would you like to use for your connector?",
|
|
30
|
+
type: "input",
|
|
31
|
+
default: "my-connector",
|
|
32
|
+
});
|
|
33
|
+
let cloudSqlInstanceId = "";
|
|
34
|
+
let newInstance = false;
|
|
35
|
+
let locationId = "";
|
|
36
|
+
if (setup.projectId) {
|
|
37
|
+
const instances = await cloudsql.listInstances(setup.projectId);
|
|
38
|
+
const choices = instances.map((i) => {
|
|
39
|
+
return { name: i.name, value: i.name, location: i.region };
|
|
40
|
+
});
|
|
41
|
+
const freeTrialInstanceId = await (0, freeTrial_1.checkForFreeTrialInstance)(setup.projectId);
|
|
42
|
+
if (!freeTrialInstanceId) {
|
|
43
|
+
choices.push({ name: "Create a new instance", value: "", location: "" });
|
|
44
|
+
}
|
|
45
|
+
if (instances.length) {
|
|
46
|
+
cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
|
|
47
|
+
message: `Which CloudSSQL instance would you like to use?`,
|
|
48
|
+
type: "list",
|
|
49
|
+
choices,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
locationId = choices.find((c) => c.value === cloudSqlInstanceId).location;
|
|
53
|
+
}
|
|
54
|
+
if (cloudSqlInstanceId === "") {
|
|
55
|
+
let locationOptions = [
|
|
56
|
+
{ name: "us-central1", value: "us-central1" },
|
|
57
|
+
{ name: "europe-north1", value: "europe-north1" },
|
|
58
|
+
{ name: "europe-central2", value: "europe-central2" },
|
|
59
|
+
{ name: "europe-west1", value: "europe-west1" },
|
|
60
|
+
{ name: "southamerica-west1", value: "southamerica-west1" },
|
|
61
|
+
{ name: "us-east4", value: "us-east4" },
|
|
62
|
+
{ name: "us-west1", value: "us-west1" },
|
|
63
|
+
{ name: "asia-southeast1", value: "asia-southeast1" },
|
|
64
|
+
];
|
|
65
|
+
if (setup.projectId) {
|
|
66
|
+
const locations = await (0, client_1.listLocations)(setup.projectId);
|
|
67
|
+
locationOptions = locations.map((l) => {
|
|
68
|
+
return { name: l, value: l };
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
newInstance = true;
|
|
72
|
+
cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
|
|
73
|
+
message: `What ID would you like to use for your new CloudSQL instance?`,
|
|
74
|
+
type: "input",
|
|
75
|
+
default: `dataconnect-test`,
|
|
76
|
+
});
|
|
77
|
+
locationId = await (0, prompt_1.promptOnce)({
|
|
78
|
+
message: "What location would you use for this instance?",
|
|
79
|
+
type: "list",
|
|
80
|
+
choices: locationOptions,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const dir = config.get("dataconnect.source") || "dataconnect";
|
|
84
|
+
if (!config.has("dataconnect")) {
|
|
85
|
+
config.set("dataconnect.source", dir);
|
|
86
|
+
config.set("dataconnect.location", locationId);
|
|
87
|
+
}
|
|
88
|
+
let cloudSqlDatabase = "";
|
|
89
|
+
let newDB = false;
|
|
90
|
+
if (!newInstance && setup.projectId) {
|
|
91
|
+
const dbs = await cloudsql.listDatabases(setup.projectId, cloudSqlInstanceId);
|
|
92
|
+
const choices = dbs.map((d) => {
|
|
93
|
+
return { name: d.name, value: d.name };
|
|
94
|
+
});
|
|
95
|
+
choices.push({ name: "Create a new database", value: "" });
|
|
96
|
+
if (dbs.length) {
|
|
97
|
+
cloudSqlDatabase = await (0, prompt_1.promptOnce)({
|
|
98
|
+
message: `Which database in ${cloudSqlInstanceId} would you like to use?`,
|
|
99
|
+
type: "list",
|
|
100
|
+
choices,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (cloudSqlDatabase === "") {
|
|
105
|
+
newDB = true;
|
|
106
|
+
cloudSqlDatabase = await (0, prompt_1.promptOnce)({
|
|
107
|
+
message: `What ID would you like to use for your new database in ${cloudSqlInstanceId}?`,
|
|
108
|
+
type: "input",
|
|
109
|
+
default: `dataconnect`,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const defaultConnectionString = setup.rcfile.dataconnectEmulatorConfig?.postgres?.localConnectionString ??
|
|
113
|
+
emulators_1.DEFAULT_POSTGRES_CONNECTION;
|
|
114
|
+
const localConnectionString = await (0, prompt_1.promptOnce)({
|
|
115
|
+
type: "input",
|
|
116
|
+
name: "localConnectionString",
|
|
117
|
+
message: `What is the connection string of the local Postgres instance you would like to use with the Data Connect emulator?`,
|
|
118
|
+
default: defaultConnectionString,
|
|
119
|
+
});
|
|
120
|
+
setup.rcfile.dataconnectEmulatorConfig = { postgres: { localConnectionString } };
|
|
121
|
+
const subbedDataconnectYaml = subValues(DATACONNECT_YAML_TEMPLATE, {
|
|
122
|
+
serviceId,
|
|
123
|
+
cloudSqlInstanceId,
|
|
124
|
+
cloudSqlDatabase,
|
|
125
|
+
connectorId,
|
|
126
|
+
});
|
|
127
|
+
const subbedConnectorYaml = subValues(CONNECTOR_YAML_TEMPLATE, {
|
|
128
|
+
serviceId,
|
|
129
|
+
cloudSqlInstanceId,
|
|
130
|
+
cloudSqlDatabase,
|
|
131
|
+
connectorId,
|
|
132
|
+
});
|
|
133
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml);
|
|
134
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "connector", "connector.yaml"), subbedConnectorYaml);
|
|
135
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "schema", "schema.gql"), SCHEMA_TEMPLATE);
|
|
136
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "connector", "queries.gql"), QUERIES_TEMPLATE);
|
|
137
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "connector", "mutations.gql"), MUTATIONS_TEMPLATE);
|
|
138
|
+
if (setup.projectId &&
|
|
139
|
+
(newInstance || newDB) &&
|
|
140
|
+
(await (0, prompt_1.confirm)({
|
|
141
|
+
message: "Would you like to provision your CloudSQL instance and database now? This will take a few minutes.",
|
|
142
|
+
default: true,
|
|
143
|
+
}))) {
|
|
144
|
+
await (0, provisionCloudSql_1.provisionCloudSql)({
|
|
145
|
+
projectId: setup.projectId,
|
|
146
|
+
locationId,
|
|
147
|
+
instanceId: cloudSqlInstanceId,
|
|
148
|
+
databaseId: cloudSqlDatabase,
|
|
149
|
+
enableGoogleMlIntegration: false,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.doSetup = doSetup;
|
|
154
|
+
function subValues(template, replacementValues) {
|
|
155
|
+
const replacements = {
|
|
156
|
+
serviceId: "__serviceId__",
|
|
157
|
+
cloudSqlDatabase: "__cloudSqlDatabase__",
|
|
158
|
+
cloudSqlInstanceId: "__cloudSqlInstanceId__",
|
|
159
|
+
connectorId: "__connectorId__",
|
|
160
|
+
};
|
|
161
|
+
let replaced = template;
|
|
162
|
+
for (const [k, v] of Object.entries(replacementValues)) {
|
|
163
|
+
replaced = replaced.replace(replacements[k], v);
|
|
164
|
+
}
|
|
165
|
+
return replaced;
|
|
166
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.doSetup = void 0;
|
|
3
|
+
exports.doSetup = exports.DEFAULT_POSTGRES_CONNECTION = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
5
|
const _ = require("lodash");
|
|
6
6
|
const utils = require("../../utils");
|
|
@@ -8,6 +8,7 @@ const prompt_1 = require("../../prompt");
|
|
|
8
8
|
const types_1 = require("../../emulator/types");
|
|
9
9
|
const constants_1 = require("../../emulator/constants");
|
|
10
10
|
const downloadableEmulators_1 = require("../../emulator/downloadableEmulators");
|
|
11
|
+
exports.DEFAULT_POSTGRES_CONNECTION = "postgresql://localhost:5432?sslmode=disable";
|
|
11
12
|
async function doSetup(setup, config) {
|
|
12
13
|
const choices = types_1.ALL_SERVICE_EMULATORS.map((e) => {
|
|
13
14
|
return {
|
|
@@ -76,6 +77,17 @@ async function doSetup(setup, config) {
|
|
|
76
77
|
ui.port = isNaN(portNum) ? undefined : portNum;
|
|
77
78
|
}
|
|
78
79
|
}
|
|
80
|
+
if (selections.emulators.includes(types_1.Emulators.DATACONNECT)) {
|
|
81
|
+
const defaultConnectionString = setup.rcfile.dataconnectEmulatorConfig?.postgres?.localConnectionString ??
|
|
82
|
+
exports.DEFAULT_POSTGRES_CONNECTION;
|
|
83
|
+
const localConnectionString = await (0, prompt_1.promptOnce)({
|
|
84
|
+
type: "input",
|
|
85
|
+
name: "localConnectionString",
|
|
86
|
+
message: `What is the connection string of the local Postgres instance you would like to use with the Data Connect emulator?`,
|
|
87
|
+
default: defaultConnectionString,
|
|
88
|
+
});
|
|
89
|
+
setup.rcfile.dataconnectEmulatorConfig = { postgres: { localConnectionString } };
|
|
90
|
+
}
|
|
79
91
|
await (0, prompt_1.prompt)(selections, [
|
|
80
92
|
{
|
|
81
93
|
name: "download",
|