firebase-tools 10.1.0 → 10.1.4
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/accountExporter.js +9 -8
- package/lib/accountImporter.js +10 -8
- package/lib/apiv2.js +91 -48
- package/lib/archiveDirectory.js +63 -73
- package/lib/bin/firebase.js +1 -1
- package/lib/commands/auth-export.js +26 -25
- package/lib/commands/auth-import.js +88 -78
- package/lib/commands/ext-configure.js +1 -1
- package/lib/commands/ext-dev-init.js +1 -1
- package/lib/commands/ext-dev-publish.js +1 -1
- package/lib/commands/ext-dev-register.js +1 -1
- package/lib/commands/ext-dev-usage.js +3 -8
- package/lib/commands/ext-info.js +1 -1
- package/lib/commands/ext-install.js +1 -1
- package/lib/commands/ext-uninstall.js +1 -1
- package/lib/commands/ext-update.js +1 -1
- package/lib/commands/functions-config-clone.js +22 -23
- package/lib/commands/functions-config-get.js +22 -22
- package/lib/commands/functions-config-set.js +24 -22
- package/lib/commands/functions-config-unset.js +20 -22
- package/lib/commands/help.js +12 -12
- package/lib/commands/hosting-channel-create.js +1 -1
- package/lib/commands/hosting-channel-delete.js +2 -2
- package/lib/commands/hosting-channel-deploy.js +1 -1
- package/lib/commands/hosting-clone.js +1 -1
- package/lib/commands/login-ci.js +10 -10
- package/lib/commands/remoteconfig-versions-list.js +6 -1
- package/lib/commands/setup-emulators-database.js +8 -7
- package/lib/commands/setup-emulators-firestore.js +8 -7
- package/lib/commands/setup-emulators-pubsub.js +5 -4
- package/lib/commands/setup-emulators-storage.js +3 -2
- package/lib/commands/setup-emulators-ui.js +8 -7
- package/lib/commands/target-apply.js +17 -16
- package/lib/commands/target-clear.js +11 -10
- package/lib/commands/target-remove.js +10 -9
- package/lib/commands/target.js +20 -20
- package/lib/database/metadata.js +16 -24
- package/lib/defaultCredentials.js +3 -3
- package/lib/deploy/functions/backend.js +3 -1
- package/lib/deploy/functions/prepare.js +17 -11
- package/lib/deploy/functions/release/fabricator.js +4 -1
- package/lib/deploy/functions/runtimes/golang/index.js +6 -9
- package/lib/deploy/functions/runtimes/index.js +6 -10
- package/lib/deploy/functions/runtimes/node/index.js +5 -9
- package/lib/deploy/functions/runtimes/node/validate.js +2 -1
- package/lib/deploy/functions/validate.js +32 -4
- package/lib/deploy/hosting/convertConfig.js +45 -24
- package/lib/deploy/hosting/prepare.js +1 -1
- package/lib/emulator/auth/widget_ui.js +1 -1
- package/lib/emulator/downloadableEmulators.js +3 -2
- package/lib/emulator/functionsEmulator.js +9 -1
- package/lib/emulator/functionsEmulatorRuntime.js +4 -4
- package/lib/emulator/storage/apis/gcloud.js +2 -2
- package/lib/emulator/storage/files.js +8 -3
- package/lib/emulator/storage/rules/runtime.js +5 -4
- package/lib/extensions/askUserForConsent.js +1 -1
- package/lib/extensions/askUserForParam.js +1 -1
- package/lib/extensions/billingMigrationHelper.js +1 -1
- package/lib/extensions/changelog.js +1 -1
- package/lib/extensions/displayExtensionInfo.js +1 -1
- package/lib/extensions/extensionsApi.js +57 -112
- package/lib/extensions/extensionsHelper.js +19 -15
- package/lib/extensions/provisioningHelper.js +7 -10
- package/lib/extensions/resolveSource.js +5 -5
- package/lib/extensions/updateHelper.js +1 -1
- package/lib/extensions/warnings.js +1 -1
- package/lib/functionsConfig.js +4 -5
- package/lib/gcp/cloudbilling.js +8 -19
- package/lib/gcp/cloudfunctions.js +22 -46
- package/lib/gcp/cloudlogging.js +8 -11
- package/lib/gcp/cloudmonitoring.js +8 -5
- package/lib/gcp/cloudscheduler.js +7 -18
- package/lib/gcp/firedata.js +5 -4
- package/lib/gcp/firestore.js +5 -5
- package/lib/gcp/iam.js +18 -33
- package/lib/gcp/resourceManager.js +8 -13
- package/lib/gcp/rules.js +18 -41
- package/lib/gcp/runtimeconfig.js +31 -53
- package/lib/gcp/secretManager.js +21 -43
- package/lib/gcp/storage.js +25 -29
- package/lib/projectUtils.js +1 -1
- package/lib/remoteconfig/get.js +14 -8
- package/lib/remoteconfig/rollback.js +13 -6
- package/lib/remoteconfig/versionslist.js +13 -7
- package/npm-shrinkwrap.json +1439 -2295
- package/package.json +16 -11
- package/schema/firebase-config.json +387 -12
- package/standalone/firepit.js +4 -4
- package/templates/init/hosting/index.html +1 -1
- package/lib/commands/functions-config-legacy.js +0 -45
- package/lib/prepareFirebaseRules.js +0 -58
|
@@ -5,12 +5,14 @@ const clc = require("cli-color");
|
|
|
5
5
|
const error_1 = require("../error");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
7
7
|
const previews_1 = require("../previews");
|
|
8
|
-
const api = require("../api");
|
|
9
8
|
const backend = require("../deploy/functions/backend");
|
|
10
9
|
const utils = require("../utils");
|
|
11
10
|
const proto = require("./proto");
|
|
12
11
|
const runtimes = require("../deploy/functions/runtimes");
|
|
12
|
+
const apiv2_1 = require("../apiv2");
|
|
13
|
+
const api_1 = require("../api");
|
|
13
14
|
exports.API_VERSION = "v1";
|
|
15
|
+
const client = new apiv2_1.Client({ urlPrefix: api_1.functionsOrigin, apiVersion: exports.API_VERSION });
|
|
14
16
|
function validateFunction(func) {
|
|
15
17
|
proto.assertOneOf("Cloud Function", func, "sourceCode", "sourceArchiveUrl", "sourceRepository", "sourceUploadUrl");
|
|
16
18
|
proto.assertOneOf("Cloud Function", func, "trigger", "httpsTrigger", "eventTrigger");
|
|
@@ -30,16 +32,10 @@ function functionsOpLogReject(funcName, type, err) {
|
|
|
30
32
|
}
|
|
31
33
|
async function generateUploadUrl(projectId, location) {
|
|
32
34
|
const parent = "projects/" + projectId + "/locations/" + location;
|
|
33
|
-
const endpoint =
|
|
35
|
+
const endpoint = `/${parent}/functions:generateUploadUrl`;
|
|
34
36
|
try {
|
|
35
|
-
const res = await
|
|
36
|
-
|
|
37
|
-
json: false,
|
|
38
|
-
origin: api.functionsOrigin,
|
|
39
|
-
retryCodes: [503],
|
|
40
|
-
});
|
|
41
|
-
const responseBody = JSON.parse(res.body);
|
|
42
|
-
return responseBody.uploadUrl;
|
|
37
|
+
const res = await client.post(endpoint, {}, { retryCodes: [503] });
|
|
38
|
+
return res.body.uploadUrl;
|
|
43
39
|
}
|
|
44
40
|
catch (err) {
|
|
45
41
|
logger_1.logger.info("\n\nThere was an issue deploying your functions. Verify that your project has a Google App Engine instance setup at https://console.cloud.google.com/appengine and try again. If this issue persists, please contact support.");
|
|
@@ -49,18 +45,13 @@ async function generateUploadUrl(projectId, location) {
|
|
|
49
45
|
exports.generateUploadUrl = generateUploadUrl;
|
|
50
46
|
async function createFunction(cloudFunction) {
|
|
51
47
|
const apiPath = cloudFunction.name.substring(0, cloudFunction.name.lastIndexOf("/"));
|
|
52
|
-
const endpoint = `/${
|
|
48
|
+
const endpoint = `/${apiPath}`;
|
|
53
49
|
try {
|
|
54
50
|
const headers = {};
|
|
55
51
|
if (previews_1.previews.artifactregistry) {
|
|
56
52
|
headers["X-Firebase-Artifact-Registry"] = "optin";
|
|
57
53
|
}
|
|
58
|
-
const res = await
|
|
59
|
-
headers,
|
|
60
|
-
auth: true,
|
|
61
|
-
data: cloudFunction,
|
|
62
|
-
origin: api.functionsOrigin,
|
|
63
|
-
});
|
|
54
|
+
const res = await client.post(endpoint, cloudFunction, { headers });
|
|
64
55
|
return {
|
|
65
56
|
name: res.body.name,
|
|
66
57
|
type: "create",
|
|
@@ -73,15 +64,11 @@ async function createFunction(cloudFunction) {
|
|
|
73
64
|
}
|
|
74
65
|
exports.createFunction = createFunction;
|
|
75
66
|
async function setIamPolicy(options) {
|
|
76
|
-
const endpoint = `/${
|
|
67
|
+
const endpoint = `/${options.name}:setIamPolicy`;
|
|
77
68
|
try {
|
|
78
|
-
await
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
policy: options.policy,
|
|
82
|
-
updateMask: Object.keys(options.policy).join(","),
|
|
83
|
-
},
|
|
84
|
-
origin: api.functionsOrigin,
|
|
69
|
+
await client.post(endpoint, {
|
|
70
|
+
policy: options.policy,
|
|
71
|
+
updateMask: Object.keys(options.policy).join(","),
|
|
85
72
|
});
|
|
86
73
|
}
|
|
87
74
|
catch (err) {
|
|
@@ -92,12 +79,10 @@ async function setIamPolicy(options) {
|
|
|
92
79
|
}
|
|
93
80
|
exports.setIamPolicy = setIamPolicy;
|
|
94
81
|
async function getIamPolicy(fnName) {
|
|
95
|
-
const endpoint = `/${
|
|
82
|
+
const endpoint = `/${fnName}:getIamPolicy`;
|
|
96
83
|
try {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
origin: api.functionsOrigin,
|
|
100
|
-
});
|
|
84
|
+
const res = await client.get(endpoint);
|
|
85
|
+
return res.body;
|
|
101
86
|
}
|
|
102
87
|
catch (err) {
|
|
103
88
|
throw new error_1.FirebaseError(`Failed to get the IAM Policy on the function ${fnName}`, {
|
|
@@ -148,21 +133,18 @@ async function setInvokerUpdate(projectId, fnName, invoker) {
|
|
|
148
133
|
}
|
|
149
134
|
exports.setInvokerUpdate = setInvokerUpdate;
|
|
150
135
|
async function updateFunction(cloudFunction) {
|
|
151
|
-
const endpoint = `/${
|
|
136
|
+
const endpoint = `/${cloudFunction.name}`;
|
|
152
137
|
const fieldMasks = proto.fieldMasks(cloudFunction, "labels", "environmentVariables");
|
|
153
138
|
try {
|
|
154
139
|
const headers = {};
|
|
155
140
|
if (previews_1.previews.artifactregistry) {
|
|
156
141
|
headers["X-Firebase-Artifact-Registry"] = "optin";
|
|
157
142
|
}
|
|
158
|
-
const res = await
|
|
143
|
+
const res = await client.patch(endpoint, cloudFunction, {
|
|
159
144
|
headers,
|
|
160
|
-
|
|
145
|
+
queryParams: {
|
|
161
146
|
updateMask: fieldMasks.join(","),
|
|
162
147
|
},
|
|
163
|
-
auth: true,
|
|
164
|
-
data: cloudFunction,
|
|
165
|
-
origin: api.functionsOrigin,
|
|
166
148
|
});
|
|
167
149
|
return {
|
|
168
150
|
done: false,
|
|
@@ -176,12 +158,9 @@ async function updateFunction(cloudFunction) {
|
|
|
176
158
|
}
|
|
177
159
|
exports.updateFunction = updateFunction;
|
|
178
160
|
async function deleteFunction(name) {
|
|
179
|
-
const endpoint = `/${
|
|
161
|
+
const endpoint = `/${name}`;
|
|
180
162
|
try {
|
|
181
|
-
const res = await
|
|
182
|
-
auth: true,
|
|
183
|
-
origin: api.functionsOrigin,
|
|
184
|
-
});
|
|
163
|
+
const res = await client.delete(endpoint);
|
|
185
164
|
return {
|
|
186
165
|
done: false,
|
|
187
166
|
name: res.body.name,
|
|
@@ -194,12 +173,9 @@ async function deleteFunction(name) {
|
|
|
194
173
|
}
|
|
195
174
|
exports.deleteFunction = deleteFunction;
|
|
196
175
|
async function list(projectId, region) {
|
|
197
|
-
const endpoint = "/
|
|
176
|
+
const endpoint = "/projects/" + projectId + "/locations/" + region + "/functions";
|
|
198
177
|
try {
|
|
199
|
-
const res = await
|
|
200
|
-
auth: true,
|
|
201
|
-
origin: api.functionsOrigin,
|
|
202
|
-
});
|
|
178
|
+
const res = await client.get(endpoint);
|
|
203
179
|
if (res.body.unreachable && res.body.unreachable.length > 0) {
|
|
204
180
|
logger_1.logger.debug(`[functions] unable to reach the following regions: ${res.body.unreachable.join(", ")}`);
|
|
205
181
|
}
|
package/lib/gcp/cloudlogging.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.listEntries = void 0;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
5
6
|
const error_1 = require("../error");
|
|
6
7
|
const API_VERSION = "v2";
|
|
7
8
|
async function listEntries(projectId, filter, pageSize, order) {
|
|
8
|
-
const
|
|
9
|
+
const client = new apiv2_1.Client({ urlPrefix: api_1.cloudloggingOrigin, apiVersion: API_VERSION });
|
|
9
10
|
try {
|
|
10
|
-
const result = await
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
orderBy: "timestamp " + order,
|
|
16
|
-
pageSize: pageSize,
|
|
17
|
-
},
|
|
18
|
-
origin: api.cloudloggingOrigin,
|
|
11
|
+
const result = await client.post("/entries:list", {
|
|
12
|
+
resourceNames: [`projects/${projectId}`],
|
|
13
|
+
filter: filter,
|
|
14
|
+
orderBy: `timestamp ${order}`,
|
|
15
|
+
pageSize: pageSize,
|
|
19
16
|
});
|
|
20
17
|
return result.body.entries;
|
|
21
18
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.queryTimeSeries = exports.ValueType = exports.Reducer = exports.MetricKind = exports.Aligner = exports.TimeSeriesView = exports.CLOUD_MONITORING_VERSION = void 0;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
5
6
|
const error_1 = require("../error");
|
|
6
7
|
exports.CLOUD_MONITORING_VERSION = "v3";
|
|
7
8
|
var TimeSeriesView;
|
|
@@ -57,11 +58,13 @@ var ValueType;
|
|
|
57
58
|
ValueType["STRING"] = "STRING";
|
|
58
59
|
})(ValueType = exports.ValueType || (exports.ValueType = {}));
|
|
59
60
|
async function queryTimeSeries(query, projectNumber) {
|
|
61
|
+
const client = new apiv2_1.Client({
|
|
62
|
+
urlPrefix: api_1.cloudMonitoringOrigin,
|
|
63
|
+
apiVersion: exports.CLOUD_MONITORING_VERSION,
|
|
64
|
+
});
|
|
60
65
|
try {
|
|
61
|
-
const res = await
|
|
62
|
-
|
|
63
|
-
origin: api.cloudMonitoringOrigin,
|
|
64
|
-
data: query,
|
|
66
|
+
const res = await client.get(`/projects/${projectNumber}/timeSeries/`, {
|
|
67
|
+
queryParams: query,
|
|
65
68
|
});
|
|
66
69
|
return res.body.timeSeries;
|
|
67
70
|
}
|
|
@@ -4,7 +4,8 @@ exports.jobFromEndpoint = exports.createOrReplaceJob = exports.updateJob = expor
|
|
|
4
4
|
const _ = require("lodash");
|
|
5
5
|
const error_1 = require("../error");
|
|
6
6
|
const logger_1 = require("../logger");
|
|
7
|
-
const
|
|
7
|
+
const api_1 = require("../api");
|
|
8
|
+
const apiv2_1 = require("../apiv2");
|
|
8
9
|
const backend = require("../deploy/functions/backend");
|
|
9
10
|
const proto = require("./proto");
|
|
10
11
|
const functional_1 = require("../functional");
|
|
@@ -17,36 +18,24 @@ function assertValidJob(job) {
|
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
exports.assertValidJob = assertValidJob;
|
|
21
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: api_1.cloudschedulerOrigin, apiVersion: VERSION });
|
|
20
22
|
function createJob(job) {
|
|
21
23
|
const strippedName = job.name.substring(0, job.name.lastIndexOf("/"));
|
|
22
|
-
return
|
|
23
|
-
auth: true,
|
|
24
|
-
origin: api.cloudschedulerOrigin,
|
|
25
|
-
data: Object.assign({ timeZone: DEFAULT_TIME_ZONE }, job),
|
|
26
|
-
});
|
|
24
|
+
return apiClient.post(`/${strippedName}`, Object.assign({ timeZone: DEFAULT_TIME_ZONE }, job));
|
|
27
25
|
}
|
|
28
26
|
exports.createJob = createJob;
|
|
29
27
|
function deleteJob(name) {
|
|
30
|
-
return
|
|
31
|
-
auth: true,
|
|
32
|
-
origin: api.cloudschedulerOrigin,
|
|
33
|
-
});
|
|
28
|
+
return apiClient.delete(`/${name}`);
|
|
34
29
|
}
|
|
35
30
|
exports.deleteJob = deleteJob;
|
|
36
31
|
function getJob(name) {
|
|
37
|
-
return
|
|
38
|
-
auth: true,
|
|
39
|
-
origin: api.cloudschedulerOrigin,
|
|
32
|
+
return apiClient.get(`/${name}`, {
|
|
40
33
|
resolveOnHTTPError: true,
|
|
41
34
|
});
|
|
42
35
|
}
|
|
43
36
|
exports.getJob = getJob;
|
|
44
37
|
function updateJob(job) {
|
|
45
|
-
return
|
|
46
|
-
auth: true,
|
|
47
|
-
origin: api.cloudschedulerOrigin,
|
|
48
|
-
data: Object.assign({ timeZone: DEFAULT_TIME_ZONE }, job),
|
|
49
|
-
});
|
|
38
|
+
return apiClient.patch(`/${job.name}`, Object.assign({ timeZone: DEFAULT_TIME_ZONE }, job));
|
|
50
39
|
}
|
|
51
40
|
exports.updateJob = updateJob;
|
|
52
41
|
async function createOrReplaceJob(job) {
|
package/lib/gcp/firedata.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.listDatabaseInstances = void 0;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
5
6
|
const logger_1 = require("../logger");
|
|
6
7
|
const utils = require("../utils");
|
|
7
8
|
function _handleErrorResponse(response) {
|
|
@@ -14,9 +15,9 @@ function _handleErrorResponse(response) {
|
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
17
|
async function listDatabaseInstances(projectNumber) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
const client = new apiv2_1.Client({ urlPrefix: api_1.firedataOrigin, apiVersion: "v1" });
|
|
19
|
+
const response = await client.get(`/projects/${projectNumber}/databases`, {
|
|
20
|
+
resolveOnHTTPError: true,
|
|
20
21
|
});
|
|
21
22
|
if (response.status === 200) {
|
|
22
23
|
return response.body.instance;
|
package/lib/gcp/firestore.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteDocuments = exports.deleteDocument = exports.listCollectionIds = void 0;
|
|
4
4
|
const api_1 = require("../api");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
6
|
+
const apiClient = new apiv2_1.Client({
|
|
7
7
|
auth: true,
|
|
8
8
|
apiVersion: "v1",
|
|
9
9
|
urlPrefix: api_1.firestoreOriginOrEmulator,
|
|
@@ -13,13 +13,13 @@ function listCollectionIds(project) {
|
|
|
13
13
|
const data = {
|
|
14
14
|
pageSize: 2147483647,
|
|
15
15
|
};
|
|
16
|
-
return
|
|
16
|
+
return apiClient.post(url, data).then((res) => {
|
|
17
17
|
return res.body.collectionIds || [];
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
exports.listCollectionIds = listCollectionIds;
|
|
21
21
|
async function deleteDocument(doc) {
|
|
22
|
-
return
|
|
22
|
+
return apiClient.delete(doc.name);
|
|
23
23
|
}
|
|
24
24
|
exports.deleteDocument = deleteDocument;
|
|
25
25
|
async function deleteDocuments(project, docs) {
|
|
@@ -28,7 +28,7 @@ async function deleteDocuments(project, docs) {
|
|
|
28
28
|
return { delete: doc.name };
|
|
29
29
|
});
|
|
30
30
|
const data = { writes };
|
|
31
|
-
const res = await
|
|
31
|
+
const res = await apiClient.post(url, data);
|
|
32
32
|
return res.body.writeResults.length;
|
|
33
33
|
}
|
|
34
34
|
exports.deleteDocuments = deleteDocuments;
|
package/lib/gcp/iam.js
CHANGED
|
@@ -1,72 +1,57 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.testIamPermissions = exports.testResourceIamPermissions = exports.getRole = exports.deleteServiceAccount = exports.createServiceAccountKey = exports.getServiceAccount = exports.createServiceAccount = void 0;
|
|
4
|
-
const
|
|
5
|
-
const utils_1 = require("../utils");
|
|
4
|
+
const api_1 = require("../api");
|
|
6
5
|
const lodash_1 = require("lodash");
|
|
7
6
|
const logger_1 = require("../logger");
|
|
7
|
+
const apiv2_1 = require("../apiv2");
|
|
8
8
|
const API_VERSION = "v1";
|
|
9
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: api_1.iamOrigin, apiVersion: API_VERSION });
|
|
9
10
|
async function createServiceAccount(projectId, accountId, description, displayName) {
|
|
10
|
-
const response = await
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
serviceAccount: {
|
|
16
|
-
displayName,
|
|
17
|
-
description,
|
|
18
|
-
},
|
|
11
|
+
const response = await apiClient.post(`/projects/${projectId}/serviceAccounts`, {
|
|
12
|
+
accountId,
|
|
13
|
+
serviceAccount: {
|
|
14
|
+
displayName,
|
|
15
|
+
description,
|
|
19
16
|
},
|
|
20
17
|
});
|
|
21
18
|
return response.body;
|
|
22
19
|
}
|
|
23
20
|
exports.createServiceAccount = createServiceAccount;
|
|
24
21
|
async function getServiceAccount(projectId, serviceAccountName) {
|
|
25
|
-
const response = await
|
|
26
|
-
auth: true,
|
|
27
|
-
origin: api.iamOrigin,
|
|
28
|
-
});
|
|
22
|
+
const response = await apiClient.get(`/projects/${projectId}/serviceAccounts/${serviceAccountName}@${projectId}.iam.gserviceaccount.com`);
|
|
29
23
|
return response.body;
|
|
30
24
|
}
|
|
31
25
|
exports.getServiceAccount = getServiceAccount;
|
|
32
26
|
async function createServiceAccountKey(projectId, serviceAccountName) {
|
|
33
|
-
const response = await
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
data: {
|
|
37
|
-
keyAlgorithm: "KEY_ALG_UNSPECIFIED",
|
|
38
|
-
privateKeyType: "TYPE_GOOGLE_CREDENTIALS_FILE",
|
|
39
|
-
},
|
|
27
|
+
const response = await apiClient.post(`/projects/${projectId}/serviceAccounts/${serviceAccountName}@${projectId}.iam.gserviceaccount.com/keys`, {
|
|
28
|
+
keyAlgorithm: "KEY_ALG_UNSPECIFIED",
|
|
29
|
+
privateKeyType: "TYPE_GOOGLE_CREDENTIALS_FILE",
|
|
40
30
|
});
|
|
41
31
|
return response.body;
|
|
42
32
|
}
|
|
43
33
|
exports.createServiceAccountKey = createServiceAccountKey;
|
|
44
34
|
function deleteServiceAccount(projectId, accountEmail) {
|
|
45
|
-
return
|
|
46
|
-
auth: true,
|
|
47
|
-
origin: api.iamOrigin,
|
|
35
|
+
return apiClient.delete(`/projects/${projectId}/serviceAccounts/${accountEmail}`, {
|
|
48
36
|
resolveOnHTTPError: true,
|
|
49
37
|
});
|
|
50
38
|
}
|
|
51
39
|
exports.deleteServiceAccount = deleteServiceAccount;
|
|
52
40
|
async function getRole(role) {
|
|
53
|
-
const response = await
|
|
54
|
-
auth: true,
|
|
55
|
-
origin: api.iamOrigin,
|
|
41
|
+
const response = await apiClient.get(`/roles/${role}`, {
|
|
56
42
|
retryCodes: [500, 503],
|
|
57
43
|
});
|
|
58
44
|
return response.body;
|
|
59
45
|
}
|
|
60
46
|
exports.getRole = getRole;
|
|
61
47
|
async function testResourceIamPermissions(origin, apiVersion, resourceName, permissions) {
|
|
48
|
+
const localClient = new apiv2_1.Client({ urlPrefix: origin, apiVersion });
|
|
62
49
|
if (process.env.FIREBASE_SKIP_INFORMATIONAL_IAM) {
|
|
63
50
|
logger_1.logger.debug("[iam] skipping informational check of permissions", JSON.stringify(permissions), "on resource", resourceName);
|
|
64
51
|
return { allowed: permissions, missing: [], passed: true };
|
|
65
52
|
}
|
|
66
|
-
const response = await
|
|
67
|
-
|
|
68
|
-
data: { permissions },
|
|
69
|
-
origin,
|
|
53
|
+
const response = await localClient.post(`/${resourceName}:testIamPermissions`, {
|
|
54
|
+
permissions,
|
|
70
55
|
});
|
|
71
56
|
const allowed = (response.body.permissions || []).sort();
|
|
72
57
|
const missing = (0, lodash_1.difference)(permissions, allowed);
|
|
@@ -78,6 +63,6 @@ async function testResourceIamPermissions(origin, apiVersion, resourceName, perm
|
|
|
78
63
|
}
|
|
79
64
|
exports.testResourceIamPermissions = testResourceIamPermissions;
|
|
80
65
|
async function testIamPermissions(projectId, permissions) {
|
|
81
|
-
return testResourceIamPermissions(
|
|
66
|
+
return testResourceIamPermissions(api_1.resourceManagerOrigin, "v1", `projects/${projectId}`, permissions);
|
|
82
67
|
}
|
|
83
68
|
exports.testIamPermissions = testIamPermissions;
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addServiceAccountToRoles = exports.setIamPolicy = exports.getIamPolicy = exports.firebaseRoles = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
|
-
const
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const apiv2_1 = require("../apiv2");
|
|
6
7
|
const iam_1 = require("./iam");
|
|
7
8
|
const API_VERSION = "v1";
|
|
9
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: api_1.resourceManagerOrigin, apiVersion: API_VERSION });
|
|
8
10
|
exports.firebaseRoles = {
|
|
9
11
|
apiKeysViewer: "roles/serviceusage.apiKeysViewer",
|
|
10
12
|
authAdmin: "roles/firebaseauth.admin",
|
|
@@ -12,21 +14,14 @@ exports.firebaseRoles = {
|
|
|
12
14
|
runViewer: "roles/run.viewer",
|
|
13
15
|
};
|
|
14
16
|
async function getIamPolicy(projectId) {
|
|
15
|
-
const response = await
|
|
16
|
-
auth: true,
|
|
17
|
-
origin: api.resourceManagerOrigin,
|
|
18
|
-
});
|
|
17
|
+
const response = await apiClient.post(`/projects/${projectId}:getIamPolicy`);
|
|
19
18
|
return response.body;
|
|
20
19
|
}
|
|
21
20
|
exports.getIamPolicy = getIamPolicy;
|
|
22
|
-
async function setIamPolicy(projectId, newPolicy, updateMask) {
|
|
23
|
-
const response = await
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
data: {
|
|
27
|
-
policy: newPolicy,
|
|
28
|
-
updateMask: updateMask,
|
|
29
|
-
},
|
|
21
|
+
async function setIamPolicy(projectId, newPolicy, updateMask = "") {
|
|
22
|
+
const response = await apiClient.post(`/projects/${projectId}:setIamPolicy`, {
|
|
23
|
+
policy: newPolicy,
|
|
24
|
+
updateMask: updateMask,
|
|
30
25
|
});
|
|
31
26
|
return response.body;
|
|
32
27
|
}
|
package/lib/gcp/rules.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.testRuleset = exports.updateOrCreateRelease = exports.updateRelease = exports.createRelease = exports.createRuleset = exports.deleteRuleset = exports.getRulesetId = exports.listAllRulesets = exports.listRulesets = exports.getRulesetContent = exports.listAllReleases = exports.listReleases = exports.getLatestRulesetName = void 0;
|
|
4
4
|
const _ = require("lodash");
|
|
5
|
-
const
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const apiv2_1 = require("../apiv2");
|
|
6
7
|
const logger_1 = require("../logger");
|
|
7
8
|
const utils = require("../utils");
|
|
8
9
|
const API_VERSION = "v1";
|
|
10
|
+
const apiClient = new apiv2_1.Client({ urlPrefix: api_1.rulesOrigin, apiVersion: API_VERSION });
|
|
9
11
|
function _handleErrorResponse(response) {
|
|
10
12
|
if (response.body && response.body.error) {
|
|
11
13
|
return utils.reject(response.body.error, { code: 2 });
|
|
@@ -18,7 +20,7 @@ function _handleErrorResponse(response) {
|
|
|
18
20
|
async function getLatestRulesetName(projectId, service) {
|
|
19
21
|
const releases = await listAllReleases(projectId);
|
|
20
22
|
const prefix = `projects/${projectId}/releases/${service}`;
|
|
21
|
-
const release = _.find(releases, (r) => r.name.
|
|
23
|
+
const release = _.find(releases, (r) => r.name.startsWith(prefix));
|
|
22
24
|
if (!release) {
|
|
23
25
|
return null;
|
|
24
26
|
}
|
|
@@ -26,11 +28,9 @@ async function getLatestRulesetName(projectId, service) {
|
|
|
26
28
|
}
|
|
27
29
|
exports.getLatestRulesetName = getLatestRulesetName;
|
|
28
30
|
const MAX_RELEASES_PAGE_SIZE = 10;
|
|
29
|
-
async function listReleases(projectId, pageToken) {
|
|
30
|
-
const response = await
|
|
31
|
-
|
|
32
|
-
origin: api.rulesOrigin,
|
|
33
|
-
query: {
|
|
31
|
+
async function listReleases(projectId, pageToken = "") {
|
|
32
|
+
const response = await apiClient.get(`/projects/${projectId}/releases`, {
|
|
33
|
+
queryParams: {
|
|
34
34
|
pageSize: MAX_RELEASES_PAGE_SIZE,
|
|
35
35
|
pageToken,
|
|
36
36
|
},
|
|
@@ -55,9 +55,8 @@ async function listAllReleases(projectId) {
|
|
|
55
55
|
}
|
|
56
56
|
exports.listAllReleases = listAllReleases;
|
|
57
57
|
async function getRulesetContent(name) {
|
|
58
|
-
const response = await
|
|
59
|
-
|
|
60
|
-
origin: api.rulesOrigin,
|
|
58
|
+
const response = await apiClient.get(`/${name}`, {
|
|
59
|
+
skipLog: { resBody: true },
|
|
61
60
|
});
|
|
62
61
|
if (response.status === 200) {
|
|
63
62
|
const source = response.body.source;
|
|
@@ -67,14 +66,13 @@ async function getRulesetContent(name) {
|
|
|
67
66
|
}
|
|
68
67
|
exports.getRulesetContent = getRulesetContent;
|
|
69
68
|
const MAX_RULESET_PAGE_SIZE = 100;
|
|
70
|
-
async function listRulesets(projectId, pageToken) {
|
|
71
|
-
const response = await
|
|
72
|
-
|
|
73
|
-
origin: api.rulesOrigin,
|
|
74
|
-
query: {
|
|
69
|
+
async function listRulesets(projectId, pageToken = "") {
|
|
70
|
+
const response = await apiClient.get(`/projects/${projectId}/rulesets`, {
|
|
71
|
+
queryParams: {
|
|
75
72
|
pageSize: MAX_RULESET_PAGE_SIZE,
|
|
76
73
|
pageToken,
|
|
77
74
|
},
|
|
75
|
+
skipLog: { resBody: true },
|
|
78
76
|
});
|
|
79
77
|
if (response.status === 200) {
|
|
80
78
|
return response.body;
|
|
@@ -100,10 +98,7 @@ function getRulesetId(ruleset) {
|
|
|
100
98
|
}
|
|
101
99
|
exports.getRulesetId = getRulesetId;
|
|
102
100
|
async function deleteRuleset(projectId, id) {
|
|
103
|
-
const response = await
|
|
104
|
-
auth: true,
|
|
105
|
-
origin: api.rulesOrigin,
|
|
106
|
-
});
|
|
101
|
+
const response = await apiClient.delete(`/projects/${projectId}/rulesets/${id}`);
|
|
107
102
|
if (response.status === 200) {
|
|
108
103
|
return;
|
|
109
104
|
}
|
|
@@ -112,11 +107,7 @@ async function deleteRuleset(projectId, id) {
|
|
|
112
107
|
exports.deleteRuleset = deleteRuleset;
|
|
113
108
|
async function createRuleset(projectId, files) {
|
|
114
109
|
const payload = { source: { files } };
|
|
115
|
-
const response = await
|
|
116
|
-
auth: true,
|
|
117
|
-
data: payload,
|
|
118
|
-
origin: api.rulesOrigin,
|
|
119
|
-
});
|
|
110
|
+
const response = await apiClient.post(`/projects/${projectId}/rulesets`, payload, { skipLog: { body: true } });
|
|
120
111
|
if (response.status === 200) {
|
|
121
112
|
logger_1.logger.debug("[rules] created ruleset", response.body.name);
|
|
122
113
|
return response.body.name;
|
|
@@ -129,11 +120,7 @@ async function createRelease(projectId, rulesetName, releaseName) {
|
|
|
129
120
|
name: `projects/${projectId}/releases/${releaseName}`,
|
|
130
121
|
rulesetName,
|
|
131
122
|
};
|
|
132
|
-
const response = await
|
|
133
|
-
auth: true,
|
|
134
|
-
data: payload,
|
|
135
|
-
origin: api.rulesOrigin,
|
|
136
|
-
});
|
|
123
|
+
const response = await apiClient.post(`/projects/${projectId}/releases`, payload);
|
|
137
124
|
if (response.status === 200) {
|
|
138
125
|
logger_1.logger.debug("[rules] created release", response.body.name);
|
|
139
126
|
return response.body.name;
|
|
@@ -148,11 +135,7 @@ async function updateRelease(projectId, rulesetName, releaseName) {
|
|
|
148
135
|
rulesetName,
|
|
149
136
|
},
|
|
150
137
|
};
|
|
151
|
-
const response = await
|
|
152
|
-
auth: true,
|
|
153
|
-
data: payload,
|
|
154
|
-
origin: api.rulesOrigin,
|
|
155
|
-
});
|
|
138
|
+
const response = await apiClient.patch(`/projects/${projectId}/releases/${releaseName}`, payload);
|
|
156
139
|
if (response.status === 200) {
|
|
157
140
|
logger_1.logger.debug("[rules] updated release", response.body.name);
|
|
158
141
|
return response.body.name;
|
|
@@ -169,12 +152,6 @@ async function updateOrCreateRelease(projectId, rulesetName, releaseName) {
|
|
|
169
152
|
}
|
|
170
153
|
exports.updateOrCreateRelease = updateOrCreateRelease;
|
|
171
154
|
function testRuleset(projectId, files) {
|
|
172
|
-
return
|
|
173
|
-
origin: api.rulesOrigin,
|
|
174
|
-
data: {
|
|
175
|
-
source: { files },
|
|
176
|
-
},
|
|
177
|
-
auth: true,
|
|
178
|
-
});
|
|
155
|
+
return apiClient.post(`/projects/${encodeURIComponent(projectId)}:test`, { source: { files } }, { skipLog: { body: true } });
|
|
179
156
|
}
|
|
180
157
|
exports.testRuleset = testRuleset;
|