From 1b7d9cfbbe7e4cfa0e9f4c14bd59d4b8624b4796 Mon Sep 17 00:00:00 2001 From: David Longworth Date: Wed, 6 Dec 2017 15:24:13 +0000 Subject: [PATCH] Remove underscore string (#305) * feat: remove underscore.string #198 * feat: simplify token path generation * fix: readability * fix: cache flush * fix: bearer token --- dadi/lib/auth/bearer.js | 13 ++++++------ dadi/lib/help.js | 44 ++++++++++------------------------------- dadi/lib/index.js | 2 -- package.json | 1 - 4 files changed, 16 insertions(+), 44 deletions(-) diff --git a/dadi/lib/auth/bearer.js b/dadi/lib/auth/bearer.js index fc9b7b54..9cc37ed9 100644 --- a/dadi/lib/auth/bearer.js +++ b/dadi/lib/auth/bearer.js @@ -1,6 +1,5 @@ var path = require('path') var config = require(path.join(__dirname, '/../../../config.js')) -var help = require(path.join(__dirname, '/../help')) var Passport = require('@dadi/passport') var BearerAuthStrategy = function (options) { @@ -30,12 +29,12 @@ BearerAuthStrategy.prototype.getToken = function (authStrategy, done) { walletOptions: { path: config.get('paths.tokenWallets') + - '/' + - help.generateTokenWalletFilename( - strategy.host, - strategy.port, - strategy.credentials.clientId - ) + '/token.' + + strategy.host + + strategy.port + + '.' + + strategy.credentials.clientId + + '.json' } }) .then(function (bearerToken) { diff --git a/dadi/lib/help.js b/dadi/lib/help.js index ae977827..6392904b 100755 --- a/dadi/lib/help.js +++ b/dadi/lib/help.js @@ -17,8 +17,6 @@ const config = require(path.join(__dirname, '/../../config.js')) const Passport = require('@dadi/passport') const errorView = require(path.join(__dirname, '/view/errors')) -var self = this - module.exports.getVersion = function () { if (config.get('debug')) return version } @@ -116,15 +114,13 @@ module.exports.validateRequestCredentials = function (req, res) { res.statusCode = 401 res.end() return false - } - - if (clientId !== authConfig.clientId || secret !== authConfig.secret) { + } else if (clientId !== authConfig.clientId || secret !== authConfig.secret) { res.statusCode = 401 res.end() return false + } else { + return true } - - return true } /** @@ -246,28 +242,8 @@ module.exports.clearCache = function (req, Cache, callback) { } /** - * Creates a URL/filename friendly version (slug) of any object that implements `toString()` - * @param {Object} input - object to be slugified + * Uses @dadi/passport to get a token to access a DADI API */ -module.exports.slugify = function (input) { - return require('underscore.string').slugify(input.toString()) -} - -/** - * Generates a filename for a token wallet file - * @param {String} host - Issuer host - * @param {Number} port - Issuer port - * @param {String} clientId - Client ID - */ -module.exports.generateTokenWalletFilename = function (host, port, clientId) { - return ( - 'token.' + - self.slugify(host + port) + - '.' + - self.slugify(clientId) + - '.json' - ) -} module.exports.getToken = function () { return Passport({ @@ -284,12 +260,12 @@ module.exports.getToken = function () { walletOptions: { path: config.get('paths.tokenWallets') + - '/' + - this.generateTokenWalletFilename( - config.get('api.host'), - config.get('api.port'), - config.get('auth.clientId') - ) + '/token.' + + config.get('api.host') + + config.get('api.port') + + '.' + + config.get('auth.clientId') + + '.json' } }) } diff --git a/dadi/lib/index.js b/dadi/lib/index.js index e58770a8..a19dde2f 100755 --- a/dadi/lib/index.js +++ b/dadi/lib/index.js @@ -407,8 +407,6 @@ Server.prototype.loadApi = function (options, reload, callback) { message: 'Cache cleared successfully' }) }) - } else { - next() } }) diff --git a/package.json b/package.json index 601f3028..bf4ecf27 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,6 @@ "snyk": "^1.47.0", "through": "~2.3.8", "toobusy-js": "~0.5.1", - "underscore.string": "~3.3.0", "wildcard": "~1.1.2" }, "devDependencies": {