mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Added configurable hostname and basic auth in config file.
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
{
|
||||
"port": 80,
|
||||
"rootGitDirectory": "/var/wlgb/git",
|
||||
"apiKey": ""
|
||||
"apiKey": "",
|
||||
"hostname": "https://radiant-wind-3058.herokuapp.com/",
|
||||
"username": "staging",
|
||||
"password": "6kUfbv0R"
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
+12
-3
@@ -7,10 +7,10 @@ import com.ning.http.client.Realm;
|
||||
*/
|
||||
public abstract class SnapshotAPIRequest<T extends Result> extends Request<T> {
|
||||
|
||||
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<T extends Result> extends Request<T> {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static void setBasicAuth(String username, String password) {
|
||||
USERNAME = username;
|
||||
PASSWORD = password;
|
||||
}
|
||||
|
||||
public static void setBaseURL(String baseURL) {
|
||||
BASE_URL = baseURL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user