Add support for bindIp and idleTimeout to config object

This commit is contained in:
Simon Detheridge 2021-06-24 17:00:04 +01:00
parent 28d98f1a25
commit cafa94fcba
4 changed files with 30 additions and 0 deletions

View file

@ -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;
}

View file

@ -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" +

View file

@ -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" +

View file

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