Skip to content

Commit

Permalink
fetched latest from upstream release-4.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
karthik-tarento committed Dec 20, 2021
2 parents dbf19f1 + c8c92fd commit abf3042
Show file tree
Hide file tree
Showing 19 changed files with 511 additions and 11,577 deletions.
9 changes: 6 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1
jobs:
build:
docker:
- image: circleci/node:9.0.0
- image: circleci/node:10.0.0
working_directory: ~/project/src
steps:
- checkout
Expand All @@ -13,11 +13,14 @@ jobs:
- run: cd opt/content/ && npm install --unsafe-perm
- save_cache:
key: dependency-cache-{{ checksum "src/package.json" }}
paths: ./node_modules
paths: ./node_modules
- run: cd opt && zip -r content.zip content
- store_artifacts:
path: opt/content.zip
destination: content.zip
destination: content.zip
- run:
name: Run test cases
command: 'cd src && npm install --unsafe-perm && npm run coverage'
- run:
name: Install sonar scanner
command: 'sudo npm install -g sonarqube-scanner'
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/src/node_modules/
/src/npm-debug.log
/src/coverage/
/src/**/*.log
/src/**/*.log
src/.env
/src/.nyc_output
18 changes: 4 additions & 14 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,17 @@ node('build-slave') {
else
println(ANSI_BOLD + ANSI_GREEN + "Found environment variable named hub_org with value as: " + hub_org + ANSI_NORMAL)
cleanWs()
if (params.github_release_tag == "") {
checkout scm
commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
branch_name = sh(script: 'git name-rev --name-only HEAD | rev | cut -d "/" -f1| rev', returnStdout: true).trim()
build_tag = branch_name + "_" + commit_hash + "_" + env.BUILD_NUMBER
println(ANSI_BOLD + ANSI_YELLOW + "github_release_tag not specified, using the latest commit hash: " + commit_hash + ANSI_NORMAL)
}
else {
def scmVars = checkout scm
checkout scm: [$class: 'GitSCM', branches: [[name: "refs/tags/$params.github_release_tag"]], userRemoteConfigs: [[url: scmVars.GIT_URL]]]
build_tag = params.github_release_tag + "_" + env.BUILD_NUMBER
println(ANSI_BOLD + ANSI_YELLOW + "github_release_tag specified, building from github_release_tag: " + params.github_release_tag + ANSI_NORMAL)
}
checkout scm
commit_hash = sh(script: 'git rev-parse --short HEAD', returnStdout: true).trim()
build_tag = sh(script: "echo " + params.github_release_tag.split('/')[-1] + "_" + commit_hash + "_" + env.BUILD_NUMBER, returnStdout: true).trim()
echo "build_tag: " + build_tag
}

stage('Build') {
env.NODE_ENV = "build"
print "Environment will be : ${env.NODE_ENV}"
sh('git submodule update --init')
sh('git submodule update --init --recursive --remote')
// sh('git submodule update --init --recursive --remote')
sh('chmod 777 build.sh')
sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}")
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The code in this repository is licensed under MIT unless otherwise noted. Please

