use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class AdminRouteService method checkIndexStatus.
public String checkIndexStatus(Request request, Response response) {
if (request.queryParams().contains("reponame")) {
String reponame = request.queryParams("reponame");
String reposLocation = Properties.getProperties().getProperty(Values.REPOSITORYLOCATION, Values.DEFAULTREPOSITORYLOCATION);
IndexBaseRepoJob indexBaseRepoJob = new IndexFileRepoJob();
RepoResult repoResult = Singleton.getRepo().getRepoByName(reponame);
String indexStatus = Values.EMPTYSTRING;
if (repoResult != null) {
indexStatus = repoResult.getData().indexStatus;
}
if (indexBaseRepoJob.checkIndexSucess(reposLocation + "/" + reponame) || "success".equals(indexStatus)) {
return "Indexed ✓";
}
if ("indexing".equals(indexStatus)) {
return "Indexing...";
}
}
return Values.EMPTYSTRING;
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ApiRouteService method repositoryIndex.
public ApiResponse repositoryIndex(Request request, Response response) {
if (!this.apiEnabled) {
return new ApiResponse(false, "API not enabled");
}
String repoUrl = request.queryParams("repoUrl");
RepoResult repoByUrl = this.repo.getRepoByUrl(repoUrl);
if (repoByUrl != null) {
this.jobService.forceEnqueue(repoByUrl);
return new ApiResponse(true, "Enqueued repository " + repoUrl);
}
return new ApiResponse(false, "Was unable to find repository " + repoUrl);
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class JobService method forceEnqueue.
@Override
public boolean forceEnqueue() {
if (!Singleton.getSharedService().getBackgroundJobsEnabled()) {
return false;
}
// Get all of the repositories and enqueue them
List<RepoResult> repoResultList = Singleton.getRepo().getAllRepo();
Singleton.getLogger().info("Adding repositories to be indexed. " + repoResultList.size());
for (RepoResult rr : repoResultList) {
enqueueRepository(rr);
}
return true;
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ApiRouteService method getRepo.
public RepoResult getRepo(Request request, Response response) {
if (request.queryParams().contains("reponame")) {
RepoResult reponame = Singleton.getRepo().getRepoByName(request.queryParams("reponame"));
if (reponame == null) {
return null;
}
reponame.setUsername(null);
reponame.setPassword(null);
return reponame;
}
return null;
}
use of com.searchcode.app.model.RepoResult in project searchcode-server by boyter.
the class ApiRouteService method repoAdd.
public ApiResponse repoAdd(Request request, Response response) {
if (!this.apiEnabled) {
return new ApiResponse(false, "API not enabled");
}
String publicKey = request.queryParams("pub");
String signedKey = request.queryParams("sig");
String reponames = request.queryParams("reponame");
String repourls = request.queryParams("repourl");
String repotype = request.queryParams("repotype");
String repousername = request.queryParams("repousername");
String repopassword = request.queryParams("repopassword");
String reposource = request.queryParams("reposource");
String repobranch = request.queryParams("repobranch");
String hmacTypeString = request.queryParams("hmac");
hmacTypeString = hmacTypeString == null ? Values.EMPTYSTRING : hmacTypeString;
if (reponames == null || reponames.trim().equals(Values.EMPTYSTRING)) {
return new ApiResponse(false, "reponame is a required parameter");
}
if (repourls == null || repourls.trim().equals(Values.EMPTYSTRING)) {
return new ApiResponse(false, "repourl is a required parameter");
}
if (repotype == null) {
return new ApiResponse(false, "repotype is a required parameter");
}
if (repousername == null) {
return new ApiResponse(false, "repousername is a required parameter");
}
if (repopassword == null) {
return new ApiResponse(false, "repopassword is a required parameter");
}
if (reposource == null) {
return new ApiResponse(false, "reposource is a required parameter");
}
if (repobranch == null) {
return new ApiResponse(false, "repobranch is a required parameter");
}
if (apiAuth) {
if (publicKey == null || publicKey.trim().equals(Values.EMPTYSTRING)) {
return new ApiResponse(false, "pub is a required parameter");
}
if (signedKey == null || signedKey.trim().equals(Values.EMPTYSTRING)) {
return new ApiResponse(false, "sig is a required parameter");
}
String toValidate = String.format("pub=%s&reponame=%s&repourl=%s&repotype=%s&repousername=%s&repopassword=%s&reposource=%s&repobranch=%s", URLEncoder.encode(publicKey), URLEncoder.encode(reponames), URLEncoder.encode(repourls), URLEncoder.encode(repotype), URLEncoder.encode(repousername), URLEncoder.encode(repopassword), URLEncoder.encode(reposource), URLEncoder.encode(repobranch));
ApiService.HmacType hmacType = hmacTypeString.toLowerCase().equals("sha512") ? ApiService.HmacType.SHA512 : ApiService.HmacType.SHA1;
boolean validRequest = apiService.validateRequest(publicKey, signedKey, toValidate, hmacType);
if (!validRequest) {
Singleton.getLogger().apiLog("Invalid signed repoAdd API call using publicKey=" + publicKey);
return new ApiResponse(false, "invalid signed url");
}
}
if (repobranch.trim().equals(Values.EMPTYSTRING)) {
repobranch = "master";
}
repotype = repotype.trim().toLowerCase();
if (!"git".equals(repotype) && !"svn".equals(repotype) && !"file".equals(repotype)) {
repotype = "git";
}
RepoResult repoResult = this.repo.getRepoByName(reponames);
if (repoResult != null) {
return new ApiResponse(false, "repository name already exists");
}
RepoResult newRepoResult = new RepoResult(-1, reponames, repotype, repourls, repousername, repopassword, reposource, repobranch, "{}");
ValidatorResult validate = this.validatorService.validate(newRepoResult);
if (!validate.isValid) {
return new ApiResponse(false, validate.reason);
}
this.repo.saveRepo(newRepoResult);
Singleton.getLogger().apiLog("Valid signed repoAdd API call using publicKey=" + publicKey);
return new ApiResponse(true, "added repository successfully");
}
Aggregations