소스 검색

Added ssl enabled option for postback url construction (#4, #2) and removed api key setting (#3).

Winston Li 11 년 전
부모
커밋
16d7373800

+ 5 - 2
services/git-bridge/README.md

@@ -29,11 +29,14 @@ The configuration file is in `.json` format. There is an example at `bin/config.
     {
         "port" (int): the port number,
         "rootGitDirectory" (string): the directory in which to store git repos and the db/atts,
-        "apiKey" (string): currently does nothing,
         "apiBaseUrl" (string): base url for the snapshot api,
         "username" (string, optional): username for http basic auth,
         "password" (string, optional): password for http basic auth,
-        "serviceName" (string): current name of writeLaTeX in case it ever changes ;)
+        "serviceName" (string): current name of writeLaTeX in case it ever changes,
+        "hostname": (string): the public hostname of the server, for postback,
+        "ssl": { (object): ssl configuration
+            "enabled": (boolean): decides on http or https for the postback url
+        }
     }
 
 You have to restart the server for configuration changes to take effect.

+ 4 - 2
services/git-bridge/bin/config.json

@@ -1,10 +1,12 @@
 {
 	"port": 80,
 	"rootGitDirectory": "/var/wlgb/git",
-	"apiKey": "",
 	"apiBaseUrl": "https://radiant-wind-3058.herokuapp.com/api/v0",
 	"username": "staging",
 	"password": "6kUfbv0R",
 	"serviceName": "Overleaf",
-	"hostname": "git.overleaf.com"
+	"hostname": "git.overleaf.com",
+	"ssl": {
+		"enabled": false
+	}
 }

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

@@ -22,6 +22,7 @@ public class Config implements JSONSource {
     private String apiBaseURL;
     private String serviceName;
     private String hostname;
+    private SSLConfig ssl;
 
     public Config(String configFilePath) throws InvalidConfigFileException, IOException {
         try {
@@ -45,6 +46,7 @@ public class Config implements JSONSource {
         this.apiBaseURL = apiBaseURL;
         serviceName = getElement(configObject, "serviceName").getAsString();
         hostname = getOptionalString(configObject, "hostname");
+        ssl = new SSLConfig(getElement(configObject, "ssl").getAsJsonObject());
     }
 
     public int getPort() {
@@ -91,4 +93,8 @@ public class Config implements JSONSource {
         return hostname;
     }
 
+    public SSLConfig getSSL() {
+        return ssl;
+    }
+
 }

+ 28 - 0
services/git-bridge/src/uk/ac/ic/wlgitbridge/application/SSLConfig.java

@@ -0,0 +1,28 @@
+package uk.ac.ic.wlgitbridge.application;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import uk.ac.ic.wlgitbridge.writelatex.api.request.base.JSONSource;
+
+/**
+ * Created by Winston on 05/01/15.
+ */
+public class SSLConfig implements JSONSource {
+
+    private boolean enabled;
+
+    public SSLConfig(JsonObject ssl) {
+        fromJSON(ssl);
+    }
+
+    @Override
+    public void fromJSON(JsonElement json) {
+        JsonObject obj = json.getAsJsonObject();
+        enabled = obj.get("enabled").getAsJsonPrimitive().getAsBoolean();
+    }
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+}

+ 3 - 0
services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeServer.java

@@ -55,6 +55,8 @@ public class WLGitBridgeServer {
         SnapshotAPIRequest.setBaseURL(writeLatexHostname);
         Util.setServiceName(config.getServiceName());
         Util.setHostname(config.getHostname());
+        Util.setSSL(config.getSSL());
+        Util.setPort(config.getPort());
     }
 
     /**
@@ -67,6 +69,7 @@ public class WLGitBridgeServer {
             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("SSL enabled: " + Util.getSSLConfig().isEnabled());
             System.out.println("Bridged to: " + writeLatexHostname);
             System.out.println("Root git directory path: " + rootGitDirectoryPath);
         } catch (BindException e) {

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

@@ -1,5 +1,7 @@
 package uk.ac.ic.wlgitbridge.util;
 
+import uk.ac.ic.wlgitbridge.application.SSLConfig;
+
 import java.io.BufferedReader;
 import java.io.IOException;
 
@@ -10,6 +12,8 @@ public class Util {
 
     private static String SERVICE_NAME;
     private static String HOSTNAME;
+    private static SSLConfig SSL_CONFIG;
+    private static int PORT;
 
     public static String entries(int entries) {
         if (entries == 1) {
@@ -73,4 +77,20 @@ public class Util {
         return HOSTNAME;
     }
 
+    public static SSLConfig getSSLConfig() {
+        return SSL_CONFIG;
+    }
+
+    public static void setSSL(SSLConfig ssl) {
+        SSL_CONFIG = ssl;
+    }
+
+    public static int getPort() {
+        return PORT;
+    }
+
+    public static void setPort(int port) {
+        PORT = port;
+    }
+
 }

+ 7 - 1
services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/WLDirectoryNodeSnapshot.java

@@ -5,6 +5,7 @@ import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import uk.ac.ic.wlgitbridge.bridge.CandidateSnapshot;
 import uk.ac.ic.wlgitbridge.bridge.CandidateSnapshotCallback;
+import uk.ac.ic.wlgitbridge.util.Util;
 import uk.ac.ic.wlgitbridge.writelatex.filestore.node.FileNode;
 import uk.ac.ic.wlgitbridge.writelatex.filestore.node.WLDirectoryNode;
 import uk.ac.ic.wlgitbridge.writelatex.model.WLProject;
@@ -24,7 +25,12 @@ public class WLDirectoryNodeSnapshot implements CandidateSnapshot {
     public WLDirectoryNodeSnapshot(WLProject project, WLDirectoryNode directoryNode, String hostname, String postbackKey, CandidateSnapshotCallback callback) {
         previousVersionID = project.getLatestSnapshotID();
         projectName = project.getName();
-        projectURL = "http://" + hostname + "/" + projectName;
+        String protocol = "http";
+        if (Util.getSSLConfig().isEnabled()) {
+            protocol += "s";
+        }
+        projectURL = protocol + "://" + hostname + ":" + Util.getPort() + "/" + projectName;
+
         this.directoryNode = directoryNode;
         this.postbackKey = postbackKey;
         this.callback = callback;