Skip to content

Commit

Permalink
Adds reprocess config files
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsMurumba committed May 22, 2024
1 parent 679e2b6 commit af4a58e
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
42 changes: 42 additions & 0 deletions reprocess-mediator/docker-compose.config.yml
Original file line number Diff line number Diff line change
@@ -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:
72 changes: 72 additions & 0 deletions reprocess-mediator/openhimConfig.js
Original file line number Diff line number Diff line change
@@ -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 || "[email protected]";

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, "");
12 changes: 12 additions & 0 deletions reprocess-mediator/reprocessor-ui-app.json
Original file line number Diff line number Diff line change
@@ -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"
}

1 change: 1 addition & 0 deletions reprocess-mediator/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit af4a58e

Please sign in to comment.