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());
}
}
Aggregations