parent
6f34377949
commit
697e5b9ef3
|
@ -54,6 +54,12 @@ public class AppConfig {
|
|||
@Value("${websocket.addr}")
|
||||
private String serverUrl;
|
||||
|
||||
@Value("${gitUsername}")
|
||||
private String gitUsername;
|
||||
|
||||
@Value("${gitPassword}")
|
||||
private String gitPassword;
|
||||
|
||||
public String getServerUrl() {
|
||||
return serverUrl;
|
||||
}
|
||||
|
@ -125,4 +131,20 @@ public class AppConfig {
|
|||
public void setSecretKey(String secretKey) {
|
||||
this.secretKey = secretKey;
|
||||
}
|
||||
|
||||
public String getGitUsername() {
|
||||
return gitUsername;
|
||||
}
|
||||
|
||||
public void setGitUsername(String gitUsername) {
|
||||
this.gitUsername = gitUsername;
|
||||
}
|
||||
|
||||
public String getGitPassword() {
|
||||
return gitPassword;
|
||||
}
|
||||
|
||||
public void setGitPassword(String gitPassword) {
|
||||
this.gitPassword = gitPassword;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.educoder.bridge.common.utils;
|
|||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -302,4 +303,13 @@ public class GameHelper {
|
|||
timeCost.put(period, cost);
|
||||
JedisUtil.set(key, timeCost.toJSONString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取加权限的gitURL:
|
||||
* 加上超级用户的用户名密码
|
||||
* 形如:https://edugit:xinedugit@bdgit.educoder.net/educoder/mnf6b7z3.git
|
||||
*/
|
||||
public static String appendGitUrlWithUser(String gitUsername, String gitPassword, String gitUrl) {
|
||||
return new StringBuffer(gitUrl).insert(gitUrl.indexOf("//") + 2, gitUsername + ":" + gitPassword + "@").toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,7 @@ public class GameController extends BaseController {
|
|||
|
||||
// 对当前TPI,从TPM clone 版本库
|
||||
tpmGitURL = Base64Util.decode(tpmGitURL);
|
||||
tpmGitURL = GameHelper.appendGitUrlWithUser(appConfig.getGitUsername(), appConfig.getGitPassword(), tpmGitURL);
|
||||
gameService.gitClone(tpiWorkSpace, tpmGitURL, "remote_origin", tpiRepoName);
|
||||
|
||||
response.put("code", 0);
|
||||
|
@ -117,6 +118,7 @@ public class GameController extends BaseController {
|
|||
|
||||
// 参数处理
|
||||
tpiGitURL = Base64Util.decode(tpiGitURL);
|
||||
tpiGitURL = GameHelper.appendGitUrlWithUser(appConfig.getGitUsername(), appConfig.getGitPassword(), tpiGitURL);
|
||||
needPortMapping = needPortMapping == null ? 0 : needPortMapping;
|
||||
timeLimit = timeLimit == null ? Integer.parseInt(appConfig.getDefaultTimeLimit()) : timeLimit;
|
||||
testCases = Base64Util.decode(testCases);
|
||||
|
@ -409,7 +411,9 @@ public class GameController extends BaseController {
|
|||
JSONObject response = new JSONObject();
|
||||
|
||||
tpiGitURL = Base64Util.decode(tpiGitURL);
|
||||
tpiGitURL = GameHelper.appendGitUrlWithUser(appConfig.getGitUsername(), appConfig.getGitPassword(), tpiGitURL);
|
||||
tpmGitURL = Base64Util.decode(tpmGitURL);
|
||||
tpmGitURL = GameHelper.appendGitUrlWithUser(appConfig.getGitUsername(), appConfig.getGitPassword(), tpmGitURL);
|
||||
String tpiRepoName = GameHelper.getRepoName(tpiGitURL);
|
||||
String path = appConfig.getWorkspace() + File.separator + "myshixun_" + tpiID;
|
||||
|
||||
|
|
|
@ -277,10 +277,6 @@ public class GameService {
|
|||
// 从URL中取仓库名
|
||||
String tpiRepoName = GameHelper.getRepoName(tpiGitURL);
|
||||
|
||||
// 获取加权限的gitURL,获取push权限
|
||||
String user = "educoder:" + identifier + "@";
|
||||
tpiGitURL = new StringBuffer(tpiGitURL).insert(7, user).toString();
|
||||
|
||||
// push之前,先判断origin主机是否存在,若不存在,则先创建
|
||||
String output = ShellUtil.execute("cd " + path + "/" + tpiRepoName + " && git remote | grep ^origin$");
|
||||
if (StringUtils.isEmpty(output)) {
|
||||
|
|
|
@ -53,4 +53,8 @@ gitIP=10.9.54.50
|
|||
outputSize=65535
|
||||
|
||||
#认证密钥
|
||||
secretKey=priEn3UwXfJs3PmyXnSG
|
||||
secretKey=priEn3UwXfJs3PmyXnSG
|
||||
|
||||
#git用户名及密码
|
||||
gitUsername=edugit
|
||||
gitPassword=xinedugit#
|
Loading…
Reference in New Issue