firebase-tools 13.6.0 → 13.7.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 +1 -1
- package/lib/apphosting/config.js +31 -0
- package/lib/apphosting/githubConnections.js +261 -0
- package/lib/{init/features/apphosting → apphosting}/index.js +21 -17
- package/lib/{init/features/apphosting → apphosting}/repo.js +9 -9
- package/lib/apphosting/secrets/dialogs.js +169 -0
- package/lib/apphosting/secrets/index.js +98 -0
- package/lib/commands/apphosting-backends-create.js +4 -2
- package/lib/commands/apphosting-backends-delete.js +1 -1
- 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 +45 -0
- package/lib/commands/apphosting-secrets-set.js +105 -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 +2 -2
- package/lib/commands/index.js +6 -0
- package/lib/deploy/functions/checkIam.js +3 -6
- package/lib/deploy/functions/containerCleaner.js +1 -11
- package/lib/deploy/functions/params.js +2 -2
- package/lib/deploy/functions/prepare.js +12 -3
- package/lib/deploy/functions/prompts.js +39 -7
- package/lib/deploy/functions/release/fabricator.js +5 -5
- package/lib/deploy/functions/release/index.js +17 -2
- package/lib/deploy/functions/release/planner.js +11 -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 +11 -7
- package/lib/deploy/functions/runtimes/supported.js +135 -0
- package/lib/deploy/functions/services/index.js +4 -0
- package/lib/emulator/controller.js +8 -1
- package/lib/emulator/functionsEmulator.js +2 -2
- package/lib/emulator/hub.js +5 -0
- package/lib/experiments.js +12 -0
- package/lib/extensions/emulator/specHelper.js +4 -3
- package/lib/frameworks/next/constants.js +2 -1
- package/lib/frameworks/next/index.js +22 -12
- package/lib/frameworks/next/utils.js +32 -3
- package/lib/functional.js +2 -2
- package/lib/functions/events/v2.js +7 -1
- package/lib/functions/secrets.js +40 -22
- package/lib/gcp/apphosting.js +15 -2
- 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/computeEngine.js +7 -0
- package/lib/gcp/devConnect.js +24 -11
- package/lib/gcp/iam.js +9 -1
- package/lib/gcp/secretManager.js +53 -13
- package/lib/gcp/serviceusage.js +21 -5
- package/lib/init/features/functions/python.js +4 -3
- package/lib/init/features/index.js +1 -1
- package/lib/utils.js +6 -6
- package/package.json +1 -1
- package/schema/firebase-config.json +12 -2
- /package/lib/{init/features/apphosting → apphosting}/constants.js +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
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 secretManager_1 = require("../../gcp/secretManager");
|
|
9
|
+
const secretManager_2 = require("../../gcp/secretManager");
|
|
10
|
+
const utils = require("../../utils");
|
|
11
|
+
const prompt = require("../../prompt");
|
|
12
|
+
function toMulti(accounts) {
|
|
13
|
+
const m = {
|
|
14
|
+
buildServiceAccounts: [accounts.buildServiceAccount],
|
|
15
|
+
runServiceAccounts: [],
|
|
16
|
+
};
|
|
17
|
+
if (accounts.buildServiceAccount !== accounts.runServiceAccount) {
|
|
18
|
+
m.runServiceAccounts.push(accounts.runServiceAccount);
|
|
19
|
+
}
|
|
20
|
+
return m;
|
|
21
|
+
}
|
|
22
|
+
exports.toMulti = toMulti;
|
|
23
|
+
function serviceAccountsForBackend(projectNumber, backend) {
|
|
24
|
+
if (backend.serviceAccount) {
|
|
25
|
+
return {
|
|
26
|
+
buildServiceAccount: backend.serviceAccount,
|
|
27
|
+
runServiceAccount: backend.serviceAccount,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
buildServiceAccount: gcb.getDefaultServiceAccount(projectNumber),
|
|
32
|
+
runServiceAccount: gce.getDefaultServiceAccount(projectNumber),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
exports.serviceAccountsForBackend = serviceAccountsForBackend;
|
|
36
|
+
async function grantSecretAccess(projectId, secretName, accounts) {
|
|
37
|
+
const newBindings = [
|
|
38
|
+
{
|
|
39
|
+
role: "roles/secretmanager.secretAccessor",
|
|
40
|
+
members: [...accounts.buildServiceAccounts, ...accounts.runServiceAccounts].map((sa) => `serviceAccount:${sa}`),
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
role: "roles/secretmanager.viewer",
|
|
44
|
+
members: accounts.buildServiceAccounts.map((sa) => `serviceAccount:${sa}`),
|
|
45
|
+
},
|
|
46
|
+
];
|
|
47
|
+
let existingBindings;
|
|
48
|
+
try {
|
|
49
|
+
existingBindings = (await gcsm.getIamPolicy({ projectId, name: secretName })).bindings || [];
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
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 });
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const updatedBindings = existingBindings.concat(newBindings);
|
|
56
|
+
await gcsm.setIamPolicy({ projectId, name: secretName }, updatedBindings);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
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 });
|
|
60
|
+
}
|
|
61
|
+
utils.logSuccess(`Successfully set IAM bindings on secret ${secretName}.\n`);
|
|
62
|
+
}
|
|
63
|
+
exports.grantSecretAccess = grantSecretAccess;
|
|
64
|
+
async function upsertSecret(project, secret, location) {
|
|
65
|
+
var _a, _b, _c, _d;
|
|
66
|
+
let existing;
|
|
67
|
+
try {
|
|
68
|
+
existing = await gcsm.getSecret(project, secret);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
if (err.status !== 404) {
|
|
72
|
+
throw new error_1.FirebaseError("Unexpected error loading secret", { original: err });
|
|
73
|
+
}
|
|
74
|
+
await gcsm.createSecret(project, secret, gcsm.labels("apphosting"), location);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
const replication = (_a = existing.replication) === null || _a === void 0 ? void 0 : _a.userManaged;
|
|
78
|
+
if (location &&
|
|
79
|
+
(((_b = replication === null || replication === void 0 ? void 0 : replication.replicas) === null || _b === void 0 ? void 0 : _b.length) !== 1 || ((_d = (_c = replication === null || replication === void 0 ? void 0 : replication.replicas) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.location) !== location)) {
|
|
80
|
+
utils.logLabeledError("apphosting", "Secret replication policies cannot be changed after creation");
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
if ((0, secretManager_2.isFunctionsManaged)(existing)) {
|
|
84
|
+
utils.logLabeledWarning("apphosting", `Cloud Functions for Firebase currently manages versions of ${secret}. Continuing will disable ` +
|
|
85
|
+
"automatic deletion of old versions.");
|
|
86
|
+
const stopTracking = await prompt.confirm({
|
|
87
|
+
message: "Do you wish to continue?",
|
|
88
|
+
default: false,
|
|
89
|
+
});
|
|
90
|
+
if (!stopTracking) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
delete existing.labels[secretManager_1.FIREBASE_MANAGED];
|
|
94
|
+
await gcsm.patchSecret(project, secret, existing.labels);
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
exports.upsertSecret = upsertSecret;
|
|
@@ -4,17 +4,19 @@ exports.command = void 0;
|
|
|
4
4
|
const command_1 = require("../command");
|
|
5
5
|
const projectUtils_1 = require("../projectUtils");
|
|
6
6
|
const requireInteractive_1 = require("../requireInteractive");
|
|
7
|
-
const apphosting_1 = require("../
|
|
7
|
+
const apphosting_1 = require("../apphosting");
|
|
8
8
|
const apphosting_2 = require("../gcp/apphosting");
|
|
9
9
|
exports.command = new command_1.Command("apphosting:backends:create")
|
|
10
10
|
.description("create a backend in a Firebase project")
|
|
11
11
|
.option("-l, --location <location>", "specify the region of the backend", "")
|
|
12
12
|
.option("-s, --service-account <serviceAccount>", "specify the service account used to run the server", "")
|
|
13
|
+
.option("-w, --with-dev-connect", "use the Developer Connect flow insetad of Cloud Build Repositories (testing)", false)
|
|
13
14
|
.before(apphosting_2.ensureApiEnabled)
|
|
14
15
|
.before(requireInteractive_1.default)
|
|
15
16
|
.action(async (options) => {
|
|
16
17
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
17
18
|
const location = options.location;
|
|
18
19
|
const serviceAccount = options.serviceAccount;
|
|
19
|
-
|
|
20
|
+
const withDevConnect = options.withDevConnect;
|
|
21
|
+
await (0, apphosting_1.doSetup)(projectId, location, serviceAccount, withDevConnect);
|
|
20
22
|
});
|
|
@@ -5,7 +5,7 @@ const command_1 = require("../command");
|
|
|
5
5
|
const projectUtils_1 = require("../projectUtils");
|
|
6
6
|
const error_1 = require("../error");
|
|
7
7
|
const prompt_1 = require("../prompt");
|
|
8
|
-
const constants_1 = require("../
|
|
8
|
+
const constants_1 = require("../apphosting/constants");
|
|
9
9
|
const utils = require("../utils");
|
|
10
10
|
const apphosting = require("../gcp/apphosting");
|
|
11
11
|
const apphosting_backends_list_1 = require("./apphosting-backends-list");
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const logger_1 = require("../logger");
|
|
6
|
+
const projectUtils_1 = require("../projectUtils");
|
|
7
|
+
const secretManager_1 = require("../gcp/secretManager");
|
|
8
|
+
const requireAuth_1 = require("../requireAuth");
|
|
9
|
+
const secretManager = require("../gcp/secretManager");
|
|
10
|
+
const requirePermissions_1 = require("../requirePermissions");
|
|
11
|
+
exports.command = new command_1.Command("apphosting:secrets:access <secretName>[@version]")
|
|
12
|
+
.description("Access secret value given secret and its version. Defaults to accessing the latest version.")
|
|
13
|
+
.before(requireAuth_1.requireAuth)
|
|
14
|
+
.before(secretManager.ensureApi)
|
|
15
|
+
.before(requirePermissions_1.requirePermissions, ["secretmanager.versions.access"])
|
|
16
|
+
.action(async (key, options) => {
|
|
17
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
18
|
+
let [name, version] = key.split("@");
|
|
19
|
+
if (!version) {
|
|
20
|
+
version = "latest";
|
|
21
|
+
}
|
|
22
|
+
const value = await (0, secretManager_1.accessSecretVersion)(projectId, name, version);
|
|
23
|
+
logger_1.logger.info(value);
|
|
24
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const projectUtils_1 = require("../projectUtils");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
const requireAuth_1 = require("../requireAuth");
|
|
8
|
+
const secretManager_1 = require("../gcp/secretManager");
|
|
9
|
+
const secretManager = require("../gcp/secretManager");
|
|
10
|
+
const requirePermissions_1 = require("../requirePermissions");
|
|
11
|
+
const Table = require("cli-table");
|
|
12
|
+
exports.command = new command_1.Command("apphosting:secrets:describe <secretName>")
|
|
13
|
+
.description("Get metadata for secret and its versions.")
|
|
14
|
+
.before(requireAuth_1.requireAuth)
|
|
15
|
+
.before(secretManager.ensureApi)
|
|
16
|
+
.before(requirePermissions_1.requirePermissions, ["secretmanager.secrets.get"])
|
|
17
|
+
.action(async (secretName, options) => {
|
|
18
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
19
|
+
const versions = await (0, secretManager_1.listSecretVersions)(projectId, secretName);
|
|
20
|
+
const table = new Table({
|
|
21
|
+
head: ["Name", "Version", "Status", "Create Time"],
|
|
22
|
+
style: { head: ["yellow"] },
|
|
23
|
+
});
|
|
24
|
+
for (const version of versions) {
|
|
25
|
+
table.push([secretName, version.versionId, version.state, version.createTime]);
|
|
26
|
+
}
|
|
27
|
+
logger_1.logger.info(table.toString());
|
|
28
|
+
return { secrets: versions };
|
|
29
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const command_1 = require("../command");
|
|
5
|
+
const projectUtils_1 = require("../projectUtils");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const requireAuth_1 = require("../requireAuth");
|
|
8
|
+
const secretManager = require("../gcp/secretManager");
|
|
9
|
+
const requirePermissions_1 = require("../requirePermissions");
|
|
10
|
+
const apphosting = require("../gcp/apphosting");
|
|
11
|
+
const secrets = require("../apphosting/secrets");
|
|
12
|
+
exports.command = new command_1.Command("apphosting:secrets:grantaccess <secretName>")
|
|
13
|
+
.description("grant service accounts permissions to the provided secret")
|
|
14
|
+
.option("-l, --location <location>", "app backend location")
|
|
15
|
+
.option("-b, --backend <backend>", "app backend name")
|
|
16
|
+
.before(requireAuth_1.requireAuth)
|
|
17
|
+
.before(secretManager.ensureApi)
|
|
18
|
+
.before(apphosting.ensureApiEnabled)
|
|
19
|
+
.before(requirePermissions_1.requirePermissions, [
|
|
20
|
+
"secretmanager.secrets.create",
|
|
21
|
+
"secretmanager.secrets.get",
|
|
22
|
+
"secretmanager.secrets.update",
|
|
23
|
+
"secretmanager.versions.add",
|
|
24
|
+
"secretmanager.secrets.getIamPolicy",
|
|
25
|
+
"secretmanager.secrets.setIamPolicy",
|
|
26
|
+
])
|
|
27
|
+
.action(async (secretName, options) => {
|
|
28
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
29
|
+
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
30
|
+
if (!options.location) {
|
|
31
|
+
throw new error_1.FirebaseError("Missing required flag --location. See firebase apphosting:secrets:grantaccess --help for more info");
|
|
32
|
+
}
|
|
33
|
+
const location = options.location;
|
|
34
|
+
if (!options.backend) {
|
|
35
|
+
throw new error_1.FirebaseError("Missing required flag --backend. See firebase apphosting:secrets:grantaccess --help for more info");
|
|
36
|
+
}
|
|
37
|
+
const exists = await secretManager.secretExists(projectId, secretName);
|
|
38
|
+
if (!exists) {
|
|
39
|
+
throw new error_1.FirebaseError(`Cannot find secret ${secretName}`);
|
|
40
|
+
}
|
|
41
|
+
const backendId = options.backend;
|
|
42
|
+
const backend = await apphosting.getBackend(projectId, location, backendId);
|
|
43
|
+
const accounts = secrets.toMulti(secrets.serviceAccountsForBackend(projectNumber, backend));
|
|
44
|
+
await secrets.grantSecretAccess(projectId, secretName, accounts);
|
|
45
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const tty = require("tty");
|
|
5
|
+
const clc = require("colorette");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const command_1 = require("../command");
|
|
8
|
+
const projectUtils_1 = require("../projectUtils");
|
|
9
|
+
const requireAuth_1 = require("../requireAuth");
|
|
10
|
+
const fs = require("fs");
|
|
11
|
+
const gcsm = require("../gcp/secretManager");
|
|
12
|
+
const apphosting = require("../gcp/apphosting");
|
|
13
|
+
const requirePermissions_1 = require("../requirePermissions");
|
|
14
|
+
const prompt_1 = require("../prompt");
|
|
15
|
+
const secrets = require("../apphosting/secrets");
|
|
16
|
+
const dialogs = require("../apphosting/secrets/dialogs");
|
|
17
|
+
const config = require("../apphosting/config");
|
|
18
|
+
const utils_1 = require("../utils");
|
|
19
|
+
exports.command = new command_1.Command("apphosting:secrets:set <secretName>")
|
|
20
|
+
.description("grant service accounts permissions to the provided secret")
|
|
21
|
+
.option("-l, --location <location>", "optional location to retrict secret replication")
|
|
22
|
+
.withForce("Automatically create a secret, grant permissions, and add to YAML.")
|
|
23
|
+
.before(requireAuth_1.requireAuth)
|
|
24
|
+
.before(gcsm.ensureApi)
|
|
25
|
+
.before(apphosting.ensureApiEnabled)
|
|
26
|
+
.before(requirePermissions_1.requirePermissions, [
|
|
27
|
+
"secretmanager.secrets.create",
|
|
28
|
+
"secretmanager.secrets.get",
|
|
29
|
+
"secretmanager.secrets.update",
|
|
30
|
+
"secretmanager.versions.add",
|
|
31
|
+
"secretmanager.secrets.getIamPolicy",
|
|
32
|
+
"secretmanager.secrets.setIamPolicy",
|
|
33
|
+
])
|
|
34
|
+
.option("--data-file <dataFile>", 'File path from which to read secret data. Set to "-" to read the secret data from stdin.')
|
|
35
|
+
.action(async (secretName, options) => {
|
|
36
|
+
var _a;
|
|
37
|
+
const howToAccess = `You can access the contents of the secret's latest value with ${clc.bold(`firebase apphosting:secrets:access ${secretName}`)}`;
|
|
38
|
+
const grantAccess = `To use this secret in your backend, you must grant access. You can do so in the future with ${clc.bold("firebase apphosting:secrets:grantAccess")}`;
|
|
39
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
40
|
+
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
41
|
+
const created = await secrets.upsertSecret(projectId, secretName, options.location);
|
|
42
|
+
if (created === null) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
let secretValue;
|
|
46
|
+
if ((!options.dataFile || options.dataFile === "-") && tty.isatty(0)) {
|
|
47
|
+
secretValue = await (0, prompt_1.promptOnce)({
|
|
48
|
+
type: "password",
|
|
49
|
+
message: `Enter a value for ${secretName}`,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
let dataFile = 0;
|
|
54
|
+
if (options.dataFile && options.dataFile !== "-") {
|
|
55
|
+
dataFile = options.dataFile;
|
|
56
|
+
}
|
|
57
|
+
secretValue = fs.readFileSync(dataFile, "utf-8");
|
|
58
|
+
}
|
|
59
|
+
if (created) {
|
|
60
|
+
(0, utils_1.logSuccess)(`Created new secret projects/${projectId}/secrets/${secretName}`);
|
|
61
|
+
}
|
|
62
|
+
const version = await gcsm.addVersion(projectId, secretName, secretValue);
|
|
63
|
+
(0, utils_1.logSuccess)(`Created new secret version ${gcsm.toSecretVersionResourceName(version)}`);
|
|
64
|
+
(0, utils_1.logSuccess)(howToAccess);
|
|
65
|
+
if (!created) {
|
|
66
|
+
(0, utils_1.logWarning)(grantAccess);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const accounts = await dialogs.selectBackendServiceAccounts(projectNumber, projectId, options);
|
|
70
|
+
if (!accounts.buildServiceAccounts.length && !accounts.runServiceAccounts.length) {
|
|
71
|
+
(0, utils_1.logWarning)(grantAccess);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
await secrets.grantSecretAccess(projectId, secretName, accounts);
|
|
75
|
+
}
|
|
76
|
+
let path = config.yamlPath(process.cwd());
|
|
77
|
+
let yaml = {};
|
|
78
|
+
if (path) {
|
|
79
|
+
yaml = config.load(path);
|
|
80
|
+
if ((_a = yaml.env) === null || _a === void 0 ? void 0 : _a.find((env) => env.variable === secretName)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const addToYaml = await (0, prompt_1.confirm)({
|
|
85
|
+
message: "Would you like to add this secret to apphosting.yaml?",
|
|
86
|
+
default: true,
|
|
87
|
+
});
|
|
88
|
+
if (!addToYaml) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!path) {
|
|
92
|
+
path = await (0, prompt_1.promptOnce)({
|
|
93
|
+
message: "It looks like you don't have an apphosting.yaml yet. Where would you like to store it?",
|
|
94
|
+
default: process.cwd(),
|
|
95
|
+
});
|
|
96
|
+
path = (0, path_1.join)(path, "apphosting.yaml");
|
|
97
|
+
}
|
|
98
|
+
const envName = await dialogs.envVarForSecret(secretName);
|
|
99
|
+
yaml.env = yaml.env || [];
|
|
100
|
+
yaml.env.push({
|
|
101
|
+
variable: envName,
|
|
102
|
+
secret: secretName,
|
|
103
|
+
});
|
|
104
|
+
config.store(path, yaml);
|
|
105
|
+
});
|
|
@@ -6,11 +6,11 @@ const logger_1 = require("../logger");
|
|
|
6
6
|
const projectUtils_1 = require("../projectUtils");
|
|
7
7
|
const secretManager_1 = require("../gcp/secretManager");
|
|
8
8
|
const requireAuth_1 = require("../requireAuth");
|
|
9
|
-
const
|
|
9
|
+
const secretManager = require("../gcp/secretManager");
|
|
10
10
|
exports.command = new command_1.Command("functions:secrets:access <KEY>[@version]")
|
|
11
11
|
.description("Access secret value given secret and its version. Defaults to accessing the latest version.")
|
|
12
12
|
.before(requireAuth_1.requireAuth)
|
|
13
|
-
.before(
|
|
13
|
+
.before(secretManager.ensureApi)
|
|
14
14
|
.action(async (key, options) => {
|
|
15
15
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
16
16
|
let [name, version] = key.split("@");
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.command = void 0;
|
|
4
|
+
const requireAuth_1 = require("../requireAuth");
|
|
5
|
+
const command_1 = require("../command");
|
|
6
|
+
const requirePermissions_1 = require("../requirePermissions");
|
|
7
|
+
const secretManager = require("../gcp/secretManager");
|
|
8
|
+
const secrets = require("../functions/secrets");
|
|
9
|
+
exports.command = new command_1.Command("functions:secrets:describe <KEY>")
|
|
10
|
+
.description("Get metadata for secret and its versions. Alias for functions:secrets:get to align with gcloud")
|
|
11
|
+
.before(requireAuth_1.requireAuth)
|
|
12
|
+
.before(secretManager.ensureApi)
|
|
13
|
+
.before(requirePermissions_1.requirePermissions, ["secretmanager.secrets.get"])
|
|
14
|
+
.action(secrets.describeSecret);
|
|
@@ -13,7 +13,7 @@ exports.command = new command_1.Command("functions:secrets:destroy <KEY>[@versio
|
|
|
13
13
|
.description("Destroy a secret. Defaults to destroying the latest version.")
|
|
14
14
|
.withForce("Destroys a secret without confirmation.")
|
|
15
15
|
.before(requireAuth_1.requireAuth)
|
|
16
|
-
.before(
|
|
16
|
+
.before(secretManager_1.ensureApi)
|
|
17
17
|
.action(async (key, options) => {
|
|
18
18
|
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
19
19
|
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
@@ -54,7 +54,7 @@ exports.command = new command_1.Command("functions:secrets:destroy <KEY>[@versio
|
|
|
54
54
|
await (0, secretManager_1.destroySecretVersion)(projectId, name, version);
|
|
55
55
|
(0, utils_1.logBullet)(`Destroyed secret version ${name}@${sv.versionId}`);
|
|
56
56
|
const secret = await (0, secretManager_1.getSecret)(projectId, name);
|
|
57
|
-
if (
|
|
57
|
+
if ((0, secretManager_1.isFunctionsManaged)(secret)) {
|
|
58
58
|
const versions = await (0, secretManager_1.listSecretVersions)(projectId, name);
|
|
59
59
|
if (versions.filter((v) => v.state === "ENABLED").length === 0) {
|
|
60
60
|
(0, utils_1.logBullet)(`No active secret versions left. Destroying secret ${name}`);
|
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.command = void 0;
|
|
4
|
-
const Table = require("cli-table");
|
|
5
4
|
const requireAuth_1 = require("../requireAuth");
|
|
6
5
|
const command_1 = require("../command");
|
|
7
|
-
const logger_1 = require("../logger");
|
|
8
|
-
const projectUtils_1 = require("../projectUtils");
|
|
9
|
-
const secretManager_1 = require("../gcp/secretManager");
|
|
10
6
|
const requirePermissions_1 = require("../requirePermissions");
|
|
7
|
+
const secretManager = require("../gcp/secretManager");
|
|
11
8
|
const secrets = require("../functions/secrets");
|
|
12
9
|
exports.command = new command_1.Command("functions:secrets:get <KEY>")
|
|
13
10
|
.description("Get metadata for secret and its versions")
|
|
14
11
|
.before(requireAuth_1.requireAuth)
|
|
15
|
-
.before(
|
|
12
|
+
.before(secretManager.ensureApi)
|
|
16
13
|
.before(requirePermissions_1.requirePermissions, ["secretmanager.secrets.get"])
|
|
17
|
-
.action(
|
|
18
|
-
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
19
|
-
const versions = await (0, secretManager_1.listSecretVersions)(projectId, key);
|
|
20
|
-
const table = new Table({
|
|
21
|
-
head: ["Version", "State"],
|
|
22
|
-
style: { head: ["yellow"] },
|
|
23
|
-
});
|
|
24
|
-
for (const version of versions) {
|
|
25
|
-
table.push([version.versionId, version.state]);
|
|
26
|
-
}
|
|
27
|
-
logger_1.logger.info(table.toString());
|
|
28
|
-
});
|
|
14
|
+
.action(secrets.describeSecret);
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.command = void 0;
|
|
4
4
|
const backend = require("../deploy/functions/backend");
|
|
5
5
|
const secrets = require("../functions/secrets");
|
|
6
|
+
const secretManager = require("../gcp/secretManager");
|
|
6
7
|
const command_1 = require("../command");
|
|
7
8
|
const projectUtils_1 = require("../projectUtils");
|
|
8
9
|
const requirePermissions_1 = require("../requirePermissions");
|
|
@@ -15,7 +16,7 @@ exports.command = new command_1.Command("functions:secrets:prune")
|
|
|
15
16
|
.withForce("Destroys unused secrets without prompt")
|
|
16
17
|
.description("Destroys unused secrets")
|
|
17
18
|
.before(requireAuth_1.requireAuth)
|
|
18
|
-
.before(
|
|
19
|
+
.before(secretManager.ensureApi)
|
|
19
20
|
.before(requirePermissions_1.requirePermissions, [
|
|
20
21
|
"cloudfunctions.functions.list",
|
|
21
22
|
"secretmanager.secrets.list",
|
|
@@ -20,7 +20,7 @@ exports.command = new command_1.Command("functions:secrets:set <KEY>")
|
|
|
20
20
|
.description("Create or update a secret for use in Cloud Functions for Firebase.")
|
|
21
21
|
.withForce("Automatically updates functions to use the new secret.")
|
|
22
22
|
.before(requireAuth_1.requireAuth)
|
|
23
|
-
.before(
|
|
23
|
+
.before(secretManager_1.ensureApi)
|
|
24
24
|
.before(requirePermissions_1.requirePermissions, [
|
|
25
25
|
"secretmanager.secrets.create",
|
|
26
26
|
"secretmanager.secrets.get",
|
|
@@ -50,7 +50,7 @@ exports.command = new command_1.Command("functions:secrets:set <KEY>")
|
|
|
50
50
|
}
|
|
51
51
|
const secretVersion = await (0, secretManager_1.addVersion)(projectId, key, secretValue);
|
|
52
52
|
(0, utils_1.logSuccess)(`Created a new secret version ${(0, secretManager_1.toSecretVersionResourceName)(secretVersion)}`);
|
|
53
|
-
if (!
|
|
53
|
+
if (!(0, secretManager_1.isFunctionsManaged)(secret)) {
|
|
54
54
|
(0, utils_1.logBullet)("Please deploy your functions for the change to take effect by running:\n\t" +
|
|
55
55
|
clc.bold("firebase deploy --only functions"));
|
|
56
56
|
return;
|
package/lib/commands/index.js
CHANGED
|
@@ -129,6 +129,7 @@ function load(client) {
|
|
|
129
129
|
client.functions.secrets.access = loadCommand("functions-secrets-access");
|
|
130
130
|
client.functions.secrets.destroy = loadCommand("functions-secrets-destroy");
|
|
131
131
|
client.functions.secrets.get = loadCommand("functions-secrets-get");
|
|
132
|
+
client.functions.secrets.describe = loadCommand("functions-secrets-describe");
|
|
132
133
|
client.functions.secrets.prune = loadCommand("functions-secrets-prune");
|
|
133
134
|
client.functions.secrets.set = loadCommand("functions-secrets-set");
|
|
134
135
|
client.help = loadCommand("help");
|
|
@@ -164,6 +165,11 @@ function load(client) {
|
|
|
164
165
|
client.apphosting.builds = {};
|
|
165
166
|
client.apphosting.builds.get = loadCommand("apphosting-builds-get");
|
|
166
167
|
client.apphosting.builds.create = loadCommand("apphosting-builds-create");
|
|
168
|
+
client.apphosting.secrets = {};
|
|
169
|
+
client.apphosting.secrets.set = loadCommand("apphosting-secrets-set");
|
|
170
|
+
client.apphosting.secrets.grantaccess = loadCommand("apphosting-secrets-grantaccess");
|
|
171
|
+
client.apphosting.secrets.describe = loadCommand("apphosting-secrets-describe");
|
|
172
|
+
client.apphosting.secrets.access = loadCommand("apphosting-secrets-access");
|
|
167
173
|
client.apphosting.rollouts = {};
|
|
168
174
|
client.apphosting.rollouts.create = loadCommand("apphosting-rollouts-create");
|
|
169
175
|
client.apphosting.rollouts.list = loadCommand("apphosting-rollouts-list");
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ensureServiceAgentRoles = exports.mergeBindings = exports.obtainDefaultComputeServiceAgentBindings = exports.obtainPubSubServiceAgentBindings = exports.
|
|
3
|
+
exports.ensureServiceAgentRoles = exports.mergeBindings = exports.obtainDefaultComputeServiceAgentBindings = exports.obtainPubSubServiceAgentBindings = exports.checkHttpIam = exports.checkServiceAccountIam = exports.EVENTARC_EVENT_RECEIVER_ROLE = exports.RUN_INVOKER_ROLE = exports.SERVICE_ACCOUNT_TOKEN_CREATOR_ROLE = void 0;
|
|
4
4
|
const colorette_1 = require("colorette");
|
|
5
5
|
const logger_1 = require("../../logger");
|
|
6
6
|
const functionsDeployHelper_1 = require("./functionsDeployHelper");
|
|
7
7
|
const error_1 = require("../../error");
|
|
8
8
|
const functional_1 = require("../../functional");
|
|
9
9
|
const iam = require("../../gcp/iam");
|
|
10
|
+
const gce = require("../../gcp/computeEngine");
|
|
10
11
|
const backend = require("./backend");
|
|
11
12
|
const track_1 = require("../../track");
|
|
12
13
|
const utils = require("../../utils");
|
|
@@ -73,10 +74,6 @@ exports.checkHttpIam = checkHttpIam;
|
|
|
73
74
|
function getPubsubServiceAgent(projectNumber) {
|
|
74
75
|
return `service-${projectNumber}@gcp-sa-pubsub.iam.gserviceaccount.com`;
|
|
75
76
|
}
|
|
76
|
-
function getDefaultComputeServiceAgent(projectNumber) {
|
|
77
|
-
return `${projectNumber}-compute@developer.gserviceaccount.com`;
|
|
78
|
-
}
|
|
79
|
-
exports.getDefaultComputeServiceAgent = getDefaultComputeServiceAgent;
|
|
80
77
|
function reduceEventsToServices(services, endpoint) {
|
|
81
78
|
const service = (0, services_1.serviceForEndpoint)(endpoint);
|
|
82
79
|
if (service.requiredProjectBindings && !services.find((s) => s.name === service.name)) {
|
|
@@ -93,7 +90,7 @@ function obtainPubSubServiceAgentBindings(projectNumber) {
|
|
|
93
90
|
}
|
|
94
91
|
exports.obtainPubSubServiceAgentBindings = obtainPubSubServiceAgentBindings;
|
|
95
92
|
function obtainDefaultComputeServiceAgentBindings(projectNumber) {
|
|
96
|
-
const defaultComputeServiceAgent = `serviceAccount:${
|
|
93
|
+
const defaultComputeServiceAgent = `serviceAccount:${gce.getDefaultServiceAccount(projectNumber)}`;
|
|
97
94
|
const runInvokerBinding = {
|
|
98
95
|
role: exports.RUN_INVOKER_ROLE,
|
|
99
96
|
members: [defaultComputeServiceAgent],
|
|
@@ -49,7 +49,7 @@ async function cleanupBuildImages(haveFunctions, deletedFunctions, cleaners = {}
|
|
|
49
49
|
}));
|
|
50
50
|
cleanup.push(...deletedFunctions.map(async (func) => {
|
|
51
51
|
try {
|
|
52
|
-
await
|
|
52
|
+
await arCleaner.cleanupFunction(func);
|
|
53
53
|
}
|
|
54
54
|
catch (err) {
|
|
55
55
|
const path = `${func.project}/${func.region}/gcf-artifacts`;
|
|
@@ -106,13 +106,6 @@ class ArtifactRegistryCleaner {
|
|
|
106
106
|
}
|
|
107
107
|
await poller.pollOperation(Object.assign(Object.assign({}, ArtifactRegistryCleaner.POLLER_OPTIONS), { pollerName: `cleanup-${func.region}-${func.id}`, operationResourceName: op.name }));
|
|
108
108
|
}
|
|
109
|
-
async cleanupFunctionCache(func) {
|
|
110
|
-
const op = await artifactregistry.deletePackage(`${ArtifactRegistryCleaner.packagePath(func)}%2Fcache`);
|
|
111
|
-
if (op.done) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
await poller.pollOperation(Object.assign(Object.assign({}, ArtifactRegistryCleaner.POLLER_OPTIONS), { pollerName: `cleanup-cache-${func.region}-${func.id}`, operationResourceName: op.name }));
|
|
115
|
-
}
|
|
116
109
|
}
|
|
117
110
|
exports.ArtifactRegistryCleaner = ArtifactRegistryCleaner;
|
|
118
111
|
ArtifactRegistryCleaner.POLLER_OPTIONS = {
|
|
@@ -124,9 +117,6 @@ class NoopArtifactRegistryCleaner extends ArtifactRegistryCleaner {
|
|
|
124
117
|
cleanupFunction() {
|
|
125
118
|
return Promise.resolve();
|
|
126
119
|
}
|
|
127
|
-
cleanupFunctionCache() {
|
|
128
|
-
return Promise.resolve();
|
|
129
|
-
}
|
|
130
120
|
}
|
|
131
121
|
exports.NoopArtifactRegistryCleaner = NoopArtifactRegistryCleaner;
|
|
132
122
|
class ContainerRegistryCleaner {
|
|
@@ -8,7 +8,7 @@ const functional_1 = require("../../functional");
|
|
|
8
8
|
const secretManager = require("../../gcp/secretManager");
|
|
9
9
|
const storage_1 = require("../../gcp/storage");
|
|
10
10
|
const cel_1 = require("./cel");
|
|
11
|
-
const
|
|
11
|
+
const secretManager_1 = require("../../gcp/secretManager");
|
|
12
12
|
function dependenciesCEL(expr) {
|
|
13
13
|
const deps = [];
|
|
14
14
|
const paramCapture = /{{ params\.(\w+) }}/g;
|
|
@@ -222,7 +222,7 @@ async function handleSecret(secretParam, projectId) {
|
|
|
222
222
|
type: "password",
|
|
223
223
|
message: `This secret will be stored in Cloud Secret Manager (https://cloud.google.com/secret-manager/pricing) as ${secretParam.name}. Enter a value for ${secretParam.label || secretParam.name}:`,
|
|
224
224
|
});
|
|
225
|
-
await secretManager.createSecret(projectId, secretParam.name, (0,
|
|
225
|
+
await secretManager.createSecret(projectId, secretParam.name, (0, secretManager_1.labels)());
|
|
226
226
|
await secretManager.addVersion(projectId, secretParam.name, secretValue);
|
|
227
227
|
return secretValue;
|
|
228
228
|
}
|
|
@@ -8,6 +8,7 @@ const ensureApiEnabled = require("../../ensureApiEnabled");
|
|
|
8
8
|
const functionsConfig = require("../../functionsConfig");
|
|
9
9
|
const functionsEnv = require("../../functions/env");
|
|
10
10
|
const runtimes = require("./runtimes");
|
|
11
|
+
const supported = require("./runtimes/supported");
|
|
11
12
|
const validate = require("./validate");
|
|
12
13
|
const ensure = require("./ensure");
|
|
13
14
|
const api_1 = require("../../api");
|
|
@@ -284,12 +285,20 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
|
|
|
284
285
|
projectId,
|
|
285
286
|
sourceDir,
|
|
286
287
|
projectDir: options.config.projectDir,
|
|
287
|
-
runtime: codebaseConfig.runtime || "",
|
|
288
288
|
};
|
|
289
|
+
const firebaseJsonRuntime = codebaseConfig.runtime;
|
|
290
|
+
if (firebaseJsonRuntime && !supported.isRuntime(firebaseJsonRuntime)) {
|
|
291
|
+
throw new error_1.FirebaseError(`Functions codebase ${codebase} has invalid runtime ` +
|
|
292
|
+
`${firebaseJsonRuntime} specified in firebase.json. Valid values are: ` +
|
|
293
|
+
Object.keys(supported.RUNTIMES)
|
|
294
|
+
.map((s) => `- ${s}`)
|
|
295
|
+
.join("\n"));
|
|
296
|
+
}
|
|
289
297
|
const runtimeDelegate = await runtimes.getRuntimeDelegate(delegateContext);
|
|
290
|
-
logger_1.logger.debug(`Validating ${runtimeDelegate.
|
|
298
|
+
logger_1.logger.debug(`Validating ${runtimeDelegate.language} source`);
|
|
299
|
+
supported.guardVersionSupport(runtimeDelegate.runtime);
|
|
291
300
|
await runtimeDelegate.validate();
|
|
292
|
-
logger_1.logger.debug(`Building ${runtimeDelegate.
|
|
301
|
+
logger_1.logger.debug(`Building ${runtimeDelegate.language} source`);
|
|
293
302
|
await runtimeDelegate.build();
|
|
294
303
|
const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId);
|
|
295
304
|
(0, utils_1.logLabeledBullet)("functions", `Loading and analyzing source code for codebase ${codebase} to determine what to deploy`);
|