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,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBackendForAmbiguousLocation = exports.promptLocation = exports.deleteBackendAndPoll = exports.orchestrateRollout = exports.setDefaultTrafficPolicy = exports.createBackend = exports.ensureAppHostingComputeServiceAccount = exports.doSetup = void 0;
|
|
4
|
+
const clc = require("colorette");
|
|
5
|
+
const poller = require("../operation-poller");
|
|
6
|
+
const apphosting = require("../gcp/apphosting");
|
|
7
|
+
const githubConnections = require("./githubConnections");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const api_1 = require("../api");
|
|
10
|
+
const apphosting_1 = require("../gcp/apphosting");
|
|
11
|
+
const resourceManager_1 = require("../gcp/resourceManager");
|
|
12
|
+
const iam = require("../gcp/iam");
|
|
13
|
+
const error_1 = require("../error");
|
|
14
|
+
const prompt_1 = require("../prompt");
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
|
+
const ensureApiEnabled_1 = require("../ensureApiEnabled");
|
|
17
|
+
const deploymentTool = require("../deploymentTool");
|
|
18
|
+
const app_1 = require("./app");
|
|
19
|
+
const ora = require("ora");
|
|
20
|
+
const node_fetch_1 = require("node-fetch");
|
|
21
|
+
const DEFAULT_COMPUTE_SERVICE_ACCOUNT_NAME = "firebase-app-hosting-compute";
|
|
22
|
+
const apphostingPollerOptions = {
|
|
23
|
+
apiOrigin: (0, api_1.apphostingOrigin)(),
|
|
24
|
+
apiVersion: apphosting_1.API_VERSION,
|
|
25
|
+
masterTimeout: 25 * 60 * 1000,
|
|
26
|
+
maxBackoff: 10000,
|
|
27
|
+
};
|
|
28
|
+
async function tlsReady(url) {
|
|
29
|
+
try {
|
|
30
|
+
await (0, node_fetch_1.default)(url);
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
const maybeNodeError = err;
|
|
35
|
+
if (/HANDSHAKE_FAILURE/.test(maybeNodeError?.cause?.code)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function awaitTlsReady(url) {
|
|
42
|
+
let ready;
|
|
43
|
+
do {
|
|
44
|
+
ready = await tlsReady(url);
|
|
45
|
+
if (!ready) {
|
|
46
|
+
await (0, utils_1.sleep)(1000);
|
|
47
|
+
}
|
|
48
|
+
} while (!ready);
|
|
49
|
+
}
|
|
50
|
+
async function doSetup(projectId, webAppName, location, serviceAccount) {
|
|
51
|
+
await Promise.all([
|
|
52
|
+
(0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.developerConnectOrigin)(), "apphosting", true),
|
|
53
|
+
(0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.cloudbuildOrigin)(), "apphosting", true),
|
|
54
|
+
(0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.secretManagerOrigin)(), "apphosting", true),
|
|
55
|
+
(0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.cloudRunApiOrigin)(), "apphosting", true),
|
|
56
|
+
(0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.artifactRegistryDomain)(), "apphosting", true),
|
|
57
|
+
(0, ensureApiEnabled_1.ensure)(projectId, (0, api_1.iamOrigin)(), "apphosting", true),
|
|
58
|
+
]);
|
|
59
|
+
await ensureAppHostingComputeServiceAccount(projectId, serviceAccount);
|
|
60
|
+
const allowedLocations = (await apphosting.listLocations(projectId)).map((loc) => loc.locationId);
|
|
61
|
+
if (location) {
|
|
62
|
+
if (!allowedLocations.includes(location)) {
|
|
63
|
+
throw new error_1.FirebaseError(`Invalid location ${location}. Valid choices are ${allowedLocations.join(", ")}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
location =
|
|
67
|
+
location || (await promptLocation(projectId, "Select a location to host your backend:\n"));
|
|
68
|
+
const gitRepositoryConnection = await githubConnections.linkGitHubRepository(projectId, location);
|
|
69
|
+
const rootDir = await (0, prompt_1.promptOnce)({
|
|
70
|
+
name: "rootDir",
|
|
71
|
+
type: "input",
|
|
72
|
+
default: "/",
|
|
73
|
+
message: "Specify your app's root directory relative to your repository",
|
|
74
|
+
});
|
|
75
|
+
const branch = await (0, prompt_1.promptOnce)({
|
|
76
|
+
name: "branch",
|
|
77
|
+
type: "input",
|
|
78
|
+
default: "main",
|
|
79
|
+
message: "Pick a branch for continuous deployment",
|
|
80
|
+
});
|
|
81
|
+
(0, utils_1.logSuccess)(`Repo linked successfully!\n`);
|
|
82
|
+
(0, utils_1.logBullet)(`${clc.yellow("===")} Set up your backend`);
|
|
83
|
+
const backendId = await promptNewBackendId(projectId, location, {
|
|
84
|
+
name: "backendId",
|
|
85
|
+
type: "input",
|
|
86
|
+
default: "my-web-app",
|
|
87
|
+
message: "Provide a name for your backend [1-30 characters]",
|
|
88
|
+
});
|
|
89
|
+
(0, utils_1.logSuccess)(`Name set to ${backendId}\n`);
|
|
90
|
+
const webApp = await app_1.webApps.getOrCreateWebApp(projectId, webAppName, backendId);
|
|
91
|
+
if (!webApp) {
|
|
92
|
+
(0, utils_1.logWarning)(`Firebase web app not set`);
|
|
93
|
+
}
|
|
94
|
+
const createBackendSpinner = ora("Creating your new backend...").start();
|
|
95
|
+
const backend = await createBackend(projectId, location, backendId, gitRepositoryConnection, serviceAccount, webApp?.id, rootDir);
|
|
96
|
+
createBackendSpinner.succeed(`Successfully created backend!\n\t${backend.name}\n`);
|
|
97
|
+
await setDefaultTrafficPolicy(projectId, location, backendId, branch);
|
|
98
|
+
const confirmRollout = await (0, prompt_1.promptOnce)({
|
|
99
|
+
type: "confirm",
|
|
100
|
+
name: "rollout",
|
|
101
|
+
default: true,
|
|
102
|
+
message: "Do you want to deploy now?",
|
|
103
|
+
});
|
|
104
|
+
if (!confirmRollout) {
|
|
105
|
+
(0, utils_1.logSuccess)(`Your backend will be deployed at:\n\thttps://${backend.uri}`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const url = `https://${backend.uri}`;
|
|
109
|
+
(0, utils_1.logBullet)(`You may also track this rollout at:\n\t${(0, api_1.consoleOrigin)()}/project/${projectId}/apphosting`);
|
|
110
|
+
const createRolloutSpinner = ora("Starting a new rollout; this may take a few minutes. It's safe to exit now.").start();
|
|
111
|
+
await orchestrateRollout(projectId, location, backendId, {
|
|
112
|
+
source: {
|
|
113
|
+
codebase: {
|
|
114
|
+
branch,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
createRolloutSpinner.succeed("Rollout complete");
|
|
119
|
+
if (!(await tlsReady(url))) {
|
|
120
|
+
const tlsSpinner = ora("Finalizing your backend's TLS certificate; this may take a few minutes.").start();
|
|
121
|
+
await awaitTlsReady(url);
|
|
122
|
+
tlsSpinner.succeed("TLS certificate ready");
|
|
123
|
+
}
|
|
124
|
+
(0, utils_1.logSuccess)(`Your backend is now deployed at:\n\thttps://${backend.uri}`);
|
|
125
|
+
}
|
|
126
|
+
exports.doSetup = doSetup;
|
|
127
|
+
async function ensureAppHostingComputeServiceAccount(projectId, serviceAccount) {
|
|
128
|
+
const sa = serviceAccount || defaultComputeServiceAccountEmail(projectId);
|
|
129
|
+
const name = `projects/${projectId}/serviceAccounts/${sa}`;
|
|
130
|
+
try {
|
|
131
|
+
await iam.testResourceIamPermissions((0, api_1.iamOrigin)(), "v1", name, ["iam.serviceAccounts.actAs"], `projects/${projectId}`);
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
if (!(err instanceof error_1.FirebaseError)) {
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
137
|
+
if (err.status === 404) {
|
|
138
|
+
await provisionDefaultComputeServiceAccount(projectId);
|
|
139
|
+
}
|
|
140
|
+
else if (err.status === 403) {
|
|
141
|
+
throw new error_1.FirebaseError(`Failed to create backend due to missing delegation permissions for ${sa}. Make sure you have the iam.serviceAccounts.actAs permission.`, { original: err });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.ensureAppHostingComputeServiceAccount = ensureAppHostingComputeServiceAccount;
|
|
146
|
+
async function promptNewBackendId(projectId, location, prompt) {
|
|
147
|
+
while (true) {
|
|
148
|
+
const backendId = await (0, prompt_1.promptOnce)(prompt);
|
|
149
|
+
try {
|
|
150
|
+
await apphosting.getBackend(projectId, location, backendId);
|
|
151
|
+
}
|
|
152
|
+
catch (err) {
|
|
153
|
+
if (err.status === 404) {
|
|
154
|
+
return backendId;
|
|
155
|
+
}
|
|
156
|
+
throw new error_1.FirebaseError(`Failed to check if backend with id ${backendId} already exists in ${location}`, { original: err });
|
|
157
|
+
}
|
|
158
|
+
(0, utils_1.logWarning)(`Backend with id ${backendId} already exists in ${location}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function defaultComputeServiceAccountEmail(projectId) {
|
|
162
|
+
return `${DEFAULT_COMPUTE_SERVICE_ACCOUNT_NAME}@${projectId}.iam.gserviceaccount.com`;
|
|
163
|
+
}
|
|
164
|
+
async function createBackend(projectId, location, backendId, repository, serviceAccount, webAppId, rootDir = "/") {
|
|
165
|
+
const defaultServiceAccount = defaultComputeServiceAccountEmail(projectId);
|
|
166
|
+
const backendReqBody = {
|
|
167
|
+
servingLocality: "GLOBAL_ACCESS",
|
|
168
|
+
codebase: {
|
|
169
|
+
repository: `${repository.name}`,
|
|
170
|
+
rootDirectory: rootDir,
|
|
171
|
+
},
|
|
172
|
+
labels: deploymentTool.labels(),
|
|
173
|
+
serviceAccount: serviceAccount || defaultServiceAccount,
|
|
174
|
+
appId: webAppId,
|
|
175
|
+
};
|
|
176
|
+
async function createBackendAndPoll() {
|
|
177
|
+
const op = await apphosting.createBackend(projectId, location, backendReqBody, backendId);
|
|
178
|
+
return await poller.pollOperation({
|
|
179
|
+
...apphostingPollerOptions,
|
|
180
|
+
pollerName: `create-${projectId}-${location}-${backendId}`,
|
|
181
|
+
operationResourceName: op.name,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
return await createBackendAndPoll();
|
|
185
|
+
}
|
|
186
|
+
exports.createBackend = createBackend;
|
|
187
|
+
async function provisionDefaultComputeServiceAccount(projectId) {
|
|
188
|
+
try {
|
|
189
|
+
await iam.createServiceAccount(projectId, DEFAULT_COMPUTE_SERVICE_ACCOUNT_NAME, "Default service account used to run builds and deploys for Firebase App Hosting", "Firebase App Hosting compute service account");
|
|
190
|
+
}
|
|
191
|
+
catch (err) {
|
|
192
|
+
if (err.status !== 409) {
|
|
193
|
+
throw err;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
await (0, resourceManager_1.addServiceAccountToRoles)(projectId, defaultComputeServiceAccountEmail(projectId), [
|
|
197
|
+
"roles/firebaseapphosting.computeRunner",
|
|
198
|
+
"roles/firebase.sdkAdminServiceAgent",
|
|
199
|
+
"roles/developerconnect.readTokenAccessor",
|
|
200
|
+
], true);
|
|
201
|
+
}
|
|
202
|
+
async function setDefaultTrafficPolicy(projectId, location, backendId, codebaseBranch) {
|
|
203
|
+
const traffic = {
|
|
204
|
+
rolloutPolicy: {
|
|
205
|
+
codebaseBranch: codebaseBranch,
|
|
206
|
+
stages: [
|
|
207
|
+
{
|
|
208
|
+
progression: "IMMEDIATE",
|
|
209
|
+
targetPercent: 100,
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
const op = await apphosting.updateTraffic(projectId, location, backendId, traffic);
|
|
215
|
+
await poller.pollOperation({
|
|
216
|
+
...apphostingPollerOptions,
|
|
217
|
+
pollerName: `updateTraffic-${projectId}-${location}-${backendId}`,
|
|
218
|
+
operationResourceName: op.name,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
exports.setDefaultTrafficPolicy = setDefaultTrafficPolicy;
|
|
222
|
+
async function orchestrateRollout(projectId, location, backendId, buildInput) {
|
|
223
|
+
const buildId = await apphosting.getNextRolloutId(projectId, location, backendId, 1);
|
|
224
|
+
const buildOp = await apphosting.createBuild(projectId, location, backendId, buildId, buildInput);
|
|
225
|
+
const rolloutBody = {
|
|
226
|
+
build: `projects/${projectId}/locations/${location}/backends/${backendId}/builds/${buildId}`,
|
|
227
|
+
};
|
|
228
|
+
let tries = 0;
|
|
229
|
+
let done = false;
|
|
230
|
+
while (!done) {
|
|
231
|
+
tries++;
|
|
232
|
+
try {
|
|
233
|
+
const validateOnly = true;
|
|
234
|
+
await apphosting.createRollout(projectId, location, backendId, buildId, rolloutBody, validateOnly);
|
|
235
|
+
done = true;
|
|
236
|
+
}
|
|
237
|
+
catch (err) {
|
|
238
|
+
if (err instanceof error_1.FirebaseError && err.status === 400) {
|
|
239
|
+
if (tries >= 5) {
|
|
240
|
+
throw err;
|
|
241
|
+
}
|
|
242
|
+
await (0, utils_1.sleep)(1000);
|
|
243
|
+
}
|
|
244
|
+
else {
|
|
245
|
+
throw err;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const rolloutOp = await apphosting.createRollout(projectId, location, backendId, buildId, rolloutBody);
|
|
250
|
+
const rolloutPoll = poller.pollOperation({
|
|
251
|
+
...apphostingPollerOptions,
|
|
252
|
+
pollerName: `create-${projectId}-${location}-backend-${backendId}-rollout-${buildId}`,
|
|
253
|
+
operationResourceName: rolloutOp.name,
|
|
254
|
+
});
|
|
255
|
+
const buildPoll = poller.pollOperation({
|
|
256
|
+
...apphostingPollerOptions,
|
|
257
|
+
pollerName: `create-${projectId}-${location}-backend-${backendId}-build-${buildId}`,
|
|
258
|
+
operationResourceName: buildOp.name,
|
|
259
|
+
});
|
|
260
|
+
const [rollout, build] = await Promise.all([rolloutPoll, buildPoll]);
|
|
261
|
+
if (build.state !== "READY") {
|
|
262
|
+
if (!build.buildLogsUri) {
|
|
263
|
+
throw new error_1.FirebaseError("Failed to build your app, but failed to get build logs as well. " +
|
|
264
|
+
"This is an internal error and should be reported");
|
|
265
|
+
}
|
|
266
|
+
throw new error_1.FirebaseError(`Failed to build your app. Please inspect the build logs at ${build.buildLogsUri}.`, { children: [build.error] });
|
|
267
|
+
}
|
|
268
|
+
return { rollout, build };
|
|
269
|
+
}
|
|
270
|
+
exports.orchestrateRollout = orchestrateRollout;
|
|
271
|
+
async function deleteBackendAndPoll(projectId, location, backendId) {
|
|
272
|
+
const op = await apphosting.deleteBackend(projectId, location, backendId);
|
|
273
|
+
await poller.pollOperation({
|
|
274
|
+
...apphostingPollerOptions,
|
|
275
|
+
pollerName: `delete-${projectId}-${location}-${backendId}`,
|
|
276
|
+
operationResourceName: op.name,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
exports.deleteBackendAndPoll = deleteBackendAndPoll;
|
|
280
|
+
async function promptLocation(projectId, prompt = "Please select a location:") {
|
|
281
|
+
const allowedLocations = (await apphosting.listLocations(projectId)).map((loc) => loc.locationId);
|
|
282
|
+
if (allowedLocations.length === 1) {
|
|
283
|
+
return allowedLocations[0];
|
|
284
|
+
}
|
|
285
|
+
const location = (await (0, prompt_1.promptOnce)({
|
|
286
|
+
name: "location",
|
|
287
|
+
type: "list",
|
|
288
|
+
default: constants_1.DEFAULT_LOCATION,
|
|
289
|
+
message: prompt,
|
|
290
|
+
choices: allowedLocations,
|
|
291
|
+
}));
|
|
292
|
+
(0, utils_1.logSuccess)(`Location set to ${location}.\n`);
|
|
293
|
+
return location;
|
|
294
|
+
}
|
|
295
|
+
exports.promptLocation = promptLocation;
|
|
296
|
+
async function getBackendForAmbiguousLocation(projectId, backendId, locationDisambugationPrompt) {
|
|
297
|
+
let { unreachable, backends } = await apphosting.listBackends(projectId, "-");
|
|
298
|
+
if (unreachable && unreachable.length !== 0) {
|
|
299
|
+
(0, utils_1.logWarning)(`The following locations are currently unreachable: ${unreachable}.\n` +
|
|
300
|
+
"If your backend is in one of these regions, please try again later.");
|
|
301
|
+
}
|
|
302
|
+
backends = backends.filter((backend) => apphosting.parseBackendName(backend.name).id === backendId);
|
|
303
|
+
if (backends.length === 0) {
|
|
304
|
+
throw new error_1.FirebaseError(`No backend named "${backendId}" found.`);
|
|
305
|
+
}
|
|
306
|
+
if (backends.length === 1) {
|
|
307
|
+
return backends[0];
|
|
308
|
+
}
|
|
309
|
+
const backendsByLocation = new Map();
|
|
310
|
+
backends.forEach((backend) => backendsByLocation.set(apphosting.parseBackendName(backend.name).location, backend));
|
|
311
|
+
const location = await (0, prompt_1.promptOnce)({
|
|
312
|
+
name: "location",
|
|
313
|
+
type: "list",
|
|
314
|
+
message: locationDisambugationPrompt,
|
|
315
|
+
choices: [...backendsByLocation.keys()],
|
|
316
|
+
});
|
|
317
|
+
return backendsByLocation.get(location);
|
|
318
|
+
}
|
|
319
|
+
exports.getBackendForAmbiguousLocation = getBackendForAmbiguousLocation;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchAllRepositories = exports.listAppHostingConnections = exports.getOrCreateRepository = exports.getOrCreateConnection = exports.createConnection = exports.getOrCreateOauthConnection = exports.linkGitHubRepository = exports.parseConnectionName = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
|
-
const gcb = require("
|
|
6
|
-
const rm = require("
|
|
7
|
-
const poller = require("
|
|
8
|
-
const utils = require("
|
|
9
|
-
const api_1 = require("
|
|
10
|
-
const error_1 = require("
|
|
11
|
-
const prompt_1 = require("
|
|
12
|
-
const getProjectNumber_1 = require("
|
|
5
|
+
const gcb = require("../gcp/cloudbuild");
|
|
6
|
+
const rm = require("../gcp/resourceManager");
|
|
7
|
+
const poller = require("../operation-poller");
|
|
8
|
+
const utils = require("../utils");
|
|
9
|
+
const api_1 = require("../api");
|
|
10
|
+
const error_1 = require("../error");
|
|
11
|
+
const prompt_1 = require("../prompt");
|
|
12
|
+
const getProjectNumber_1 = require("../getProjectNumber");
|
|
13
13
|
const fuzzy = require("fuzzy");
|
|
14
14
|
const inquirer = require("inquirer");
|
|
15
15
|
const APPHOSTING_CONN_PATTERN = /.+\/apphosting-github-conn-.+$/;
|
|
@@ -50,7 +50,7 @@ function generateConnectionId() {
|
|
|
50
50
|
}
|
|
51
51
|
const ADD_CONN_CHOICE = "@ADD_CONN";
|
|
52
52
|
async function linkGitHubRepository(projectId, location) {
|
|
53
|
-
utils.logBullet(clc.bold(`${clc.yellow("===")}
|
|
53
|
+
utils.logBullet(clc.bold(`${clc.yellow("===")} Import a GitHub repository`));
|
|
54
54
|
const oauthConn = await getOrCreateOauthConnection(projectId, location);
|
|
55
55
|
const existingConns = await listAppHostingConnections(projectId);
|
|
56
56
|
if (existingConns.length === 0) {
|
|
@@ -83,7 +83,7 @@ async function createFullyInstalledConnection(projectId, location, connectionId,
|
|
|
83
83
|
});
|
|
84
84
|
while (conn.installationState.stage !== "COMPLETE") {
|
|
85
85
|
utils.logBullet("Install the Cloud Build GitHub app to enable access to GitHub repositories");
|
|
86
|
-
const targetUri = conn.installationState.actionUri
|
|
86
|
+
const targetUri = conn.installationState.actionUri;
|
|
87
87
|
utils.logBullet(targetUri);
|
|
88
88
|
await utils.openInBrowser(targetUri);
|
|
89
89
|
await (0, prompt_1.promptOnce)({
|
|
@@ -129,7 +129,7 @@ async function promptRepositoryUri(projectId, connections) {
|
|
|
129
129
|
const remoteUri = await (0, prompt_1.promptOnce)({
|
|
130
130
|
type: "autocomplete",
|
|
131
131
|
name: "remoteUri",
|
|
132
|
-
message: "Which
|
|
132
|
+
message: "Which GitHub repo do you want to deploy?",
|
|
133
133
|
source: (_, input = "") => {
|
|
134
134
|
return new Promise((resolve) => resolve([
|
|
135
135
|
new inquirer.Separator(),
|
|
@@ -155,7 +155,7 @@ async function promptRepositoryUri(projectId, connections) {
|
|
|
155
155
|
}
|
|
156
156
|
async function ensureSecretManagerAdminGrant(projectId) {
|
|
157
157
|
const projectNumber = await (0, getProjectNumber_1.getProjectNumber)({ projectId });
|
|
158
|
-
const cbsaEmail = gcb.
|
|
158
|
+
const cbsaEmail = gcb.getDefaultServiceAgent(projectNumber);
|
|
159
159
|
const alreadyGranted = await rm.serviceAccountHasRoles(projectId, cbsaEmail, ["roles/secretmanager.admin"], true);
|
|
160
160
|
if (alreadyGranted) {
|
|
161
161
|
return;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.envVarForSecret = exports.selectBackendServiceAccounts = exports.GRANT_ACCESS_IN_FUTURE = exports.WARN_NO_BACKENDS = exports.selectFromMetadata = exports.tableForBackends = exports.serviceAccountDisplay = exports.toMetadata = void 0;
|
|
4
|
+
const clc = require("colorette");
|
|
5
|
+
const Table = require("cli-table");
|
|
6
|
+
const _1 = require(".");
|
|
7
|
+
const apphosting = require("../../gcp/apphosting");
|
|
8
|
+
const prompt = require("../../prompt");
|
|
9
|
+
const utils = require("../../utils");
|
|
10
|
+
const logger_1 = require("../../logger");
|
|
11
|
+
const env = require("../../functions/env");
|
|
12
|
+
function toMetadata(projectNumber, backends) {
|
|
13
|
+
const metadata = [];
|
|
14
|
+
for (const backend of backends) {
|
|
15
|
+
const [, , , location, , id] = backend.name.split("/");
|
|
16
|
+
metadata.push({ location, id, ...(0, _1.serviceAccountsForBackend)(projectNumber, backend) });
|
|
17
|
+
}
|
|
18
|
+
return metadata.sort((left, right) => {
|
|
19
|
+
const cmplocation = left.location.localeCompare(right.location);
|
|
20
|
+
if (cmplocation) {
|
|
21
|
+
return cmplocation;
|
|
22
|
+
}
|
|
23
|
+
return left.id.localeCompare(right.id);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
exports.toMetadata = toMetadata;
|
|
27
|
+
function serviceAccountDisplay(metadata) {
|
|
28
|
+
if (sameServiceAccount(metadata)) {
|
|
29
|
+
return metadata.runServiceAccount;
|
|
30
|
+
}
|
|
31
|
+
return `${metadata.buildServiceAccount}, ${metadata.runServiceAccount}`;
|
|
32
|
+
}
|
|
33
|
+
exports.serviceAccountDisplay = serviceAccountDisplay;
|
|
34
|
+
function sameServiceAccount(metadata) {
|
|
35
|
+
return metadata.buildServiceAccount === metadata.runServiceAccount;
|
|
36
|
+
}
|
|
37
|
+
const matchesServiceAccounts = (target) => (test) => {
|
|
38
|
+
return (target.buildServiceAccount === test.buildServiceAccount &&
|
|
39
|
+
target.runServiceAccount === test.runServiceAccount);
|
|
40
|
+
};
|
|
41
|
+
function tableForBackends(metadata) {
|
|
42
|
+
const headers = [
|
|
43
|
+
"location",
|
|
44
|
+
"backend",
|
|
45
|
+
metadata.every(sameServiceAccount) ? "service account" : "service accounts",
|
|
46
|
+
];
|
|
47
|
+
const rows = metadata.map((m) => [m.location, m.id, serviceAccountDisplay(m)]);
|
|
48
|
+
return [headers, rows];
|
|
49
|
+
}
|
|
50
|
+
exports.tableForBackends = tableForBackends;
|
|
51
|
+
function selectFromMetadata(input, selected) {
|
|
52
|
+
const buildAccounts = new Set();
|
|
53
|
+
const runAccounts = new Set();
|
|
54
|
+
for (const sa of selected) {
|
|
55
|
+
if (input.find((m) => m.buildServiceAccount === sa)) {
|
|
56
|
+
buildAccounts.add(sa);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
runAccounts.add(sa);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
buildServiceAccounts: [...buildAccounts],
|
|
64
|
+
runServiceAccounts: [...runAccounts],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
exports.selectFromMetadata = selectFromMetadata;
|
|
68
|
+
exports.WARN_NO_BACKENDS = "To use this secret, your backend's service account must be granted access." +
|
|
69
|
+
"It does not look like you have a backend yet. After creating a backend, grant access with " +
|
|
70
|
+
clc.bold("firebase apphosting:secrets:grantaccess");
|
|
71
|
+
exports.GRANT_ACCESS_IN_FUTURE = `To grant access in the future, run ${clc.bold("firebase apphosting:secrets:grantaccess")}`;
|
|
72
|
+
async function selectBackendServiceAccounts(projectNumber, projectId, options) {
|
|
73
|
+
const listBackends = await apphosting.listBackends(projectId, "-");
|
|
74
|
+
if (listBackends.unreachable.length) {
|
|
75
|
+
utils.logWarning(`Could not reach location(s) ${listBackends.unreachable.join(", ")}. You may need to run ` +
|
|
76
|
+
`${clc.bold("firebase apphosting:secrets:grantaccess")} at a later time if you have backends in these locations`);
|
|
77
|
+
}
|
|
78
|
+
if (!listBackends.backends.length) {
|
|
79
|
+
utils.logWarning(exports.WARN_NO_BACKENDS);
|
|
80
|
+
return { buildServiceAccounts: [], runServiceAccounts: [] };
|
|
81
|
+
}
|
|
82
|
+
if (listBackends.backends.length === 1) {
|
|
83
|
+
const grant = await prompt.confirm({
|
|
84
|
+
nonInteractive: options.nonInteractive,
|
|
85
|
+
default: true,
|
|
86
|
+
message: "To use this secret, your backend's service account must be granted access. Would you like to grant access now?",
|
|
87
|
+
});
|
|
88
|
+
if (grant) {
|
|
89
|
+
return (0, _1.toMulti)((0, _1.serviceAccountsForBackend)(projectNumber, listBackends.backends[0]));
|
|
90
|
+
}
|
|
91
|
+
utils.logBullet(exports.GRANT_ACCESS_IN_FUTURE);
|
|
92
|
+
return { buildServiceAccounts: [], runServiceAccounts: [] };
|
|
93
|
+
}
|
|
94
|
+
const metadata = toMetadata(projectNumber, listBackends.backends);
|
|
95
|
+
if (metadata.every(matchesServiceAccounts(metadata[0]))) {
|
|
96
|
+
utils.logBullet("To use this secret, your backend's service account must be granted access.");
|
|
97
|
+
utils.logBullet("All of your backends share the following " +
|
|
98
|
+
(sameServiceAccount(metadata[0]) ? "service account: " : "service accounts: ") +
|
|
99
|
+
serviceAccountDisplay(metadata[0]) +
|
|
100
|
+
".\nGranting access to one backend will grant access to all backends.");
|
|
101
|
+
const grant = await prompt.confirm({
|
|
102
|
+
nonInteractive: options.nonInteractive,
|
|
103
|
+
default: true,
|
|
104
|
+
message: "Would you like to grant access to all backends now?",
|
|
105
|
+
});
|
|
106
|
+
if (grant) {
|
|
107
|
+
return selectFromMetadata(metadata, [
|
|
108
|
+
metadata[0].buildServiceAccount,
|
|
109
|
+
metadata[0].runServiceAccount,
|
|
110
|
+
]);
|
|
111
|
+
}
|
|
112
|
+
utils.logBullet(exports.GRANT_ACCESS_IN_FUTURE);
|
|
113
|
+
return { buildServiceAccounts: [], runServiceAccounts: [] };
|
|
114
|
+
}
|
|
115
|
+
utils.logBullet("To use this secret, your backend's service account must be granted access. Your backends use the following service accounts:");
|
|
116
|
+
const tableData = tableForBackends(metadata);
|
|
117
|
+
const table = new Table({
|
|
118
|
+
head: tableData[0],
|
|
119
|
+
style: { head: ["green"] },
|
|
120
|
+
rows: tableData[1],
|
|
121
|
+
});
|
|
122
|
+
logger_1.logger.info(table.toString());
|
|
123
|
+
const allAccounts = metadata.reduce((accum, row) => {
|
|
124
|
+
accum.add(row.buildServiceAccount);
|
|
125
|
+
accum.add(row.runServiceAccount);
|
|
126
|
+
return accum;
|
|
127
|
+
}, new Set());
|
|
128
|
+
const chosen = await prompt.promptOnce({
|
|
129
|
+
type: "checkbox",
|
|
130
|
+
message: "Which service accounts would you like to grant access? " +
|
|
131
|
+
"Press Space to select accounts, then Enter to confirm your choices.",
|
|
132
|
+
choices: [...allAccounts.values()].sort(),
|
|
133
|
+
});
|
|
134
|
+
if (!chosen.length) {
|
|
135
|
+
utils.logBullet(exports.GRANT_ACCESS_IN_FUTURE);
|
|
136
|
+
}
|
|
137
|
+
return selectFromMetadata(metadata, chosen);
|
|
138
|
+
}
|
|
139
|
+
exports.selectBackendServiceAccounts = selectBackendServiceAccounts;
|
|
140
|
+
function toUpperSnakeCase(key) {
|
|
141
|
+
return key
|
|
142
|
+
.replace(/[.-]/g, "_")
|
|
143
|
+
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
144
|
+
.toUpperCase();
|
|
145
|
+
}
|
|
146
|
+
async function envVarForSecret(secret) {
|
|
147
|
+
const upper = toUpperSnakeCase(secret);
|
|
148
|
+
if (upper === secret) {
|
|
149
|
+
try {
|
|
150
|
+
env.validateKey(secret);
|
|
151
|
+
return secret;
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
do {
|
|
157
|
+
const test = await prompt.promptOnce({
|
|
158
|
+
message: "What environment variable name would you like to use?",
|
|
159
|
+
default: upper,
|
|
160
|
+
});
|
|
161
|
+
try {
|
|
162
|
+
env.validateKey(test);
|
|
163
|
+
return test;
|
|
164
|
+
}
|
|
165
|
+
catch (err) {
|
|
166
|
+
utils.logLabeledError("apphosting", err.message);
|
|
167
|
+
}
|
|
168
|
+
} while (true);
|
|
169
|
+
}
|
|
170
|
+
exports.envVarForSecret = envVarForSecret;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.upsertSecret = exports.grantSecretAccess = exports.serviceAccountsForBackend = exports.toMulti = void 0;
|
|
4
|
+
const error_1 = require("../../error");
|
|
5
|
+
const gcsm = require("../../gcp/secretManager");
|
|
6
|
+
const gcb = require("../../gcp/cloudbuild");
|
|
7
|
+
const gce = require("../../gcp/computeEngine");
|
|
8
|
+
const apphosting = require("../../gcp/apphosting");
|
|
9
|
+
const secretManager_1 = require("../../gcp/secretManager");
|
|
10
|
+
const secretManager_2 = require("../../gcp/secretManager");
|
|
11
|
+
const utils = require("../../utils");
|
|
12
|
+
const prompt = require("../../prompt");
|
|
13
|
+
function toMulti(accounts) {
|
|
14
|
+
const m = {
|
|
15
|
+
buildServiceAccounts: [accounts.buildServiceAccount],
|
|
16
|
+
runServiceAccounts: [],
|
|
17
|
+
};
|
|
18
|
+
if (accounts.buildServiceAccount !== accounts.runServiceAccount) {
|
|
19
|
+
m.runServiceAccounts.push(accounts.runServiceAccount);
|
|
20
|
+
}
|
|
21
|
+
return m;
|
|
22
|
+
}
|
|
23
|
+
exports.toMulti = toMulti;
|
|
24
|
+
function serviceAccountsForBackend(projectNumber, backend) {
|
|
25
|
+
if (backend.serviceAccount) {
|
|
26
|
+
return {
|
|
27
|
+
buildServiceAccount: backend.serviceAccount,
|
|
28
|
+
runServiceAccount: backend.serviceAccount,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
buildServiceAccount: gcb.getDefaultServiceAccount(projectNumber),
|
|
33
|
+
runServiceAccount: gce.getDefaultServiceAccount(projectNumber),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.serviceAccountsForBackend = serviceAccountsForBackend;
|
|
37
|
+
async function grantSecretAccess(projectId, projectNumber, secretName, accounts) {
|
|
38
|
+
const p4saEmail = apphosting.serviceAgentEmail(projectNumber);
|
|
39
|
+
const newBindings = [
|
|
40
|
+
{
|
|
41
|
+
role: "roles/secretmanager.secretAccessor",
|
|
42
|
+
members: [...accounts.buildServiceAccounts, ...accounts.runServiceAccounts].map((sa) => `serviceAccount:${sa}`),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
role: "roles/secretmanager.viewer",
|
|
46
|
+
members: accounts.buildServiceAccounts.map((sa) => `serviceAccount:${sa}`),
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
role: "roles/secretmanager.secretVersionManager",
|
|
50
|
+
members: [`serviceAccount:${p4saEmail}`],
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
let existingBindings;
|
|
54
|
+
try {
|
|
55
|
+
existingBindings = (await gcsm.getIamPolicy({ projectId, name: secretName })).bindings || [];
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
throw new error_1.FirebaseError(`Failed to get IAM bindings on secret: ${secretName}. Ensure you have the permissions to do so and try again.`, { original: err });
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const updatedBindings = existingBindings.concat(newBindings);
|
|
62
|
+
await gcsm.setIamPolicy({ projectId, name: secretName }, updatedBindings);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
throw new error_1.FirebaseError(`Failed to set IAM bindings ${JSON.stringify(newBindings)} on secret: ${secretName}. Ensure you have the permissions to do so and try again.`, { original: err });
|
|
66
|
+
}
|
|
67
|
+
utils.logSuccess(`Successfully set IAM bindings on secret ${secretName}.\n`);
|
|
68
|
+
}
|
|
69
|
+
exports.grantSecretAccess = grantSecretAccess;
|
|
70
|
+
async function upsertSecret(project, secret, location) {
|
|
71
|
+
let existing;
|
|
72
|
+
try {
|
|
73
|
+
existing = await gcsm.getSecret(project, secret);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
if (err.status !== 404) {
|
|
77
|
+
throw new error_1.FirebaseError("Unexpected error loading secret", { original: err });
|
|
78
|
+
}
|
|
79
|
+
await gcsm.createSecret(project, secret, gcsm.labels("apphosting"), location);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
const replication = existing.replication?.userManaged;
|
|
83
|
+
if (location &&
|
|
84
|
+
(replication?.replicas?.length !== 1 || replication?.replicas?.[0]?.location !== location)) {
|
|
85
|
+
utils.logLabeledError("apphosting", "Secret replication policies cannot be changed after creation");
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
if ((0, secretManager_2.isFunctionsManaged)(existing)) {
|
|
89
|
+
utils.logLabeledWarning("apphosting", `Cloud Functions for Firebase currently manages versions of ${secret}. Continuing will disable ` +
|
|
90
|
+
"automatic deletion of old versions.");
|
|
91
|
+
const stopTracking = await prompt.confirm({
|
|
92
|
+
message: "Do you wish to continue?",
|
|
93
|
+
default: false,
|
|
94
|
+
});
|
|
95
|
+
if (!stopTracking) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
delete existing.labels[secretManager_1.FIREBASE_MANAGED];
|
|
99
|
+
await gcsm.patchSecret(project, secret, existing.labels);
|
|
100
|
+
}
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
exports.upsertSecret = upsertSecret;
|
|
@@ -19,7 +19,14 @@ function targetsHaveFilters(...targets) {
|
|
|
19
19
|
function targetsHaveNoFilters(...targets) {
|
|
20
20
|
return targets.some((t) => !t.includes(":"));
|
|
21
21
|
}
|
|
22
|
-
const FILTERABLE_TARGETS = new Set([
|
|
22
|
+
const FILTERABLE_TARGETS = new Set([
|
|
23
|
+
"hosting",
|
|
24
|
+
"functions",
|
|
25
|
+
"firestore",
|
|
26
|
+
"storage",
|
|
27
|
+
"database",
|
|
28
|
+
"dataconnect",
|
|
29
|
+
]);
|
|
23
30
|
async function checkValidTargetFilters(options) {
|
|
24
31
|
const only = !options.only ? [] : options.only.split(",");
|
|
25
32
|
return new Promise((resolve, reject) => {
|