Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Register
Sign in
Toggle navigation
Menu
UPSMF
knowledge-mw-service
Commits
c9dc3c7b
Commit
c9dc3c7b
authored
6 years ago
by
loganathan.shanmugam@tarento.com
Committed by
kochhar
6 years ago
Browse files
Options
Download
Patches
Plain Diff
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
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/helpers/configHelper.js
+76
-72
src/helpers/configHelper.js
src/test/helpers/configHelperSpec.js
+7
-10
src/test/helpers/configHelperSpec.js
with
83 additions
and
82 deletions
+83
-82
src/helpers/configHelper.js
+
76
−
72
View file @
c9dc3c7b
...
...
@@ -34,36 +34,38 @@ function getRootOrgs (requestObj, cb) {
/**
* This function returns the config string based on condition for channel filters which
* 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
)
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
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
}
function
getFilterConfig
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getFilterConfig
'
,
'
allowed channels
'
,
allowedChannels
))
getAllChannelsFromAPI
(
function
(
err
,
allChannels
)
{
if
(
err
)
{
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
'
,
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
)
LOG
.
error
(
utilsService
.
getLoggerData
({},
'
ERROR
'
,
filename
,
'
getFilterConfig
'
,
'
getAllChannelsFromAPI callback
'
,
err
))
}
allowedChannels
=
_
.
pull
(
allowedChannels
,
'
$.instance.all
'
).
concat
(
allChannels
)
reject
(
err
)
})
}
else
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getFilterConfig
'
,
'
all whitelisted channels count
'
,
allowedChannels
.
length
))
cb
(
null
,
getconfigStringFromChannels
(
allowedChannels
,
blackListedChannels
))
})
}
else
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getFilterConfig
'
,
'
allowed channels
'
,
allowedChannels
))
cb
(
null
,
getconfigStringFromChannels
(
allowedChannels
,
blackListedChannels
))
}
filename
,
'
getFilterConfig
'
,
'
allowed channels
'
,
allowedChannels
))
resolve
(
getconfigStringFromChannels
(
allowedChannels
,
blackListedChannels
))
}
})
}
/**
...
...
@@ -90,56 +92,59 @@ function getconfigStringFromChannels (allowedChannels, blackListedChannels) {
* This method gets all channels through 'getRootOrgs' method response
* data asynchronously and return callback
* @param cb callback method which takes error and allchannels as param
* @returns
callback
* @returns
promise
*/
function
getAllChannelsFromAPI
(
cb
)
{
var
limit
=
200
var
offset
=
0
var
allChannels
=
[]
var
channelReqObj
=
{
'
request
'
:
{
'
filters
'
:
{
'
isRootOrg
'
:
true
},
'
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
)
function
getAllChannelsFromAPI
()
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
limit
=
200
var
offset
=
0
var
allChannels
=
[]
var
channelReqObj
=
{
'
request
'
:
{
'
filters
'
:
{
'
isRootOrg
'
:
true
},
'
offset
'
:
offset
,
'
limit
'
:
limit
}
}
const
orgCount
=
res
.
result
.
response
.
count
allChannels
=
_
.
without
(
_
.
map
(
res
.
result
.
response
.
content
,
'
hashTagId
'
),
null
)
// if more orgs are there get them iteratively using async
if
(
limit
<
orgCount
)
{
var
channelReqArr
=
[]
while
((
offset
+
limit
)
<
orgCount
)
{
offset
=
offset
+
limit
channelReqObj
.
request
.
offset
=
offset
channelReqArr
.
push
(
_
.
cloneDeep
(
channelReqObj
))
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getAllChannelsFromAPI
'
,
'
fetching all channels req
'
,
channelReqObj
))
getRootOrgs
(
channelReqObj
,
function
(
err
,
res
)
{
if
(
err
)
{
reject
(
err
)
}
async
.
map
(
channelReqArr
,
getRootOrgs
,
function
(
err
,
mappedResArr
)
{
if
(
err
)
{
LOG
.
error
(
utilsService
.
getLoggerData
({},
'
ERROR
'
,
filename
,
'
getFilterConfig
'
,
'
getAllChannelsFromAPI callback
'
,
err
))
const
orgCount
=
res
.
result
.
response
.
count
allChannels
=
_
.
without
(
_
.
map
(
res
.
result
.
response
.
content
,
'
hashTagId
'
),
null
)
// if more orgs are there get them iteratively using async
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
* of responseMap to generate the whitelisted channels array
* */
_
.
forEach
(
mappedResArr
,
function
(
item
)
{
allChannels
.
push
(
_
.
map
(
item
.
result
.
response
.
content
,
'
hashTagId
'
))
async
.
map
(
channelReqArr
,
getRootOrgs
,
function
(
err
,
mappedResArr
)
{
if
(
err
)
{
LOG
.
error
(
utilsService
.
getLoggerData
({},
'
ERROR
'
,
filename
,
'
getFilterConfig
'
,
'
getAllChannelsFromAPI callback
'
,
err
))
}
/**
* 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
'
,
filename
,
'
getAllChannelsFromAPI
'
,
'
all channels arr
'
,
allChannels
))
cb
(
null
,
allChannels
)
})
}
else
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
getAllChannelsFromAPI
'
,
'
all channels arr
'
,
allChannels
))
cb
(
null
,
allChannels
)
}
resolve
(
allChannels
)
}
})
})
}
...
...
@@ -148,14 +153,13 @@ function getAllChannelsFromAPI (cb) {
* @param configString configstring which contains the whitelisted channels
*/
function
updateConfig
()
{
getFilterConfig
(
function
(
err
,
configString
)
{
if
(
err
)
{
LOG
.
error
(
utilsService
.
getLoggerData
({},
'
ERROR
'
,
filename
,
'
updateConfig
'
,
'
error
'
,
err
))
}
getFilterConfig
().
then
((
configString
)
=>
{
LOG
.
info
(
utilsService
.
getLoggerData
({},
'
INFO
'
,
filename
,
'
updateConfig
'
,
'
config string
'
,
configString
))
configUtil
.
setConfig
(
'
CHANNEL_FILTER_QUERY_STRING
'
,
configString
)
},
(
err
)
=>
{
LOG
.
error
(
utilsService
.
getLoggerData
({},
'
ERROR
'
,
filename
,
'
updateConfig
'
,
'
error
'
,
err
))
})
}
...
...
This diff is collapsed.
Click to expand it.
src/test/helpers/configHelperSpec.js
+
7
−
10
View file @
c9dc3c7b
var
configHelper
=
require
(
'
../../helpers/configHelper
'
)
var
configUtil
=
require
(
'
sb-config-util
'
)
describe
(
'
configuration settings
'
,
function
()
{
it
(
'
should set the configuration
'
,
function
(
done
)
{
describe
(
'
configuration helper methods
'
,
function
()
{
it
(
'
should set the configuration
'
,
function
()
{
spyOn
(
configHelper
,
'
getFilterConfig
'
)
configHelper
.
updateConfig
()
expect
(
configUtil
.
getConfig
(
'
CHANNEL_FILTER_QUERY_STRING
'
)).
toEqual
([])
done
()
expect
(
configHelper
.
getFilterConfig
).
toHaveBeenCalled
()
})
})
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
=
'
505c7c48ac6dc1edc9b08f21db5a571d,b00bc992ef25f1a9a8d63291e20efc8d,$.instance.all
'
process
.
env
.
sunbird_content_service_blacklisted_channels
=
'
b00bc992ef25f1a9a8d63291e20efc8d
'
configHelper
.
getFilterConfig
(
function
(
err
,
configStr
)
{
expect
(
err
).
toBeNull
()
configHelper
.
getFilterConfig
().
then
(
function
(
configStr
)
{
expect
(
configStr
.
length
).
toBeGreaterThanOrEqual
(
process
.
env
.
sunbird_content_service_whitelisted_channels
.
length
)
done
()
})
...
...
@@ -23,8 +21,7 @@ describe('configuration string', function () {
process
.
env
.
sunbird_content_service_whitelisted_channels
=
'
505c7c48ac6dc1edc9b08f21db5a571d,b00bc992ef25f1a9a8d63291e20efc8d
'
process
.
env
.
sunbird_content_service_blacklisted_channels
=
'
b00bc992ef25f1a9a8d63291e20efc8d
'
configHelper
.
getFilterConfig
(
function
(
err
,
configStr
)
{
expect
(
err
).
toBeNull
()
configHelper
.
getFilterConfig
().
then
(
function
(
configStr
)
{
expect
(
configStr
.
length
).
toBeLessThanOrEqual
(
process
.
env
.
sunbird_content_service_whitelisted_channels
.
length
)
done
()
})
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets