From 43734ded14268af31628f4949d99a797cb91a163 Mon Sep 17 00:00:00 2001
From: librelois <c@elo.tf>
Date: Sat, 15 May 2021 00:59:23 +0200
Subject: [PATCH] fix(bma): create endpoint with env var conf

---
 app/modules/bma/index.ts | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/app/modules/bma/index.ts b/app/modules/bma/index.ts
index 4fde4d9d0..4dcd16745 100644
--- a/app/modules/bma/index.ts
+++ b/app/modules/bma/index.ts
@@ -197,6 +197,19 @@ export const BmaDependency = {
 
     service: {
       input: (server: Server, conf: NetworkConfDTO, logger: any) => {
+        // Override conf with environment variables
+        if (process.env.DUNITER_BMA_ENABLED) {
+          conf.nobma = false;
+          if (!conf.ipv4) {
+            conf.ipv4 = "127.0.0.1";
+          }
+        }
+        if (process.env.DUNITER_BMA_REMOTE_HOST) {
+          conf.remotehost = process.env.DUNITER_BMA_REMOTE_HOST;
+        }
+        if (process.env.DUNITER_BMA_REMOTE_PORT) {
+          conf.remoteport = parseInt(process.env.DUNITER_BMA_REMOTE_PORT);
+        }
         // Configuration errors
         if (!conf.nobma) {
           if (!conf.ipv4 && !conf.ipv6) {
@@ -211,7 +224,7 @@ export const BmaDependency = {
             throw new Error("BMA: no port for remote contact.");
           }
         }
-        if (!conf.nobma) {
+        if (!conf.nobma || process.env.DUNITER_BMA_ENABLED) {
           server.addEndpointsDefinitions(() =>
             Promise.resolve(getEndpoint(conf))
           );
-- 
GitLab