use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class AbstractResourceActions method test.
public final ValidationActionResponse test(T resource) {
if (!authorizationManager.hasExecutePermission(context, descriptorKey)) {
logger.debug(String.format(FORBIDDEN_ACTION_FORMAT, "Test"));
ValidationResponseModel responseModel = ValidationResponseModel.generalError(ActionResponse.FORBIDDEN_MESSAGE);
return new ValidationActionResponse(HttpStatus.FORBIDDEN, responseModel);
}
ValidationActionResponse validationResponse = validateWithoutChecks(resource);
if (validationResponse.isError()) {
return ValidationActionResponse.createOKResponseWithContent(validationResponse);
}
return testWithoutChecks(resource);
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class ConfigurationValidationHelperTest method testValidationWithError.
@Test
public void testValidationWithError() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ConfigurationValidationHelper validationHelper = new ConfigurationValidationHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = validationHelper.validate(() -> ValidationResponseModel.generalError("generalError"));
ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class TestHelperConfigurationTest method testMessageSuccess.
@Test
public void testMessageSuccess() {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = new ChannelKey("channel_key", "channel-display-name");
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
ConfigurationTestHelper testHelper = new ConfigurationTestHelper(authorizationManager, ConfigContextEnum.GLOBAL, descriptorKey);
ValidationActionResponse response = testHelper.test(() -> new ValidationActionResponse(HttpStatus.OK, ValidationResponseModel.success()), () -> ConfigurationTestResult.success("Success"));
ValidationResponseModel validationResponseModel = response.getContent().orElseThrow(() -> new IllegalStateException("Validation content missing"));
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertFalse(validationResponseModel.hasErrors());
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class ConfigurationCrudHelper method create.
public <T extends Obfuscated<T>> ActionResponse<T> create(Supplier<ValidationResponseModel> validator, BooleanSupplier existingModelSupplier, ThrowingSupplier<T, Exception> modelCreator) {
String actionName = "create";
logger.trace(ACTION_CALLED_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
if (!authorizationManager.hasCreatePermission(context, descriptorKey)) {
logger.trace(ACTION_MISSING_PERMISSIONS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return ActionResponse.createForbiddenResponse();
}
ValidationResponseModel validationResponse = validator.get();
if (validationResponse.hasErrors()) {
logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResponse.getMessage());
}
boolean configurationExists = existingModelSupplier.getAsBoolean();
if (configurationExists) {
logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, "A configuration with this name already exists.");
}
try {
return new ActionResponse<>(HttpStatus.OK, modelCreator.get().obfuscate());
} catch (AlertConfigurationException ex) {
logger.trace(ACTION_BAD_REQUEST_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
return new ActionResponse<>(HttpStatus.BAD_REQUEST, String.format("Error creating config: %s", ex.getMessage()));
} catch (Exception ex) {
logger.error("Error creating config:", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error creating config: %s", ex.getMessage()));
} finally {
logger.trace(ACTION_SUCCESS_TEMPLATE, descriptorKey.getUniversalKey(), actionName);
}
}
use of com.synopsys.integration.alert.api.common.model.ValidationResponseModel in project blackduck-alert by blackducksoftware.
the class EnvironmentVariableHandler method updateFromEnvironment.
public EnvironmentProcessingResult updateFromEnvironment() {
boolean configurationMissing = configurationMissingCheck();
if (configurationMissing) {
T configurationModel = configureModel();
ValidationResponseModel validationResponseModel = validateConfiguration(configurationModel);
if (validationResponseModel.hasErrors()) {
logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
for (AlertFieldStatus errorStatus : validationResponseModel.getErrors().values()) {
logger.error("Field: '{}' failed with the error: {}", errorStatus.getFieldName(), errorStatus.getFieldMessage());
}
return EnvironmentProcessingResult.empty();
}
EnvironmentProcessingResult processingResult = buildProcessingResult(configurationModel.obfuscate());
if (processingResult.hasValues()) {
saveConfiguration(configurationModel, processingResult);
}
return processingResult;
}
return EnvironmentProcessingResult.empty();
}
Aggregations