mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Allowed postback root to be specified as a config setting (#2)
This commit is contained in:
parent
128e24d2fb
commit
995f862669
6 changed files with 28 additions and 13 deletions
|
@ -5,5 +5,6 @@
|
||||||
"apiBaseUrl": "https://radiant-wind-3058.herokuapp.com/api/v0",
|
"apiBaseUrl": "https://radiant-wind-3058.herokuapp.com/api/v0",
|
||||||
"username": "staging",
|
"username": "staging",
|
||||||
"password": "6kUfbv0R",
|
"password": "6kUfbv0R",
|
||||||
"serviceName": "WriteLatex"
|
"serviceName": "Overleaf",
|
||||||
|
"hostname": "git.overleaf.com"
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,11 @@ public class Config implements JSONSource {
|
||||||
|
|
||||||
private int port;
|
private int port;
|
||||||
private String rootGitDirectory;
|
private String rootGitDirectory;
|
||||||
private String apiKey;
|
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
private String apiBaseURL;
|
private String apiBaseURL;
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
|
private String hostname;
|
||||||
|
|
||||||
public Config(String configFilePath) throws InvalidConfigFileException, IOException {
|
public Config(String configFilePath) throws InvalidConfigFileException, IOException {
|
||||||
try {
|
try {
|
||||||
|
@ -36,7 +36,6 @@ public class Config implements JSONSource {
|
||||||
JsonObject configObject = json.getAsJsonObject();
|
JsonObject configObject = json.getAsJsonObject();
|
||||||
port = getElement(configObject, "port").getAsInt();
|
port = getElement(configObject, "port").getAsInt();
|
||||||
rootGitDirectory = getElement(configObject, "rootGitDirectory").getAsString();
|
rootGitDirectory = getElement(configObject, "rootGitDirectory").getAsString();
|
||||||
apiKey = getElement(configObject, "apiKey").getAsString();
|
|
||||||
username = getOptionalString(configObject, "username");
|
username = getOptionalString(configObject, "username");
|
||||||
password = getOptionalString(configObject, "password");
|
password = getOptionalString(configObject, "password");
|
||||||
String apiBaseURL = getElement(configObject, "apiBaseUrl").getAsString();
|
String apiBaseURL = getElement(configObject, "apiBaseUrl").getAsString();
|
||||||
|
@ -45,6 +44,7 @@ public class Config implements JSONSource {
|
||||||
}
|
}
|
||||||
this.apiBaseURL = apiBaseURL;
|
this.apiBaseURL = apiBaseURL;
|
||||||
serviceName = getElement(configObject, "serviceName").getAsString();
|
serviceName = getElement(configObject, "serviceName").getAsString();
|
||||||
|
hostname = getOptionalString(configObject, "hostname");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
|
@ -55,10 +55,6 @@ public class Config implements JSONSource {
|
||||||
return rootGitDirectory;
|
return rootGitDirectory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAPIKey() {
|
|
||||||
return apiKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
@ -91,4 +87,8 @@ public class Config implements JSONSource {
|
||||||
return serviceName;
|
return serviceName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getHostname() {
|
||||||
|
return hostname;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,10 +38,9 @@ public class WLGitBridgeServer {
|
||||||
* Constructs an instance of the server.
|
* Constructs an instance of the server.
|
||||||
* @param port the port number to listen on
|
* @param port the port number to listen on
|
||||||
* @param rootGitDirectoryPath the root directory path containing the git repositories
|
* @param rootGitDirectoryPath the root directory path containing the git repositories
|
||||||
* @param apiKey
|
|
||||||
* @throws ServletException if the servlet throws an exception
|
* @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.port = port;
|
||||||
this.rootGitDirectoryPath = rootGitDirectoryPath;
|
this.rootGitDirectoryPath = rootGitDirectoryPath;
|
||||||
Log.setLog(new NullLogger());
|
Log.setLog(new NullLogger());
|
||||||
|
@ -50,11 +49,12 @@ public class WLGitBridgeServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public WLGitBridgeServer(Config config) throws ServletException, InvalidRootDirectoryPathException {
|
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());
|
SnapshotAPIRequest.setBasicAuth(config.getUsername(), config.getPassword());
|
||||||
writeLatexHostname = config.getAPIBaseURL();
|
writeLatexHostname = config.getAPIBaseURL();
|
||||||
SnapshotAPIRequest.setBaseURL(writeLatexHostname);
|
SnapshotAPIRequest.setBaseURL(writeLatexHostname);
|
||||||
Util.setServiceName(config.getServiceName());
|
Util.setServiceName(config.getServiceName());
|
||||||
|
Util.setHostname(config.getHostname());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +64,8 @@ public class WLGitBridgeServer {
|
||||||
try {
|
try {
|
||||||
jettyServer.start();
|
jettyServer.start();
|
||||||
System.out.println();
|
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("Listening on port: " + port);
|
||||||
System.out.println("Bridged to: " + writeLatexHostname);
|
System.out.println("Bridged to: " + writeLatexHostname);
|
||||||
System.out.println("Root git directory path: " + rootGitDirectoryPath);
|
System.out.println("Root git directory path: " + rootGitDirectoryPath);
|
||||||
|
|
|
@ -7,6 +7,7 @@ import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
|
||||||
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
|
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
|
||||||
import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
|
import uk.ac.ic.wlgitbridge.bridge.WriteLatexDataSource;
|
||||||
import uk.ac.ic.wlgitbridge.git.handler.hook.WriteLatexPutHook;
|
import uk.ac.ic.wlgitbridge.git.handler.hook.WriteLatexPutHook;
|
||||||
|
import uk.ac.ic.wlgitbridge.util.Util;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
|
@ -25,7 +26,11 @@ public class WLReceivePackFactory implements ReceivePackFactory<HttpServletReque
|
||||||
@Override
|
@Override
|
||||||
public ReceivePack create(HttpServletRequest httpServletRequest, Repository repository) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
|
public ReceivePack create(HttpServletRequest httpServletRequest, Repository repository) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
|
||||||
ReceivePack receivePack = new ReceivePack(repository);
|
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;
|
return receivePack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
||||||
public class Util {
|
public class Util {
|
||||||
|
|
||||||
private static String SERVICE_NAME;
|
private static String SERVICE_NAME;
|
||||||
|
private static String HOSTNAME;
|
||||||
|
|
||||||
public static String entries(int entries) {
|
public static String entries(int entries) {
|
||||||
if (entries == 1) {
|
if (entries == 1) {
|
||||||
|
@ -64,4 +65,12 @@ public class Util {
|
||||||
return SERVICE_NAME;
|
return SERVICE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setHostname(String hostname) {
|
||||||
|
HOSTNAME = hostname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getHostname() {
|
||||||
|
return HOSTNAME;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/test/unit" 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/system" isTestSource="true" />
|
||||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
|
Loading…
Reference in a new issue