backtrace-service
Advanced tools
Comparing version 3.0.8-alpha4 to 3.0.8-alpha6
@@ -52,2 +52,7 @@ import { NextFunction, Request, Response } from 'express'; | ||
/** | ||
* Retrieves the zeroconf from a coronerd | ||
* to store data for later client consumption. | ||
*/ | ||
private retrieveAndStoreCoronerdInfo; | ||
/** | ||
* @deprecated: these methods will be removed in new backtrace-service update | ||
@@ -54,0 +59,0 @@ * Check if authtoken is a valid token generated by coronerd |
@@ -81,3 +81,3 @@ "use strict"; | ||
/* | ||
* Stores coronerd values stored at the register step, | ||
* Stores coronerd values at the register step, | ||
* to be attached during authRequest step. | ||
@@ -137,7 +137,12 @@ */ | ||
_this.registeredCoronerds[normalizedUrl] = {}; | ||
console.log("Registered " + normalizedUrl); | ||
} | ||
// Aynchronously update registeredCoronerds with more data | ||
_this.retrieveAndStoreCoronerdInfo({ | ||
coronerdUrl: url, | ||
normalizedUrl: normalizedUrl, | ||
hmac: hmac, | ||
nonce: nonce | ||
}); | ||
_this.registeredCoronerds[normalizedUrl].service_to_coronerd_url = | ||
service_to_coronerd_url; | ||
console.log("Stored service_to_coronerd_url for " + normalizedUrl + ": " + _this.registeredCoronerds[normalizedUrl].service_to_coronerd_url); | ||
if (opts && opts.coronerdCallback) { | ||
@@ -167,3 +172,3 @@ opts.coronerdCallback(url); | ||
return function (request, response, next) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, url, token, serverConfiguration, authRequest, normalizedUrl, delimiter_1, requestingUniverse_1, universeKey, universeInfo, err_1; | ||
var _a, url, token, serverConfiguration, authRequest, normalizedUrl, requestingUniverse_1, universeInfo, err_1; | ||
return __generator(this, function (_b) { | ||
@@ -192,12 +197,5 @@ switch (_b.label) { | ||
} | ||
/** | ||
* Append service_to_coronerd_url if available. | ||
* It comes from coronerds that have successfully registered | ||
* with the service and have cached their info. | ||
*/ | ||
console.log("Request has url " + url); | ||
normalizedUrl = backtraceUniverseHelper_1.UniverseHelper.normalizeUrl(url); | ||
if (authRequest && this.registeredCoronerds[normalizedUrl] && | ||
this.registeredCoronerds[normalizedUrl].service_to_coronerd_url) { | ||
console.log("Normalized url " + normalizedUrl + " found in registeredCoronerds; service_to_coronerd_url: " + this.registeredCoronerds[normalizedUrl].service_to_coronerd_url); | ||
authRequest.service_to_coronerd_url = this.registeredCoronerds[normalizedUrl] | ||
@@ -207,14 +205,9 @@ .service_to_coronerd_url; | ||
else if (authRequest && authRequest.cfg) { | ||
delimiter_1 = authRequest.cfg.tenant_separator; | ||
requestingUniverse_1 = authRequest.cfg.universe.name; | ||
console.log("Searching for requested universe " + requestingUniverse_1 + " with delimiter=" + delimiter_1); | ||
universeKey = Object.keys(this.registeredCoronerds).find(function (urlKey) { | ||
var pieces = urlKey.split(delimiter_1); | ||
var universeMaybe = pieces.length > 0 ? pieces[0] : undefined; | ||
return universeMaybe === requestingUniverse_1; | ||
universeInfo = Object.values(this.registeredCoronerds) | ||
.find(function (info) { | ||
return info.universes && info.universes.includes(requestingUniverse_1); | ||
}); | ||
if (universeKey) { | ||
universeInfo = this.registeredCoronerds[universeKey]; | ||
if (universeInfo === null || universeInfo === void 0 ? void 0 : universeInfo.service_to_coronerd_url) { | ||
authRequest.service_to_coronerd_url = universeInfo.service_to_coronerd_url; | ||
console.log("Requested universe " + requestingUniverse_1 + " found in registeredCoronerds; service_to_coronerd_url: " + universeInfo.service_to_coronerd_url); | ||
} | ||
@@ -346,2 +339,48 @@ } | ||
/** | ||
* Retrieves the zeroconf from a coronerd | ||
* to store data for later client consumption. | ||
*/ | ||
IdentityManager.prototype.retrieveAndStoreCoronerdInfo = function (_a) { | ||
var coronerdUrl = _a.coronerdUrl, normalizedUrl = _a.normalizedUrl, hmac = _a.hmac, nonce = _a.nonce; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var prefix, protocol, requestUrl, result, cfg, universes, err_3; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (!coronerdUrl) { | ||
throw new Error('CoronerdUrl is undefined or empty string'); | ||
} | ||
prefix = coronerdUrl.endsWith('/') ? '' : '/'; | ||
protocol = coronerdUrl.startsWith('http') ? '' : 'http://'; | ||
requestUrl = "" + protocol + coronerdUrl + prefix + "api/login"; | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, axios_1.default.post(requestUrl, null, { | ||
httpsAgent: this.httpsAgent, | ||
headers: { | ||
'X-Service-Name': this.descr.name, | ||
'X-Service-Nonce': nonce, | ||
'X-Service-HMAC': hmac, | ||
}, | ||
})]; | ||
case 2: | ||
result = _b.sent(); | ||
cfg = result.status === 200 ? result.data : undefined; | ||
if (cfg === null || cfg === void 0 ? void 0 : cfg.universes) { | ||
universes = Object.keys(cfg.universes); | ||
this.registeredCoronerds[normalizedUrl].universes = universes; | ||
this.log('info', "Stored " + universes.length + " universes for " + coronerdUrl); | ||
} | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
err_3 = _b.sent(); | ||
this.log('error', "Cannot login to coronerd. Reason " + err_3.message); | ||
return [2 /*return*/, undefined]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* @deprecated: these methods will be removed in new backtrace-service update | ||
@@ -373,3 +412,3 @@ * Check if authtoken is a valid token generated by coronerd | ||
return __awaiter(this, void 0, void 0, function () { | ||
var prefix, protocol, requestUrl, result, err_3; | ||
var prefix, protocol, requestUrl, result, err_4; | ||
return __generator(this, function (_a) { | ||
@@ -396,3 +435,3 @@ switch (_a.label) { | ||
case 3: | ||
err_3 = _a.sent(); | ||
err_4 = _a.sent(); | ||
return [2 /*return*/, undefined]; | ||
@@ -399,0 +438,0 @@ case 4: return [2 /*return*/]; |
{ | ||
"name": "backtrace-service", | ||
"version": "3.0.8-alpha4", | ||
"version": "3.0.8-alpha6", | ||
"description": "Common tools for Backtrace Node services", | ||
@@ -5,0 +5,0 @@ "author": "Backtrace", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
165674
70
2293