firebase-tools 10.1.2 → 10.1.3
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/apiv2.js +91 -48
- package/lib/archiveDirectory.js +63 -73
- package/lib/commands/ext-dev-usage.js +3 -8
- package/lib/database/metadata.js +16 -24
- package/lib/deploy/functions/backend.js +3 -1
- package/lib/deploy/functions/prepare.js +2 -2
- package/lib/deploy/functions/release/fabricator.js +4 -1
- package/lib/deploy/functions/validate.js +28 -1
- package/lib/deploy/hosting/convertConfig.js +45 -24
- package/lib/deploy/hosting/prepare.js +1 -1
- package/lib/emulator/functionsEmulator.js +3 -1
- package/lib/extensions/extensionsApi.js +0 -1
- 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/runtimeconfig.js +31 -53
- package/lib/gcp/secretManager.js +21 -43
- package/lib/gcp/storage.js +24 -29
- package/npm-shrinkwrap.json +965 -970
- package/package.json +4 -2
- package/schema/firebase-config.json +387 -12
- package/templates/init/hosting/index.html +1 -1
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertConfig = void 0;
|
|
4
|
+
const error_1 = require("../../error");
|
|
5
|
+
function has(obj, k) {
|
|
6
|
+
return obj[k] !== undefined;
|
|
7
|
+
}
|
|
4
8
|
function extractPattern(type, spec) {
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
let glob = "";
|
|
10
|
+
let regex = "";
|
|
11
|
+
if ("source" in spec) {
|
|
12
|
+
glob = spec.source;
|
|
13
|
+
}
|
|
14
|
+
if ("glob" in spec) {
|
|
15
|
+
glob = spec.glob;
|
|
16
|
+
}
|
|
17
|
+
if ("regex" in spec) {
|
|
18
|
+
regex = spec.regex;
|
|
19
|
+
}
|
|
7
20
|
if (glob && regex) {
|
|
8
|
-
throw new FirebaseError(
|
|
21
|
+
throw new error_1.FirebaseError(`Cannot specify a ${type} pattern with both a glob and regex.`);
|
|
9
22
|
}
|
|
10
23
|
else if (glob) {
|
|
11
24
|
return { glob: glob };
|
|
@@ -13,33 +26,38 @@ function extractPattern(type, spec) {
|
|
|
13
26
|
else if (regex) {
|
|
14
27
|
return { regex: regex };
|
|
15
28
|
}
|
|
16
|
-
throw new FirebaseError(
|
|
29
|
+
throw new error_1.FirebaseError(`Cannot specify a ${type} with no pattern (either a glob or regex required).`);
|
|
17
30
|
}
|
|
18
|
-
|
|
31
|
+
function convertConfig(config) {
|
|
32
|
+
if (Array.isArray(config)) {
|
|
33
|
+
throw new error_1.FirebaseError(`convertConfig should be given a single configuration, not an array.`, {
|
|
34
|
+
exit: 2,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
19
37
|
const out = {};
|
|
20
38
|
if (!config) {
|
|
21
39
|
return out;
|
|
22
40
|
}
|
|
23
|
-
if (
|
|
24
|
-
out.rewrites = config.rewrites.map(
|
|
41
|
+
if (Array.isArray(config.rewrites)) {
|
|
42
|
+
out.rewrites = config.rewrites.map((rewrite) => {
|
|
25
43
|
const vRewrite = extractPattern("rewrite", rewrite);
|
|
26
|
-
if (rewrite
|
|
44
|
+
if ("destination" in rewrite) {
|
|
27
45
|
vRewrite.path = rewrite.destination;
|
|
28
46
|
}
|
|
29
|
-
else if (rewrite
|
|
47
|
+
else if ("function" in rewrite) {
|
|
30
48
|
vRewrite.function = rewrite.function;
|
|
31
49
|
}
|
|
32
|
-
else if (rewrite
|
|
50
|
+
else if ("dynamicLinks" in rewrite) {
|
|
33
51
|
vRewrite.dynamicLinks = rewrite.dynamicLinks;
|
|
34
52
|
}
|
|
35
|
-
else if (rewrite
|
|
53
|
+
else if ("run" in rewrite) {
|
|
36
54
|
vRewrite.run = Object.assign({ region: "us-central1" }, rewrite.run);
|
|
37
55
|
}
|
|
38
56
|
return vRewrite;
|
|
39
57
|
});
|
|
40
58
|
}
|
|
41
|
-
if (
|
|
42
|
-
out.redirects = config.redirects.map(
|
|
59
|
+
if (Array.isArray(config.redirects)) {
|
|
60
|
+
out.redirects = config.redirects.map((redirect) => {
|
|
43
61
|
const vRedirect = extractPattern("redirect", redirect);
|
|
44
62
|
vRedirect.location = redirect.destination;
|
|
45
63
|
if (redirect.type) {
|
|
@@ -48,17 +66,19 @@ module.exports = function (config) {
|
|
|
48
66
|
return vRedirect;
|
|
49
67
|
});
|
|
50
68
|
}
|
|
51
|
-
if (
|
|
52
|
-
out.headers = config.headers.map(
|
|
69
|
+
if (Array.isArray(config.headers)) {
|
|
70
|
+
out.headers = config.headers.map((header) => {
|
|
53
71
|
const vHeader = extractPattern("header", header);
|
|
54
72
|
vHeader.headers = {};
|
|
55
|
-
(header.headers
|
|
56
|
-
|
|
57
|
-
|
|
73
|
+
if (Array.isArray(header.headers) && header.headers.length) {
|
|
74
|
+
header.headers.forEach((h) => {
|
|
75
|
+
vHeader.headers[h.key] = h.value;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
58
78
|
return vHeader;
|
|
59
79
|
});
|
|
60
80
|
}
|
|
61
|
-
if (
|
|
81
|
+
if (has(config, "cleanUrls")) {
|
|
62
82
|
out.cleanUrls = config.cleanUrls;
|
|
63
83
|
}
|
|
64
84
|
if (config.trailingSlash === true) {
|
|
@@ -67,11 +87,12 @@ module.exports = function (config) {
|
|
|
67
87
|
else if (config.trailingSlash === false) {
|
|
68
88
|
out.trailingSlashBehavior = "REMOVE";
|
|
69
89
|
}
|
|
70
|
-
if (
|
|
90
|
+
if (has(config, "appAssociation")) {
|
|
71
91
|
out.appAssociation = config.appAssociation;
|
|
72
92
|
}
|
|
73
|
-
if (
|
|
93
|
+
if (has(config, "i18n")) {
|
|
74
94
|
out.i18n = config.i18n;
|
|
75
95
|
}
|
|
76
96
|
return out;
|
|
77
|
-
}
|
|
97
|
+
}
|
|
98
|
+
exports.convertConfig = convertConfig;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const _ = require("lodash");
|
|
3
3
|
const api = require("../../api");
|
|
4
|
-
const convertConfig = require("./convertConfig");
|
|
4
|
+
const { convertConfig } = require("./convertConfig");
|
|
5
5
|
const deploymentTool = require("../../deploymentTool");
|
|
6
6
|
const { FirebaseError } = require("../../error");
|
|
7
7
|
const { normalizedHostingConfigs } = require("../../hosting/normalizedHostingConfigs");
|
|
@@ -525,7 +525,9 @@ class FunctionsEmulator {
|
|
|
525
525
|
if (requestedMajorVersion === hostMajorVersion) {
|
|
526
526
|
this.logger.logLabeled("SUCCESS", "functions", `Using node@${requestedMajorVersion} from host.`);
|
|
527
527
|
}
|
|
528
|
-
|
|
528
|
+
else {
|
|
529
|
+
this.logger.log("WARN", `Your requested "node" version "${requestedMajorVersion}" doesn't match your global version "${hostMajorVersion}". Using node@${hostMajorVersion} from host.`);
|
|
530
|
+
}
|
|
529
531
|
return process.execPath;
|
|
530
532
|
}
|
|
531
533
|
getUserEnvs(backend) {
|
|
@@ -256,7 +256,6 @@ async function listExtensions(publisherId) {
|
|
|
256
256
|
const getNextPage = async (pageToken = "") => {
|
|
257
257
|
const res = await apiClient.get(`/publishers/${publisherId}/extensions`, {
|
|
258
258
|
queryParams: {
|
|
259
|
-
showUnpublished: "false",
|
|
260
259
|
pageSize: PAGE_SIZE_MAX,
|
|
261
260
|
pageToken,
|
|
262
261
|
},
|
package/lib/gcp/cloudbilling.js
CHANGED
|
@@ -1,36 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.listBillingAccounts = exports.setBillingAccount = exports.checkBillingEnabled = void 0;
|
|
4
|
-
const
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const apiv2_1 = require("../apiv2");
|
|
5
6
|
const utils = require("../utils");
|
|
6
7
|
const API_VERSION = "v1";
|
|
8
|
+
const client = new apiv2_1.Client({ urlPrefix: api_1.cloudbillingOrigin, apiVersion: API_VERSION });
|
|
7
9
|
async function checkBillingEnabled(projectId) {
|
|
8
|
-
const res = await
|
|
9
|
-
auth: true,
|
|
10
|
-
origin: api.cloudbillingOrigin,
|
|
11
|
-
retryCodes: [500, 503],
|
|
12
|
-
});
|
|
10
|
+
const res = await client.get(utils.endpoint(["projects", projectId, "billingInfo"]), { retryCodes: [500, 503] });
|
|
13
11
|
return res.body.billingEnabled;
|
|
14
12
|
}
|
|
15
13
|
exports.checkBillingEnabled = checkBillingEnabled;
|
|
16
14
|
async function setBillingAccount(projectId, billingAccountName) {
|
|
17
|
-
const res = await
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
retryCodes: [500, 503],
|
|
21
|
-
data: {
|
|
22
|
-
billingAccountName: billingAccountName,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
15
|
+
const res = await client.put(utils.endpoint(["projects", projectId, "billingInfo"]), {
|
|
16
|
+
billingAccountName: billingAccountName,
|
|
17
|
+
}, { retryCodes: [500, 503] });
|
|
25
18
|
return res.body.billingEnabled;
|
|
26
19
|
}
|
|
27
20
|
exports.setBillingAccount = setBillingAccount;
|
|
28
21
|
async function listBillingAccounts() {
|
|
29
|
-
const res = await
|
|
30
|
-
auth: true,
|
|
31
|
-
origin: api.cloudbillingOrigin,
|
|
32
|
-
retryCodes: [500, 503],
|
|
33
|
-
});
|
|
22
|
+
const res = await client.get(utils.endpoint(["billingAccounts"]), { retryCodes: [500, 503] });
|
|
34
23
|
return res.body.billingAccounts || [];
|
|
35
24
|
}
|
|
36
25
|
exports.listBillingAccounts = listBillingAccounts;
|
|
@@ -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
|
}
|