-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #953 from varadeth/DIV-8225
DIV-8225 | EU_Vaccine_Proph, EU_Vaccine_Code, EU_Vaccine_Manuf as ETCD
- Loading branch information
Showing
7 changed files
with
253 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,18 @@ | ||
const EU_DISEASE = {"covid-19": "840539006"}; | ||
const EU_VACCINE_PROPH = { | ||
"covaxin": "J07BX03", | ||
"covishield": "J07BX03", | ||
"sputnik": "J07BX03", | ||
"pfizer-biontech": "J07BX03", | ||
"comirnaty": "J07BX03", | ||
"janssen": "J07BX03", | ||
"moderna": "J07BX03", | ||
"spikevax": "J07BX03", | ||
"astrazeneca": "J07BX03", | ||
"vaxzevria": "J07BX03", | ||
"sinovac": "J07BX03", | ||
"coronavac": "J07BX03", | ||
"bbibp-corv": "J07BX03", | ||
"sinopharm": "J07BX03", | ||
"convidecia": "J07BX03", | ||
"novavax": "J07BX03", | ||
"covovax": "J07BX03" | ||
}; | ||
const EU_VACCINE_CODE = { | ||
"covaxin": "Covaxin", | ||
"covishield": "Covishield", | ||
"sputnik": "Sputnik-V", | ||
"pfizer-biontech": "EU/1/20/1528", | ||
"comirnaty": "EU/1/20/1528", | ||
"janssen": "EU/1/20/1525", | ||
"moderna": "EU/1/20/1507", | ||
"spikevax": "EU/1/20/1507", | ||
"astrazeneca": "EU/1/21/1529", | ||
"vaxzevria": "EU/1/21/1529", | ||
"sinovac": "CoronaVac", | ||
"coronavac": "CoronaVac", | ||
"bbibp-corv": "BBIBP- CorV", | ||
"sinopharm": "BBIBP- CorV", | ||
"convidecia": "Convidecia", | ||
"novavax": "NVX - CoV2373", | ||
"covovax": "NVX - CoV2373" | ||
} | ||
const VACCINE_MANUF = { | ||
"bharat": "Bharat-Biotech", | ||
"serum": "ORG-100001981", | ||
"gamaleya": "Gamaleya-Research-Institute", | ||
"biontech": "ORG-100030215", | ||
"janssen": "ORG-100001417", | ||
"moderna": "ORG-100031184", | ||
"astrazeneca": "ORG-100001699", | ||
"sinovac": "Sinovac- Biontech", | ||
"sinopharm": "ORG-100020693", | ||
"canSino": "ORG-100013793", | ||
"novavax": "ORG-100032020" | ||
}; | ||
|
||
const TEMPLATES = { | ||
VACCINATION_CERTIFICATE: "vaccineCertificateTemplate", | ||
TEST_CERTIFICATE: "testCertificateTemplate" | ||
}; | ||
Object.freeze(TEMPLATES); | ||
|
||
const EU_VACCINE_CONFIG_KEYS = { | ||
PROPHYLAXIS_TYPE: "euVaccineProph", | ||
VACCINE_CODE: "euVaccineCode", | ||
MANUFACTURER: "euVaccineManuf" | ||
} | ||
|
||
module.exports = { | ||
EU_DISEASE, | ||
EU_VACCINE_PROPH, | ||
EU_VACCINE_CODE, | ||
VACCINE_MANUF, | ||
TEMPLATES | ||
TEMPLATES, | ||
EU_VACCINE_CONFIG_KEYS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
backend/certificate_api/src/services/configuration_service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
const {Etcd3} = require('etcd3'); | ||
const sanitizeHtml = require('sanitize-html'); | ||
|
||
const config = require('../../configs/config'); | ||
const {TEMPLATES, EU_VACCINE_CONFIG_KEYS} = require('../../configs/constants'); | ||
let etcdClient; | ||
let configuration; | ||
let vaccineCertificateTemplate = null, testCertificateTemplate = null; | ||
let EU_VACCINE_PROPH = null, EU_VACCINE_CODE = null, EU_VACCINE_MANUF = null; | ||
|
||
function init() { | ||
etcdClient = new Etcd3({hosts: config.ETCD_URL}); | ||
setUpWatcher(TEMPLATES.VACCINATION_CERTIFICATE, ); | ||
setUpWatcher(TEMPLATES.TEST_CERTIFICATE); | ||
setUpWatcher(EU_VACCINE_CONFIG_KEYS.VACCINE_CODE); | ||
setUpWatcher(EU_VACCINE_CONFIG_KEYS.MANUFACTURER); | ||
setUpWatcher(EU_VACCINE_CONFIG_KEYS.PROPHYLAXIS_TYPE); | ||
configuration = config.CONFIGURATION_LAYER.toLowerCase() === 'etcd' ? new etcd(): null ; | ||
} | ||
|
||
function cleanHTML(html) { | ||
if(html === null) { | ||
return null; | ||
} | ||
const cleanedHtml = sanitizeHtml(html, { | ||
allowedTags: false, | ||
allowedAttributes: false, | ||
allowedClasses: { | ||
"*": ["*"] | ||
}, | ||
parser: { | ||
lowerCaseAttributeNames: false | ||
}, | ||
allowedScriptDomains: [''], | ||
allowedScriptHostnames: [''], | ||
allowedIframeHostnames: [''], | ||
allowedIframeDomains: [''] | ||
}); | ||
return cleanedHtml; | ||
} | ||
|
||
function updateConfigValues(key, value) { | ||
switch(key) { | ||
case TEMPLATES.VACCINATION_CERTIFICATE: | ||
vaccineCertificateTemplate = value; | ||
break; | ||
case TEMPLATES.TEST_CERTIFICATE: | ||
testCertificateTemplate = value; | ||
break; | ||
case EU_VACCINE_CONFIG_KEYS.VACCINE_CODE: | ||
EU_VACCINE_CODE = value; | ||
break; | ||
case EU_VACCINE_CONFIG_KEYS.MANUFACTURER: | ||
EU_VACCINE_MANUF = value; | ||
break; | ||
case EU_VACCINE_CONFIG_KEYS.PROPHYLAXIS_TYPE: | ||
EU_VACCINE_PROPH = value; | ||
break; | ||
} | ||
} | ||
|
||
function setUpWatcher(templateKey) { | ||
etcdClient.watch() | ||
.key(templateKey) | ||
.create() | ||
.then(watcher => { | ||
watcher | ||
.on('end', (end) => { | ||
console.log('end') | ||
}) | ||
.on('connected', (req) => { | ||
console.log('connected'); | ||
}) | ||
.on('put', res => { | ||
updateConfigValues(templateKey, res.value.toString()); | ||
}); | ||
}) | ||
.catch(err => { | ||
console.log(err); | ||
}); | ||
} | ||
|
||
async function loadConfigurationValues(key, fetchConfigCallbackFunc) { | ||
let value; | ||
switch(key) { | ||
case TEMPLATES.VACCINATION_CERTIFICATE: | ||
value = vaccineCertificateTemplate; | ||
break; | ||
case TEMPLATES.TEST_CERTIFICATE: | ||
value = testCertificateTemplate; | ||
break; | ||
case EU_VACCINE_CONFIG_KEYS.MANUFACTURER: | ||
value = EU_VACCINE_MANUF; | ||
break; | ||
case EU_VACCINE_CONFIG_KEYS.VACCINE_CODE: | ||
value = EU_VACCINE_CODE; | ||
break; | ||
case EU_VACCINE_CONFIG_KEYS.PROPHYLAXIS_TYPE: | ||
value = EU_VACCINE_PROPH; | ||
break; | ||
} | ||
if(value === null || value === undefined) { | ||
if(configuration === null || configuration === undefined) { | ||
return null; | ||
} | ||
value = fetchConfigCallbackFunc(); | ||
} | ||
return value; | ||
} | ||
|
||
class ConfigurationService { | ||
async getCertificateTemplate(key) { | ||
let certificateTemplate = await loadConfigurationValues(key, async() => await configuration.getCertificateTemplate(key)); | ||
certificateTemplate = cleanHTML(certificateTemplate); | ||
updateConfigValues(key, certificateTemplate); | ||
return certificateTemplate; | ||
} | ||
|
||
async getEUVaccineDetails(key) { | ||
let details = await loadConfigurationValues(key, async() => JSON.parse(await configuration.getEUVaccineDetails(key))); | ||
updateConfigValues(key, details); | ||
return details; | ||
} | ||
} | ||
|
||
const etcd = function() { | ||
this.getCertificateTemplate = async function(templateKey) { | ||
const template = (await etcdClient.get(templateKey).string()); | ||
return template; | ||
} | ||
|
||
this.getEUVaccineDetails = async function(key) { | ||
const value = (await etcdClient.get(key).string()); | ||
return value; | ||
} | ||
} | ||
|
||
module.exports = { | ||
ConfigurationService, init | ||
} |
Oops, something went wrong.