Fix checkSetup page and add checkSetupSecret endpoints to show apikey and secret the proxy is seeing

This commit is contained in:
elroy 2017-08-09 21:41:53 +02:00
parent 07a997b7a4
commit 768736abfd
3 changed files with 41 additions and 18 deletions

View File

@ -5,7 +5,7 @@
<groupId>nl.komtek</groupId>
<artifactId>GunbotProxyCommunity</artifactId>
<version>0.9.9</version>
<version>0.9.9.1</version>
<packaging>jar</packaging>
<name>GunbotProxyCommunity</name>

View File

@ -14,7 +14,7 @@ import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
/**
@ -31,7 +31,7 @@ public class CheckSetupController {
@RequestMapping("/checkSetup/**")
public ModelAndView checkSetup(ModelMap modelMap) {
modelMap.put("setupData", setupData());
modelMap.put("setupData", setupData(false));
return new ModelAndView("setupData", modelMap);
}
@ -40,30 +40,44 @@ public class CheckSetupController {
public String checkSetupLinux() throws IOException {
StringBuilder stringData = new StringBuilder();
stringData.append("\n\n");
Map<String, String> setupData = setupData();
for (Map.Entry entry : setupData.entrySet()) {
stringData.append(String.format("%s -- %s \n", entry.getKey(), entry.getValue()));
}
Map<String, String> setupData = setupData(false);
setupData.forEach((key, value) -> stringData.append(String.format("%s -- %s \n", key, value)));
return stringData.toString();
}
private Map<String, String> setupData() {
Map<String, String> setupData = new HashMap<>();
@RequestMapping("/checkSetupSecret/**")
public ModelAndView checkSetupSecret(ModelMap modelMap) {
modelMap.put("setupData", setupData(true));
return new ModelAndView("setupData", modelMap);
}
@ResponseBody
@RequestMapping("/checkSetupLinuxSecret/**")
public String checkSetupLinuxSecret() throws IOException {
StringBuilder stringData = new StringBuilder();
stringData.append("\n\n");
Map<String, String> setupData = setupData(true);
setupData.forEach((key, value) -> stringData.append(String.format("%s -- %s \n", key, value)));
return stringData.toString();
}
private Map<String, String> setupData(boolean showSecret) {
Map<String, String> setupData = new LinkedHashMap<>();
if (!gunbotProxyService.isUsingMultipleMarkets()) {
checkApiKeysForMarket(setupData, "");
checkApiKeysForMarket(setupData, "", showSecret);
} else {
if (gunbotProxyService.isActiveMarket("BTC")) {
checkApiKeysForMarket(setupData, "BTC_");
checkApiKeysForMarket(setupData, "BTC_", showSecret);
}
if (gunbotProxyService.isActiveMarket("ETH")) {
checkApiKeysForMarket(setupData, "ETH_");
checkApiKeysForMarket(setupData, "ETH_", showSecret);
}
if (gunbotProxyService.isActiveMarket("XMR")) {
checkApiKeysForMarket(setupData, "XMR_");
checkApiKeysForMarket(setupData, "XMR_", showSecret);
}
if (gunbotProxyService.isActiveMarket("USDT")) {
checkApiKeysForMarket(setupData, "USDT_");
checkApiKeysForMarket(setupData, "USDT_", showSecret);
}
}
//check if hostfile was setup correctly
@ -107,7 +121,7 @@ public class CheckSetupController {
return setupData;
}
private void checkApiKeysForMarket(Map<String, String> setupData, String market) {
private void checkApiKeysForMarket(Map<String, String> setupData, String market, boolean showSecret) {
String keyName = String.format("default_%sapiKey", market);
String secretName = String.format("default_%sapiSecret", market);
try {
@ -116,6 +130,10 @@ public class CheckSetupController {
if (StringUtils.isEmpty(apiKey) || StringUtils.isEmpty(apiSecret)) {
setupData.put(keyName, String.format("Please setup %s and %s", keyName, secretName));
} else {
if (showSecret) {
setupData.put(String.format("Your Key %s", keyName), String.format("**%s**", apiKey));
setupData.put(String.format("Your Secret %s", secretName), String.format("**%s**", apiSecret));
}
String theMarket = market.replace("_", "");
if (StringUtils.isEmpty(theMarket)) {
theMarket = "default";
@ -124,7 +142,7 @@ public class CheckSetupController {
setupData.put(keyName, "Looking good!");
}
} catch (Exception e) {
setupData.put(keyName, e.getMessage());
setupData.put(keyName + "", e.getMessage());
}
for (int i = 1; i <= 10; i++) {
@ -140,6 +158,10 @@ public class CheckSetupController {
break;
}
try {
if (showSecret) {
setupData.put(String.format("Your Key %s", keyName), String.format("**%s**", apiKey));
setupData.put(String.format("Your Secret %s", secretName), String.format("**%s**", apiSecret));
}
if (StringUtils.isEmpty(market)) {
gunbotProxyService.analyzeResult(gunbotProxyService.checkTradingKey(apiKey));
} else {

View File

@ -408,6 +408,8 @@ public class GunbotProxyService {
throw new ProxyHandledException("No value was returned");
} else if (result.contains("Nonce")) {
throw new ProxyHandledException("nonce error: " + result);
} else if (result.contains("Invalid API")) {
throw new ProxyHandledException(result);
} else if (result.contains("Connection timed out")) {
throw new ProxyHandledException(result);
}
@ -451,10 +453,9 @@ public class GunbotProxyService {
public String checkDefaultKey(String market) {
PoloniexTradingAPIClient tradingAPIClient = getMarketDefaultTradingClient(market);
String result = Failsafe.with(retryPolicy)
return Failsafe.with(retryPolicy)
.onFailedAttempt(this::handleException)
.get(() -> analyzeResult(tradingAPIClient.returnOpenOrders("ALL")));
return result;
}
public String checkTradingKey(String apiKey) {