Browse Source

Allowed postback root to be specified as a config setting (#2)

Winston Li 11 years ago
parent
commit
995f862669

+ 2 - 1
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"
 }

+ 6 - 6
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;
+    }
+
 }

+ 5 - 4
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);

+ 6 - 1
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<HttpServletReque
     @Override
     public ReceivePack create(HttpServletRequest httpServletRequest, Repository repository) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
         ReceivePack receivePack = new ReceivePack(repository);
-        receivePack.setPreReceiveHook(new WriteLatexPutHook(writeLatexDataSource, httpServletRequest.getLocalName()));
+        String hostname = Util.getHostname();
+        if (hostname == null) {
+            hostname = httpServletRequest.getLocalName();
+        }
+        receivePack.setPreReceiveHook(new WriteLatexPutHook(writeLatexDataSource, hostname));
         return receivePack;
     }
 

+ 9 - 0
services/git-bridge/src/uk/ac/ic/wlgitbridge/util/Util.java

@@ -9,6 +9,7 @@ import java.io.IOException;
 public class Util {
 
     private static String SERVICE_NAME;
+    private static String HOSTNAME;
 
     public static String entries(int entries) {
         if (entries == 1) {
@@ -64,4 +65,12 @@ public class Util {
         return SERVICE_NAME;
     }
 
+    public static void setHostname(String hostname) {
+        HOSTNAME = hostname;
+    }
+
+    public static String getHostname() {
+        return HOSTNAME;
+    }
+
 }

+ 0 - 1
services/git-bridge/writelatex-git-bridge.iml

@@ -7,7 +7,6 @@
       <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/test/unit" isTestSource="true" />
       <sourceFolder url="file://$MODULE_DIR$/test/system" isTestSource="true" />
-      <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />