From 995f862669b3cb0a69547663c69eabec84ea0748 Mon Sep 17 00:00:00 2001 From: Winston Li Date: Mon, 5 Jan 2015 00:39:08 +0000 Subject: [PATCH] Allowed postback root to be specified as a config setting (#2) --- services/git-bridge/bin/config.json | 3 ++- .../src/uk/ac/ic/wlgitbridge/application/Config.java | 12 ++++++------ .../wlgitbridge/application/WLGitBridgeServer.java | 9 +++++---- .../git/handler/WLReceivePackFactory.java | 7 ++++++- .../src/uk/ac/ic/wlgitbridge/util/Util.java | 9 +++++++++ services/git-bridge/writelatex-git-bridge.iml | 1 - 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/services/git-bridge/bin/config.json b/services/git-bridge/bin/config.json index 39ab8fdcbc..3cc83dd2d1 100644 --- a/services/git-bridge/bin/config.json +++ b/services/git-bridge/bin/config.json @@ -5,5 +5,6 @@ "apiBaseUrl": "https://radiant-wind-3058.herokuapp.com/api/v0", "username": "staging", "password": "6kUfbv0R", - "serviceName": "WriteLatex" + "serviceName": "Overleaf", + "hostname": "git.overleaf.com" } diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/Config.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/Config.java index ce197be71d..c861122107 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/Config.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/Config.java @@ -17,11 +17,11 @@ public class Config implements JSONSource { private int port; private String rootGitDirectory; - private String apiKey; private String username; private String password; private String apiBaseURL; private String serviceName; + private String hostname; public Config(String configFilePath) throws InvalidConfigFileException, IOException { try { @@ -36,7 +36,6 @@ public class Config implements JSONSource { JsonObject configObject = json.getAsJsonObject(); port = getElement(configObject, "port").getAsInt(); rootGitDirectory = getElement(configObject, "rootGitDirectory").getAsString(); - apiKey = getElement(configObject, "apiKey").getAsString(); username = getOptionalString(configObject, "username"); password = getOptionalString(configObject, "password"); String apiBaseURL = getElement(configObject, "apiBaseUrl").getAsString(); @@ -45,6 +44,7 @@ public class Config implements JSONSource { } this.apiBaseURL = apiBaseURL; serviceName = getElement(configObject, "serviceName").getAsString(); + hostname = getOptionalString(configObject, "hostname"); } public int getPort() { @@ -55,10 +55,6 @@ public class Config implements JSONSource { return rootGitDirectory; } - public String getAPIKey() { - return apiKey; - } - public String getUsername() { return username; } @@ -91,4 +87,8 @@ public class Config implements JSONSource { return serviceName; } + public String getHostname() { + return hostname; + } + } diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java index 5ce2200111..e8b7dda108 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java @@ -38,10 +38,9 @@ public class WLGitBridgeServer { * Constructs an instance of the server. * @param port the port number to listen on * @param rootGitDirectoryPath the root directory path containing the git repositories - * @param apiKey * @throws ServletException if the servlet throws an exception */ - private WLGitBridgeServer(final int port, String rootGitDirectoryPath, String apiKey) throws ServletException, InvalidRootDirectoryPathException { + private WLGitBridgeServer(final int port, String rootGitDirectoryPath) throws ServletException, InvalidRootDirectoryPathException { this.port = port; this.rootGitDirectoryPath = rootGitDirectoryPath; Log.setLog(new NullLogger()); @@ -50,11 +49,12 @@ public class WLGitBridgeServer { } public WLGitBridgeServer(Config config) throws ServletException, InvalidRootDirectoryPathException { - this(config.getPort(), config.getRootGitDirectory(), config.getAPIKey()); + this(config.getPort(), config.getRootGitDirectory()); SnapshotAPIRequest.setBasicAuth(config.getUsername(), config.getPassword()); writeLatexHostname = config.getAPIBaseURL(); SnapshotAPIRequest.setBaseURL(writeLatexHostname); Util.setServiceName(config.getServiceName()); + Util.setHostname(config.getHostname()); } /** @@ -64,7 +64,8 @@ public class WLGitBridgeServer { try { jettyServer.start(); System.out.println(); - System.out.println("WriteLatex-Git Bridge server started"); + System.out.println(Util.getServiceName() + "-Git Bridge server started"); + System.out.println("Hostname: " + Util.getHostname()); System.out.println("Listening on port: " + port); System.out.println("Bridged to: " + writeLatexHostname); System.out.println("Root git directory path: " + rootGitDirectoryPath); diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/git/handler/WLReceivePackFactory.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/git/handler/WLReceivePackFactory.java index f5174a8fb4..c68a01d7c7 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/git/handler/WLReceivePackFactory.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/git/handler/WLReceivePackFactory.java @@ -7,6 +7,7 @@ import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException; import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException; import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource; import uk.ac.ic.wlgitbridge.git.handler.hook.WriteLatexPutHook; +import uk.ac.ic.wlgitbridge.util.Util; import javax.servlet.http.HttpServletRequest; @@ -25,7 +26,11 @@ public class WLReceivePackFactory implements ReceivePackFactory -