Search in sources :

Example 1 with InvalidRepositoryPathException

use of com.walmartlabs.concord.server.repository.InvalidRepositoryPathException in project concord by walmartlabs.

the class ConsoleService method testRepository.

@POST
@Path("/repository/test")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public boolean testRepository(RepositoryTestRequest req) {
    OrganizationEntry org = orgManager.assertAccess(null, req.getOrgName(), false);
    ProjectEntry project = projectAccessManager.assertAccess(org.getId(), null, req.getProjectName(), ResourceAccessLevel.READER, false);
    try {
        String secretName = secretDao.getName(req.getSecretId());
        repositoryManager.testConnection(project.getOrgId(), project.getId(), req.getUrl(), req.getBranch(), req.getCommitId(), req.getPath(), secretName);
        return true;
    } catch (InvalidRepositoryPathException e) {
        Map<String, String> m = new HashMap<>();
        m.put("message", "Repository validation error");
        m.put("level", "WARN");
        m.put("details", e.getMessage());
        throw new ConcordApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(m).build());
    } catch (Exception e) {
        String msg;
        Throwable t = e;
        while (true) {
            msg = t.getMessage();
            t = t.getCause();
            if (t == null) {
                break;
            }
        }
        if (msg == null) {
            msg = "Repository test error";
        }
        throw new ConcordApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN).entity(msg).build());
    }
}
Also used : ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) InvalidRepositoryPathException(com.walmartlabs.concord.server.repository.InvalidRepositoryPathException) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) InvalidRepositoryPathException(com.walmartlabs.concord.server.repository.InvalidRepositoryPathException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Aggregations

OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)1 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)1 InvalidRepositoryPathException (com.walmartlabs.concord.server.repository.InvalidRepositoryPathException)1 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)1 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)1 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)1