firebase-tools-with-isolate 13.15.0-0 → 13.26.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 +3 -1
- package/lib/apiv2.js +10 -3
- package/lib/appdistribution/client.js +62 -8
- package/lib/appdistribution/distribution.js +1 -1
- package/lib/apphosting/backend.js +299 -0
- package/lib/apphosting/config.js +31 -8
- package/lib/apphosting/githubConnections.js +70 -22
- package/lib/apphosting/index.js +3 -312
- package/lib/apphosting/rollout.js +138 -0
- package/lib/apphosting/secrets/index.js +70 -5
- package/lib/apphosting/utils.js +41 -0
- package/lib/apphosting/yaml.js +82 -0
- package/lib/archiveDirectory.js +1 -1
- package/lib/auth.js +31 -5
- package/lib/bin/firebase.js +2 -2
- package/lib/command.js +18 -4
- package/lib/commands/appdistribution-distribute.js +4 -4
- package/lib/commands/{appdistribution-group-create.js → appdistribution-groups-create.js} +2 -1
- package/lib/commands/{appdistribution-group-delete.js → appdistribution-groups-delete.js} +3 -2
- package/lib/commands/appdistribution-groups-list.js +55 -0
- package/lib/commands/appdistribution-testers-list.js +52 -0
- package/lib/commands/appdistribution-testers-remove.js +1 -1
- package/lib/commands/apphosting-backends-create.js +4 -4
- package/lib/commands/apphosting-backends-delete.js +7 -15
- package/lib/commands/apphosting-backends-get.js +1 -1
- package/lib/commands/apphosting-config-export.js +51 -0
- package/lib/commands/apphosting-repos-create.js +23 -0
- package/lib/commands/apphosting-rollouts-create.js +14 -15
- package/lib/commands/apphosting-secrets-grantaccess.js +2 -2
- package/lib/commands/database-import.js +4 -2
- package/lib/commands/database-push.js +4 -2
- package/lib/commands/database-set.js +4 -2
- package/lib/commands/database-settings-get.js +1 -1
- package/lib/commands/database-settings-set.js +1 -1
- package/lib/commands/dataconnect-sdk-generate.js +4 -1
- package/lib/commands/dataconnect-services-list.js +4 -3
- package/lib/commands/dataconnect-sql-diff.js +1 -1
- package/lib/commands/dataconnect-sql-grant.js +37 -0
- package/lib/commands/dataconnect-sql-migrate.js +1 -1
- package/lib/commands/dataconnect-sql-shell.js +115 -0
- package/lib/commands/deploy.js +5 -1
- package/lib/commands/emulators-start.js +4 -1
- package/lib/commands/ext-dev-init.js +2 -2
- package/lib/commands/ext-dev-list.js +1 -1
- package/lib/commands/ext-dev-register.js +2 -2
- package/lib/commands/ext-dev-upload.js +2 -2
- package/lib/commands/ext-dev-usage.js +2 -2
- package/lib/commands/ext-info.js +3 -1
- package/lib/commands/ext-install.js +2 -2
- package/lib/commands/ext-sdk-install.js +88 -0
- package/lib/commands/ext.js +1 -0
- package/lib/commands/firestore-databases-restore.js +39 -1
- package/lib/commands/functions-secrets-access.js +2 -4
- package/lib/commands/index.js +15 -2
- package/lib/commands/init.js +25 -15
- package/lib/commands/setup-emulators-dataconnect.js +0 -13
- package/lib/commands/use.js +1 -1
- package/lib/config.js +14 -4
- package/lib/crashlytics/buildToolsJarHelper.js +2 -2
- package/lib/dataconnect/client.js +3 -2
- package/lib/dataconnect/dataplaneClient.js +12 -9
- package/lib/dataconnect/ensureApis.js +6 -1
- package/lib/dataconnect/fileUtils.js +29 -12
- package/lib/dataconnect/freeTrial.js +45 -9
- package/lib/dataconnect/load.js +3 -1
- package/lib/dataconnect/provisionCloudSql.js +41 -24
- package/lib/dataconnect/schemaMigration.js +215 -74
- package/lib/dataconnect/types.js +4 -1
- package/lib/dataconnect/webhook.js +32 -0
- package/lib/deploy/dataconnect/deploy.js +18 -15
- package/lib/deploy/dataconnect/prepare.js +41 -0
- package/lib/deploy/dataconnect/release.js +16 -7
- package/lib/deploy/extensions/deploy.js +3 -1
- package/lib/deploy/extensions/deploymentSummary.js +7 -3
- package/lib/deploy/extensions/planner.js +95 -5
- package/lib/deploy/extensions/prepare.js +89 -42
- package/lib/deploy/extensions/release.js +17 -10
- package/lib/deploy/extensions/tasks.js +32 -21
- package/lib/deploy/firestore/prepare.js +9 -0
- package/lib/deploy/firestore/release.js +3 -6
- package/lib/deploy/functions/build.js +5 -5
- package/lib/deploy/functions/checkIam.js +7 -2
- package/lib/deploy/functions/deploy.js +12 -12
- package/lib/deploy/functions/ensure.js +11 -3
- package/lib/deploy/functions/params.js +5 -3
- package/lib/deploy/functions/prepare.js +18 -3
- package/lib/deploy/functions/release/index.js +4 -0
- package/lib/deploy/functions/release/planner.js +2 -1
- package/lib/deploy/functions/runtimes/discovery/index.js +6 -2
- package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
- package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +46 -0
- package/lib/deploy/functions/runtimes/node/index.js +5 -0
- package/lib/deploy/functions/services/auth.js +34 -3
- package/lib/deploy/functions/services/index.js +2 -0
- package/lib/deploy/index.js +8 -5
- package/lib/deploy/lifecycleHooks.js +2 -1
- package/lib/emulator/apphosting/config.js +27 -0
- package/lib/emulator/apphosting/index.js +38 -0
- package/lib/emulator/apphosting/serve.js +50 -0
- package/lib/emulator/apphosting/utils.js +18 -0
- package/lib/emulator/auth/handlers.js +27 -0
- package/lib/emulator/auth/operations.js +41 -2
- package/lib/emulator/auth/state.js +2 -1
- package/lib/emulator/commandUtils.js +8 -3
- package/lib/emulator/constants.js +11 -1
- package/lib/emulator/controller.js +59 -6
- package/lib/emulator/dataconnect/pg-gateway/auth/base-auth-flow.js +11 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/cert.js +58 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/index.js +22 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/md5.js +124 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/password.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/sasl-mechanism.js +34 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/sasl/scram-sha-256.js +270 -0
- package/lib/emulator/dataconnect/pg-gateway/auth/trust.js +2 -0
- package/lib/emulator/dataconnect/pg-gateway/backend-error.js +75 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-reader.js +54 -0
- package/lib/emulator/dataconnect/pg-gateway/buffer-writer.js +79 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.js +315 -0
- package/lib/emulator/dataconnect/pg-gateway/connection.types.js +8 -0
- package/lib/emulator/dataconnect/pg-gateway/crypto.js +40 -0
- package/lib/emulator/dataconnect/pg-gateway/duplex.js +53 -0
- package/lib/emulator/dataconnect/pg-gateway/index.js +27 -0
- package/lib/emulator/dataconnect/pg-gateway/message-buffer.js +82 -0
- package/lib/emulator/dataconnect/pg-gateway/message-codes.js +52 -0
- package/lib/emulator/dataconnect/pg-gateway/platforms/node/index.js +16 -0
- package/lib/emulator/dataconnect/pg-gateway/polyfills/readable-stream-async-iterator.js +35 -0
- package/lib/emulator/dataconnect/pg-gateway/utils.js +40 -0
- package/lib/emulator/dataconnect/pgliteServer.js +95 -0
- package/lib/emulator/dataconnectEmulator.js +58 -75
- package/lib/emulator/dataconnectToolkitController.js +44 -0
- package/lib/emulator/downloadableEmulators.js +30 -19
- package/lib/emulator/emulatorLogger.js +3 -0
- package/lib/emulator/env.js +3 -0
- package/lib/emulator/eventarcEmulator.js +1 -1
- package/lib/emulator/extensionsEmulator.js +38 -6
- package/lib/emulator/functionsEmulator.js +115 -42
- package/lib/emulator/functionsEmulatorShared.js +18 -1
- package/lib/emulator/functionsRuntimeWorker.js +2 -1
- package/lib/emulator/hub.js +13 -9
- package/lib/emulator/hubExport.js +10 -3
- package/lib/emulator/loggingEmulator.js +2 -2
- package/lib/emulator/portUtils.js +11 -11
- package/lib/emulator/registry.js +2 -0
- package/lib/emulator/storage/persistence.js +2 -2
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/emulator/taskQueue.js +348 -0
- package/lib/emulator/tasksEmulator.js +240 -0
- package/lib/emulator/types.js +6 -0
- package/lib/emulator/ui.js +51 -25
- package/lib/error.js +31 -1
- package/lib/experiments.js +5 -0
- package/lib/extensions/askUserForEventsConfig.js +18 -8
- package/lib/extensions/askUserForParam.js +2 -1
- package/lib/extensions/displayExtensionInfo.js +5 -5
- package/lib/extensions/emulator/triggerHelper.js +1 -1
- package/lib/extensions/extensionsApi.js +15 -11
- package/lib/extensions/extensionsHelper.js +39 -8
- package/lib/extensions/localHelper.js +32 -1
- package/lib/extensions/refs.js +26 -11
- package/lib/extensions/runtimes/common.js +215 -0
- package/lib/extensions/runtimes/node.js +401 -0
- package/lib/extensions/types.js +67 -1
- package/lib/extensions/warnings.js +5 -2
- package/lib/firestore/api.js +2 -1
- package/lib/firestore/checkDatabaseType.js +10 -3
- package/lib/firestore/delete.js +11 -0
- package/lib/firestore/options.js +7 -0
- package/lib/frameworks/angular/index.js +15 -3
- package/lib/frameworks/constants.js +2 -2
- package/lib/frameworks/flutter/index.js +6 -6
- package/lib/frameworks/flutter/utils.js +34 -1
- package/lib/frameworks/next/constants.js +1 -1
- package/lib/frameworks/next/index.js +45 -17
- package/lib/frameworks/next/utils.js +57 -4
- package/lib/frameworks/vite/index.js +2 -2
- package/lib/fsutils.js +13 -1
- package/lib/functions/constants.js +4 -0
- package/lib/functions/events/v1.js +9 -2
- package/lib/gcp/apphosting.js +1 -1
- package/lib/gcp/cloudmonitoring.js +3 -3
- package/lib/gcp/cloudsql/cloudsqladmin.js +32 -20
- package/lib/gcp/cloudsql/connect.js +49 -37
- package/lib/gcp/cloudsql/interactive.js +49 -0
- package/lib/gcp/cloudsql/permissions.js +165 -0
- package/lib/gcp/devConnect.js +38 -1
- package/lib/gcp/firestore.js +5 -1
- package/lib/gcp/secretManager.js +12 -5
- package/lib/getProjectNumber.js +1 -1
- package/lib/init/features/apphosting.js +15 -0
- package/lib/init/features/dataconnect/index.js +166 -121
- package/lib/init/features/dataconnect/sdk.js +90 -81
- package/lib/init/features/emulators.js +2 -15
- package/lib/init/features/firestore/index.js +20 -1
- package/lib/init/features/firestore/indexes.js +4 -4
- package/lib/init/features/genkit/index.js +444 -0
- package/lib/init/features/hosting/index.js +2 -2
- package/lib/init/features/index.js +1 -1
- package/lib/init/features/project.js +6 -6
- package/lib/init/features/storage.js +0 -2
- package/lib/init/index.js +1 -0
- package/lib/init/spawn.js +23 -2
- package/lib/logger.js +2 -2
- package/lib/management/projects.js +24 -4
- package/lib/projectUtils.js +1 -1
- package/lib/prompt.js +22 -1
- package/lib/rc.js +1 -8
- package/lib/requireAuth.js +19 -5
- package/lib/requireDatabaseInstance.js +1 -1
- package/lib/requirePermissions.js +1 -1
- package/lib/responseToError.js +5 -2
- package/lib/rulesDeploy.js +1 -1
- package/lib/templates.js +2 -2
- package/lib/utils.js +16 -11
- package/lib/vsCodeUtils.js +8 -0
- package/package.json +8 -7
- package/schema/connector-yaml.json +57 -17
- package/schema/firebase-config.json +36 -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/genkit/firebase.0.9.0.template +57 -0
- package/templates/init/apphosting/apphosting.yaml +23 -0
- package/templates/init/dataconnect/connector.yaml +4 -3
- package/templates/init/dataconnect/dataconnect-fdccompatiblemode.yaml +12 -0
- package/templates/init/dataconnect/dataconnect.yaml +6 -6
- package/templates/init/dataconnect/mutations.gql +44 -29
- package/templates/init/dataconnect/queries.gql +65 -38
- package/templates/init/dataconnect/schema.gql +38 -21
- package/templates/init/functions/javascript/package.lint.json +2 -2
- package/templates/init/functions/javascript/package.nolint.json +2 -2
- package/templates/init/functions/typescript/package.lint.json +2 -2
- package/templates/init/functions/typescript/package.nolint.json +2 -2
- package/lib/ensureCloudResourceLocation.js +0 -12
- package/lib/init/features/genkit.js +0 -53
|
@@ -33,27 +33,34 @@ async function createInstance(projectId, location, instanceId, enableGoogleMlInt
|
|
|
33
33
|
if (enableGoogleMlIntegration) {
|
|
34
34
|
databaseFlags.push({ name: "cloudsql.enable_google_ml_integration", value: "on" });
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
36
|
+
let op;
|
|
37
|
+
try {
|
|
38
|
+
op = await client.post(`projects/${projectId}/instances`, {
|
|
39
|
+
name: instanceId,
|
|
40
|
+
region: location,
|
|
41
|
+
databaseVersion: "POSTGRES_15",
|
|
42
|
+
settings: {
|
|
43
|
+
tier: "db-f1-micro",
|
|
44
|
+
edition: "ENTERPRISE",
|
|
45
|
+
ipConfiguration: {
|
|
46
|
+
authorizedNetworks: [],
|
|
47
|
+
},
|
|
48
|
+
enableGoogleMlIntegration,
|
|
49
|
+
databaseFlags,
|
|
50
|
+
storageAutoResize: false,
|
|
51
|
+
userLabels: { "firebase-data-connect": "ft" },
|
|
52
|
+
insightsConfig: {
|
|
53
|
+
queryInsightsEnabled: true,
|
|
54
|
+
queryPlansPerMinute: 5,
|
|
55
|
+
queryStringLength: 1024,
|
|
56
|
+
},
|
|
54
57
|
},
|
|
55
|
-
}
|
|
56
|
-
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
handleAllowlistError(err, location);
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
57
64
|
if (!waitForCreation) {
|
|
58
65
|
return;
|
|
59
66
|
}
|
|
@@ -93,6 +100,11 @@ async function updateInstanceForDataConnect(instance, enableGoogleMlIntegration)
|
|
|
93
100
|
return pollRes;
|
|
94
101
|
}
|
|
95
102
|
exports.updateInstanceForDataConnect = updateInstanceForDataConnect;
|
|
103
|
+
function handleAllowlistError(err, region) {
|
|
104
|
+
if (err.message.includes("Not allowed to set system label: firebase-data-connect")) {
|
|
105
|
+
throw new error_1.FirebaseError(`Cloud SQL free trial instances are not yet available in ${region}. Please check https://firebase.google.com/docs/data-connect/ for a full list of available regions.`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
96
108
|
function setDatabaseFlag(flag, flags = []) {
|
|
97
109
|
const temp = flags.filter((f) => f.name !== flag.name);
|
|
98
110
|
temp.push(flag);
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.toDatabaseUser = exports.setupIAMUsers = exports.getIAMUser = exports.getDataConnectP4SA = exports.executeSqlCmdsAsSuperUser = exports.executeSqlCmdsAsIamUser = exports.execute = void 0;
|
|
4
4
|
const pg = require("pg");
|
|
5
5
|
const cloud_sql_connector_1 = require("@google-cloud/cloud-sql-connector");
|
|
6
6
|
const requireAuth_1 = require("../../requireAuth");
|
|
7
7
|
const projectUtils_1 = require("../../projectUtils");
|
|
8
|
+
const api_1 = require("../../api");
|
|
8
9
|
const cloudSqlAdminClient = require("./cloudsqladmin");
|
|
9
10
|
const utils = require("../../utils");
|
|
10
11
|
const logger_1 = require("../../logger");
|
|
11
12
|
const error_1 = require("../../error");
|
|
12
13
|
const fbToolsAuthClient_1 = require("./fbToolsAuthClient");
|
|
14
|
+
const permissions_1 = require("./permissions");
|
|
13
15
|
async function execute(sqlStatements, opts) {
|
|
14
16
|
const logFn = opts.silent ? logger_1.logger.debug : logger_1.logger.info;
|
|
15
17
|
const instance = await cloudSqlAdminClient.getInstance(opts.projectId, opts.instanceId);
|
|
@@ -87,52 +89,61 @@ async function execute(sqlStatements, opts) {
|
|
|
87
89
|
connector.close();
|
|
88
90
|
}
|
|
89
91
|
exports.execute = execute;
|
|
90
|
-
async function
|
|
92
|
+
async function executeSqlCmdsAsIamUser(options, instanceId, databaseId, cmds, silent = false) {
|
|
91
93
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
94
|
+
const { user: iamUser } = await getIAMUser(options);
|
|
95
|
+
return await execute(cmds, {
|
|
96
|
+
projectId,
|
|
97
|
+
instanceId,
|
|
98
|
+
databaseId,
|
|
99
|
+
username: iamUser,
|
|
100
|
+
silent: silent,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
exports.executeSqlCmdsAsIamUser = executeSqlCmdsAsIamUser;
|
|
104
|
+
async function executeSqlCmdsAsSuperUser(options, instanceId, databaseId, cmds, silent = false) {
|
|
105
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
106
|
+
const superuser = "firebasesuperuser";
|
|
107
|
+
const temporaryPassword = utils.generateId(20);
|
|
108
|
+
await cloudSqlAdminClient.createUser(projectId, instanceId, "BUILT_IN", superuser, temporaryPassword);
|
|
109
|
+
return await execute([`SET ROLE = cloudsqlsuperuser`, ...cmds], {
|
|
110
|
+
projectId,
|
|
111
|
+
instanceId,
|
|
112
|
+
databaseId,
|
|
113
|
+
username: superuser,
|
|
114
|
+
password: temporaryPassword,
|
|
115
|
+
silent: silent,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
exports.executeSqlCmdsAsSuperUser = executeSqlCmdsAsSuperUser;
|
|
119
|
+
function getDataConnectP4SA(projectNumber) {
|
|
120
|
+
return `service-${projectNumber}@${(0, api_1.dataconnectP4SADomain)()}`;
|
|
121
|
+
}
|
|
122
|
+
exports.getDataConnectP4SA = getDataConnectP4SA;
|
|
123
|
+
async function getIAMUser(options) {
|
|
92
124
|
const account = await (0, requireAuth_1.requireAuth)(options);
|
|
93
125
|
if (!account) {
|
|
94
126
|
throw new error_1.FirebaseError("No account to set up! Run `firebase login` or set Application Default Credentials");
|
|
95
127
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
128
|
+
return toDatabaseUser(account);
|
|
129
|
+
}
|
|
130
|
+
exports.getIAMUser = getIAMUser;
|
|
131
|
+
async function setupIAMUsers(instanceId, databaseId, options) {
|
|
132
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
133
|
+
const { user, mode } = await getIAMUser(options);
|
|
100
134
|
await cloudSqlAdminClient.createUser(projectId, instanceId, mode, user);
|
|
135
|
+
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
136
|
+
const { user: fdcP4SAUser, mode: fdcP4SAmode } = toDatabaseUser(getDataConnectP4SA(projectNumber));
|
|
137
|
+
await cloudSqlAdminClient.createUser(projectId, instanceId, fdcP4SAmode, fdcP4SAUser);
|
|
138
|
+
await (0, permissions_1.setupSQLPermissions)(instanceId, databaseId, options, true);
|
|
101
139
|
const grants = [
|
|
102
|
-
`
|
|
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`,
|
|
140
|
+
`GRANT "${(0, permissions_1.firebaseowner)(databaseId)}" TO "${user}"`,
|
|
141
|
+
`GRANT "${(0, permissions_1.firebasewriter)(databaseId)}" TO "${fdcP4SAUser}"`,
|
|
120
142
|
];
|
|
121
|
-
await
|
|
122
|
-
projectId,
|
|
123
|
-
instanceId,
|
|
124
|
-
databaseId,
|
|
125
|
-
username: setupUser,
|
|
126
|
-
password: temporaryPassword,
|
|
127
|
-
silent: true,
|
|
128
|
-
});
|
|
143
|
+
await executeSqlCmdsAsSuperUser(options, instanceId, databaseId, grants, true);
|
|
129
144
|
return user;
|
|
130
145
|
}
|
|
131
|
-
exports.
|
|
132
|
-
function firebaseowner(databaseId) {
|
|
133
|
-
return `firebaseowner_${databaseId}_public`;
|
|
134
|
-
}
|
|
135
|
-
exports.firebaseowner = firebaseowner;
|
|
146
|
+
exports.setupIAMUsers = setupIAMUsers;
|
|
136
147
|
function toDatabaseUser(account) {
|
|
137
148
|
let mode = "CLOUD_IAM_USER";
|
|
138
149
|
let user = account;
|
|
@@ -142,3 +153,4 @@ function toDatabaseUser(account) {
|
|
|
142
153
|
}
|
|
143
154
|
return { user, mode };
|
|
144
155
|
}
|
|
156
|
+
exports.toDatabaseUser = toDatabaseUser;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.interactiveExecuteQuery = exports.confirmDangerousQuery = void 0;
|
|
4
|
+
const ora = require("ora");
|
|
5
|
+
const clc = require("colorette");
|
|
6
|
+
const logger_1 = require("../../logger");
|
|
7
|
+
const prompt_1 = require("../../prompt");
|
|
8
|
+
const Table = require("cli-table");
|
|
9
|
+
const destructiveSqlKeywords = ["DROP", "DELETE"];
|
|
10
|
+
function checkIsDestructiveSql(query) {
|
|
11
|
+
const upperCaseQuery = query.toUpperCase();
|
|
12
|
+
return destructiveSqlKeywords.some((keyword) => upperCaseQuery.includes(keyword.toUpperCase()));
|
|
13
|
+
}
|
|
14
|
+
async function confirmDangerousQuery(query) {
|
|
15
|
+
if (checkIsDestructiveSql(query)) {
|
|
16
|
+
return await (0, prompt_1.confirm)({
|
|
17
|
+
message: clc.yellow("This query may be destructive. Are you sure you want to proceed?"),
|
|
18
|
+
default: false,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
exports.confirmDangerousQuery = confirmDangerousQuery;
|
|
24
|
+
async function interactiveExecuteQuery(query, conn) {
|
|
25
|
+
const spinner = ora("Executing query...").start();
|
|
26
|
+
try {
|
|
27
|
+
const results = await conn.query(query);
|
|
28
|
+
spinner.succeed(clc.green("Query executed successfully"));
|
|
29
|
+
if (Array.isArray(results.rows) && results.rows.length > 0) {
|
|
30
|
+
const table = new Table({
|
|
31
|
+
head: Object.keys(results.rows[0]).map((key) => clc.cyan(key)),
|
|
32
|
+
style: { head: [], border: [] },
|
|
33
|
+
});
|
|
34
|
+
for (const row of results.rows) {
|
|
35
|
+
table.push(Object.values(row));
|
|
36
|
+
}
|
|
37
|
+
logger_1.logger.info(table.toString());
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (query.toUpperCase().includes("SELECT")) {
|
|
41
|
+
logger_1.logger.info(clc.yellow("No results returned"));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
spinner.fail(clc.red(`Failed executing query: ${err}`));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.interactiveExecuteQuery = interactiveExecuteQuery;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupSQLPermissions = exports.iamUserIsCSQLAdmin = exports.checkSQLRoleIsGranted = exports.fdcSqlRoleMap = exports.firebasewriter = exports.firebasereader = exports.firebaseowner = void 0;
|
|
4
|
+
const projectUtils_1 = require("../../projectUtils");
|
|
5
|
+
const connect_1 = require("./connect");
|
|
6
|
+
const iam_1 = require("../iam");
|
|
7
|
+
const logger_1 = require("../../logger");
|
|
8
|
+
const lodash_1 = require("lodash");
|
|
9
|
+
const error_1 = require("../../error");
|
|
10
|
+
function firebaseowner(databaseId) {
|
|
11
|
+
return `firebaseowner_${databaseId}_public`;
|
|
12
|
+
}
|
|
13
|
+
exports.firebaseowner = firebaseowner;
|
|
14
|
+
function firebasereader(databaseId) {
|
|
15
|
+
return `firebasereader_${databaseId}_public`;
|
|
16
|
+
}
|
|
17
|
+
exports.firebasereader = firebasereader;
|
|
18
|
+
function firebasewriter(databaseId) {
|
|
19
|
+
return `firebasewriter_${databaseId}_public`;
|
|
20
|
+
}
|
|
21
|
+
exports.firebasewriter = firebasewriter;
|
|
22
|
+
exports.fdcSqlRoleMap = {
|
|
23
|
+
owner: firebaseowner,
|
|
24
|
+
writer: firebasewriter,
|
|
25
|
+
reader: firebasereader,
|
|
26
|
+
};
|
|
27
|
+
async function checkSQLRoleIsGranted(options, instanceId, databaseId, grantedRole, granteeRole) {
|
|
28
|
+
const checkCmd = `
|
|
29
|
+
DO $$
|
|
30
|
+
DECLARE
|
|
31
|
+
role_count INTEGER;
|
|
32
|
+
BEGIN
|
|
33
|
+
-- Count the number of rows matching the criteria
|
|
34
|
+
SELECT COUNT(*)
|
|
35
|
+
INTO role_count
|
|
36
|
+
FROM
|
|
37
|
+
pg_auth_members m
|
|
38
|
+
JOIN
|
|
39
|
+
pg_roles grantee ON grantee.oid = m.member
|
|
40
|
+
JOIN
|
|
41
|
+
pg_roles granted ON granted.oid = m.roleid
|
|
42
|
+
JOIN
|
|
43
|
+
pg_roles grantor ON grantor.oid = m.grantor
|
|
44
|
+
WHERE
|
|
45
|
+
granted.rolname = '${grantedRole}'
|
|
46
|
+
AND grantee.rolname = '${granteeRole}';
|
|
47
|
+
|
|
48
|
+
-- If no rows were found, raise an exception
|
|
49
|
+
IF role_count = 0 THEN
|
|
50
|
+
RAISE EXCEPTION 'Role "%", is not granted to role "%".', '${grantedRole}', '${granteeRole}';
|
|
51
|
+
END IF;
|
|
52
|
+
END $$;
|
|
53
|
+
`;
|
|
54
|
+
try {
|
|
55
|
+
await (0, connect_1.executeSqlCmdsAsIamUser)(options, instanceId, databaseId, [checkCmd], true);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (e instanceof error_1.FirebaseError && e.message.includes("not granted to role")) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
logger_1.logger.error(`Role Check Failed: ${e}`);
|
|
63
|
+
throw e;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.checkSQLRoleIsGranted = checkSQLRoleIsGranted;
|
|
67
|
+
async function iamUserIsCSQLAdmin(options) {
|
|
68
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
69
|
+
const requiredPermissions = [
|
|
70
|
+
"cloudsql.instances.connect",
|
|
71
|
+
"cloudsql.instances.get",
|
|
72
|
+
"cloudsql.users.create",
|
|
73
|
+
"cloudsql.users.update",
|
|
74
|
+
];
|
|
75
|
+
try {
|
|
76
|
+
const iamResult = await (0, iam_1.testIamPermissions)(projectId, requiredPermissions);
|
|
77
|
+
return iamResult.passed;
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
logger_1.logger.debug(`[iam] error while checking permissions, command may fail: ${err}`);
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.iamUserIsCSQLAdmin = iamUserIsCSQLAdmin;
|
|
85
|
+
function ownerRolePermissions(databaseId, superuser, schema) {
|
|
86
|
+
const firebaseOwnerRole = firebaseowner(databaseId);
|
|
87
|
+
return [
|
|
88
|
+
`do
|
|
89
|
+
$$
|
|
90
|
+
begin
|
|
91
|
+
if not exists (select FROM pg_catalog.pg_roles
|
|
92
|
+
WHERE rolname = '${firebaseOwnerRole}') then
|
|
93
|
+
CREATE ROLE "${firebaseOwnerRole}" WITH ADMIN "${superuser}";
|
|
94
|
+
end if;
|
|
95
|
+
end
|
|
96
|
+
$$
|
|
97
|
+
;`,
|
|
98
|
+
`GRANT "${firebaseOwnerRole}" TO "cloudsqlsuperuser"`,
|
|
99
|
+
`ALTER SCHEMA "${schema}" OWNER TO "${firebaseOwnerRole}"`,
|
|
100
|
+
`GRANT USAGE ON SCHEMA "${schema}" TO "${firebaseOwnerRole}"`,
|
|
101
|
+
`GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseOwnerRole}"`,
|
|
102
|
+
`GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseOwnerRole}"`,
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
function writerRolePermissions(databaseId, superuser, schema) {
|
|
106
|
+
const firebaseWriterRole = firebasewriter(databaseId);
|
|
107
|
+
return [
|
|
108
|
+
`do
|
|
109
|
+
$$
|
|
110
|
+
begin
|
|
111
|
+
if not exists (select FROM pg_catalog.pg_roles
|
|
112
|
+
WHERE rolname = '${firebaseWriterRole}') then
|
|
113
|
+
CREATE ROLE "${firebaseWriterRole}" WITH ADMIN "${superuser}";
|
|
114
|
+
end if;
|
|
115
|
+
end
|
|
116
|
+
$$
|
|
117
|
+
;`,
|
|
118
|
+
`GRANT "${firebaseWriterRole}" TO "cloudsqlsuperuser"`,
|
|
119
|
+
`GRANT USAGE ON SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
120
|
+
`GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
121
|
+
`GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
122
|
+
`GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "${schema}" TO "${firebaseWriterRole}"`,
|
|
123
|
+
`SET ROLE = '${firebaseowner(databaseId)}';`,
|
|
124
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT SELECT, INSERT, UPDATE, DELETE, TRUNCATE ON TABLES TO "${firebaseWriterRole}";`,
|
|
125
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT USAGE ON SEQUENCES TO "${firebaseWriterRole}";`,
|
|
126
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT EXECUTE ON FUNCTIONS TO "${firebaseWriterRole}"`,
|
|
127
|
+
`SET ROLE = cloudsqlsuperuser`,
|
|
128
|
+
];
|
|
129
|
+
}
|
|
130
|
+
function readerRolePermissions(databaseId, superuser, schema) {
|
|
131
|
+
const firebaseReaderRole = firebasereader(databaseId);
|
|
132
|
+
return [
|
|
133
|
+
`do
|
|
134
|
+
$$
|
|
135
|
+
begin
|
|
136
|
+
if not exists (select FROM pg_catalog.pg_roles
|
|
137
|
+
WHERE rolname = '${firebaseReaderRole}') then
|
|
138
|
+
CREATE ROLE "${firebaseReaderRole}" WITH ADMIN "${superuser}";
|
|
139
|
+
end if;
|
|
140
|
+
end
|
|
141
|
+
$$
|
|
142
|
+
;`,
|
|
143
|
+
`GRANT "${firebaseReaderRole}" TO "cloudsqlsuperuser"`,
|
|
144
|
+
`GRANT USAGE ON SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
145
|
+
`GRANT SELECT ON ALL TABLES IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
146
|
+
`GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
147
|
+
`GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "${schema}" TO "${firebaseReaderRole}"`,
|
|
148
|
+
`SET ROLE = '${firebaseowner(databaseId)}';`,
|
|
149
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT SELECT ON TABLES TO "${firebaseReaderRole}";`,
|
|
150
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT SELECT, USAGE ON SEQUENCES TO "${firebaseReaderRole}";`,
|
|
151
|
+
`ALTER DEFAULT PRIVILEGES IN SCHEMA "${schema}" GRANT EXECUTE ON FUNCTIONS TO "${firebaseReaderRole}"`,
|
|
152
|
+
`SET ROLE = cloudsqlsuperuser`,
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
async function setupSQLPermissions(instanceId, databaseId, options, silent = false) {
|
|
156
|
+
const superuser = "firebasesuperuser";
|
|
157
|
+
const revokes = [];
|
|
158
|
+
if (await checkSQLRoleIsGranted(options, instanceId, databaseId, "cloudsqlsuperuser", firebaseowner(databaseId))) {
|
|
159
|
+
logger_1.logger.warn("Detected cloudsqlsuperuser was previously given to firebase owner, revoking to improve database security.");
|
|
160
|
+
revokes.push(`REVOKE "cloudsqlsuperuser" FROM "${firebaseowner(databaseId)}"`);
|
|
161
|
+
}
|
|
162
|
+
const sqlRoleSetupCmds = (0, lodash_1.concat)(revokes, [`CREATE SCHEMA IF NOT EXISTS "public"`], ownerRolePermissions(databaseId, superuser, "public"), writerRolePermissions(databaseId, superuser, "public"), readerRolePermissions(databaseId, superuser, "public"));
|
|
163
|
+
return (0, connect_1.executeSqlCmdsAsSuperUser)(options, instanceId, databaseId, sqlRoleSetupCmds, silent);
|
|
164
|
+
}
|
|
165
|
+
exports.setupSQLPermissions = setupSQLPermissions;
|
package/lib/gcp/devConnect.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateP4SA = exports.serviceAgentEmail = exports.sortConnectionsByCreateTime = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.fetchGitHubInstallations = exports.listAllBranches = exports.listAllLinkableGitRepositories = exports.listAllConnections = exports.getConnection = exports.deleteConnection = exports.createConnection = exports.client = void 0;
|
|
3
|
+
exports.getRepoDetailsFromBackend = exports.extractGitRepositoryLinkComponents = exports.generateP4SA = exports.serviceAgentEmail = exports.sortConnectionsByCreateTime = exports.fetchGitRepositoryLinkReadToken = exports.getGitRepositoryLink = exports.createGitRepositoryLink = exports.fetchGitHubInstallations = exports.listAllBranches = 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
6
|
const serviceusage_1 = require("./serviceusage");
|
|
7
|
+
const error_1 = require("../error");
|
|
8
|
+
const githubConnections_1 = require("../apphosting/githubConnections");
|
|
7
9
|
const PAGE_SIZE_MAX = 1000;
|
|
8
10
|
const LOCATION_OVERRIDE = process.env.FIREBASE_DEVELOPERCONNECT_LOCATION_OVERRIDE;
|
|
9
11
|
exports.client = new apiv2_1.Client({
|
|
@@ -115,6 +117,12 @@ async function getGitRepositoryLink(projectId, location, connectionId, gitReposi
|
|
|
115
117
|
return res.body;
|
|
116
118
|
}
|
|
117
119
|
exports.getGitRepositoryLink = getGitRepositoryLink;
|
|
120
|
+
async function fetchGitRepositoryLinkReadToken(projectId, location, connectionId, gitRepositoryLinkId) {
|
|
121
|
+
const name = `projects/${projectId}/locations/${LOCATION_OVERRIDE ?? location}/connections/${connectionId}/gitRepositoryLinks/${gitRepositoryLinkId}:fetchReadToken`;
|
|
122
|
+
const res = await exports.client.post(name);
|
|
123
|
+
return res.body;
|
|
124
|
+
}
|
|
125
|
+
exports.fetchGitRepositoryLinkReadToken = fetchGitRepositoryLinkReadToken;
|
|
118
126
|
function sortConnectionsByCreateTime(connections) {
|
|
119
127
|
return connections.sort((a, b) => {
|
|
120
128
|
return Date.parse(a.createTime) - Date.parse(b.createTime);
|
|
@@ -130,3 +138,32 @@ async function generateP4SA(projectNumber) {
|
|
|
130
138
|
await (0, serviceusage_1.generateServiceIdentityAndPoll)(projectNumber, new URL(devConnectOrigin).hostname, "apphosting");
|
|
131
139
|
}
|
|
132
140
|
exports.generateP4SA = generateP4SA;
|
|
141
|
+
function extractGitRepositoryLinkComponents(path) {
|
|
142
|
+
const connectionMatch = /connections\/([^\/]+)/.exec(path);
|
|
143
|
+
const repositoryMatch = /gitRepositoryLinks\/([^\/]+)/.exec(path);
|
|
144
|
+
const connection = connectionMatch ? connectionMatch[1] : null;
|
|
145
|
+
const gitRepoLink = repositoryMatch ? repositoryMatch[1] : null;
|
|
146
|
+
return { connection, gitRepoLink };
|
|
147
|
+
}
|
|
148
|
+
exports.extractGitRepositoryLinkComponents = extractGitRepositoryLinkComponents;
|
|
149
|
+
async function getRepoDetailsFromBackend(projectId, location, gitRepoLinkPath) {
|
|
150
|
+
const { connection, gitRepoLink } = extractGitRepositoryLinkComponents(gitRepoLinkPath);
|
|
151
|
+
if (!connection || !gitRepoLink) {
|
|
152
|
+
throw new error_1.FirebaseError(`Failed to extract connection or repository resource names from backend repository name.`);
|
|
153
|
+
}
|
|
154
|
+
const repoLink = await getGitRepositoryLink(projectId, location, connection, gitRepoLink);
|
|
155
|
+
const repoSlug = (0, githubConnections_1.extractRepoSlugFromUri)(repoLink.cloneUri);
|
|
156
|
+
const owner = repoSlug?.split("/")[0];
|
|
157
|
+
const repo = repoSlug?.split("/")[1];
|
|
158
|
+
if (!owner || !repo) {
|
|
159
|
+
throw new error_1.FirebaseError("Failed to parse owner and repo from git repository link");
|
|
160
|
+
}
|
|
161
|
+
const readToken = await fetchGitRepositoryLinkReadToken(projectId, location, connection, gitRepoLink);
|
|
162
|
+
return {
|
|
163
|
+
repoLink,
|
|
164
|
+
owner,
|
|
165
|
+
repo,
|
|
166
|
+
readToken,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
exports.getRepoDetailsFromBackend = getRepoDetailsFromBackend;
|
package/lib/gcp/firestore.js
CHANGED
|
@@ -62,7 +62,11 @@ async function deleteDocuments(project, docs, allowEmulator = false) {
|
|
|
62
62
|
return { delete: doc.name };
|
|
63
63
|
});
|
|
64
64
|
const data = { writes };
|
|
65
|
-
const res = await apiClient.post(url, data
|
|
65
|
+
const res = await apiClient.post(url, data, {
|
|
66
|
+
retries: 10,
|
|
67
|
+
retryCodes: [429, 409, 503],
|
|
68
|
+
retryMaxTimeout: 20 * 1000,
|
|
69
|
+
});
|
|
66
70
|
return res.body.writeResults.length;
|
|
67
71
|
}
|
|
68
72
|
exports.deleteDocuments = deleteDocuments;
|
package/lib/gcp/secretManager.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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;
|
|
3
|
+
exports.labels = exports.ensureApi = exports.isAppHostingManaged = exports.isFunctionsManaged = exports.FIREBASE_MANAGED = exports.checkServiceAgentRole = 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");
|
|
@@ -228,6 +228,14 @@ async function setIamPolicy(secret, bindings) {
|
|
|
228
228
|
}
|
|
229
229
|
exports.setIamPolicy = setIamPolicy;
|
|
230
230
|
async function ensureServiceAgentRole(secret, serviceAccountEmails, role) {
|
|
231
|
+
const bindings = await checkServiceAgentRole(secret, serviceAccountEmails, role);
|
|
232
|
+
if (bindings.length) {
|
|
233
|
+
await module.exports.setIamPolicy(secret, bindings);
|
|
234
|
+
}
|
|
235
|
+
(0, utils_1.logLabeledSuccess)("secretmanager", `Granted ${role} on projects/${secret.projectId}/secrets/${secret.name} to ${serviceAccountEmails.join(", ")}`);
|
|
236
|
+
}
|
|
237
|
+
exports.ensureServiceAgentRole = ensureServiceAgentRole;
|
|
238
|
+
async function checkServiceAgentRole(secret, serviceAccountEmails, role) {
|
|
231
239
|
const policy = await module.exports.getIamPolicy(secret);
|
|
232
240
|
const bindings = policy.bindings || [];
|
|
233
241
|
let binding = bindings.find((b) => b.role === role);
|
|
@@ -243,11 +251,10 @@ async function ensureServiceAgentRole(secret, serviceAccountEmails, role) {
|
|
|
243
251
|
}
|
|
244
252
|
}
|
|
245
253
|
if (shouldShortCircuit)
|
|
246
|
-
return;
|
|
247
|
-
|
|
248
|
-
(0, utils_1.logLabeledSuccess)("secretmanager", `Granted ${role} on projects/${secret.projectId}/secrets/${secret.name} to ${serviceAccountEmails.join(", ")}`);
|
|
254
|
+
return [];
|
|
255
|
+
return bindings;
|
|
249
256
|
}
|
|
250
|
-
exports.
|
|
257
|
+
exports.checkServiceAgentRole = checkServiceAgentRole;
|
|
251
258
|
exports.FIREBASE_MANAGED = "firebase-managed";
|
|
252
259
|
function isFunctionsManaged(secret) {
|
|
253
260
|
return (secret.labels[exports.FIREBASE_MANAGED] === "true" || secret.labels[exports.FIREBASE_MANAGED] === "functions");
|
package/lib/getProjectNumber.js
CHANGED
|
@@ -8,7 +8,7 @@ async function getProjectNumber(options) {
|
|
|
8
8
|
return options.projectNumber;
|
|
9
9
|
}
|
|
10
10
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
11
|
-
const metadata = await (0, projects_1.
|
|
11
|
+
const metadata = await (0, projects_1.getProject)(projectId);
|
|
12
12
|
options.projectNumber = metadata.projectNumber;
|
|
13
13
|
return options.projectNumber;
|
|
14
14
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.doSetup = void 0;
|
|
4
|
+
const clc = require("colorette");
|
|
5
|
+
const utils = require("../../utils");
|
|
6
|
+
const templates_1 = require("../../templates");
|
|
7
|
+
const cloudbilling_1 = require("../../gcp/cloudbilling");
|
|
8
|
+
const APPHOSTING_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/apphosting/apphosting.yaml");
|
|
9
|
+
async function doSetup(setup, config) {
|
|
10
|
+
await (0, cloudbilling_1.checkBillingEnabled)(setup.projectId);
|
|
11
|
+
utils.logBullet("Writing default settings to " + clc.bold("apphosting.yaml") + "...");
|
|
12
|
+
await config.askWriteProjectFile("apphosting.yaml", APPHOSTING_YAML_TEMPLATE);
|
|
13
|
+
utils.logSuccess("Create a new App Hosting backend with `firebase apphosting:backends:create`");
|
|
14
|
+
}
|
|
15
|
+
exports.doSetup = doSetup;
|