From 31dc234eb7b10d1ace88fc7697e03cb90bf1cc03 Mon Sep 17 00:00:00 2001 From: skutner Date: Mon, 4 Jul 2022 13:02:41 +0300 Subject: [PATCH] PharmaLedger-IMI/epi-workspace#806 get bdnsHosts from github repo at boot --- components/bdns/index.js | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/components/bdns/index.js b/components/bdns/index.js index 026198c..5fca767 100644 --- a/components/bdns/index.js +++ b/components/bdns/index.js @@ -15,11 +15,20 @@ function BDNS(server) { const {headersMiddleware} = require('../../utils/middlewares'); let bdnsCache; + const config = require("../../config"); + const bdnsConfig = config.getConfig("componentsConfig", "bdns"); + + async function getBDNSHostsFromURL(url) { + const http = require("opendsu").loadAPI("http"); + const bdnsHosts = await http.fetch(url).then(res => res.json()); + return bdnsHosts + } let init_process_runned = false; - async function initialize(){ - if(init_process_runned){ - return true; + + async function initialize() { + if (init_process_runned) { + return true; } init_process_runned = true; const fs = require("fs"); @@ -29,16 +38,27 @@ function BDNS(server) { bdnsCache = fs.readFileSync(bdnsHostsPath).toString(); - try{ + if (bdnsConfig && bdnsConfig.url) { + try { + const bdnsExtensions = await getBDNSHostsFromURL(bdnsConfig.url); + let newRegistry = JSON.parse(bdnsCache); + Object.assign(newRegistry, bdnsExtensions); + bdnsCache = JSON.stringify(newRegistry); + } catch (e) { + console.log(`Failed to get bdns hosts from url`, e); + } + } + + try { console.log("Testing to see if admin component is active and can be used to expand BDNS configuration."); let adminService = require("./../admin").getAdminService(); let getDomains = $$.promisify(adminService.getDomains); let domains = await getDomains(); - if(domains){ + if (domains) { let bdnsExtensions = {}; - for(let i=0; i