diff --git a/services/git-bridge/bin/config.json b/services/git-bridge/bin/config.json index 8f84bc94a8..a34a3c7b61 100644 --- a/services/git-bridge/bin/config.json +++ b/services/git-bridge/bin/config.json @@ -1,5 +1,8 @@ { "port": 80, "rootGitDirectory": "/var/wlgb/git", - "apiKey": "" + "apiKey": "", + "hostname": "https://radiant-wind-3058.herokuapp.com/", + "username": "staging", + "password": "6kUfbv0R" } 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 e90cd74e9e..dae5a557e7 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 @@ -18,6 +18,9 @@ public class Config implements JSONSource { private int port; private String rootGitDirectory; private String apiKey; + private String username; + private String password; + private String hostname; public Config(String configFilePath) throws InvalidConfigFileException, IOException { try { @@ -33,6 +36,9 @@ public class Config implements JSONSource { port = getElement(configObject, "port").getAsInt(); rootGitDirectory = getElement(configObject, "rootGitDirectory").getAsString(); apiKey = getElement(configObject, "apiKey").getAsString(); + username = getElement(configObject, "username").getAsString(); + password = getElement(configObject, "password").getAsString(); + hostname = getElement(configObject, "hostname").getAsString(); } public int getPort() { @@ -47,6 +53,18 @@ public class Config implements JSONSource { return apiKey; } + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getHostname() { + return hostname; + } + private JsonElement getElement(JsonObject configObject, String name) { JsonElement element = configObject.get(name); if (element == null) { diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeApplication.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeApplication.java index 2d709713a6..e5bfdf3abc 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeApplication.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/application/WLGitBridgeApplication.java @@ -47,7 +47,7 @@ public class WLGitBridgeApplication { */ public void run() { try { - new WLGitBridgeServer(config.getPort(), config.getRootGitDirectory(), config.getAPIKey()).start(); + new WLGitBridgeServer(config).start(); } catch (ServletException e) { e.printStackTrace(); } catch (InvalidRootDirectoryPathException e) { 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 f13116e80a..f39a16e8d2 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 @@ -12,6 +12,7 @@ import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource; import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException; import uk.ac.ic.wlgitbridge.git.servlet.WLGitServlet; import uk.ac.ic.wlgitbridge.writelatex.WriteLatexAPI; +import uk.ac.ic.wlgitbridge.writelatex.api.request.base.SnapshotAPIRequest; import uk.ac.ic.wlgitbridge.writelatex.model.WLDataModel; import javax.servlet.ServletException; @@ -38,7 +39,7 @@ public class WLGitBridgeServer { * @param apiKey * @throws ServletException if the servlet throws an exception */ - public WLGitBridgeServer(final int port, String rootGitDirectoryPath, String apiKey) throws ServletException, InvalidRootDirectoryPathException { + private WLGitBridgeServer(final int port, String rootGitDirectoryPath, String apiKey) throws ServletException, InvalidRootDirectoryPathException { this.port = port; this.rootGitDirectoryPath = rootGitDirectoryPath; Log.setLog(new NullLogger()); @@ -46,6 +47,12 @@ public class WLGitBridgeServer { configureJettyServer(); } + public WLGitBridgeServer(Config config) throws ServletException, InvalidRootDirectoryPathException { + this(config.getPort(), config.getRootGitDirectory(), config.getAPIKey()); + SnapshotAPIRequest.setBasicAuth(config.getUsername(), config.getPassword()); + SnapshotAPIRequest.setBaseURL(config.getHostname()); + } + /** * Starts the server on the port given on construction. */ diff --git a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/api/request/base/SnapshotAPIRequest.java b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/api/request/base/SnapshotAPIRequest.java index c31e2ebb75..a46228e891 100644 --- a/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/api/request/base/SnapshotAPIRequest.java +++ b/services/git-bridge/src/uk/ac/ic/wlgitbridge/writelatex/api/request/base/SnapshotAPIRequest.java @@ -7,10 +7,10 @@ import com.ning.http.client.Realm; */ public abstract class SnapshotAPIRequest extends Request { - private static final String USERNAME = "staging"; - private static final String PASSWORD = "6kUfbv0R"; + private static String USERNAME; + private static String PASSWORD; - private static final String BASE_URL = "https://radiant-wind-3058.herokuapp.com/api/v0/docs"; + private static String BASE_URL; public SnapshotAPIRequest(String projectName, String apiCall) { super(BASE_URL + "/" + projectName + apiCall); @@ -25,4 +25,13 @@ public abstract class SnapshotAPIRequest extends Request { .build(); } + public static void setBasicAuth(String username, String password) { + USERNAME = username; + PASSWORD = password; + } + + public static void setBaseURL(String baseURL) { + BASE_URL = baseURL; + } + }