use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class AbstractUploadAction method deleteFile.
public ActionResponse<Void> deleteFile() {
if (isTargetUndefined()) {
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, META_DATA_MISSING);
}
if (!authorizationManager.hasUploadDeletePermission(target.getContext(), target.getDescriptorKey())) {
return new ActionResponse<>(HttpStatus.FORBIDDEN, ActionResponse.FORBIDDEN_MESSAGE);
}
try {
String targetFilename = target.getFilename();
File fileToValidate = filePersistenceUtil.createUploadsFile(targetFilename);
filePersistenceUtil.delete(fileToValidate);
} catch (IOException ex) {
logger.error("Error deleting file - file: {}, context: {}, descriptor: {} ", target.getFilename(), target.getContext(), target.getDescriptorKey().getUniversalKey());
logger.error("Error deleting file caused by: ", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, "Error deleting uploaded file from server.");
}
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class AbstractUploadAction method writeFile.
private ActionResponse<Void> writeFile(Resource fileResource) {
try {
String targetFilename = target.getFilename();
String tempFilename = "temp_" + targetFilename;
Optional<UploadValidationFunction> validationFunction = target.getValidationFunction();
if (validationFunction.isPresent()) {
writeFile(tempFilename, fileResource);
File tempFileToValidate = filePersistenceUtil.createUploadsFile(tempFilename);
ValidationResult validationResult = validationFunction.get().apply(tempFileToValidate);
filePersistenceUtil.delete(tempFileToValidate);
if (validationResult.hasErrors()) {
return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResult.combineErrorMessages());
}
}
writeFile(targetFilename, fileResource);
} catch (IOException ex) {
logger.error("Error uploading file - file: {}, context: {}, descriptor: {} ", target.getFilename(), target.getContext(), target.getDescriptorKey().getUniversalKey());
logger.error("Error uploading file caused by: ", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, "Error uploading file to server.");
}
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class AzureBoardsCustomFunctionAction method createActionResponse.
@Override
public ActionResponse<OAuthEndpointResponse> createActionResponse(FieldModel fieldModel, HttpServletContentWrapper servletContentWrapper) {
try {
Optional<FieldModel> savedFieldModel = saveIfValid(fieldModel);
if (!savedFieldModel.isPresent()) {
return createErrorResponse("The configuration is invalid. Please test the configuration.");
}
FieldUtility fieldUtility = createFieldAccessor(savedFieldModel.get());
Optional<String> clientId = fieldUtility.getString(AzureBoardsDescriptor.KEY_CLIENT_ID);
if (!clientId.isPresent()) {
return createErrorResponse("App ID not found.");
}
Optional<String> alertServerUrl = alertWebServerUrlManager.getServerUrl();
if (!alertServerUrl.isPresent()) {
return createErrorResponse("Could not determine the alert server url for the callback.");
}
String requestKey = oAuthRequestValidator.generateRequestKey();
// since we have only one OAuth channel now remove any other requests.
// if we have more OAuth clients then the "remove requests" will have to be removed from here.
// beginning authentication process create the request id at the start.
oAuthRequestValidator.removeRequestsOlderThan5MinutesAgo();
oAuthRequestValidator.addAuthorizationRequest(requestKey);
logger.info("OAuth authorization request created: {}", requestKey);
String authUrl = createAuthURL(clientId.get(), requestKey);
logger.debug("Authenticating Azure OAuth URL: {}", authUrl);
return new ActionResponse<>(HttpStatus.OK, new OAuthEndpointResponse(isAuthenticated(fieldUtility), authUrl, "Authenticating..."));
} catch (Exception ex) {
logger.error("Error activating Azure Boards", ex);
return createErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, "Error activating azure oauth.");
}
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class AzureBoardsCustomFunctionAction method createErrorResponse.
private ActionResponse<OAuthEndpointResponse> createErrorResponse(HttpStatus httpStatus, String errorMessage) {
oAuthRequestValidator.removeAllRequests();
OAuthEndpointResponse oAuthEndpointResponse = new OAuthEndpointResponse(false, "", errorMessage);
return new ActionResponse<>(httpStatus, errorMessage, oAuthEndpointResponse);
}
use of com.synopsys.integration.alert.common.action.ActionResponse in project blackduck-alert by blackducksoftware.
the class CertificateActions method updateWithoutChecks.
@Override
protected ActionResponse<CertificateModel> updateWithoutChecks(Long id, CertificateModel resource) {
try {
Optional<CustomCertificateModel> existingCertificate = certificateAccessor.getCertificate(id);
String logableId = escapeUtil.replaceWithUnderscore(resource.getId());
String loggableAlias = escapeUtil.replaceWithUnderscore(resource.getAlias());
logger.info("Updating certificate with id: {} and alias: {}", logableId, loggableAlias);
if (existingCertificate.isPresent()) {
CertificateModel certificateModel = importCertificate(resource);
return new ActionResponse<>(HttpStatus.NO_CONTENT, certificateModel);
}
logger.error("Certificate with id: {} missing.", logableId);
return new ActionResponse<>(HttpStatus.NOT_FOUND, "Certificate not found.");
} catch (AlertException ex) {
logger.error("Error occurred updating certificate", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
Aggregations