Skip to content

Commit

Permalink
Remove underscore string (#305)
Browse files Browse the repository at this point in the history
* feat: remove underscore.string #198

* feat: simplify token path generation

* fix: readability

* fix: cache flush

* fix: bearer token
  • Loading branch information
David Longworth authored Dec 6, 2017
1 parent 307943e commit 1b7d9cf
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 44 deletions.
13 changes: 6 additions & 7 deletions dadi/lib/auth/bearer.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
44 changes: 10 additions & 34 deletions dadi/lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -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({
Expand All @@ -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'
}
})
}
Expand Down
2 changes: 0 additions & 2 deletions dadi/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,6 @@ Server.prototype.loadApi = function (options, reload, callback) {
message: 'Cache cleared successfully'
})
})
} else {
next()
}
})

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 1b7d9cf

Please sign in to comment.