Skip to content

Commit

Permalink
Issue #SB-21295 feat: added Blob path env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
JagadishPujari committed Jan 8, 2021
1 parent e08fa38 commit 6e642dc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
1 change: 1 addition & 0 deletions helm_charts/router/values.j2
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ routerenv:
WHATSAPP_SECRET_KEY: "{{sunbird_whatsapp_secret_key | default("''")}}"
WHATSAPP_AUTH_TOKEN: "{{sunbird_whatsapp_auth_token | default("''")}}"
WHATSAPP_SOURCE: "{{sunbird_whatsapp_source | default("''")}}"
CONFIG_BLOB_PATH: "{{sunbird_public_storage_account_name}}"
52 changes: 29 additions & 23 deletions router/appRest.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,35 @@ appBot.post('/whatsapp', function (req, res) {

// Update latest config from blob
appBot.post('/refresh', function(req, response) {
var domian = config.ENV_URL[req.headers.host]
var url = domian + 'chatbot/router/config/'
var dest = './config/'

var literalsStr = 'literals.js';
var chatflowStr = 'chatflow.js';
updateConfigFromBlob(url, dest, literalsStr, function(){
try {
literals = reload('./config/literals');
updateConfigFromBlob(url, dest, chatflowStr, function(){
try {
chatflow = reload('./config/chatflow');
response.send({'msg': 'Configuration is updated successfully for chatflow and literals!!!'})
} catch (e) {
//if this threw an error, the api variable is still set to the old, working version
console.error("Failed to reload literals.js! Error: ", e);
}
})
} catch (e) {
//if this threw an error, the api variable is still set to the old, working version
console.error("Failed to reload literals.js! Error: ", e);
}
})
if(config.CONFIG_BLOB_PATH) {
var domian = "https://" + config.CONFIG_BLOB_PATH + ".blob.core.windows.net"
var url = domian + '/chatbot/router/config/'
var dest = 'router/config/'

var literalsStr = 'literals.js';
var chatflowStr = 'chatflow.js';
updateConfigFromBlob(url, dest, literalsStr, function(){
try {
literals = reload('./config/literals');
updateConfigFromBlob(url, dest, chatflowStr, function(){
try {
chatflow = reload('./config/chatflow');
response.send({'msg': 'Configuration is updated successfully for chatflow and literals!!!'})
} catch (e) {
//if this threw an error, the api variable is still set to the old, working version
console.error("Failed to reload chatflow.js! Error: ", e);
response.send({'msg': e.message})
}
})
} catch (e) {
//if this threw an error, the api variable is still set to the old, working version
console.error("Failed to reload literals.js! Error: ", e);
response.send({'msg': e.message})
}
})
} else {
response.send({'msg': 'ENV configuration blob path is not defined'})
}
})

var updateConfigFromBlob = function(url, dest, configName, cb) {
Expand Down
8 changes: 1 addition & 7 deletions router/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ config.UNKNOWN_OPTION = 'unknown_option'

config.TELEGRAM_BOT_ENDPOINT = 'https://api.telegram.org/bot<bot_secret_key>/sendMessage'

config.ENV_URL = {
'diksha.gov.in': 'https://ntpproductionall.blob.core.windows.net/',
'staging.sunbirded.org':'https://ntpstagingall.blob.core.windows.net/',
'preprod.ntp.net.in':'https://preprodall.blob.core.windows.net/',
'dev.sunbirded.org':'https://sunbirddev.blob.core.windows.net/',
'vdn.diksha.gov.in/': ''
}
config.CONFIG_BLOB_PATH = env.CONFIG_BLOB_PATH

module.exports = config;

0 comments on commit 6e642dc

Please sign in to comment.