Search in sources :

Example 1 with RepoResult

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;
}
Also used : IndexFileRepoJob(com.searchcode.app.jobs.repository.IndexFileRepoJob) IndexBaseRepoJob(com.searchcode.app.jobs.repository.IndexBaseRepoJob) RepoResult(com.searchcode.app.model.RepoResult)

Example 2 with RepoResult

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);
}
Also used : ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse) RepoResult(com.searchcode.app.model.RepoResult)

Example 3 with RepoResult

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;
}
Also used : RepoResult(com.searchcode.app.model.RepoResult)

Example 4 with RepoResult

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;
}
Also used : RepoResult(com.searchcode.app.model.RepoResult)

Example 5 with RepoResult

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");
}
Also used : ValidatorResult(com.searchcode.app.model.ValidatorResult) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse) RepoResult(com.searchcode.app.model.RepoResult)

Aggregations

RepoResult (com.searchcode.app.model.RepoResult)59 Repo (com.searchcode.app.dao.Repo)13 ApiResponse (com.searchcode.app.dto.api.ApiResponse)9 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)9 Request (spark.Request)9 ValidatorResult (com.searchcode.app.model.ValidatorResult)8 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)8 UniqueRepoQueue (com.searchcode.app.util.UniqueRepoQueue)8 Connection (java.sql.Connection)5 PreparedStatement (java.sql.PreparedStatement)5 SQLException (java.sql.SQLException)5 ResultSet (java.sql.ResultSet)4 ArrayList (java.util.ArrayList)3 RepositoryChanged (com.searchcode.app.dto.RepositoryChanged)2 RunningIndexJob (com.searchcode.app.dto.RunningIndexJob)2 File (java.io.File)2 Gson (com.google.gson.Gson)1 Data (com.searchcode.app.dao.Data)1 IndexBaseRepoJob (com.searchcode.app.jobs.repository.IndexBaseRepoJob)1 IndexFileRepoJob (com.searchcode.app.jobs.repository.IndexFileRepoJob)1