Commit c9dc3c7b authored by loganathan.shanmugam@tarento.com's avatar loganathan.shanmugam@tarento.com Committed by kochhar
Browse files

Issue #SB-4854 fix: resolved conflicts

parent 54ef046a
master dependabot/npm_and_yarn/src/async-2.6.4 dependabot/npm_and_yarn/src/decode-uri-component-0.2.2 dependabot/npm_and_yarn/src/flat-and-mocha-5.0.2 dependabot/npm_and_yarn/src/handlebars-4.7.7 dependabot/npm_and_yarn/src/jsonwebtoken-9.0.0 dependabot/npm_and_yarn/src/lodash-4.17.21 dependabot/npm_and_yarn/src/minimist-and-project-sunbird/telemetry-sdk-and-handlebars-and-mkdirp-1.2.8 release-3.6.0 release-4.3.0 release-4.8.0 release-5.2.0 release-5.3.0 release-5.6.0 release-6.0.0 v1.13.3 v1.13 v1.12 v1.11.1 v1.11 v1.10.1 v1.10 v1.9 tmp-testPR tmp-sunbird-bootcamp tmp-rjshrjndrn-patch-1 tmp-revert-118-testPR tmp-revert-110-logs tmp-revert-99-revert-98-revert-97-revert-96-rjshrjndrn-patch-1 tmp-revert-98-revert-97-revert-96-rjshrjndrn-patch-1 tmp-revert-97-revert-96-rjshrjndrn-patch-1 tmp-revert-96-rjshrjndrn-patch-1 tmp-release-sonarcloud tmp-release-2.6.0 tmp-release-2.3.0 tmp-release-2.1.1 tmp-release-2.1.0 tmp-release-2.1.0_pluginSearch tmp-release-2.0.0 tmp-release-1.15 tmp-release-1.14.3 tmp-release-1.14 tmp-release-1.14-sp3 tmp-refactored-dev-deploy tmp-master tmp-loadtest tmp-load-testing tmp-jenkins-test tmp-jenkins-pipeline tmp-final-variable-refac tmp-dial-assemble-api tmp-content-update-read tmp-circleci release-5.6.0_RC1 release-5.2.0_RC1 release-4.8.5_RC1 release-4.8.0_RC2 release-4.8.0_RC1 release-4.3.0_RC1 release-3.8.0_RC3 release-3.8.0_RC2 release-3.8.0_RC1 release-3.7.0_RC2 release-3.7.0_RC1 release-3.6.0_RC1 release-3.2.0_RC2 release-3.2.0_RC1 release-3.1.0 release-3.1.0_RC2 release-3.1.0_RC1 release-3.0.1_RC1 release-3.0.0 release-3.0.0_RC1 release-2.10.0 release-2.10.0_RC2 release-2.10.0_RC1 release-2.9.0_RC3 release-2.9.0_RC2 release-2.9.0_RC1 release-2.8.0 release-2.8.0_RC4 release-2.8.0_RC3 release-2.8.0_RC2 release-2.8.0_RC1 release-2.7.0 release-2.7.0_RC2 release-2.7.0_RC1 release-2.6.0 release-2.6.0_RC4 release-2.6.0_RC3 release-2.6.0_RC2 release-2.6.0_RC1 release-2.3.0 release-2.3.0_RC2 release-2.3.0_RC1 release-2.1.1_RC1 release-2.1.0_RC2 release-2.1.0_RC1 release-2.0.0 release-2.0.0_RC5 release-2.0.0_RC4 release-2.0.0_RC3 release-2.0.0_RC2 release-2.0.0_RC1 release-1.15.0 release-1.15_RC7 release-1.15_RC6 release-1.15_RC5 release-1.15_RC4 release-1.15_RC3 release-1.15_RC2 release-1.15_RC1 release-1.14.0
No related merge requests found
Showing with 83 additions and 82 deletions
+83 -82
...@@ -34,36 +34,38 @@ function getRootOrgs (requestObj, cb) { ...@@ -34,36 +34,38 @@ function getRootOrgs (requestObj, cb) {
/** /**
* This function returns the config string based on condition for channel filters which * This function returns the config string based on condition for channel filters which
* contains the whitelisted channels * contains the whitelisted channels
* @returns Js object or array which contains the allowed whitelisted channels * @returns Promise which contains the allowed whitelisted channels
*/ */
function getFilterConfig (cb) { function getFilterConfig () {
LOG.info(utilsService.getLoggerData({}, 'INFO', return new Promise(function (resolve, reject) {
filename, 'getFilterConfig', 'environment info', process.env))
var allowedChannels = whiteListedChannelList ? whiteListedChannelList.split(',') : []
var blackListedChannels = blackListedChannelList ? blackListedChannelList.split(',') : []
if (_.includes(allowedChannels, '$.instance.all')) {
if (channelRefreshCronStr && !ischannelRefreshEnabled) {
setChannelRefreshTask()
ischannelRefreshEnabled = true
}
LOG.info(utilsService.getLoggerData({}, 'INFO', LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'getFilterConfig', 'allowed channels', allowedChannels)) filename, 'getFilterConfig', 'environment info', process.env))
getAllChannelsFromAPI(function (err, allChannels) { var allowedChannels = whiteListedChannelList ? whiteListedChannelList.split(',') : []
if (err) { var blackListedChannels = blackListedChannelList ? blackListedChannelList.split(',') : []
if (_.includes(allowedChannels, '$.instance.all')) {
if (channelRefreshCronStr && !ischannelRefreshEnabled) {
setChannelRefreshTask()
ischannelRefreshEnabled = true
}
LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'getFilterConfig', 'allowed channels', allowedChannels))
getAllChannelsFromAPI().then(allChannels => {
allowedChannels = _.pull(allowedChannels, '$.instance.all').concat(allChannels)
LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'getFilterConfig', 'all whitelisted channels count', allowedChannels.length))
resolve(getconfigStringFromChannels(allowedChannels, blackListedChannels))
}, (err) => {
console.log(err) console.log(err)
LOG.error(utilsService.getLoggerData({}, 'ERROR', LOG.error(utilsService.getLoggerData({}, 'ERROR',
filename, 'getFilterConfig', 'getAllChannelsFromAPI callback', err)) filename, 'getFilterConfig', 'getAllChannelsFromAPI callback', err))
} reject(err)
allowedChannels = _.pull(allowedChannels, '$.instance.all').concat(allChannels) })
} else {
LOG.info(utilsService.getLoggerData({}, 'INFO', LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'getFilterConfig', 'all whitelisted channels count', allowedChannels.length)) filename, 'getFilterConfig', 'allowed channels', allowedChannels))
cb(null, getconfigStringFromChannels(allowedChannels, blackListedChannels)) resolve(getconfigStringFromChannels(allowedChannels, blackListedChannels))
}) }
} else { })
LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'getFilterConfig', 'allowed channels', allowedChannels))
cb(null, getconfigStringFromChannels(allowedChannels, blackListedChannels))
}
} }
/** /**
...@@ -90,56 +92,59 @@ function getconfigStringFromChannels (allowedChannels, blackListedChannels) { ...@@ -90,56 +92,59 @@ function getconfigStringFromChannels (allowedChannels, blackListedChannels) {
* This method gets all channels through 'getRootOrgs' method response * This method gets all channels through 'getRootOrgs' method response
* data asynchronously and return callback * data asynchronously and return callback
* @param cb callback method which takes error and allchannels as param * @param cb callback method which takes error and allchannels as param
* @returns callback * @returns promise
*/ */
function getAllChannelsFromAPI (cb) { function getAllChannelsFromAPI () {
var limit = 200 return new Promise(function (resolve, reject) {
var offset = 0 var limit = 200
var allChannels = [] var offset = 0
var channelReqObj = { var allChannels = []
'request': { var channelReqObj = {
'filters': { 'isRootOrg': true }, 'request': {
'offset': offset, 'filters': { 'isRootOrg': true },
'limit': limit 'offset': offset,
} 'limit': limit
} }
LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'getAllChannelsFromAPI', 'fetching all channels req', channelReqObj))
getRootOrgs(channelReqObj, function (err, res) {
if (err) {
cb(err, null)
} }
const orgCount = res.result.response.count LOG.info(utilsService.getLoggerData({}, 'INFO',
allChannels = _.without(_.map(res.result.response.content, 'hashTagId'), null) filename, 'getAllChannelsFromAPI', 'fetching all channels req', channelReqObj))
// if more orgs are there get them iteratively using async getRootOrgs(channelReqObj, function (err, res) {
if (limit < orgCount) { if (err) {
var channelReqArr = [] reject(err)
while ((offset + limit) < orgCount) {
offset = offset + limit
channelReqObj.request.offset = offset
channelReqArr.push(_.cloneDeep(channelReqObj))
} }
async.map(channelReqArr, getRootOrgs, function (err, mappedResArr) { const orgCount = res.result.response.count
if (err) { allChannels = _.without(_.map(res.result.response.content, 'hashTagId'), null)
LOG.error(utilsService.getLoggerData({}, 'ERROR', // if more orgs are there get them iteratively using async
filename, 'getFilterConfig', 'getAllChannelsFromAPI callback', err)) if (limit < orgCount) {
var channelReqArr = []
while ((offset + limit) < orgCount) {
offset = offset + limit
channelReqObj.request.offset = offset
channelReqArr.push(_.cloneDeep(channelReqObj))
} }
/** extract hashTagId which represents the channelID from each response async.map(channelReqArr, getRootOrgs, function (err, mappedResArr) {
* of responseMap to generate the whitelisted channels array if (err) {
* */ LOG.error(utilsService.getLoggerData({}, 'ERROR',
_.forEach(mappedResArr, function (item) { filename, 'getFilterConfig', 'getAllChannelsFromAPI callback', err))
allChannels.push(_.map(item.result.response.content, 'hashTagId')) }
/**
* extract hashTagId which represents the channelID from each response
* of responseMap to generate the whitelisted channels array
* */
_.forEach(mappedResArr, function (item) {
allChannels.push(_.map(item.result.response.content, 'hashTagId'))
})
allChannels = _.without(_.flatten(allChannels), null)
LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'getAllChannelsFromAPI', 'all channels arr', allChannels))
resolve(allChannels)
}) })
allChannels = _.without(_.flatten(allChannels), null) } else {
LOG.info(utilsService.getLoggerData({}, 'INFO', LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'getAllChannelsFromAPI', 'all channels arr', allChannels)) filename, 'getAllChannelsFromAPI', 'all channels arr', allChannels))
cb(null, allChannels) resolve(allChannels)
}) }
} else { })
LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'getAllChannelsFromAPI', 'all channels arr', allChannels))
cb(null, allChannels)
}
}) })
} }
...@@ -148,14 +153,13 @@ function getAllChannelsFromAPI (cb) { ...@@ -148,14 +153,13 @@ function getAllChannelsFromAPI (cb) {
* @param configString configstring which contains the whitelisted channels * @param configString configstring which contains the whitelisted channels
*/ */
function updateConfig () { function updateConfig () {
getFilterConfig(function (err, configString) { getFilterConfig().then((configString) => {
if (err) {
LOG.error(utilsService.getLoggerData({}, 'ERROR',
filename, 'updateConfig', 'error', err))
}
LOG.info(utilsService.getLoggerData({}, 'INFO', LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'updateConfig', 'config string', configString)) filename, 'updateConfig', 'config string', configString))
configUtil.setConfig('CHANNEL_FILTER_QUERY_STRING', configString) configUtil.setConfig('CHANNEL_FILTER_QUERY_STRING', configString)
}, (err) => {
LOG.error(utilsService.getLoggerData({}, 'ERROR',
filename, 'updateConfig', 'error', err))
}) })
} }
......
var configHelper = require('../../helpers/configHelper') var configHelper = require('../../helpers/configHelper')
var configUtil = require('sb-config-util')
describe('configuration settings', function () { describe('configuration helper methods', function () {
it('should set the configuration ', function (done) { it('should set the configuration ', function () {
spyOn(configHelper, 'getFilterConfig')
configHelper.updateConfig() configHelper.updateConfig()
expect(configUtil.getConfig('CHANNEL_FILTER_QUERY_STRING')).toEqual([]) expect(configHelper.getFilterConfig).toHaveBeenCalled()
done()
}) })
}) })
describe('configuration string', function () { describe('configuration string', function () {
it('should return the config string with all channels', function (done) { it('should return the config string with all channels when $.instance.all is present', function (done) {
process.env.sunbird_content_service_whitelisted_channels = process.env.sunbird_content_service_whitelisted_channels =
'505c7c48ac6dc1edc9b08f21db5a571d,b00bc992ef25f1a9a8d63291e20efc8d,$.instance.all' '505c7c48ac6dc1edc9b08f21db5a571d,b00bc992ef25f1a9a8d63291e20efc8d,$.instance.all'
process.env.sunbird_content_service_blacklisted_channels = 'b00bc992ef25f1a9a8d63291e20efc8d' process.env.sunbird_content_service_blacklisted_channels = 'b00bc992ef25f1a9a8d63291e20efc8d'
configHelper.getFilterConfig(function (err, configStr) { configHelper.getFilterConfig().then(function (configStr) {
expect(err).toBeNull()
expect(configStr.length).toBeGreaterThanOrEqual(process.env.sunbird_content_service_whitelisted_channels.length) expect(configStr.length).toBeGreaterThanOrEqual(process.env.sunbird_content_service_whitelisted_channels.length)
done() done()
}) })
...@@ -23,8 +21,7 @@ describe('configuration string', function () { ...@@ -23,8 +21,7 @@ describe('configuration string', function () {
process.env.sunbird_content_service_whitelisted_channels = process.env.sunbird_content_service_whitelisted_channels =
'505c7c48ac6dc1edc9b08f21db5a571d,b00bc992ef25f1a9a8d63291e20efc8d' '505c7c48ac6dc1edc9b08f21db5a571d,b00bc992ef25f1a9a8d63291e20efc8d'
process.env.sunbird_content_service_blacklisted_channels = 'b00bc992ef25f1a9a8d63291e20efc8d' process.env.sunbird_content_service_blacklisted_channels = 'b00bc992ef25f1a9a8d63291e20efc8d'
configHelper.getFilterConfig(function (err, configStr) { configHelper.getFilterConfig().then(function (configStr) {
expect(err).toBeNull()
expect(configStr.length).toBeLessThanOrEqual(process.env.sunbird_content_service_whitelisted_channels.length) expect(configStr.length).toBeLessThanOrEqual(process.env.sunbird_content_service_whitelisted_channels.length)
done() done()
}) })
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment