From e13fada6a7f98604cd65dd61e537a56cd813b959 Mon Sep 17 00:00:00 2001 From: sudip mukherjee Date: Tue, 15 Dec 2020 12:49:58 +0530 Subject: [PATCH 1/4] Issue #SB-21181 fix: Added offline token verification call brfore server gets started --- src/app.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index c9199aa9..d8b973d6 100644 --- a/src/app.js +++ b/src/app.js @@ -11,6 +11,8 @@ var configUtil = require('sb-config-util') var _ = require('lodash') var logger = require('sb_logger_util_v2') +const { loadTokenPublicKeys } = require('sb_api_interceptor') + const contentProvider = require('sb_content_provider_util') var contentMetaProvider = require('./contentMetaFilter') // TODO below configuration should to be refactored in a seperate file @@ -58,6 +60,8 @@ const isHealthCheckEnabled = process.env.sunbird_health_check_enable || 'true' const contentServiceLocalBaseUrl = process.env.sunbird_content_service_local_base_url ? process.env.sunbird_content_service_local_base_url : 'http://knowledge-mw-service:5000' const sunbirdGzipEnable = process.env.sunbird_gzip_enable || 'true' +const kidTokenPublicKeyBasePath = process.env.sunbird_kid_public_key_base_path + configUtil.setContentProviderApi(contentProviderApiConfig.API) configUtil.setConfig('CONTENT_SERVICE_BASE_URL', contentServiceBaseUrl) configUtil.setConfig('CONTENT_SERVICE_AUTH_TOKEN', contentServiceAuthToken) @@ -178,7 +182,8 @@ require('./routes/lockRoutes')(app) // this middleware route add after all the routes require('./middlewares/proxy.middleware')(app) -function startServer () { +async function startServer () { + await loadTokenPublicKeys(path.join(__dirname, kidTokenPublicKeyBasePath)); this.server = http.createServer(app).listen(port, function () { logger.info({ msg: `server running at PORT ${port}` }) logger.debug({ msg: `server started at ${new Date()}` }) From cdbeebfeea78bf2b38d7cc07477ee88021fe4e5d Mon Sep 17 00:00:00 2001 From: sudip mukherjee Date: Tue, 15 Dec 2020 12:56:31 +0530 Subject: [PATCH 2/4] Issue #SB-21181 fix: Added alternative directory for the local keys --- src/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app.js b/src/app.js index d8b973d6..db710037 100644 --- a/src/app.js +++ b/src/app.js @@ -60,9 +60,9 @@ const isHealthCheckEnabled = process.env.sunbird_health_check_enable || 'true' const contentServiceLocalBaseUrl = process.env.sunbird_content_service_local_base_url ? process.env.sunbird_content_service_local_base_url : 'http://knowledge-mw-service:5000' const sunbirdGzipEnable = process.env.sunbird_gzip_enable || 'true' -const kidTokenPublicKeyBasePath = process.env.sunbird_kid_public_key_base_path +const kidTokenPublicKeyBasePath = process.env.sunbird_kid_public_key_base_path || '/keys/' -configUtil.setContentProviderApi(contentProviderApiConfig.API) +configUtil.setContentProviderApi(contentProviderApiConfig.API) configUtil.setConfig('CONTENT_SERVICE_BASE_URL', contentServiceBaseUrl) configUtil.setConfig('CONTENT_SERVICE_AUTH_TOKEN', contentServiceAuthToken) configUtil.setConfig('ASSESSMENT_SERVICE_BASE_URL', assessmentServiceBaseUrl) From afb7b6cb08e423788fbdad5b5c121aebd5109b3c Mon Sep 17 00:00:00 2001 From: sudip mukherjee Date: Tue, 15 Dec 2020 18:54:56 +0530 Subject: [PATCH 3/4] Issue #SB-21181 fix: Commenting code for testing --- src/app.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app.js b/src/app.js index db710037..61461c4a 100644 --- a/src/app.js +++ b/src/app.js @@ -11,7 +11,8 @@ var configUtil = require('sb-config-util') var _ = require('lodash') var logger = require('sb_logger_util_v2') -const { loadTokenPublicKeys } = require('sb_api_interceptor') +// TODO: Commenting for testing purpose +// const { loadTokenPublicKeys } = require('sb_api_interceptor') const contentProvider = require('sb_content_provider_util') var contentMetaProvider = require('./contentMetaFilter') @@ -60,7 +61,8 @@ const isHealthCheckEnabled = process.env.sunbird_health_check_enable || 'true' const contentServiceLocalBaseUrl = process.env.sunbird_content_service_local_base_url ? process.env.sunbird_content_service_local_base_url : 'http://knowledge-mw-service:5000' const sunbirdGzipEnable = process.env.sunbird_gzip_enable || 'true' -const kidTokenPublicKeyBasePath = process.env.sunbird_kid_public_key_base_path || '/keys/' +// TODO: Commenting for testing purpose +// const kidTokenPublicKeyBasePath = process.env.sunbird_kid_public_key_base_path || '/keys/' configUtil.setContentProviderApi(contentProviderApiConfig.API) configUtil.setConfig('CONTENT_SERVICE_BASE_URL', contentServiceBaseUrl) @@ -182,8 +184,9 @@ require('./routes/lockRoutes')(app) // this middleware route add after all the routes require('./middlewares/proxy.middleware')(app) -async function startServer () { - await loadTokenPublicKeys(path.join(__dirname, kidTokenPublicKeyBasePath)); +function startServer () { + // TODO: Commenting for testing purpose + // await loadTokenPublicKeys(path.join(__dirname, kidTokenPublicKeyBasePath)); this.server = http.createServer(app).listen(port, function () { logger.info({ msg: `server running at PORT ${port}` }) logger.debug({ msg: `server started at ${new Date()}` }) From 7eadf2f939f3688a6a9d716aa94bd21868232972 Mon Sep 17 00:00:00 2001 From: sudip mukherjee Date: Tue, 15 Dec 2020 19:34:51 +0530 Subject: [PATCH 4/4] Issue #SB-21181 fix: Build breakage issue --- src/app.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/app.js b/src/app.js index 61461c4a..5be7f93c 100644 --- a/src/app.js +++ b/src/app.js @@ -11,8 +11,7 @@ var configUtil = require('sb-config-util') var _ = require('lodash') var logger = require('sb_logger_util_v2') -// TODO: Commenting for testing purpose -// const { loadTokenPublicKeys } = require('sb_api_interceptor') +var loadTokenPublicKeys = require('sb_api_interceptor') const contentProvider = require('sb_content_provider_util') var contentMetaProvider = require('./contentMetaFilter') @@ -61,8 +60,7 @@ const isHealthCheckEnabled = process.env.sunbird_health_check_enable || 'true' const contentServiceLocalBaseUrl = process.env.sunbird_content_service_local_base_url ? process.env.sunbird_content_service_local_base_url : 'http://knowledge-mw-service:5000' const sunbirdGzipEnable = process.env.sunbird_gzip_enable || 'true' -// TODO: Commenting for testing purpose -// const kidTokenPublicKeyBasePath = process.env.sunbird_kid_public_key_base_path || '/keys/' +const kidTokenPublicKeyBasePath = process.env.sunbird_kid_public_key_base_path || '/keys/' configUtil.setContentProviderApi(contentProviderApiConfig.API) configUtil.setConfig('CONTENT_SERVICE_BASE_URL', contentServiceBaseUrl) @@ -184,9 +182,9 @@ require('./routes/lockRoutes')(app) // this middleware route add after all the routes require('./middlewares/proxy.middleware')(app) -function startServer () { +async function startServer () { // TODO: Commenting for testing purpose - // await loadTokenPublicKeys(path.join(__dirname, kidTokenPublicKeyBasePath)); + await loadTokenPublicKeys(path.join(__dirname, kidTokenPublicKeyBasePath)); this.server = http.createServer(app).listen(port, function () { logger.info({ msg: `server running at PORT ${port}` }) logger.debug({ msg: `server started at ${new Date()}` })