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

This commit is contained in:
Winston Li 2015-01-05 00:39:08 +00:00
parent 128e24d2fb
commit 995f862669
6 changed files with 28 additions and 13 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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