From af4a58eeb22531227f42949386b320b97c5e08a6 Mon Sep 17 00:00:00 2001 From: ItsMurumba Date: Wed, 22 May 2024 10:26:30 +0300 Subject: [PATCH 1/2] Adds reprocess config files --- reprocess-mediator/docker-compose.config.yml | 42 ++++++++++++ reprocess-mediator/openhimConfig.js | 72 ++++++++++++++++++++ reprocess-mediator/reprocessor-ui-app.json | 12 ++++ reprocess-mediator/swarm.sh | 1 + 4 files changed, 127 insertions(+) create mode 100644 reprocess-mediator/docker-compose.config.yml create mode 100644 reprocess-mediator/openhimConfig.js create mode 100644 reprocess-mediator/reprocessor-ui-app.json diff --git a/reprocess-mediator/docker-compose.config.yml b/reprocess-mediator/docker-compose.config.yml new file mode 100644 index 00000000..d6f51e73 --- /dev/null +++ b/reprocess-mediator/docker-compose.config.yml @@ -0,0 +1,42 @@ +version: '3.9' + +services: + # container for executing config import scripts for creating the OpenHIM channels used by the Mediator + reprocess-config-importer: + image: node:erbium-alpine + networks: + openhim: + default: + environment: + OPENHIM_API_USERNAME: ${OPENHIM_USERNAME} + OPENHIM_API_PASSWORD: ${OPENHIM_PASSWORD} + # Reject unauthorised is only needed if the OpenHIM's SSL is not setup + NODE_TLS_REJECT_UNAUTHORIZED: 0 + command: sh -c "node openhimConfig.js" + configs: + - source: reprocess-openhimConfig.js + target: /openhimConfig.js + - source: reprocess-ui-app.json + target: /reprocess-ui-app.json + deploy: + replicas: 1 + restart_policy: + condition: none + +configs: + reprocess-openhimConfig.js: + file: ./openhimConfig.js + name: reprocess-openhimConfig.js-${reprocess_openhimConfig_js_DIGEST:?err} + labels: + name: reprocess + reprocess-ui-app.json: + file: ./reprocess-ui-app.json + name: reprocess-ui-app.json-${reprocess_ui_json_DIGEST:?err} + labels: + name: reprocess + +networks: + openhim: + name: openhim_public + external: true + default: diff --git a/reprocess-mediator/openhimConfig.js b/reprocess-mediator/openhimConfig.js new file mode 100644 index 00000000..b6066636 --- /dev/null +++ b/reprocess-mediator/openhimConfig.js @@ -0,0 +1,72 @@ +const fs = require("fs"); +const https = require("https"); +const path = require("path"); + +("use strict"); + +const OPENHIM_CORE_SERVICE_NAME = "openhim-core"; +const OPENHIM_MEDIATOR_API_PORT = 8080; +const OPENHIM_API_PASSWORD = process.env.OPENHIM_API_PASSWORD || "instant101"; +const OPENHIM_API_USERNAME = + process.env.OPENHIM_API_USERNAME || "root@openhim.org"; + +const authHeader = Buffer.from( + `${OPENHIM_API_USERNAME}:${OPENHIM_API_PASSWORD}` +).toString("base64"); +function makeRequest(options, data) { + const req = https.request(options, (res) => { + if (res.statusCode == 401) { + throw new Error(`Incorrect OpenHIM API credentials`); + } + + if (![201, 200].includes(res.statusCode)) { + throw new Error(`Failed to import OpenHIM config: ${res.statusCode}`); + } + + console.log("Successfully Imported OpenHIM Config"); + }); + + req.on("error", (error) => { + throw new Error(`Failed to import OpenHIM config: ${error}`); + }); + + req.write(data); + req.end(); +} + +const appJsonData = JSON.parse( + fs.readFileSync(path.resolve(__dirname, "reprocessor-ui-app.json")) +); +const appData = JSON.stringify(appJsonData); + +const options = { + protocol: "https:", + hostname: OPENHIM_CORE_SERVICE_NAME, + port: OPENHIM_MEDIATOR_API_PORT, + headers: { + "Content-Type": "application/json", + Authorization: `Basic ${authHeader}`, + }, +}; + +const appReqOptions = { + ...options, + path: "/apps", + method: "POST", + headers: { + ...options.headers, + "Content-Length": appData.length, + }, +}; + +const importMapRebuildOptions = { + ...options, + path: "/apps", + method: "GET", + headers: { + ...options.headers, + }, +}; + +makeRequest(appReqOptions, appData); +makeRequest(importMapRebuildOptions, ""); diff --git a/reprocess-mediator/reprocessor-ui-app.json b/reprocess-mediator/reprocessor-ui-app.json new file mode 100644 index 00000000..a453c344 --- /dev/null +++ b/reprocess-mediator/reprocessor-ui-app.json @@ -0,0 +1,12 @@ +{ + "name": "Reprocess", + "description": "Reprocess microfrontends app", + "category": "HIE Configuration", + "type": "esmodule", + "url": "http://localhost:3030/jembi-reprocessor-mediator-microfrontend.js", + "showInPortal": true, + "showInSideBar": false, + "access_roles": ["admin"], + "icon": "https://fonts.gstatic.com/s/i/materialicons/apps/v12/24px.svg" + } + \ No newline at end of file diff --git a/reprocess-mediator/swarm.sh b/reprocess-mediator/swarm.sh index dcb182eb..bfb6d8da 100644 --- a/reprocess-mediator/swarm.sh +++ b/reprocess-mediator/swarm.sh @@ -46,6 +46,7 @@ function initialize_package() { log error "Failed to deploy package" exit 1 } + docker::deploy_config_importer $STACK "$COMPOSE_FILE_PATH/docker-compose.config.yml" "reprocess-config-importer" "reprocess" } function destroy_package() { From 371268041b2fb1cfb83053900dd41d178ee9936f Mon Sep 17 00:00:00 2001 From: ItsMurumba Date: Wed, 22 May 2024 19:04:06 +0300 Subject: [PATCH 2/2] Cleanup Reprocess package --- reprocess-mediator/docker-compose.config.yml | 4 ++-- reprocess-mediator/openhimConfig.js | 2 +- .../{reprocessor-ui-app.json => reprocess-ui-app.json} | 0 reprocess-mediator/swarm.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename reprocess-mediator/{reprocessor-ui-app.json => reprocess-ui-app.json} (100%) diff --git a/reprocess-mediator/docker-compose.config.yml b/reprocess-mediator/docker-compose.config.yml index d6f51e73..1135b51e 100644 --- a/reprocess-mediator/docker-compose.config.yml +++ b/reprocess-mediator/docker-compose.config.yml @@ -28,12 +28,12 @@ configs: file: ./openhimConfig.js name: reprocess-openhimConfig.js-${reprocess_openhimConfig_js_DIGEST:?err} labels: - name: reprocess + name: reprocess-mediator reprocess-ui-app.json: file: ./reprocess-ui-app.json name: reprocess-ui-app.json-${reprocess_ui_json_DIGEST:?err} labels: - name: reprocess + name: reprocess-mediator networks: openhim: diff --git a/reprocess-mediator/openhimConfig.js b/reprocess-mediator/openhimConfig.js index b6066636..3f645ab4 100644 --- a/reprocess-mediator/openhimConfig.js +++ b/reprocess-mediator/openhimConfig.js @@ -35,7 +35,7 @@ function makeRequest(options, data) { } const appJsonData = JSON.parse( - fs.readFileSync(path.resolve(__dirname, "reprocessor-ui-app.json")) + fs.readFileSync(path.resolve(__dirname, "reprocess-ui-app.json")) ); const appData = JSON.stringify(appJsonData); diff --git a/reprocess-mediator/reprocessor-ui-app.json b/reprocess-mediator/reprocess-ui-app.json similarity index 100% rename from reprocess-mediator/reprocessor-ui-app.json rename to reprocess-mediator/reprocess-ui-app.json diff --git a/reprocess-mediator/swarm.sh b/reprocess-mediator/swarm.sh index bfb6d8da..045e8d9b 100644 --- a/reprocess-mediator/swarm.sh +++ b/reprocess-mediator/swarm.sh @@ -46,7 +46,7 @@ function initialize_package() { log error "Failed to deploy package" exit 1 } - docker::deploy_config_importer $STACK "$COMPOSE_FILE_PATH/docker-compose.config.yml" "reprocess-config-importer" "reprocess" + docker::deploy_config_importer $STACK "$COMPOSE_FILE_PATH/docker-compose.config.yml" "reprocess-config-importer" "reprocess-mediator" } function destroy_package() {