Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CU_86byp4xw2: Add ability to register Reprocessor UI with core #307

Merged
merged 10 commits into from
May 29, 2024
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-mediator
reprocess-ui-app.json:
file: ./reprocess-ui-app.json
name: reprocess-ui-app.json-${reprocess_ui_json_DIGEST:?err}
labels:
name: reprocess-mediator

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");
ItsMurumba marked this conversation as resolved.
Show resolved Hide resolved

("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) {
ItsMurumba marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`Incorrect OpenHIM API credentials`);
ItsMurumba marked this conversation as resolved.
Show resolved Hide resolved
}

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, "reprocess-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/reprocess-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"
}

drizzentic marked this conversation as resolved.
Show resolved Hide resolved
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-mediator"
}

function destroy_package() {
Expand Down
Loading