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
|
@@ -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;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultServiceAccount = void 0;
|
|
4
|
+
function getDefaultServiceAccount(projectNumber) {
|
|
5
|
+
return `${projectNumber}-compute@developer.gserviceaccount.com`;
|
|
6
|
+
}
|
|
7
|
+
exports.getDefaultServiceAccount = getDefaultServiceAccount;
|
package/lib/gcp/devConnect.js
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.serviceAgentEmail = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.listAllLinkableGitRepositories = exports.listAllConnections = exports.getConnection = exports.createConnection = exports.client = void 0;
|
|
3
|
+
exports.generateP4SA = exports.serviceAgentEmail = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.listAllLinkableGitRepositories = exports.listAllConnections = exports.getConnection = exports.deleteConnection = exports.createConnection = exports.client = void 0;
|
|
4
4
|
const apiv2_1 = require("../apiv2");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
|
+
const serviceusage_1 = require("./serviceusage");
|
|
6
7
|
const PAGE_SIZE_MAX = 1000;
|
|
8
|
+
const LOCATION_OVERRIDE = process.env.FIREBASE_DEVELOPERCONNECT_LOCATION_OVERRIDE;
|
|
7
9
|
exports.client = new apiv2_1.Client({
|
|
8
10
|
urlPrefix: (0, api_1.developerConnectOrigin)(),
|
|
9
11
|
auth: true,
|
|
10
12
|
apiVersion: "v1",
|
|
11
13
|
});
|
|
12
|
-
async function createConnection(projectId, location, connectionId, githubConfig) {
|
|
14
|
+
async function createConnection(projectId, location, connectionId, githubConfig = {}) {
|
|
13
15
|
const config = {
|
|
14
16
|
...githubConfig,
|
|
15
17
|
githubApp: "FIREBASE",
|
|
16
18
|
};
|
|
17
|
-
const res = await exports.client.post(`projects/${projectId}/locations/${location}/connections`, {
|
|
19
|
+
const res = await exports.client.post(`projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections`, {
|
|
18
20
|
githubConfig: config,
|
|
19
21
|
}, { queryParams: { connectionId } });
|
|
20
22
|
return res.body;
|
|
21
23
|
}
|
|
22
24
|
exports.createConnection = createConnection;
|
|
25
|
+
async function deleteConnection(projectId, location, connectionId) {
|
|
26
|
+
const name = `projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}`;
|
|
27
|
+
const res = await exports.client.delete(name, { queryParams: { force: "true" } });
|
|
28
|
+
return res.body;
|
|
29
|
+
}
|
|
30
|
+
exports.deleteConnection = deleteConnection;
|
|
23
31
|
async function getConnection(projectId, location, connectionId) {
|
|
24
|
-
const name = `projects/${projectId}/locations/${location}/connections/${connectionId}`;
|
|
32
|
+
const name = `projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}`;
|
|
25
33
|
const res = await exports.client.get(name);
|
|
26
34
|
return res.body;
|
|
27
35
|
}
|
|
@@ -29,7 +37,7 @@ exports.getConnection = getConnection;
|
|
|
29
37
|
async function listAllConnections(projectId, location) {
|
|
30
38
|
const conns = [];
|
|
31
39
|
const getNextPage = async (pageToken = "") => {
|
|
32
|
-
const res = await exports.client.get(`/projects/${projectId}/locations/${location}/connections`, {
|
|
40
|
+
const res = await exports.client.get(`/projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections`, {
|
|
33
41
|
queryParams: {
|
|
34
42
|
pageSize: PAGE_SIZE_MAX,
|
|
35
43
|
pageToken,
|
|
@@ -47,17 +55,17 @@ async function listAllConnections(projectId, location) {
|
|
|
47
55
|
}
|
|
48
56
|
exports.listAllConnections = listAllConnections;
|
|
49
57
|
async function listAllLinkableGitRepositories(projectId, location, connectionId) {
|
|
50
|
-
const name = `projects/${projectId}/locations/${location}/connections/${connectionId}:
|
|
58
|
+
const name = `projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}:fetchLinkableGitRepositories`;
|
|
51
59
|
const repos = [];
|
|
52
60
|
const getNextPage = async (pageToken = "") => {
|
|
53
61
|
const res = await exports.client.get(name, {
|
|
54
62
|
queryParams: {
|
|
55
|
-
PAGE_SIZE_MAX,
|
|
63
|
+
pageSize: PAGE_SIZE_MAX,
|
|
56
64
|
pageToken,
|
|
57
65
|
},
|
|
58
66
|
});
|
|
59
|
-
if (Array.isArray(res.body.
|
|
60
|
-
repos.push(...res.body.
|
|
67
|
+
if (Array.isArray(res.body.linkableGitRepositories)) {
|
|
68
|
+
repos.push(...res.body.linkableGitRepositories);
|
|
61
69
|
}
|
|
62
70
|
if (res.body.nextPageToken) {
|
|
63
71
|
await getNextPage(res.body.nextPageToken);
|
|
@@ -68,17 +76,22 @@ async function listAllLinkableGitRepositories(projectId, location, connectionId)
|
|
|
68
76
|
}
|
|
69
77
|
exports.listAllLinkableGitRepositories = listAllLinkableGitRepositories;
|
|
70
78
|
async function createGitRepositoryLink(projectId, location, connectionId, gitRepositoryLinkId, cloneUri) {
|
|
71
|
-
const res = await exports.client.post(`projects/${projectId}/locations/${location}/connections/${connectionId}/gitRepositoryLinks`, { cloneUri }, { queryParams: { gitRepositoryLinkId } });
|
|
79
|
+
const res = await exports.client.post(`projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}/gitRepositoryLinks`, { cloneUri }, { queryParams: { gitRepositoryLinkId } });
|
|
72
80
|
return res.body;
|
|
73
81
|
}
|
|
74
82
|
exports.createGitRepositoryLink = createGitRepositoryLink;
|
|
75
83
|
async function getGitRepositoryLink(projectId, location, connectionId, gitRepositoryLinkId) {
|
|
76
|
-
const name = `projects/${projectId}/locations/${location}/connections/${connectionId}/gitRepositoryLinks/${gitRepositoryLinkId}`;
|
|
84
|
+
const name = `projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}/gitRepositoryLinks/${gitRepositoryLinkId}`;
|
|
77
85
|
const res = await exports.client.get(name);
|
|
78
86
|
return res.body;
|
|
79
87
|
}
|
|
80
88
|
exports.getGitRepositoryLink = getGitRepositoryLink;
|
|
81
89
|
function serviceAgentEmail(projectNumber) {
|
|
82
|
-
return `service-${projectNumber}@${(0, api_1.
|
|
90
|
+
return `service-${projectNumber}@${(0, api_1.developerConnectP4SADomain)()}`;
|
|
83
91
|
}
|
|
84
92
|
exports.serviceAgentEmail = serviceAgentEmail;
|
|
93
|
+
async function generateP4SA(projectNumber) {
|
|
94
|
+
const devConnectOrigin = (0, api_1.developerConnectOrigin)();
|
|
95
|
+
await (0, serviceusage_1.generateServiceIdentityAndPoll)(projectNumber, new URL(devConnectOrigin).hostname, "apphosting");
|
|
96
|
+
}
|
|
97
|
+
exports.generateP4SA = generateP4SA;
|
|
@@ -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,10 +1,19 @@
|
|
|
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 = 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" });
|
|
9
|
+
function getDefaultCloudBuildServiceAgent(projectNumber) {
|
|
10
|
+
return `${projectNumber}@cloudbuild.gserviceaccount.com`;
|
|
11
|
+
}
|
|
12
|
+
exports.getDefaultCloudBuildServiceAgent = getDefaultCloudBuildServiceAgent;
|
|
13
|
+
function getDefaultComputeEngineServiceAgent(projectNumber) {
|
|
14
|
+
return `${projectNumber}-compute@developer.gserviceaccount.com`;
|
|
15
|
+
}
|
|
16
|
+
exports.getDefaultComputeEngineServiceAgent = getDefaultComputeEngineServiceAgent;
|
|
8
17
|
async function createServiceAccount(projectId, accountId, description, displayName) {
|
|
9
18
|
const response = await apiClient.post(`/projects/${projectId}/serviceAccounts`, {
|
|
10
19
|
accountId,
|
|
@@ -74,3 +83,34 @@ async function testIamPermissions(projectId, permissions) {
|
|
|
74
83
|
return testResourceIamPermissions((0, api_1.resourceManagerOrigin)(), "v1", `projects/${projectId}`, permissions, `projects/${projectId}`);
|
|
75
84
|
}
|
|
76
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
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureServiceAgentRole = exports.setIamPolicy = exports.getIamPolicy = exports.addVersion = exports.deleteSecret = exports.patchSecret = exports.createSecret = exports.toSecretVersionResourceName = exports.parseSecretVersionResourceName = exports.parseSecretResourceName = exports.secretExists = exports.destroySecretVersion = exports.accessSecretVersion = exports.getSecretVersion = exports.listSecretVersions = exports.getSecretMetadata = exports.listSecrets = exports.getSecret = exports.secretManagerConsoleUri = void 0;
|
|
3
|
+
exports.labels = exports.ensureApi = exports.isAppHostingManaged = exports.isFunctionsManaged = exports.FIREBASE_MANAGED = exports.ensureServiceAgentRole = exports.setIamPolicy = exports.getIamPolicy = exports.addVersion = exports.deleteSecret = exports.patchSecret = exports.createSecret = exports.toSecretVersionResourceName = exports.parseSecretVersionResourceName = exports.parseSecretResourceName = exports.secretExists = exports.destroySecretVersion = exports.accessSecretVersion = exports.getSecretVersion = exports.listSecretVersions = exports.getSecretMetadata = exports.listSecrets = exports.getSecret = exports.secretManagerConsoleUri = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
const error_1 = require("../error");
|
|
6
6
|
const apiv2_1 = require("../apiv2");
|
|
7
7
|
const api_1 = require("../api");
|
|
8
|
+
const ensureApiEnabled = require("../ensureApiEnabled");
|
|
9
|
+
const projectUtils_1 = require("../projectUtils");
|
|
8
10
|
const SECRET_NAME_REGEX = new RegExp("projects\\/" +
|
|
9
11
|
"(?<project>(?:\\d+)|(?:[A-Za-z]+[A-Za-z\\d-]*[A-Za-z\\d]?))\\/" +
|
|
10
12
|
"secrets\\/" +
|
|
@@ -18,6 +20,7 @@ async function getSecret(projectId, name) {
|
|
|
18
20
|
const getRes = await client.get(`projects/${projectId}/secrets/${name}`);
|
|
19
21
|
const secret = parseSecretResourceName(getRes.body.name);
|
|
20
22
|
secret.labels = getRes.body.labels ?? {};
|
|
23
|
+
secret.replication = getRes.body.replication ?? {};
|
|
21
24
|
return secret;
|
|
22
25
|
}
|
|
23
26
|
exports.getSecret = getSecret;
|
|
@@ -35,6 +38,7 @@ async function listSecrets(projectId, filter) {
|
|
|
35
38
|
secrets.push({
|
|
36
39
|
...parseSecretResourceName(s.name),
|
|
37
40
|
labels: s.labels ?? {},
|
|
41
|
+
replication: s.replication ?? {},
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
44
|
if (!res.body.nextPageToken) {
|
|
@@ -49,7 +53,7 @@ async function getSecretMetadata(projectId, secretName, version) {
|
|
|
49
53
|
const secretInfo = {};
|
|
50
54
|
try {
|
|
51
55
|
secretInfo.secret = await getSecret(projectId, secretName);
|
|
52
|
-
secretInfo.secretVersion = getSecretVersion(projectId, secretName, version);
|
|
56
|
+
secretInfo.secretVersion = await getSecretVersion(projectId, secretName, version);
|
|
53
57
|
}
|
|
54
58
|
catch (err) {
|
|
55
59
|
if (err.status !== 404) {
|
|
@@ -73,6 +77,7 @@ async function listSecretVersions(projectId, name, filter) {
|
|
|
73
77
|
secrets.push({
|
|
74
78
|
...parseSecretVersionResourceName(s.name),
|
|
75
79
|
state: s.state,
|
|
80
|
+
createTime: s.createTime,
|
|
76
81
|
});
|
|
77
82
|
}
|
|
78
83
|
if (!res.body.nextPageToken) {
|
|
@@ -88,6 +93,7 @@ async function getSecretVersion(projectId, name, version) {
|
|
|
88
93
|
return {
|
|
89
94
|
...parseSecretVersionResourceName(getRes.body.name),
|
|
90
95
|
state: getRes.body.state,
|
|
96
|
+
createTime: getRes.body.createTime,
|
|
91
97
|
};
|
|
92
98
|
}
|
|
93
99
|
exports.getSecretVersion = getSecretVersion;
|
|
@@ -125,6 +131,8 @@ function parseSecretResourceName(resourceName) {
|
|
|
125
131
|
return {
|
|
126
132
|
projectId: match.groups.project,
|
|
127
133
|
name: match.groups.secret,
|
|
134
|
+
labels: {},
|
|
135
|
+
replication: {},
|
|
128
136
|
};
|
|
129
137
|
}
|
|
130
138
|
exports.parseSecretResourceName = parseSecretResourceName;
|
|
@@ -137,8 +145,11 @@ function parseSecretVersionResourceName(resourceName) {
|
|
|
137
145
|
secret: {
|
|
138
146
|
projectId: match.groups.project,
|
|
139
147
|
name: match.groups.secret,
|
|
148
|
+
labels: {},
|
|
149
|
+
replication: {},
|
|
140
150
|
},
|
|
141
151
|
versionId: match.groups.version,
|
|
152
|
+
createTime: "",
|
|
142
153
|
};
|
|
143
154
|
}
|
|
144
155
|
exports.parseSecretVersionResourceName = parseSecretVersionResourceName;
|
|
@@ -146,24 +157,42 @@ function toSecretVersionResourceName(secretVersion) {
|
|
|
146
157
|
return `projects/${secretVersion.secret.projectId}/secrets/${secretVersion.secret.name}/versions/${secretVersion.versionId}`;
|
|
147
158
|
}
|
|
148
159
|
exports.toSecretVersionResourceName = toSecretVersionResourceName;
|
|
149
|
-
async function createSecret(projectId, name, labels) {
|
|
160
|
+
async function createSecret(projectId, name, labels, location) {
|
|
161
|
+
let replication;
|
|
162
|
+
if (location) {
|
|
163
|
+
replication = {
|
|
164
|
+
userManaged: {
|
|
165
|
+
replicas: [
|
|
166
|
+
{
|
|
167
|
+
location,
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
replication = { automatic: {} };
|
|
175
|
+
}
|
|
150
176
|
const createRes = await client.post(`projects/${projectId}/secrets`, {
|
|
151
177
|
name,
|
|
152
|
-
replication
|
|
153
|
-
automatic: {},
|
|
154
|
-
},
|
|
178
|
+
replication,
|
|
155
179
|
labels,
|
|
156
180
|
}, { queryParams: { secretId: name } });
|
|
157
181
|
return {
|
|
158
182
|
...parseSecretResourceName(createRes.body.name),
|
|
159
183
|
labels,
|
|
184
|
+
replication,
|
|
160
185
|
};
|
|
161
186
|
}
|
|
162
187
|
exports.createSecret = createSecret;
|
|
163
188
|
async function patchSecret(projectId, name, labels) {
|
|
164
189
|
const fullName = `projects/${projectId}/secrets/${name}`;
|
|
165
190
|
const res = await client.patch(fullName, { name: fullName, labels }, { queryParams: { updateMask: "labels" } });
|
|
166
|
-
return
|
|
191
|
+
return {
|
|
192
|
+
...parseSecretResourceName(res.body.name),
|
|
193
|
+
labels: res.body.labels,
|
|
194
|
+
replication: res.body.replication,
|
|
195
|
+
};
|
|
167
196
|
}
|
|
168
197
|
exports.patchSecret = patchSecret;
|
|
169
198
|
async function deleteSecret(projectId, name) {
|
|
@@ -180,6 +209,7 @@ async function addVersion(projectId, name, payloadData) {
|
|
|
180
209
|
return {
|
|
181
210
|
...parseSecretVersionResourceName(res.body.name),
|
|
182
211
|
state: res.body.state,
|
|
212
|
+
createTime: "",
|
|
183
213
|
};
|
|
184
214
|
}
|
|
185
215
|
exports.addVersion = addVersion;
|
|
@@ -218,3 +248,21 @@ async function ensureServiceAgentRole(secret, serviceAccountEmails, role) {
|
|
|
218
248
|
(0, utils_1.logLabeledSuccess)("secretmanager", `Granted ${role} on projects/${secret.projectId}/secrets/${secret.name} to ${serviceAccountEmails.join(", ")}`);
|
|
219
249
|
}
|
|
220
250
|
exports.ensureServiceAgentRole = ensureServiceAgentRole;
|
|
251
|
+
exports.FIREBASE_MANAGED = "firebase-managed";
|
|
252
|
+
function isFunctionsManaged(secret) {
|
|
253
|
+
return (secret.labels[exports.FIREBASE_MANAGED] === "true" || secret.labels[exports.FIREBASE_MANAGED] === "functions");
|
|
254
|
+
}
|
|
255
|
+
exports.isFunctionsManaged = isFunctionsManaged;
|
|
256
|
+
function isAppHostingManaged(secret) {
|
|
257
|
+
return secret.labels[exports.FIREBASE_MANAGED] === "apphosting";
|
|
258
|
+
}
|
|
259
|
+
exports.isAppHostingManaged = isAppHostingManaged;
|
|
260
|
+
function ensureApi(options) {
|
|
261
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
262
|
+
return ensureApiEnabled.ensure(projectId, (0, api_1.secretManagerOrigin)(), "secretmanager", true);
|
|
263
|
+
}
|
|
264
|
+
exports.ensureApi = ensureApi;
|
|
265
|
+
function labels(product = "functions") {
|
|
266
|
+
return { [exports.FIREBASE_MANAGED]: product };
|
|
267
|
+
}
|
|
268
|
+
exports.labels = labels;
|
package/lib/gcp/serviceusage.js
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateServiceIdentity = void 0;
|
|
3
|
+
exports.generateServiceIdentityAndPoll = exports.generateServiceIdentity = exports.apiClient = void 0;
|
|
4
4
|
const colorette_1 = require("colorette");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
const apiv2_1 = require("../apiv2");
|
|
7
7
|
const error_1 = require("../error");
|
|
8
8
|
const utils = require("../utils");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const poller = require("../operation-poller");
|
|
10
|
+
const API_VERSION = "v1beta1";
|
|
11
|
+
const SERVICE_USAGE_ORIGIN = (0, api_1.serviceUsageOrigin)();
|
|
12
|
+
exports.apiClient = new apiv2_1.Client({
|
|
13
|
+
urlPrefix: SERVICE_USAGE_ORIGIN,
|
|
14
|
+
apiVersion: API_VERSION,
|
|
12
15
|
});
|
|
16
|
+
const serviceUsagePollerOptions = {
|
|
17
|
+
apiOrigin: SERVICE_USAGE_ORIGIN,
|
|
18
|
+
apiVersion: API_VERSION,
|
|
19
|
+
};
|
|
13
20
|
async function generateServiceIdentity(projectNumber, service, prefix) {
|
|
14
21
|
utils.logLabeledBullet(prefix, `generating the service identity for ${(0, colorette_1.bold)(service)}...`);
|
|
15
22
|
try {
|
|
16
|
-
|
|
23
|
+
const res = await exports.apiClient.post(`projects/${projectNumber}/services/${service}:generateServiceIdentity`);
|
|
24
|
+
return res.body;
|
|
17
25
|
}
|
|
18
26
|
catch (err) {
|
|
19
27
|
throw new error_1.FirebaseError(`Error generating the service identity for ${service}.`, {
|
|
@@ -22,3 +30,14 @@ async function generateServiceIdentity(projectNumber, service, prefix) {
|
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
32
|
exports.generateServiceIdentity = generateServiceIdentity;
|
|
33
|
+
async function generateServiceIdentityAndPoll(projectNumber, service, prefix) {
|
|
34
|
+
const op = await generateServiceIdentity(projectNumber, service, prefix);
|
|
35
|
+
if (op.done) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
await poller.pollOperation({
|
|
39
|
+
...serviceUsagePollerOptions,
|
|
40
|
+
operationResourceName: op.name,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.generateServiceIdentityAndPoll = generateServiceIdentityAndPoll;
|
|
@@ -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
|
}
|