Skip to content

Commit

Permalink
Write and read jwk_public_keys from redis
Browse files Browse the repository at this point in the history
  • Loading branch information
imesh committed Aug 27, 2020
1 parent 4c6c6a1 commit d311a89
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,22 +402,32 @@ const processLoad = (config, keys, callback, useSynchronizer, redisClient) => {
}
},
function(cb) {
var opts = _.clone(options);
opts['url'] = config.edge_config.jwk_public_keys || null;
opts = enableTLS(config, opts);
request.get(opts, function(err, response, body) {
if (response && response.statusCode === 200) {
_loadStatus('jwk_public_keys', opts['url'],
err, response, body, cb);
} else {
response = {};
response.statusCode = 200;
body = null;
err = null;
_loadStatus('jwk_public_keys', opts['url'],
null, response, body, cb);
}
});
if ( useSynchronizer || !config.edge_config.redisBasedConfigCache ) {
var opts = _.clone(options);
opts['url'] = config.edge_config.jwk_public_keys;
opts = enableTLS(config, opts);
request.get(opts, function(err, response, body) {
if(useSynchronizer && !err && response && response.statusCode === 200){
saveConfigToRedis(redisClient, globalOptions, config.edge_config.jwk_public_keys, body, 'jwk_public_keys', (err)=>{
if ( err ) {
writeConsoleLog('error',{component: CONSOLE_LOG_TAG_COMP}, 'error saving data to redis from %s', config.edge_config.jwk_public_keys, err);
return;
}
writeConsoleLog('info',{component: CONSOLE_LOG_TAG_COMP}, 'Saved data to redis from %s', config.edge_config.jwk_public_keys);
});
}
if ( !config.edge_config.redisBasedConfigCache) {
_loadStatus('jwk_public_keys', config.edge_config.jwk_public_keys, err, response, body, cb);
}
});
}

if ( config.edge_config.redisBasedConfigCache === true ) { //retrieve from redis db
getConfigFromRedis(redisClient, globalOptions, config.edge_config.jwk_public_keys, 'jwk_public_keys', function(err, body){
const response = err ? null : { statusCode: 200, statusMessage: 'Downloaded from redis' };
_loadStatus('jwk_public_keys', config.edgemicro.redisHost, err, response, body, cb);
});
}
}
], function(err, results) {
debug('error %s, proxies %s, products %s, jwt_public_key %s', err,
Expand Down

0 comments on commit d311a89

Please sign in to comment.