Skip to content

Commit

Permalink
Merge pull request #129 from srikanthbhadragiri/log-improvements-phase-2
Browse files Browse the repository at this point in the history
Convert console statements to logger.consoleLog statements.
  • Loading branch information
indraneeldey authored Jul 31, 2019
2 parents b05b4a1 + 232bc36 commit 393b56c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 24 deletions.
4 changes: 2 additions & 2 deletions apikeys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ module.exports.init = function(config, logger, stats) {
}
if (response.statusCode !== 200) {
if (config.allowInvalidAuthorization) {
console.warn("ignoring err");
logger.consoleLog('warn', "ignoring err"); // TODO: convert to logger.eventLog
return next();
} else {
debug("verify apikey access_denied");
Expand Down Expand Up @@ -164,7 +164,7 @@ module.exports.init = function(config, logger, stats) {
}
if (!isValid) {
if (config.allowInvalidAuthorization) {
console.warn("ignoring err");
logger.consoleLog('warn', "ignoring err"); // TODO: convert to logger.eventLog
return next();
} else {
debug("invalid token");
Expand Down
6 changes: 3 additions & 3 deletions eurekaclient/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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;

Expand All @@ -28,7 +28,7 @@ module.exports.init = function (config /*, logger, stats */) {
try {
client.start();
} catch (err) {
console.error(err);
logger.consoleLog('error', err); // TODO: convert to logger.eventLog
client.stop();
}

Expand Down Expand Up @@ -87,7 +87,7 @@ module.exports.init = function (config /*, logger, stats */) {
req.targetSecure = false;
}
} else {
console.warn("Target endpoint from Eureka not found");
logger.consoleLog('warn', "Target endpoint from Eureka not found"); // TODO: convert to logger.eventLog
}
next();
}
Expand Down
2 changes: 1 addition & 1 deletion extauth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports.init = function(config, logger, stats) {
}, function(err, response, body) {
if (err) {
debug('publickey gateway timeout');
console.log(err);
logger.consoleLog('log', err); // TODO: convert to logger.eventLog
} else {
debug("loaded public keys");
if (keyType === 'jwk') {
Expand Down
18 changes: 12 additions & 6 deletions lib/basicAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,16 @@ class BasicAuthorizerPlugin {
isValid = JWS.verifyJWT(oauthtoken, this.config.public_key, this.acceptField);
}
} catch (error) {
console.warn('error parsing jwt: ' + oauthtoken);
// TODO: convert to logger.eventLog
this.logger.consoleLog('warn', 'error parsing jwt: ' + oauthtoken);
}
return(isValid)
}

tryValidationBipass(req, res) {
if ( this.allowInvalidAuthorization ) {
console.warn('ignoring err in verify no valid JWT');
// TODO: convert to logger.eventLog
this.logger.consoleLog('warn', 'ignoring err in verify no valid JWT');
return this.next();
} else {
return this.invalidToken(req, res);
Expand Down Expand Up @@ -286,7 +288,8 @@ class BasicAuthorizerPlugin {
decodedToken = JWS.parse(oauthtoken);
} catch (err) {
if ( this.allowInvalidAuthorization ) {
console.warn('ignoring err');
// TODO: convert to logger.eventLog
this.logger.consoleLog('warn', 'ignoring err');
return next();
} else {
return this.invalidToken(req, res);
Expand Down Expand Up @@ -496,20 +499,23 @@ class BasicAuthorizerPlugin {
try {
res.setHeader('content-type', 'application/json');
} catch (e) {
console.warn("oath response object lacks setHeader")
// TODO: convert to logger.eventLog
logger.consoleLog('warn', "oath response object lacks setHeader");
}
}

try {
res.end(JSON.stringify(response));
} catch (e) {
console.warn("oath response object is not supplied by runtime")
// TODO: convert to logger.eventLog
logger.consoleLog('warn', "oath response object is not supplied by runtime");
}

try {
stats.incrementStatusCount(res.statusCode);
} catch (e) {
console.warn("oath stats object is not supplied by runtime")
// TODO: convert to logger.eventLog
logger.consoleLog('warn',"oath stats object is not supplied by runtime");
}

next(code, message);
Expand Down
17 changes: 10 additions & 7 deletions oauth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,12 @@ module.exports.init = function(config, logger, stats) {
isValid = JWS.verifyJWT(oauthtoken, config.public_key, acceptField);
}
} catch (error) {
console.warn('error parsing jwt: ' + oauthtoken);
logger.consoleLog('warn', 'error parsing jwt: ' + oauthtoken);
}
}
if (!isValid) {
if (config.allowInvalidAuthorization) {
console.warn('ignoring err');
logger.consoleLog('warn', 'ignoring err')
return next();
} else {
debug('invalid token');
Expand Down Expand Up @@ -272,11 +272,11 @@ module.exports.init = function(config, logger, stats) {
isValid = JWS.verifyJWT(oauthtoken, config.public_key, acceptField);
}
} catch (error) {
console.warn('error parsing jwt: ' + oauthtoken);
logger.consoleLog('warn', 'error parsing jwt: ' + oauthtoken);
}
if (!isValid) {
if (config.allowInvalidAuthorization) {
console.warn('ignoring err');
logger.consoleLog('warn', 'ignoring err');
return next();
} else {
debug('invalid token');
Expand Down Expand Up @@ -493,20 +493,23 @@ function sendError(req, res, next, logger, stats, code, message) {
try {
res.setHeader('content-type', 'application/json');
} catch (e) {
console.warn("oath response object lacks setHeader")
// TODO: convert to logger.eventLog
logger.consoleLog('warn', "oath response object lacks setHeader");
}
}

try {
res.end(JSON.stringify(response));
} catch (e) {
console.warn("oath response object is not supplied by runtime")
// TODO: convert to logger.eventLog
logger.consoleLog('warn', "oath response object is not supplied by runtime");
}

try {
stats.incrementStatusCount(res.statusCode);
} catch (e) {
console.warn("oath stats object is not supplied by runtime")
// TODO: convert to logger.eventLog
logger.consoleLog('warn', "oath stats object is not supplied by runtime");
}

next(code, message);
Expand Down
12 changes: 7 additions & 5 deletions oauthv2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports.init = function(config, logger, stats) {
decodedToken = JWS.parse(oauthtoken);
} catch (err) {
if (config.allowInvalidAuthorization) {
console.warn('ignoring err');
logger.consoleLog('warn', 'ignoring err');
return next();
} else {
debug('invalid token');
Expand Down Expand Up @@ -119,12 +119,12 @@ module.exports.init = function(config, logger, stats) {
isValid = JWS.verifyJWT(oauthtoken, config.public_key, acceptField);
}
} catch (error) {
console.warn('error parsing jwt: ' + oauthtoken);
logger.consoleLog('warn', 'error parsing jwt: ' + oauthtoken);
}
}
if (!isValid) {
if (config.allowInvalidAuthorization) {
console.warn('ignoring err');
logger.consoleLog('warn', 'ignoring err');
return next();
} else {
debug('invalid token');
Expand Down Expand Up @@ -154,11 +154,13 @@ module.exports.init = function(config, logger, stats) {
isValid = JWS.verifyJWT(oauthtoken, config.public_key, acceptField);
}
} catch (error) {
console.warn('error parsing jwt: ' + oauthtoken);
// TODO: convert to logger.eventLog
logger.consoleLog('warn', 'error parsing jwt: ' + oauthtoken);
}
if (!isValid) {
if (config.allowInvalidAuthorization) {
console.warn('ignoring err');
// TODO: convert to logger.eventLog
logger.consoleLog('warn', 'ignoring err');
return next();
} else {
debug('invalid token');
Expand Down

0 comments on commit 393b56c

Please sign in to comment.