## Setup Instructions
* Clone the project.eg .(git clone --recursive url)
* Run "git submodule foreach git pull origin master" to pull the latest sunbird-js-utils sub module
* Run "git submodule update --init --recursive" to pull the latest sunbird-js-utils sub module
* Change to src folder
* Run `npm install`
* Run `node app.js`
Expand Down
2 changes: 1 addition & 1 deletion auto_build_deploy
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ node('build-slave') {
env.NODE_ENV = "build"
print "Environment will be : ${env.NODE_ENV}"
sh('git submodule update --init')
sh('git submodule update --init --recursive --remote')
// sh('git submodule update --init --recursive --remote')
sh('chmod 777 build.sh')
sh("./build.sh ${build_tag} ${env.NODE_NAME} ${hub_org}")

Expand Down
2 changes: 2 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ sonar.projectName=sunbird-content-service
sonar.language=js
sonar.projectKey=project-sunbird_sunbird-content-service
sonar.host.url=https://sonarcloud.io
sonar.exclusions=src/test/**
sonar.javascript.lcov.reportPaths=src/coverage/lcov.info
sonar.organization=project-sunbird
sonar.projectVersion=1.0
54 changes: 39 additions & 15 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var fs = require('fs')
var configUtil = require('sb-config-util')
var _ = require('lodash')
var logger = require('sb_logger_util_v2')
var ApiInterceptor = require('sb_api_interceptor')

const contentProvider = require('sb_content_provider_util')
var contentMetaProvider = require('./contentMetaFilter')
Expand Down Expand Up @@ -57,6 +58,7 @@ const lockExpiryTime = process.env.sunbird_lock_expiry_time || 3600
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/'

configUtil.setContentProviderApi(contentProviderApiConfig.API)
configUtil.setConfig('CONTENT_SERVICE_BASE_URL', contentServiceBaseUrl)
Expand Down Expand Up @@ -175,10 +177,34 @@ require('./routes/externalUrlMetaRoute')(app)
require('./routes/pluginsRoutes')(app)
require('./routes/collaborationRoutes')(app)
require('./routes/lockRoutes')(app)
require('./routes/questionRoutes')(app)
// this middleware route add after all the routes
require('./middlewares/proxy.middleware')(app)

function startServer () {
async function startServer (cb) {
var keyCloakConfig = {
'authServerUrl': process.env.sunbird_keycloak_auth_server_url ? process.env.sunbird_keycloak_auth_server_url : 'https://staging.open-sunbird.org/auth',
'realm': process.env.sunbird_keycloak_realm ? process.env.sunbird_keycloak_realm : 'sunbird',
'clientId': process.env.sunbird_keycloak_client_id ? process.env.sunbird_keycloak_client_id : 'portal',
'public': process.env.sunbird_keycloak_public ? process.env.sunbird_keycloak_public : true,
'realmPublicKey': process.env.sunbird_keycloak_public_key
}
logger.info({ msg: 'keyCloakConfig', keyCloakConfig })

var cacheConfig = {
store: process.env.sunbird_cache_store ? process.env.sunbird_cache_store : 'memory',
ttl: process.env.sunbird_cache_ttl ? process.env.sunbird_cache_ttl : 1800
}

var apiInterceptor = new ApiInterceptor(keyCloakConfig, cacheConfig)

await apiInterceptor.loadTokenPublicKeys(path.join(__dirname, kidTokenPublicKeyBasePath))

if (this.server) {
cb && cb()
return
}

this.server = http.createServer(app).listen(port, function () {
logger.info({ msg: `server running at PORT ${port}` })
logger.debug({ msg: `server started at ${new Date()}` })
Expand All @@ -194,6 +220,7 @@ function startServer () {
logger.fatal({ msg: 'error in getting meta filters', err })
process.exit(1)
})
cb && cb()
})
this.server.keepAliveTimeout = 30000 * 5
}
Expand All @@ -214,12 +241,6 @@ if (defaultChannel) {
startServer()
}

// Close server, when we start for test cases
exports.close = function () {
logger.debug({ msg: `server stopped at ${new Date()}` })
this.server.close()
}

// Telemetry initialization
const telemetryBatchSize = parseInt(process.env.sunbird_telemetry_sync_batch_size, 10) || 20
telemtryEventConfig.pdata.id = producerId
Expand All @@ -234,12 +255,15 @@ const telemetryConfig = {

logger.debug({ msg: 'Telemetry is initialized.' })
telemetry.init(telemetryConfig)
process.on('unhandledRejection', (reason, p) => {
console.log("Kp-mw Unhandled Rejection", p, reason);
logger.error({msg:"Kp-mw Unhandled Rejection", p, reason})
});
process.on('unhandledRejection', (reason, p) => {
console.log('Kp-mw Unhandled Rejection', p, reason)
logger.error({ msg: 'Kp-mw Unhandled Rejection', p, reason })
})
process.on('uncaughtException', (err) => {
console.log("Kp-mw Uncaught Exception", err);
logger.error({msg:"Kp-mw Uncaught Exception", err})
process.exit(1);
});
console.log('Kp-mw Uncaught Exception', err)
logger.error({ msg: 'Kp-mw Uncaught Exception', err })
process.exit(1)
})

exports.start = startServer
exports.close = (cb) => { this.server.close(cb) }
6 changes: 2 additions & 4 deletions src/contentMetaFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ var configHelper = require('./helpers/configHelper.js')
var cron = require('node-cron')
var channelRefreshCronStr = process.env.sunbird_content_service_channel_refresh_cron
var ischannelRefreshEnabled = false
var async = require('asyncawait/async');
var await = require('asyncawait/await');
// Function to generate the Config Array

var generateConfigString = async(function(metaFiltersArray) {
var generateConfigString = ( async function(metaFiltersArray) {
var configArray = {}
_.forOwn(metaFiltersArray, function (value, key) {
var allowedMetadata = value[0]
Expand All @@ -23,7 +21,7 @@ var generateConfigString = async(function(metaFiltersArray) {
}
LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'generateConfigString', 'allowed channels', allowedMetadata))
var allChannels = await(configHelper.getAllChannelsFromAPI())
var allChannels = await (configHelper.getAllChannelsFromAPI())
allowedMetadata = _.pull(allowedMetadata, '$.instance.all').concat(allChannels)
LOG.info(utilsService.getLoggerData({}, 'INFO',
filename, 'generateConfigString', 'all whitelisted channels count', allowedMetadata.length))
Expand Down
Loading

0 comments on commit abf3042

Please sign in to comment.