-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
679e2b6
commit af4a58e
Showing
4 changed files
with
127 additions
and
0 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 |
---|---|---|
@@ -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: |
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,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, ""); |
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,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" | ||
} | ||
|
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