Skip to content

Commit

Permalink
Fixed eslint issues; (#25)
Browse files Browse the repository at this point in the history
* Fixed eslint issues;
Added eslint as part of the ci/cd pipeline;
Removed not needed asynchronous call to `jwt.verify`.

* Bumped to 8.8.7

* Simplified `array.some` loop.

* Fixed linter run in CICD pipeline.

* Use `npm ci` instead of `npm install`;
dependency cache on `package-lock.json`.
  • Loading branch information
Vassilis Barzokas authored Jan 31, 2020
1 parent 774f165 commit 1e29133
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 26 deletions.
11 changes: 7 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ jobs:
# command: npm install github:interledgerjs/five-bells-ledger-api-tests
- run:
name: Update NPM install
command: cd src && npm install
command: cd src && npm ci
- run:
name: Delete build dependencies
command: apk del build-dependencies
- save_cache:
key: dependency-cache-{{ checksum "src/package.json" }}
key: dependency-cache-{{ checksum "src/package-lock.json" }}
paths:
- src/node_modules

Expand All @@ -184,7 +184,10 @@ jobs:
- checkout
- restore_cache:
keys:
- dependency-cache-{{ checksum "src/package.json" }}
- dependency-cache-{{ checksum "src/package-lock.json" }}
- run:
name: Execute linter
command: cd src && npm run lint
- run:
name: Create dir for test results
command: cd src && mkdir -p ./test/results
Expand Down Expand Up @@ -286,7 +289,7 @@ jobs:
- run:
<<: *defaults_license_scanner
- restore_cache:
key: dependency-cache-{{ checksum "src/package.json" }}
key: dependency-cache-{{ checksum "src/package-lock.json" }}
- run:
name: Prune non-production packages before running license-scanner
command: cd src && npm prune --production
Expand Down
4 changes: 2 additions & 2 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,8 @@ module.exports = class Database {
}

async getCurrentSettlementWindowId() {
const thisSettlementWindowId = await this.connection.query(currentSettlementWindowId);
return thisSettlementWindowId[0][0].settlementWindowId;
const thisSettlementWindowId = await this.connection.query(currentSettlementWindowId);
return thisSettlementWindowId[0][0].settlementWindowId;
}

async getCurrentSettlementWindowInfo(participantId) {
Expand Down
10 changes: 7 additions & 3 deletions src/handlers/settlement-windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ const handler = (router, routesContext) => {
});

router.get('/settlement-windows/:settlementWindowId', async (ctx, next) => {
const settlementWindow = await routesContext.db.getSettlementWindowInfo(ctx.params.settlementWindowId);
const settlementWindow = await routesContext
.db.getSettlementWindowInfo(ctx.params.settlementWindowId);

try {
const api = new Model({ endpoint: routesContext.config.settlementsEndpoint });
const settlement = await api.getSettlements({ settlementWindowId: ctx.params.settlementWindowId });
const settlement = await api.getSettlements({
settlementWindowId: ctx.params.settlementWindowId,
});
settlementWindow.settlement = (settlement.length === 1 ? settlement[0] : {});
} catch(error) {
} catch (error) {
routesContext.log(error);
settlementWindow.settlement = {};
}
Expand Down
19 changes: 4 additions & 15 deletions src/handlers/validate-transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const util = require('util');

const AzureLog = require('../lib/azureLog');

const dir = './secrets'
const dir = './secrets';
const pubKeys = fs.readdirSync(dir)
.filter(fname => !fs.statSync(`${dir}/${fname}`).isDirectory())
.map(fname => fs.readFileSync(`${dir}/${fname}`, 'utf-8'));
.filter(fname => !fs.statSync(`${dir}/${fname}`).isDirectory())
.map(fname => fs.readFileSync(`${dir}/${fname}`, 'utf-8'));

const handler = (router, routesContext) => {
router.get('/validate-transfer/:transferId', async (ctx, next) => {
Expand All @@ -30,18 +30,7 @@ const handler = (router, routesContext) => {
const token = `${check.protectedHeader}.${check.body}.${check.signature}`;

try {
for (const pubKey of pubKeys) {
// TODO: Investigate the linting error
// eslint-disable-next-line
JWT.verify(token, pubKey, (err) => {
if (err) {
routesContext.log(`Error verifying JWS token: ${err.stack || util.inspect(err)}`);
} else {
isValidTransfer = true;
}
});
if (isValidTransfer === true) break;
}
isValidTransfer = pubKeys.some(pubKey => JWT.verify(token, pubKey));
} catch (err) {
routesContext.log(`Error validating JWS token: ${err.stack || util.inspect(err)}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/finance-portal-backend-service",
"version": "8.8.6",
"version": "8.8.7",
"description": "The backend service to support the finance portal web ui. Essentially a thin wrapper around SQL queries.",
"license": "Apache-2.0",
"contributors": [
Expand Down

0 comments on commit 1e29133

Please sign in to comment.