backtrace-service
Advanced tools
Comparing version 3.0.0-alpha.4 to 3.0.0-alpha.5
@@ -0,1 +1,2 @@ | ||
/// <reference types="qs" /> | ||
import { NextFunction, Request, Response } from 'express'; | ||
@@ -19,3 +20,3 @@ import { IServiceDescriptor } from '../model/serviceDescriptor'; | ||
}): void; | ||
serviceRequest(opts?: ICoronerRequestOption): ((request: Request<import("express-serve-static-core").ParamsDictionary>, response: Response, next: NextFunction) => void)[]; | ||
serviceRequest(opts?: ICoronerRequestOption): ((request: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs>, response: Response<any>, next: NextFunction) => void)[]; | ||
/** | ||
@@ -27,3 +28,3 @@ * Generate a middleware for Express.js, which authenticates a request given | ||
*/ | ||
authenticateRequest(): (request: Request<import("express-serve-static-core").ParamsDictionary>, response: Response, next: NextFunction) => Promise<void>; | ||
authenticateRequest(): (request: Request<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs>, response: Response<any>, next: NextFunction) => Promise<void>; | ||
/** | ||
@@ -30,0 +31,0 @@ * This assumes route has already passed authentication through authenticateRequest |
@@ -336,5 +336,3 @@ "use strict"; | ||
} | ||
return crypto_1.createHmac('sha256', secret) | ||
.update(nonce) | ||
.digest('hex'); | ||
return crypto_1.createHmac('sha256', secret).update(nonce).digest('hex'); | ||
}; | ||
@@ -341,0 +339,0 @@ IdentityManager.prototype.checkHmac = function (secret, nonce, proposedHMac) { |
@@ -43,3 +43,3 @@ import express from 'express'; | ||
*/ | ||
static setupMiddlewares(app: express.Express, prefix?: string): void; | ||
static setupMiddlewares(app: express.Express, prefix?: string, identityManager?: IdentityManager): void; | ||
/** | ||
@@ -49,3 +49,3 @@ * Setup express error middleware | ||
*/ | ||
static setupErrorMiddleware(app: express.Express): void; | ||
static setupErrorMiddleware(app: express.Express, identityManager?: IdentityManager): void; | ||
/** | ||
@@ -52,0 +52,0 @@ * Setup security middlewares |
@@ -50,3 +50,3 @@ "use strict"; | ||
hostUrl: (_h = (_g = this.configuration) === null || _g === void 0 ? void 0 : _g.metrics) === null || _h === void 0 ? void 0 : _h.hostUrl, | ||
disableExpressMetrics: (_k = (_j = this.configuration) === null || _j === void 0 ? void 0 : _j.metrics) === null || _k === void 0 ? void 0 : _k.disableExpressMetrics | ||
disableExpressMetrics: (_k = (_j = this.configuration) === null || _j === void 0 ? void 0 : _j.metrics) === null || _k === void 0 ? void 0 : _k.disableExpressMetrics, | ||
}, this.app, this._logger); | ||
@@ -93,3 +93,3 @@ this.prepareServiceLayer(); | ||
this.setupAuth(expressApp); | ||
this.setupMiddlewares(expressApp, service.apiPrefix); | ||
this.setupMiddlewares(expressApp, service.apiPrefix, service.identityManager); | ||
this.setupServiceLayer(expressApp, name, port, function (ip) { | ||
@@ -130,3 +130,3 @@ service.coronerdAddress.add(ip); | ||
*/ | ||
BacktraceService.setupMiddlewares = function (app, prefix) { | ||
BacktraceService.setupMiddlewares = function (app, prefix, identityManager) { | ||
app.use(body_parser_1.json()); | ||
@@ -137,2 +137,4 @@ app.use(body_parser_1.urlencoded({ extended: true })); | ||
app.get(prefix ? prefix : '/', function (_req, res) { | ||
var _a; | ||
(_a = identityManager) === null || _a === void 0 ? void 0 : _a.bypassProjectAccessCheck(res); | ||
res.type('xml'); | ||
@@ -146,3 +148,3 @@ res.status(200).send("<html></html>"); | ||
*/ | ||
BacktraceService.setupErrorMiddleware = function (app) { | ||
BacktraceService.setupErrorMiddleware = function (app, identityManager) { | ||
app.use(function (err, req, res, next) { | ||
@@ -179,2 +181,3 @@ // handle a situation when we already sent a response from onError method | ||
app.use(function (req, res, next) { | ||
var _a; | ||
// prevent overriding headers. | ||
@@ -184,2 +187,3 @@ if (res.headersSent) { | ||
} | ||
(_a = identityManager) === null || _a === void 0 ? void 0 : _a.bypassProjectAccessCheck(res); | ||
// response json might be required by front-end | ||
@@ -242,3 +246,3 @@ res.status(404).send({ | ||
} | ||
BacktraceService.setupErrorMiddleware(this.app); | ||
BacktraceService.setupErrorMiddleware(this.app, this.identityManager); | ||
__1.listenDescriptor(this._descriptor, this.app, this.configuration.ssl, function () { | ||
@@ -245,0 +249,0 @@ _this._logger.info("Application is Running. " + (_this._descriptor ? "Port: " + _this._descriptor.port : '')); |
@@ -9,3 +9,3 @@ import { NextFunction, Request, Response } from 'express'; | ||
*/ | ||
export declare function check(res: Express.Response, allKnownProjects: IProjectsExt[], scopedProjects: string[] | number[]): boolean; | ||
export declare function check(res: Express.Response, allKnownProjects: IProjectsExt[], scopedProjects: (string | number)[]): boolean; | ||
/** | ||
@@ -12,0 +12,0 @@ * Middleware for Backtrace Teams |
@@ -11,8 +11,2 @@ "use strict"; | ||
exports.setInvalid = setInvalid; | ||
function includes(arr, element) { | ||
return arr.includes(element); | ||
} | ||
function push(arr, element) { | ||
return arr.push(element); | ||
} | ||
/** | ||
@@ -25,3 +19,3 @@ * Checks if scopedProjects are in allKnownProjects and | ||
// Service owners can use original send method. | ||
if (scopedProjects.length === 0) { | ||
if (!scopedProjects || scopedProjects.length === 0) { | ||
setInvalid(res); | ||
@@ -32,5 +26,5 @@ return false; | ||
var projects = Array.from(new Set(scopedProjects)); | ||
var projectIdKey = "pid"; | ||
if ((typeof projects[0]) === "string") { | ||
projectIdKey = "name"; | ||
var projectIdKey = 'pid'; | ||
if (typeof projects[0] === 'string') { | ||
projectIdKey = 'name'; | ||
} | ||
@@ -40,4 +34,4 @@ // Loop over known projects and record ones that matched scoped list. | ||
allKnownProjects.forEach(function (projectExt) { | ||
if (includes(projects, projectExt[projectIdKey])) { | ||
push(seen, projectExt[projectIdKey]); | ||
if (projects.includes(projectExt[projectIdKey])) { | ||
seen.push(projectExt[projectIdKey]); | ||
} | ||
@@ -68,3 +62,3 @@ }); | ||
res.statusCode = 403; | ||
return originalSend.call(res, "project validation failed"); | ||
return originalSend.call(res, 'project validation failed'); | ||
}; | ||
@@ -71,0 +65,0 @@ next(); |
{ | ||
"name": "backtrace-service", | ||
"version": "3.0.0-alpha.4", | ||
"version": "3.0.0-alpha.5", | ||
"description": "Common tools for Backtrace Node services", | ||
@@ -51,2 +51,3 @@ "author": "Backtrace", | ||
"mkdirp": "^0.5.1", | ||
"tslint": "^6.1.2", | ||
"winston": "^3.2.1" | ||
@@ -64,8 +65,10 @@ }, | ||
"@types/node": "^11.13.5", | ||
"@types/supertest": "^2.0.10", | ||
"jest": "^24.7.1", | ||
"minimist": "^1.2.5", | ||
"nock": "^10.0.6", | ||
"supertest": "^4.0.2", | ||
"ts-jest": "^24.0.2", | ||
"typescript": "^3.7.3" | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
148738
11
16
64
2059
+ Addedtslint@^6.1.2
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuiltin-modules@1.1.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddiff@4.0.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedis-core-module@2.16.1(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedresolve@1.22.10(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtslint@6.1.3(transitive)
+ Addedtsutils@2.29.0(transitive)
+ Addedtypescript@5.7.3(transitive)
+ Addedwrappy@1.0.2(transitive)