Fix checkSetup page and add checkSetupSecret endpoints to show apikey and secret the proxy is seeing
This commit is contained in:
parent
07a997b7a4
commit
768736abfd
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<groupId>nl.komtek</groupId>
|
<groupId>nl.komtek</groupId>
|
||||||
<artifactId>GunbotProxyCommunity</artifactId>
|
<artifactId>GunbotProxyCommunity</artifactId>
|
||||||
<version>0.9.9</version>
|
<version>0.9.9.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>GunbotProxyCommunity</name>
|
<name>GunbotProxyCommunity</name>
|
||||||
|
|
|
@ -14,7 +14,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.HashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +31,7 @@ public class CheckSetupController {
|
||||||
|
|
||||||
@RequestMapping("/checkSetup/**")
|
@RequestMapping("/checkSetup/**")
|
||||||
public ModelAndView checkSetup(ModelMap modelMap) {
|
public ModelAndView checkSetup(ModelMap modelMap) {
|
||||||
modelMap.put("setupData", setupData());
|
modelMap.put("setupData", setupData(false));
|
||||||
return new ModelAndView("setupData", modelMap);
|
return new ModelAndView("setupData", modelMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,30 +40,44 @@ public class CheckSetupController {
|
||||||
public String checkSetupLinux() throws IOException {
|
public String checkSetupLinux() throws IOException {
|
||||||
StringBuilder stringData = new StringBuilder();
|
StringBuilder stringData = new StringBuilder();
|
||||||
stringData.append("\n\n");
|
stringData.append("\n\n");
|
||||||
Map<String, String> setupData = setupData();
|
Map<String, String> setupData = setupData(false);
|
||||||
for (Map.Entry entry : setupData.entrySet()) {
|
setupData.forEach((key, value) -> stringData.append(String.format("%s -- %s \n", key, value)));
|
||||||
stringData.append(String.format("%s -- %s \n", entry.getKey(), entry.getValue()));
|
|
||||||
}
|
|
||||||
return stringData.toString();
|
return stringData.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> setupData() {
|
@RequestMapping("/checkSetupSecret/**")
|
||||||
Map<String, String> setupData = new HashMap<>();
|
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()) {
|
if (!gunbotProxyService.isUsingMultipleMarkets()) {
|
||||||
checkApiKeysForMarket(setupData, "");
|
checkApiKeysForMarket(setupData, "", showSecret);
|
||||||
} else {
|
} else {
|
||||||
if (gunbotProxyService.isActiveMarket("BTC")) {
|
if (gunbotProxyService.isActiveMarket("BTC")) {
|
||||||
checkApiKeysForMarket(setupData, "BTC_");
|
checkApiKeysForMarket(setupData, "BTC_", showSecret);
|
||||||
}
|
}
|
||||||
if (gunbotProxyService.isActiveMarket("ETH")) {
|
if (gunbotProxyService.isActiveMarket("ETH")) {
|
||||||
checkApiKeysForMarket(setupData, "ETH_");
|
checkApiKeysForMarket(setupData, "ETH_", showSecret);
|
||||||
}
|
}
|
||||||
if (gunbotProxyService.isActiveMarket("XMR")) {
|
if (gunbotProxyService.isActiveMarket("XMR")) {
|
||||||
checkApiKeysForMarket(setupData, "XMR_");
|
checkApiKeysForMarket(setupData, "XMR_", showSecret);
|
||||||
}
|
}
|
||||||
if (gunbotProxyService.isActiveMarket("USDT")) {
|
if (gunbotProxyService.isActiveMarket("USDT")) {
|
||||||
checkApiKeysForMarket(setupData, "USDT_");
|
checkApiKeysForMarket(setupData, "USDT_", showSecret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//check if hostfile was setup correctly
|
//check if hostfile was setup correctly
|
||||||
|
@ -107,7 +121,7 @@ public class CheckSetupController {
|
||||||
return setupData;
|
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 keyName = String.format("default_%sapiKey", market);
|
||||||
String secretName = String.format("default_%sapiSecret", market);
|
String secretName = String.format("default_%sapiSecret", market);
|
||||||
try {
|
try {
|
||||||
|
@ -116,6 +130,10 @@ public class CheckSetupController {
|
||||||
if (StringUtils.isEmpty(apiKey) || StringUtils.isEmpty(apiSecret)) {
|
if (StringUtils.isEmpty(apiKey) || StringUtils.isEmpty(apiSecret)) {
|
||||||
setupData.put(keyName, String.format("Please setup %s and %s", keyName, secretName));
|
setupData.put(keyName, String.format("Please setup %s and %s", keyName, secretName));
|
||||||
} else {
|
} 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("_", "");
|
String theMarket = market.replace("_", "");
|
||||||
if (StringUtils.isEmpty(theMarket)) {
|
if (StringUtils.isEmpty(theMarket)) {
|
||||||
theMarket = "default";
|
theMarket = "default";
|
||||||
|
@ -124,7 +142,7 @@ public class CheckSetupController {
|
||||||
setupData.put(keyName, "Looking good!");
|
setupData.put(keyName, "Looking good!");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
setupData.put(keyName, e.getMessage());
|
setupData.put(keyName + "", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i <= 10; i++) {
|
for (int i = 1; i <= 10; i++) {
|
||||||
|
@ -140,6 +158,10 @@ public class CheckSetupController {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
try {
|
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)) {
|
if (StringUtils.isEmpty(market)) {
|
||||||
gunbotProxyService.analyzeResult(gunbotProxyService.checkTradingKey(apiKey));
|
gunbotProxyService.analyzeResult(gunbotProxyService.checkTradingKey(apiKey));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -408,6 +408,8 @@ public class GunbotProxyService {
|
||||||
throw new ProxyHandledException("No value was returned");
|
throw new ProxyHandledException("No value was returned");
|
||||||
} else if (result.contains("Nonce")) {
|
} else if (result.contains("Nonce")) {
|
||||||
throw new ProxyHandledException("nonce error: " + result);
|
throw new ProxyHandledException("nonce error: " + result);
|
||||||
|
} else if (result.contains("Invalid API")) {
|
||||||
|
throw new ProxyHandledException(result);
|
||||||
} else if (result.contains("Connection timed out")) {
|
} else if (result.contains("Connection timed out")) {
|
||||||
throw new ProxyHandledException(result);
|
throw new ProxyHandledException(result);
|
||||||
}
|
}
|
||||||
|
@ -451,10 +453,9 @@ public class GunbotProxyService {
|
||||||
|
|
||||||
public String checkDefaultKey(String market) {
|
public String checkDefaultKey(String market) {
|
||||||
PoloniexTradingAPIClient tradingAPIClient = getMarketDefaultTradingClient(market);
|
PoloniexTradingAPIClient tradingAPIClient = getMarketDefaultTradingClient(market);
|
||||||
String result = Failsafe.with(retryPolicy)
|
return Failsafe.with(retryPolicy)
|
||||||
.onFailedAttempt(this::handleException)
|
.onFailedAttempt(this::handleException)
|
||||||
.get(() -> analyzeResult(tradingAPIClient.returnOpenOrders("ALL")));
|
.get(() -> analyzeResult(tradingAPIClient.returnOpenOrders("ALL")));
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String checkTradingKey(String apiKey) {
|
public String checkTradingKey(String apiKey) {
|
||||||
|
|
Loading…
Reference in New Issue