Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DonMartin76 committed Feb 6, 2019
1 parent 2207a9d commit 25da133
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
24 changes: 23 additions & 1 deletion routes/systemhealth.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ systemhealth.checkHealth = function (app) {

// - Listeners
// - Portal
// - Kong
// - Kong
// - Auth Server

// Use a correlation ID when calling
const correlationId = uuid.v4();
Expand All @@ -66,6 +67,25 @@ systemhealth.checkHealth = function (app) {
request.get(req, function (err, apiResult, apiBody) {
callback(null, makeHealthEntry('kong', kongUri, err, apiResult, apiBody));
});
},
authPing: function (callback) {
try {
const authServer = utils.loadAuthServer('default');
if (authServer.exists && authServer.data && authServer.data.config && authServer.data.config.api && authServer.data.config.api.upstream_url) {
const authUri = utils.concatUrl(authServer.data.config.api.upstream_url, 'ping');
const req = { url: authUri, headers: { 'Correlation-Id': correlationId } };
request.get(req, function (err, apiResult, apiBody) {
callback(null, makeHealthEntry('auth', authUri, err, apiResult, apiBody));
});
} else {
error('Cannot query Auth Server for status - in default.json, config.api.upstream_url is not present.');
return callback(null, null);
}
} catch (err) {
error(err);
// Don't bother
return callback(null, null);
}
}
}, function (err, results) {
if (err) {
Expand All @@ -88,6 +108,8 @@ systemhealth.checkHealth = function (app) {

h.push(results.portalPing);
h.push(results.kongPing);
if (results.authPing)
h.push(results.authPing);

// Check our webhook listeners
// var listeners = webhooks.loadListeners(app);
Expand Down
11 changes: 11 additions & 0 deletions routes/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,17 @@ utils.getOrderBy = (req) => {
return orderBy;
};

utils.concatUrl = (a, b) => {
if (a.endsWith('/') && b.startsWith('/'))
return a + b.substring(1);
if (a.endsWith('/') && !b.startsWith('/'))
return a + b;
// !a.endsWith('/')
if (b.startsWith('/'))
return a + b;
return a + '/' + b;
}

// Middleware to verify a scope
utils.verifyScope = (requiredScope) => {
return function (req, res, next) {
Expand Down

0 comments on commit 25da133

Please sign in to comment.