use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class ResultsService method handleCustomIssueTracker.
private void handleCustomIssueTracker(ScanRequest request, ScanResults results) throws MachinaException {
try {
log.info("Issue tracking is custom bean implementation");
issueService.process(results, request);
} catch (HttpClientErrorException e) {
if (e.getRawStatusCode() == HttpStatus.UNAUTHORIZED.value()) {
throw new MachinaRuntimeException("Token is invalid. Please make sure your custom tokens are correct.\n" + e.getMessage());
} else {
throw e;
}
}
}
use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class BitbucketServerController method handleDeleteEvent.
public ResponseEntity<EventResponse> handleDeleteEvent(String body, String uid, PushEvent event, String signature, String product, ControllerRequest controllerRequest) {
log.info("Processing BitBucket DELETE branch request");
if (flowProperties == null) {
log.error("Properties have null values");
throw new MachinaRuntimeException();
}
verifyHmacSignature(body, signature);
String application = event.getRepository().getName();
if (!ScanUtils.empty(controllerRequest.getApplication())) {
application = controllerRequest.getApplication();
}
if (ScanUtils.empty(product)) {
product = ScanRequest.Product.CX.getProduct();
}
BitbucketServerEventHandler handler = BitbucketServerDeleteHandler.builder().controllerRequest(controllerRequest).branchNameForDelete(event.getChanges().get(INDEX_FROM_CHANGES).getRefId()).fromProjectKey(event.getRepository().getProject().getKey()).repositoryName(event.getRepository().getName()).product(product).application(application).webhookPayload(body).configProvider(this).build();
return handler.execute(uid);
}
use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class PostWebhookController method pushRequest.
@PostMapping(value = { ROOT + "/{product}", ROOT }, headers = PUSH)
public ResponseEntity<EventResponse> pushRequest(@RequestBody String body, @PathVariable(value = "product", required = false) String product, @RequestHeader(value = AUTH_HEADER, required = false) String credentials, @RequestParam(value = TOKEN_PARAM, required = false) String token, ControllerRequest controllerRequest) {
String uid = helperService.getShortUid();
MDC.put(FlowConstants.MAIN_MDC_ENTRY, uid);
log.info("Processing BitBucket(Post Web Hook) PUSH request");
validateCredentials(credentials, token);
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
BitbucketPushEvent event;
try {
event = mapper.readValue(body, BitbucketPushEvent.class);
} catch (IOException e) {
throw new MachinaRuntimeException(e);
}
String application = event.getRepository().getSlug();
if (!ScanUtils.empty(controllerRequest.getApplication())) {
application = controllerRequest.getApplication();
}
if (ScanUtils.empty(product)) {
product = ScanRequest.Product.CX.getProduct();
}
if (event.getPush().getChanges() == null || event.getPush().getChanges().length == 0) {
log.warn("Empty commit, nothing to handle.");
return getEmptyCommitMessage();
}
BitbucketPushChange change = event.getPush().getChanges()[CHANGE_INDEX];
if (change.isClosed() && change.getNewState() == null) {
return handleDelete(event, controllerRequest, product, application, body, uid);
}
BitbucketServerEventHandler handler = BitbucketServerPushHandler.builder().controllerRequest(controllerRequest).toSlug(event.getRepository().getSlug()).repositoryName(event.getRepository().getSlug()).fromSlug(event.getRepository().getSlug()).branchFromRef(!change.isCreated() ? change.getOldState().getName() : change.getNewState().getName()).toHash(change.getNewState().getTarget().getHash()).email(event.getActor().getEmailAddress()).fromProjectKey(event.getRepository().getProject().getKey()).toProjectKey(event.getRepository().getProject().getKey()).refId(change.getNewState().getName()).browseUrl(event.getRepository().getLinks().get(BROWSE_LINK_NAME).get(BROWSE_URL_INDEX).getHref()).webhookPayload(body).configProvider(this).product(product).application(application).build();
return handler.execute(uid);
}
use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class ServiceNowTracker method closeIssue.
@Override
public void closeIssue(Issue issue, ScanRequest request) throws MachinaException {
log.info("Executing closeIssue Service Now API call");
Incident incident = getCloseIncident();
try {
String query = String.format("%s%s/%s", properties.getApiUrl(), INCIDENTS, issue.getId());
log.debug("ServiceNow Close Issues URL: {}", query);
restOperations.put(query, incident);
} catch (HttpClientErrorException e) {
log.error("Error closing issue.Details are:" + e.getMessage());
throw new MachinaRuntimeException(e);
}
}
use of com.checkmarx.flow.exception.MachinaRuntimeException in project cx-flow by checkmarx-ltd.
the class ServiceNowTracker method getIncidentByIDConvertToIssue.
/**
* Find Incident By Sys ID and convert into Issue
* @return Issue object.
*/
private Optional<Issue> getIncidentByIDConvertToIssue(String sysId) {
log.debug("Executing getIncidentByIDConvertToIssue");
try {
String apiRequest = String.format("%s%s?sys_id=%s", properties.getApiUrl(), INCIDENTS, sysId);
Optional<Result> res = Optional.ofNullable(restOperations.getForObject(apiRequest, Result.class));
if (res.isPresent()) {
return res.get().getIncidents().stream().map(i -> this.mapToIssue(i)).findFirst();
}
} catch (RestClientException e) {
log.error("Error occurred while fetching ServiceNow Issue");
log.error(ExceptionUtils.getStackTrace(e));
throw new MachinaRuntimeException();
}
return Optional.empty();
}
Aggregations