backend-manager 5.9.15 → 5.9.16
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/package.json
CHANGED
|
@@ -2,25 +2,11 @@ const BaseCommand = require('./base-command');
|
|
|
2
2
|
const chalk = require('chalk').default;
|
|
3
3
|
const powertools = require('node-powertools');
|
|
4
4
|
const attachLogFile = require('../utils/attach-log-file');
|
|
5
|
-
const { execSync } = require('child_process');
|
|
6
|
-
const { homedir } = require('os');
|
|
7
5
|
const path = require('path');
|
|
8
6
|
const jetpack = require('fs-jetpack');
|
|
9
7
|
|
|
10
8
|
const DEFAULT_REGION = 'us-central1';
|
|
11
9
|
|
|
12
|
-
function gcloudExec(cmd, options = {}) {
|
|
13
|
-
const env = { ...process.env };
|
|
14
|
-
env.PATH = `${path.join(homedir(), 'google-cloud-sdk', 'bin')}:${env.PATH}`;
|
|
15
|
-
|
|
16
|
-
return execSync(cmd, {
|
|
17
|
-
encoding: 'utf8',
|
|
18
|
-
timeout: options.timeout || 30000,
|
|
19
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
20
|
-
env,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
10
|
class DeployCommand extends BaseCommand {
|
|
25
11
|
async execute() {
|
|
26
12
|
const self = this.main;
|
|
@@ -63,8 +49,8 @@ class DeployCommand extends BaseCommand {
|
|
|
63
49
|
* runtime transition. Without it, HTTP requests get a 403 at the IAM level
|
|
64
50
|
* before BEM's application-level auth (backendManagerKey) can run.
|
|
65
51
|
*
|
|
66
|
-
* Dynamically discovers all deployed functions and fixes any
|
|
67
|
-
* function missing the allUsers invoker binding.
|
|
52
|
+
* Dynamically discovers all deployed functions via gcloud and fixes any
|
|
53
|
+
* HTTP-triggered function missing the allUsers invoker binding.
|
|
68
54
|
*/
|
|
69
55
|
async ensurePublicInvoker() {
|
|
70
56
|
const projectId = this.getProjectId();
|
|
@@ -77,13 +63,12 @@ class DeployCommand extends BaseCommand {
|
|
|
77
63
|
let httpFunctions;
|
|
78
64
|
|
|
79
65
|
try {
|
|
80
|
-
const output =
|
|
66
|
+
const output = await powertools.execute(
|
|
81
67
|
`gcloud functions list --project ${projectId} --regions ${DEFAULT_REGION} --format="json(name,httpsTrigger)"`,
|
|
68
|
+
{ log: false },
|
|
82
69
|
);
|
|
83
70
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
httpFunctions = allFunctions
|
|
71
|
+
httpFunctions = JSON.parse(output)
|
|
87
72
|
.filter((fn) => fn.httpsTrigger)
|
|
88
73
|
.map((fn) => fn.name.split('/').pop());
|
|
89
74
|
} catch {
|
|
@@ -101,9 +86,9 @@ class DeployCommand extends BaseCommand {
|
|
|
101
86
|
|
|
102
87
|
for (const fnName of httpFunctions) {
|
|
103
88
|
try {
|
|
104
|
-
const policyOutput =
|
|
89
|
+
const policyOutput = await powertools.execute(
|
|
105
90
|
`gcloud functions get-iam-policy ${fnName} --project ${projectId} --region ${DEFAULT_REGION} --format=json`,
|
|
106
|
-
{
|
|
91
|
+
{ log: false },
|
|
107
92
|
);
|
|
108
93
|
|
|
109
94
|
const policy = JSON.parse(policyOutput);
|
|
@@ -117,8 +102,9 @@ class DeployCommand extends BaseCommand {
|
|
|
117
102
|
continue;
|
|
118
103
|
}
|
|
119
104
|
|
|
120
|
-
|
|
105
|
+
await powertools.execute(
|
|
121
106
|
`gcloud functions add-iam-policy-binding ${fnName} --project ${projectId} --region ${DEFAULT_REGION} --member="allUsers" --role="roles/cloudfunctions.invoker"`,
|
|
107
|
+
{ log: false },
|
|
122
108
|
);
|
|
123
109
|
|
|
124
110
|
this.log(` ${chalk.green('✓')} Set public invoker on ${chalk.cyan(fnName)}`);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const BaseTest = require('./base-test');
|
|
2
|
+
const powertools = require('node-powertools');
|
|
3
|
+
|
|
4
|
+
class GcloudCliTest extends BaseTest {
|
|
5
|
+
getName() {
|
|
6
|
+
return 'gcloud CLI is installed (required by deploy)';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
getWarning() {
|
|
10
|
+
return [
|
|
11
|
+
'gcloud CLI is not installed.',
|
|
12
|
+
'Install with: https://cloud.google.com/sdk/docs/install',
|
|
13
|
+
];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async run() {
|
|
17
|
+
try {
|
|
18
|
+
await powertools.execute('gcloud --version', { log: false });
|
|
19
|
+
return true;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return 'warn';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = GcloudCliTest;
|
|
@@ -10,6 +10,7 @@ const NvmrcVersionTest = require('./nvmrc-version');
|
|
|
10
10
|
const FirebaseCLITest = require('./firebase-cli');
|
|
11
11
|
const FirebaseAuthTest = require('./firebase-auth');
|
|
12
12
|
const JavaInstalledTest = require('./java-installed');
|
|
13
|
+
const GcloudCliTest = require('./gcloud-cli');
|
|
13
14
|
const FunctionsPackageTest = require('./functions-package');
|
|
14
15
|
const FirebaseAdminTest = require('./firebase-admin');
|
|
15
16
|
const FirebaseFunctionsTest = require('./firebase-functions');
|
|
@@ -56,6 +57,7 @@ function getTests(context) {
|
|
|
56
57
|
new FirebaseCLITest(context),
|
|
57
58
|
new FirebaseAuthTest(context),
|
|
58
59
|
new JavaInstalledTest(context),
|
|
60
|
+
new GcloudCliTest(context),
|
|
59
61
|
new FunctionsPackageTest(context),
|
|
60
62
|
new FirebaseAdminTest(context),
|
|
61
63
|
new FirebaseFunctionsTest(context),
|