1 | "use strict";
|
2 |
|
3 |
|
4 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
5 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
6 | return new (P || (P = Promise))(function (resolve, reject) {
|
7 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
8 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
9 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
10 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
11 | });
|
12 | };
|
13 | Object.defineProperty(exports, "__esModule", { value: true });
|
14 | exports.WebApi = exports.getHandlerFromToken = exports.getPersonalAccessTokenHandler = exports.getBearerHandler = exports.getNtlmHandler = exports.getBasicHandler = void 0;
|
15 | const alertm = require("./AlertApi");
|
16 | const buildm = require("./BuildApi");
|
17 | const corem = require("./CoreApi");
|
18 | const dashboardm = require("./DashboardApi");
|
19 | const extmgmtm = require("./ExtensionManagementApi");
|
20 | const featuremgmtm = require("./FeatureManagementApi");
|
21 | const filecontainerm = require("./FileContainerApi");
|
22 | const gallerym = require("./GalleryApi");
|
23 | const gitm = require("./GitApi");
|
24 | const locationsm = require("./LocationsApi");
|
25 | const managementm = require("./ManagementApi");
|
26 | const notificationm = require("./NotificationApi");
|
27 | const policym = require("./PolicyApi");
|
28 | const profilem = require("./ProfileApi");
|
29 | const projectm = require("./ProjectAnalysisApi");
|
30 | const releasem = require("./ReleaseApi");
|
31 | const securityrolesm = require("./SecurityRolesApi");
|
32 | const taskagentm = require("./TaskAgentApi");
|
33 | const taskm = require("./TaskApi");
|
34 | const testm = require("./TestApi");
|
35 | const testplanm = require("./TestPlanApi");
|
36 | const testresultsm = require("./TestResultsApi");
|
37 | const tfvcm = require("./TfvcApi");
|
38 | const wikim = require("./WikiApi");
|
39 | const workm = require("./WorkApi");
|
40 | const pipelinesm = require("./PipelinesApi");
|
41 | const cixm = require("./CIXApi");
|
42 | const workitemtrackingm = require("./WorkItemTrackingApi");
|
43 | const workitemtrackingprocessm = require("./WorkItemTrackingProcessApi");
|
44 | const workitemtrackingprocessdefinitionm = require("./WorkItemTrackingProcessDefinitionsApi");
|
45 | const basicm = require("./handlers/basiccreds");
|
46 | const bearm = require("./handlers/bearertoken");
|
47 | const ntlmm = require("./handlers/ntlm");
|
48 | const patm = require("./handlers/personalaccesstoken");
|
49 | const rm = require("typed-rest-client/RestClient");
|
50 | const vsom = require("./VsoClient");
|
51 | const crypto = require("crypto");
|
52 | const fs = require("fs");
|
53 | const os = require("os");
|
54 | const url = require("url");
|
55 | const path = require("path");
|
56 | const isBrowser = typeof window !== 'undefined';
|
57 |
|
58 |
|
59 |
|
60 | function getBasicHandler(username, password, allowCrossOriginAuthentication) {
|
61 | return new basicm.BasicCredentialHandler(username, password, allowCrossOriginAuthentication);
|
62 | }
|
63 | exports.getBasicHandler = getBasicHandler;
|
64 | function getNtlmHandler(username, password, workstation, domain) {
|
65 | return new ntlmm.NtlmCredentialHandler(username, password, workstation, domain);
|
66 | }
|
67 | exports.getNtlmHandler = getNtlmHandler;
|
68 | function getBearerHandler(token, allowCrossOriginAuthentication) {
|
69 | return new bearm.BearerCredentialHandler(token, allowCrossOriginAuthentication);
|
70 | }
|
71 | exports.getBearerHandler = getBearerHandler;
|
72 | function getPersonalAccessTokenHandler(token, allowCrossOriginAuthentication) {
|
73 | return new patm.PersonalAccessTokenCredentialHandler(token, allowCrossOriginAuthentication);
|
74 | }
|
75 | exports.getPersonalAccessTokenHandler = getPersonalAccessTokenHandler;
|
76 | function getHandlerFromToken(token, allowCrossOriginAuthentication) {
|
77 | if (token.length === 52) {
|
78 | return getPersonalAccessTokenHandler(token, allowCrossOriginAuthentication);
|
79 | }
|
80 | else {
|
81 | return getBearerHandler(token, allowCrossOriginAuthentication);
|
82 | }
|
83 | }
|
84 | exports.getHandlerFromToken = getHandlerFromToken;
|
85 | ;
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | class WebApi {
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 | constructor(defaultUrl, authHandler, options, requestSettings) {
|
97 | |
98 |
|
99 |
|
100 |
|
101 | this.isNoProxyHost = function (_url) {
|
102 | if (!process.env.no_proxy) {
|
103 | return false;
|
104 | }
|
105 | const noProxyDomains = (process.env.no_proxy || '')
|
106 | .split(',')
|
107 | .map(v => v.toLowerCase());
|
108 | const serverUrl = url.parse(_url).host.toLowerCase();
|
109 |
|
110 | return noProxyDomains.indexOf(serverUrl) !== -1;
|
111 | };
|
112 | this.serverUrl = defaultUrl;
|
113 | this.authHandler = authHandler;
|
114 | this.options = options || {};
|
115 | if (!this.isNoProxyHost(this.serverUrl)) {
|
116 |
|
117 | if (!this.options.proxy || !this.options.proxy.proxyUrl) {
|
118 | if (global['_vsts_task_lib_proxy']) {
|
119 | let proxyFromEnv = {
|
120 | proxyUrl: global['_vsts_task_lib_proxy_url'],
|
121 | proxyUsername: global['_vsts_task_lib_proxy_username'],
|
122 | proxyPassword: this._readTaskLibSecrets(global['_vsts_task_lib_proxy_password']),
|
123 | proxyBypassHosts: JSON.parse(global['_vsts_task_lib_proxy_bypass'] || "[]"),
|
124 | };
|
125 | this.options.proxy = proxyFromEnv;
|
126 | }
|
127 | }
|
128 | }
|
129 |
|
130 | if (!this.options.cert) {
|
131 | if (global['_vsts_task_lib_cert']) {
|
132 | let certFromEnv = {
|
133 | caFile: global['_vsts_task_lib_cert_ca'],
|
134 | certFile: global['_vsts_task_lib_cert_clientcert'],
|
135 | keyFile: global['_vsts_task_lib_cert_key'],
|
136 | passphrase: this._readTaskLibSecrets(global['_vsts_task_lib_cert_passphrase']),
|
137 | };
|
138 | this.options.cert = certFromEnv;
|
139 | }
|
140 | }
|
141 |
|
142 | if (!this.options.ignoreSslError) {
|
143 | this.options.ignoreSslError = !!global['_vsts_task_lib_skip_cert_validation'];
|
144 | }
|
145 | let userAgent;
|
146 | const nodeApiName = 'azure-devops-node-api';
|
147 | if (isBrowser) {
|
148 | if (requestSettings) {
|
149 | userAgent = `${requestSettings.productName}/${requestSettings.productVersion} (${nodeApiName}; ${window.navigator.userAgent})`;
|
150 | }
|
151 | else {
|
152 | userAgent = `${nodeApiName} (${window.navigator.userAgent})`;
|
153 | }
|
154 | }
|
155 | else {
|
156 | let nodeApiVersion = 'unknown';
|
157 | const packageJsonPath = path.resolve(__dirname, 'package.json');
|
158 | if (fs.existsSync(packageJsonPath)) {
|
159 | nodeApiVersion = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version;
|
160 | }
|
161 | const osName = os.platform();
|
162 | const osVersion = os.release();
|
163 | if (requestSettings) {
|
164 | userAgent = `${requestSettings.productName}/${requestSettings.productVersion} (${nodeApiName} ${nodeApiVersion}; ${osName} ${osVersion})`;
|
165 | }
|
166 | else {
|
167 | userAgent = `${nodeApiName}/${nodeApiVersion} (${osName} ${osVersion})`;
|
168 | }
|
169 | }
|
170 | this.rest = new rm.RestClient(userAgent, null, [this.authHandler], this.options);
|
171 | this.vsoClient = new vsom.VsoClient(defaultUrl, this.rest);
|
172 | }
|
173 | |
174 |
|
175 |
|
176 |
|
177 |
|
178 | static createWithBearerToken(defaultUrl, token, options) {
|
179 | let bearerHandler = getBearerHandler(token);
|
180 | return new this(defaultUrl, bearerHandler, options);
|
181 | }
|
182 | connect() {
|
183 | return __awaiter(this, void 0, void 0, function* () {
|
184 | return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
185 | try {
|
186 | let res;
|
187 | res = yield this.rest.get(this.vsoClient.resolveUrl('/_apis/connectionData'));
|
188 | resolve(res.result);
|
189 | }
|
190 | catch (err) {
|
191 | reject(err);
|
192 | }
|
193 | }));
|
194 | });
|
195 | }
|
196 | |
197 |
|
198 |
|
199 |
|
200 | getAlertApi(serverUrl, handlers) {
|
201 | return __awaiter(this, void 0, void 0, function* () {
|
202 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "0f2ca920-f269-4545-b1f4-5b4173aa784e");
|
203 | handlers = handlers || [this.authHandler];
|
204 | return new alertm.AlertApi(serverUrl, handlers, this.options);
|
205 | });
|
206 | }
|
207 | getBuildApi(serverUrl, handlers) {
|
208 | return __awaiter(this, void 0, void 0, function* () {
|
209 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, buildm.BuildApi.RESOURCE_AREA_ID);
|
210 | handlers = handlers || [this.authHandler];
|
211 | return new buildm.BuildApi(serverUrl, handlers, this.options);
|
212 | });
|
213 | }
|
214 | getCoreApi(serverUrl, handlers) {
|
215 | return __awaiter(this, void 0, void 0, function* () {
|
216 |
|
217 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "79134c72-4a58-4b42-976c-04e7115f32bf");
|
218 | handlers = handlers || [this.authHandler];
|
219 | return new corem.CoreApi(serverUrl, handlers, this.options);
|
220 | });
|
221 | }
|
222 | getDashboardApi(serverUrl, handlers) {
|
223 | return __awaiter(this, void 0, void 0, function* () {
|
224 |
|
225 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "31c84e0a-3ece-48fd-a29d-100849af99ba");
|
226 | handlers = handlers || [this.authHandler];
|
227 | return new dashboardm.DashboardApi(serverUrl, handlers, this.options);
|
228 | });
|
229 | }
|
230 | getExtensionManagementApi(serverUrl, handlers) {
|
231 | return __awaiter(this, void 0, void 0, function* () {
|
232 |
|
233 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "6c2b0933-3600-42ae-bf8b-93d4f7e83594");
|
234 | handlers = handlers || [this.authHandler];
|
235 | return new extmgmtm.ExtensionManagementApi(serverUrl, handlers, this.options);
|
236 | });
|
237 | }
|
238 | getFeatureManagementApi(serverUrl, handlers) {
|
239 | return __awaiter(this, void 0, void 0, function* () {
|
240 |
|
241 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
242 | handlers = handlers || [this.authHandler];
|
243 | return new featuremgmtm.FeatureManagementApi(serverUrl, handlers, this.options);
|
244 | });
|
245 | }
|
246 | getFileContainerApi(serverUrl, handlers) {
|
247 | return __awaiter(this, void 0, void 0, function* () {
|
248 |
|
249 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
250 | handlers = handlers || [this.authHandler];
|
251 | return new filecontainerm.FileContainerApi(serverUrl, handlers, this.options);
|
252 | });
|
253 | }
|
254 | getGalleryApi(serverUrl, handlers) {
|
255 | return __awaiter(this, void 0, void 0, function* () {
|
256 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, gallerym.GalleryApi.RESOURCE_AREA_ID);
|
257 | handlers = handlers || [this.authHandler];
|
258 | return new gallerym.GalleryApi(serverUrl, handlers, this.options);
|
259 | });
|
260 | }
|
261 | getGitApi(serverUrl, handlers) {
|
262 | return __awaiter(this, void 0, void 0, function* () {
|
263 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, gitm.GitApi.RESOURCE_AREA_ID);
|
264 | handlers = handlers || [this.authHandler];
|
265 | return new gitm.GitApi(serverUrl, handlers, this.options);
|
266 | });
|
267 | }
|
268 |
|
269 | getLocationsApi(serverUrl, handlers) {
|
270 | return __awaiter(this, void 0, void 0, function* () {
|
271 | let optionsClone = Object.assign({}, this.options);
|
272 | optionsClone.allowRetries = true;
|
273 | optionsClone.maxRetries = 5;
|
274 | serverUrl = (yield serverUrl) || this.serverUrl;
|
275 | handlers = handlers || [this.authHandler];
|
276 | return new locationsm.LocationsApi(serverUrl, handlers, optionsClone);
|
277 | });
|
278 | }
|
279 | getManagementApi(serverUrl, handlers) {
|
280 | return __awaiter(this, void 0, void 0, function* () {
|
281 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "f101720c-9790-45a6-9fb3-494a09fddeeb");
|
282 | handlers = handlers || [this.authHandler];
|
283 | return new managementm.ManagementApi(serverUrl, handlers, this.options);
|
284 | });
|
285 | }
|
286 | getNotificationApi(serverUrl, handlers) {
|
287 | return __awaiter(this, void 0, void 0, function* () {
|
288 |
|
289 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
290 | handlers = handlers || [this.authHandler];
|
291 | return new notificationm.NotificationApi(serverUrl, handlers, this.options);
|
292 | });
|
293 | }
|
294 | getPolicyApi(serverUrl, handlers) {
|
295 | return __awaiter(this, void 0, void 0, function* () {
|
296 |
|
297 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "fb13a388-40dd-4a04-b530-013a739c72ef");
|
298 | handlers = handlers || [this.authHandler];
|
299 | return new policym.PolicyApi(serverUrl, handlers, this.options);
|
300 | });
|
301 | }
|
302 | getProfileApi(serverUrl, handlers) {
|
303 | return __awaiter(this, void 0, void 0, function* () {
|
304 |
|
305 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "8ccfef3d-2b87-4e99-8ccb-66e343d2daa8");
|
306 | handlers = handlers || [this.authHandler];
|
307 | return new profilem.ProfileApi(serverUrl, handlers, this.options);
|
308 | });
|
309 | }
|
310 | getProjectAnalysisApi(serverUrl, handlers) {
|
311 | return __awaiter(this, void 0, void 0, function* () {
|
312 |
|
313 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "7658fa33-b1bf-4580-990f-fac5896773d3");
|
314 | handlers = handlers || [this.authHandler];
|
315 | return new projectm.ProjectAnalysisApi(serverUrl, handlers, this.options);
|
316 | });
|
317 | }
|
318 | getSecurityRolesApi(serverUrl, handlers) {
|
319 | return __awaiter(this, void 0, void 0, function* () {
|
320 |
|
321 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
322 | handlers = handlers || [this.authHandler];
|
323 | return new securityrolesm.SecurityRolesApi(serverUrl, handlers, this.options);
|
324 | });
|
325 | }
|
326 | getReleaseApi(serverUrl, handlers) {
|
327 | return __awaiter(this, void 0, void 0, function* () {
|
328 |
|
329 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "efc2f575-36ef-48e9-b672-0c6fb4a48ac5");
|
330 | handlers = handlers || [this.authHandler];
|
331 | return new releasem.ReleaseApi(serverUrl, handlers, this.options);
|
332 | });
|
333 | }
|
334 | getTaskApi(serverUrl, handlers) {
|
335 | return __awaiter(this, void 0, void 0, function* () {
|
336 |
|
337 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "");
|
338 | handlers = handlers || [this.authHandler];
|
339 | return new taskm.TaskApi(serverUrl, handlers, this.options);
|
340 | });
|
341 | }
|
342 | getTaskAgentApi(serverUrl, handlers) {
|
343 | return __awaiter(this, void 0, void 0, function* () {
|
344 |
|
345 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "a85b8835-c1a1-4aac-ae97-1c3d0ba72dbd");
|
346 | handlers = handlers || [this.authHandler];
|
347 | return new taskagentm.TaskAgentApi(serverUrl, handlers, this.options);
|
348 | });
|
349 | }
|
350 | getTestApi(serverUrl, handlers) {
|
351 | return __awaiter(this, void 0, void 0, function* () {
|
352 |
|
353 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "c2aa639c-3ccc-4740-b3b6-ce2a1e1d984e");
|
354 | handlers = handlers || [this.authHandler];
|
355 | return new testm.TestApi(serverUrl, handlers, this.options);
|
356 | });
|
357 | }
|
358 | getTestPlanApi(serverUrl, handlers) {
|
359 | return __awaiter(this, void 0, void 0, function* () {
|
360 |
|
361 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "e4c27205-9d23-4c98-b958-d798bc3f9cd4");
|
362 | handlers = handlers || [this.authHandler];
|
363 | return new testplanm.TestPlanApi(serverUrl, handlers, this.options);
|
364 | });
|
365 | }
|
366 | getTestResultsApi(serverUrl, handlers) {
|
367 | return __awaiter(this, void 0, void 0, function* () {
|
368 |
|
369 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "c83eaf52-edf3-4034-ae11-17d38f25404c");
|
370 | handlers = handlers || [this.authHandler];
|
371 | return new testresultsm.TestResultsApi(serverUrl, handlers, this.options);
|
372 | });
|
373 | }
|
374 | getTfvcApi(serverUrl, handlers) {
|
375 | return __awaiter(this, void 0, void 0, function* () {
|
376 |
|
377 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "8aa40520-446d-40e6-89f6-9c9f9ce44c48");
|
378 | handlers = handlers || [this.authHandler];
|
379 | return new tfvcm.TfvcApi(serverUrl, handlers, this.options);
|
380 | });
|
381 | }
|
382 | getWikiApi(serverUrl, handlers) {
|
383 | return __awaiter(this, void 0, void 0, function* () {
|
384 |
|
385 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "bf7d82a0-8aa5-4613-94ef-6172a5ea01f3");
|
386 | handlers = handlers || [this.authHandler];
|
387 | return new wikim.WikiApi(serverUrl, handlers, this.options);
|
388 | });
|
389 | }
|
390 | getWorkApi(serverUrl, handlers) {
|
391 | return __awaiter(this, void 0, void 0, function* () {
|
392 |
|
393 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "1d4f49f9-02b9-4e26-b826-2cdb6195f2a9");
|
394 | handlers = handlers || [this.authHandler];
|
395 | return new workm.WorkApi(serverUrl, handlers, this.options);
|
396 | });
|
397 | }
|
398 | getWorkItemTrackingApi(serverUrl, handlers) {
|
399 | return __awaiter(this, void 0, void 0, function* () {
|
400 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, workitemtrackingm.WorkItemTrackingApi.RESOURCE_AREA_ID);
|
401 | handlers = handlers || [this.authHandler];
|
402 | return new workitemtrackingm.WorkItemTrackingApi(serverUrl, handlers, this.options);
|
403 | });
|
404 | }
|
405 | getWorkItemTrackingProcessApi(serverUrl, handlers) {
|
406 | return __awaiter(this, void 0, void 0, function* () {
|
407 |
|
408 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "5264459e-e5e0-4bd8-b118-0985e68a4ec5");
|
409 | handlers = handlers || [this.authHandler];
|
410 | return new workitemtrackingprocessm.WorkItemTrackingProcessApi(serverUrl, handlers, this.options);
|
411 | });
|
412 | }
|
413 | getWorkItemTrackingProcessDefinitionApi(serverUrl, handlers) {
|
414 | return __awaiter(this, void 0, void 0, function* () {
|
415 |
|
416 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "5264459e-e5e0-4bd8-b118-0985e68a4ec5");
|
417 | handlers = handlers || [this.authHandler];
|
418 | return new workitemtrackingprocessdefinitionm.WorkItemTrackingProcessDefinitionsApi(serverUrl, handlers, this.options);
|
419 | });
|
420 | }
|
421 | getPipelinesApi(serverUrl, handlers) {
|
422 | return __awaiter(this, void 0, void 0, function* () {
|
423 |
|
424 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "5264459e-e5e0-4bd8-b118-0985e68a4ec5");
|
425 | handlers = handlers || [this.authHandler];
|
426 | return new pipelinesm.PipelinesApi(serverUrl, handlers, this.options);
|
427 | });
|
428 | }
|
429 | getCixApi(serverUrl, handlers) {
|
430 | return __awaiter(this, void 0, void 0, function* () {
|
431 |
|
432 | serverUrl = yield this._getResourceAreaUrl(serverUrl || this.serverUrl, "5264459e-e5e0-4bd8-b118-0985e68a4ec5");
|
433 | handlers = handlers || [this.authHandler];
|
434 | return new cixm.CixApi(serverUrl, handlers, this.options);
|
435 | });
|
436 | }
|
437 | _getResourceAreaUrl(serverUrl, resourceId) {
|
438 | return __awaiter(this, void 0, void 0, function* () {
|
439 | if (!resourceId) {
|
440 | return serverUrl;
|
441 | }
|
442 |
|
443 | const resourceAreas = yield this._getResourceAreas();
|
444 | if (resourceAreas === undefined) {
|
445 | throw new Error((`Failed to retrieve resource areas ' + 'from server: ${serverUrl}`));
|
446 | }
|
447 |
|
448 |
|
449 |
|
450 |
|
451 | if (!resourceAreas || resourceAreas.length === 0 || resourceAreas.count === 0) {
|
452 |
|
453 | return serverUrl;
|
454 | }
|
455 | for (var resourceArea of resourceAreas) {
|
456 | if (resourceArea.id.toLowerCase() === resourceId.toLowerCase()) {
|
457 | return resourceArea.locationUrl;
|
458 | }
|
459 | }
|
460 | throw new Error((`Could not find information for resource area ${resourceId} ' + 'from server: ${serverUrl}`));
|
461 | });
|
462 | }
|
463 | _getResourceAreas() {
|
464 | return __awaiter(this, void 0, void 0, function* () {
|
465 | if (!this._resourceAreas) {
|
466 | const locationClient = yield this.getLocationsApi();
|
467 | this._resourceAreas = yield locationClient.getResourceAreas();
|
468 | }
|
469 | return this._resourceAreas;
|
470 | });
|
471 | }
|
472 | _readTaskLibSecrets(lookupKey) {
|
473 | if (isBrowser) {
|
474 | throw new Error("Browsers can't securely keep secrets");
|
475 | }
|
476 |
|
477 |
|
478 | if (lookupKey && lookupKey.indexOf(':') > 0) {
|
479 | let lookupInfo = lookupKey.split(':', 2);
|
480 |
|
481 | let keyFile = new Buffer(lookupInfo[0], 'base64').toString('utf8');
|
482 | let encryptKey = new Buffer(fs.readFileSync(keyFile, 'utf8'), 'base64');
|
483 | let encryptedContent = new Buffer(lookupInfo[1], 'base64').toString('utf8');
|
484 | let decipher = crypto.createDecipher("aes-256-ctr", encryptKey);
|
485 | let decryptedContent = decipher.update(encryptedContent, 'hex', 'utf8');
|
486 | decryptedContent += decipher.final('utf8');
|
487 | return decryptedContent;
|
488 | }
|
489 | }
|
490 | }
|
491 | exports.WebApi = WebApi;
|