Skip to content

Commit

Permalink
Merge pull request #124 from apigee/for302
Browse files Browse the repository at this point in the history
For302
  • Loading branch information
keyurkarnik authored Jul 2, 2019
2 parents 9563247 + 0cb7552 commit 401bb29
Show file tree
Hide file tree
Showing 41 changed files with 2,256 additions and 142 deletions.
16 changes: 13 additions & 3 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"esversion": 6,
"node": true
}
"asi" : true,
"esversion" : 6,
"node" : true,
"sub" : true,
"strict": true,
"white": true,
"unused": true,
"eqeqeq": true,
"maxparams": 10,
"maxdepth": 10,
"maxstatements": 25,
"maxcomplexity": 10
}
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
language: node_js
node_js:
- '6.14'
- '6.14'
- '8'
- '10'
- '12'
#jobs:
# include:
# - stage: test
# script: npm test
# -
# script: echo "this is done"
# if: TRAVIS_EVENT == 'cron'
16 changes: 9 additions & 7 deletions accesscontrol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var debug = require('debug')('plugin:accesscontrol');
var util = require("util");
const dns = require('dns');

module.exports.init = function (config, logger, stats) {
module.exports.init = function (config /*, logger, stats */) {

var allow;
var deny;
Expand All @@ -19,13 +19,13 @@ module.exports.init = function (config, logger, stats) {
function checkAccessControlInfo(sourceIP) {
if (config === null) debug('WARNING: insufficient information to run accesscontrol');
else if (config.allow === null && config.deny === null) debug('WARNING: insufficient information to run accesscontrol');
else if (config.allow != null) {
else if (config.allow !== null) {
debug ('allow list: ' + util.inspect(config.allow, 2, true));
if (scanIP(config.allow, sourceIP)) {
allow = true;
}
}
else if (config.deny != null) {
else if (config.deny !== null) {
debug ('deny list: ' + util.inspect(config.deny, 2, true));
if (scanIP(config.deny, sourceIP)) {
debug ('deny incoming message');
Expand All @@ -51,22 +51,24 @@ module.exports.init = function (config, logger, stats) {
* for each list in the allow and deny, make sure they are proper
* IPv4 addresses
*/
/* never used
function validateIPList(list) {
list.forEach(function(entry){
if (!checkIsIPV4(entry)) return false;
});
return true;
}
*/

function scanIP(list, sourceIP) {

var sourceOctets = sourceIP.split('.');
//no wildcard
for (var i=0; i < list.length; i++) {
//no wildcard
if (list[i].indexOf('*') == -1 && list[i] == sourceIP) {
if (list[i].indexOf('*') === -1 && list[i] === sourceIP) {
return true;
} else if (list[i].indexOf('*') != -1) { //contains wildcard
} else if (list[i].indexOf('*') !== -1) { //contains wildcard
var listOctets = list[i].split('.');
if (octetCompare(listOctets, sourceOctets)) return true;
}
Expand All @@ -83,9 +85,9 @@ module.exports.init = function (config, logger, stats) {
var compare = false;
for (var i=0; i < listOctets.length; i++) {
//debug('list ' + listOctets[i] + ' sourceOctets ' + sourceOctets[i]);
if (listOctets[i] != '*' && parseInt(listOctets[i]) == parseInt(sourceOctets[i])) {
if (listOctets[i] !== '*' && parseInt(listOctets[i]) === parseInt(sourceOctets[i])) {
compare = true;
} else if (listOctets[i] != '*' && parseInt(listOctets[i]) != parseInt(sourceOctets[i])) {
} else if (listOctets[i] !== '*' && parseInt(listOctets[i]) !== parseInt(sourceOctets[i])) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion accumulate-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* high load or with a large number of concurrent requests. So this plugin
* should only be used when it is known that request/response bodies are small.
*/
module.exports.init = function(config, logger, stats) {
module.exports.init = function(/*config, logger, stats*/) {
function accumulate(req, data) {
if (!req._chunks) req._chunks = [];
req._chunks.push(data);
Expand Down
2 changes: 1 addition & 1 deletion accumulate-response/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* high load or with a large number of concurrent requests. So this plugin
* should only be used when it is known that request/response bodies are small.
*/
module.exports.init = function(config, logger, stats) {
module.exports.init = function(/*config, logger, stats*/) {

function accumulate(res, data) {
if (!res._chunks) res._chunks = [];
Expand Down
8 changes: 4 additions & 4 deletions analytics/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
'use strict';

var debug = require('debug')('plugin:analytics');
//var debug = require('debug')('plugin:analytics');
var volos = require('volos-analytics-apigee');
module.exports.init = function(config, logger, stats) {
module.exports.init = function(config, logger /*, stats */) {

config.finalizeRecord = function finalizeRecord(req, res, record, cb) {
if (res.proxy) {
//detect healthcheck paths; if detected, add -health to the proxy name so that ax
//can distinguish between healthcheck calls and regular apis calls.
var proxyPath = req.url.split('?')[0];
if (config.proxyPath) {
if (config.proxyPath == proxyPath) {
if (config.proxyPath === proxyPath) {
record.apiproxy = res.proxy.name + "-health";
record.apiproxy_revision = res.proxy.revision;
}
} else if (config.relativePath) {
var relativePath = "/" + proxyPath.split('/')[2];
if (config.relativePath == relativePath) {
if (config.relativePath === relativePath) {
record.apiproxy = res.proxy.name + "-health";
record.apiproxy_revision = res.proxy.revision;
}
Expand Down
44 changes: 28 additions & 16 deletions apikeys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var _ = require("lodash");
const PRIVATE_JWT_VALUES = ["application_name", "client_id", "api_product_list", "iat", "exp"];
const SUPPORTED_DOUBLE_ASTERIK_PATTERN = "**";
const SUPPORTED_SINGLE_ASTERIK_PATTERN = "*";
const SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN = "/";
// const SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN = "/"; // ?? this has yet to be used in any module.

const acceptAlg = ["RS256"];

Expand Down Expand Up @@ -44,12 +44,13 @@ module.exports.init = function(config, logger, stats) {
//this flag will enable check against resource paths only
productOnly = config.hasOwnProperty("productOnly") ? config.productOnly : false;
//if local proxy is set, ignore proxies
if (process.env.EDGEMICRO_LOCAL_PROXY == "1") {
if (process.env.EDGEMICRO_LOCAL_PROXY === "1") {
productOnly = true;
}

//leaving rest of the code same to ensure backward compatibility
if (apiKey = req.headers[apiKeyHeaderName]) {
apiKey = req.headers[apiKeyHeaderName]
if ( apiKey ) {
if (!keepApiKey) {
delete(req.headers[apiKeyHeaderName]); // don't pass this header to target
}
Expand Down Expand Up @@ -177,7 +178,7 @@ module.exports.init = function(config, logger, stats) {
return {

onrequest: function(req, res, next) {
if (process.env.EDGEMICRO_LOCAL == "1") {
if (process.env.EDGEMICRO_LOCAL === "1") {
debug ("MG running in local mode. Skipping OAuth");
next();
} else {
Expand Down Expand Up @@ -268,7 +269,7 @@ const checkIfAuthorized = module.exports.checkIfAuthorized = function checkIfAut
} else {
// if(apiproxy.includes(SUPPORTED_SINGLE_FORWARD_SLASH_PATTERN)){
// }
matchesProxyRules = urlPath == apiproxy;
matchesProxyRules = urlPath === apiproxy;

}
}
Expand All @@ -291,34 +292,45 @@ function getPEM(decodedToken, keys) {
var i = 0;
debug("jwk kid " + decodedToken.headerObj.kid);
for (; i < keys.length; i++) {
if (keys.kid == decodedToken.headerObj.kid) {
if (keys.kid === decodedToken.headerObj.kid) {
break;
}
}
var publickey = rs.KEYUTIL.getKey(keys.keys[i]);
return rs.KEYUTIL.getPEM(publickey);
}

function sendError(req, res, next, logger, stats, code, message) {

switch (code) {
case "invalid_request":
function setResponseCode(res,code) {
switch ( code ) {
case 'invalid_request': {
res.statusCode = 400;
break;
case "access_denied":
}
case 'access_denied':{
res.statusCode = 403;
break;
case "invalid_token":
case "missing_authorization":
case "invalid_request":
}
case 'invalid_token':
case 'missing_authorization':
case 'invalid_authorization': {
res.statusCode = 401;
break;
case "gateway_timeout":
}
case 'gateway_timeout': {
res.statusCode = 504;
break;
default:
}
default: {
res.statusCode = 500;
break;
}
}
}


function sendError(req, res, next, logger, stats, code, message) {

setResponseCode(res,code)

var response = {
error: code,
Expand Down
4 changes: 2 additions & 2 deletions cors/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
var debug = require('debug')('plugin:cors');

module.exports.init = function(config, logger, stats) {
module.exports.init = function(config /*, logger, stats */) {

var methods = config['cors-methods'] || 'GET, PUT, POST, DELETE, PATCH, OPTIONS';
var maxAge = config['cors-max-age'] || '3628800';
Expand All @@ -16,7 +16,7 @@ module.exports.init = function(config, logger, stats) {
if (origin) accessControlAllowOriginValue = origin;
else accessControlAllowOriginValue = req.headers['origin'];

if(req.method == 'OPTIONS') {
if(req.method === 'OPTIONS') {
res.setHeader('Access-Control-Allow-Origin', accessControlAllowOriginValue);
res.setHeader('Access-Control-Allow-Methods', methods);
res.setHeader('Access-Control-Allow-Max-Age', maxAge);
Expand Down
14 changes: 7 additions & 7 deletions eurekaclient/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
*/

var debug = require('debug')('plugin:eurekeclient');
var util = require('util');
//var util = require('util');
var os = require('os');

const port = process.env.PORT || 8000;
const Eureka = require('eureka-js-client').Eureka;

module.exports.init = function (config, logger, stats) {
module.exports.init = function (config /*, logger, stats */) {

const lookup = config.servicemap;
//const lookup = config.servicemap;

config.instance.hostName = os.hostname();
debug('local hostName: ' + config.instance.hostName);
Expand Down Expand Up @@ -49,7 +49,7 @@ module.exports.init = function (config, logger, stats) {

function getAppName(url) {
for (var index in config.lookup) {
if (url.includes(config.lookup[index].uri) || url == config.lookup[index].uri) {
if (url.includes(config.lookup[index].uri) || url === config.lookup[index].uri) {
return {
app: config.lookup[index].app,
secure: config.lookup[index].secure
Expand All @@ -63,8 +63,8 @@ module.exports.init = function (config, logger, stats) {
var instances = client.getInstancesByAppId(app);

for (var index in instances) {
if (instances[index].status == "UP") {
return (secure == true) ? {"hostName": instances[index].hostName, "port": instances[index].securePort["$"]} : {"hostName": instances[index].hostName, "port":instances[index].port["$"]};
if (instances[index].status === "UP") {
return (secure === true) ? {"hostName": instances[index].hostName, "port": instances[index].securePort["$"]} : {"hostName": instances[index].hostName, "port":instances[index].port["$"]};
}
}
return "";
Expand All @@ -87,7 +87,7 @@ module.exports.init = function (config, logger, stats) {
req.targetSecure = false;
}
} else {
console.warn("Target enpoint from Eureka not found");
console.warn("Target endpoint from Eureka not found");
}
next();
}
Expand Down
Loading

0 comments on commit 401bb29

Please sign in to comment.