ソースを参照

Add support for bindIp and idleTimeout to config object

Simon Detheridge 5 年 前
親
コミット
cafa94fcba

+ 18 - 0
services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/application/config/Config.java

@@ -24,6 +24,8 @@ public class Config implements JSONSource {
     static Config asSanitised(Config config) {
         return new Config(
                 config.port,
+                config.bindIp,
+                config.idleTimeout,
                 config.rootGitDirectory,
                 config.apiBaseURL,
                 config.postbackURL,
@@ -36,6 +38,8 @@ public class Config implements JSONSource {
     }
 
     private int port;
+    private String bindIp;
+    private int idleTimeout;
     private String rootGitDirectory;
     private String apiBaseURL;
     private String postbackURL;
@@ -62,6 +66,8 @@ public class Config implements JSONSource {
 
     public Config(
             int port,
+            String bindIp,
+            int idleTimeout,
             String rootGitDirectory,
             String apiBaseURL,
             String postbackURL,
@@ -72,6 +78,8 @@ public class Config implements JSONSource {
             SwapJobConfig swapJob
     ) {
         this.port = port;
+        this.bindIp = bindIp;
+        this.idleTimeout = idleTimeout;
         this.rootGitDirectory = rootGitDirectory;
         this.apiBaseURL = apiBaseURL;
         this.postbackURL = postbackURL;
@@ -86,6 +94,8 @@ public class Config implements JSONSource {
     public void fromJSON(JsonElement json) {
         JsonObject configObject = json.getAsJsonObject();
         port = getElement(configObject, "port").getAsInt();
+        bindIp = getElement(configObject, "bindIp").getAsString();
+        idleTimeout = getElement(configObject, "idleTimeout").getAsInt();
         rootGitDirectory = getElement(
                 configObject,
                 "rootGitDirectory"
@@ -124,6 +134,14 @@ public class Config implements JSONSource {
         return port;
     }
 
+    public String getBindIp() {
+        return bindIp;
+    }
+
+    public int getIdleTimeout() {
+        return idleTimeout;
+    }
+
     public String getRootGitDirectory() {
         return rootGitDirectory;
     }

+ 2 - 0
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/WLGitBridgeIntegrationTest.java

@@ -1063,6 +1063,8 @@ public class WLGitBridgeIntegrationTest {
         String cfgStr =
                 "{\n" +
                 "    \"port\": " + port + ",\n" +
+                "    \"bindIp\": \"127.0.0.1\",\n" +
+                "    \"idleTimeout\": 30000,\n" +
                 "    \"rootGitDirectory\": \"" +
                         wlgb.getAbsolutePath() +
                         "\",\n" +

+ 8 - 0
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/application/config/ConfigTest.java

@@ -16,6 +16,8 @@ public class ConfigTest {
      public void testConstructWithOauth() {
         Reader reader = new StringReader("{\n" +
                 "    \"port\": 80,\n" +
+                "    \"bindIp\": \"127.0.0.1\",\n" +
+                "    \"idleTimeout\": 30000,\n" +
                 "    \"rootGitDirectory\": \"/var/wlgb/git\",\n" +
                 "    \"apiBaseUrl\": \"http://127.0.0.1:60000/api/v0\",\n" +
                 "    \"postbackBaseUrl\": \"http://127.0.0.1\",\n" +
@@ -42,6 +44,8 @@ public class ConfigTest {
     public void testConstructWithoutOauth() {
         Reader reader = new StringReader("{\n" +
                 "    \"port\": 80,\n" +
+                "    \"bindIp\": \"127.0.0.1\",\n" +
+                "    \"idleTimeout\": 30000,\n" +
                 "    \"rootGitDirectory\": \"/var/wlgb/git\",\n" +
                 "    \"apiBaseUrl\": \"http://127.0.0.1:60000/api/v0\",\n" +
                 "    \"postbackBaseUrl\": \"http://127.0.0.1\",\n" +
@@ -62,6 +66,8 @@ public class ConfigTest {
     public void asSanitised() throws Exception {
         Reader reader = new StringReader("{\n" +
                 "    \"port\": 80,\n" +
+                "    \"bindIp\": \"127.0.0.1\",\n" +
+                "    \"idleTimeout\": 30000,\n" +
                 "    \"rootGitDirectory\": \"/var/wlgb/git\",\n" +
                 "    \"apiBaseUrl\": \"http://127.0.0.1:60000/api/v0\",\n" +
                 "    \"postbackBaseUrl\": \"http://127.0.0.1\",\n" +
@@ -75,6 +81,8 @@ public class ConfigTest {
         Config config = new Config(reader);
         String expected = "{\n" +
                 "  \"port\": 80,\n" +
+                "  \"bindIp\": \"127.0.0.1\",\n" +
+                "  \"idleTimeout\": 30000,\n" +
                 "  \"rootGitDirectory\": \"/var/wlgb/git\",\n" +
                 "  \"apiBaseURL\": \"http://127.0.0.1:60000/api/v0/\",\n" +
                 "  \"postbackURL\": \"http://127.0.0.1/\",\n" +

+ 2 - 0
services/git-bridge/src/test/java/uk/ac/ic/wlgitbridge/bridge/BridgeTest.java

@@ -53,6 +53,8 @@ public class BridgeTest {
         gcJob = mock(GcJob.class);
         bridge = new Bridge(
                 new Config(
+                        0,
+                        "",
                         0,
                         "",
                         "",