Search in sources :

Example 16 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class AlertStartupInitializer method saveAction.

private Collection<ConfigurationFieldModel> saveAction(DescriptorKey descriptorKey, Collection<ConfigurationFieldModel> configurationFieldModels) throws AlertException {
    Map<String, FieldValueModel> fieldValueModelMap = modelConverter.convertToFieldValuesMap(configurationFieldModels);
    FieldModel fieldModel = new FieldModel(descriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), fieldValueModelMap);
    FieldModel savedFieldModel = fieldModelProcessor.performBeforeSaveAction(fieldModel);
    return modelConverter.convertToConfigurationFieldModelMap(savedFieldModel).values();
}
Also used : DefinedFieldModel(com.synopsys.integration.alert.common.persistence.model.DefinedFieldModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel)

Example 17 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class ConfigurationOverridesStartupComponent method initialize.

@Override
protected void initialize() {
    try {
        FieldModel fieldModel = getFieldModel();
        checkAndDisableLdapAuthentication(fieldModel);
        checkAndDisableSamlAuthentication(fieldModel);
        checkAndResetDefaultAdminPassword();
        if (StringUtils.isBlank(fieldModel.getId())) {
            configUtility.save(fieldModel);
        } else {
            configUtility.update(Long.valueOf(fieldModel.getId()), fieldModel);
        }
    } catch (AlertException | NumberFormatException ex) {
        logger.error("Error performing configuration overrides.", ex);
    }
}
Also used : FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Example 18 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class BlackDuckGlobalConfigurationFieldModelValidatorTest method nonUniqueName.

@Test
public void nonUniqueName() {
    String duplicateName = "duplicateName";
    Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
    FieldValueModel apiKeyFieldValueModel = new FieldValueModel(List.of(duplicateName), true);
    defaultKeyToValues.put(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, apiKeyFieldValueModel);
    FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
    ConfigurationFieldModel configurationFieldModel = Mockito.mock(ConfigurationFieldModel.class);
    Mockito.when(configurationFieldModel.getFieldValue()).thenReturn(Optional.of(duplicateName));
    ConfigurationModel configurationModel = Mockito.mock(ConfigurationModel.class);
    Mockito.when(configurationModel.getDescriptorContext()).thenReturn(ConfigContextEnum.GLOBAL);
    Mockito.when(configurationModel.getField(Mockito.any())).thenReturn(Optional.of(configurationFieldModel));
    ConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
    Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorType(Mockito.any())).thenReturn(List.of(configurationModel));
    BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(configurationModelConfigurationAccessor);
    Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
    assertEquals(1, alertFieldStatuses.size());
    AlertFieldStatus alertFieldStatus = alertFieldStatuses.stream().findFirst().orElse(null);
    assertNotNull(alertFieldStatus);
    assertEquals(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, alertFieldStatus.getFieldName());
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) ConfigurationModelConfigurationAccessor(com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Test(org.junit.jupiter.api.Test)

Example 19 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.

the class BlackDuckGlobalConfigurationFieldModelValidatorTest method verifyValidConfiguration.

/*
     * Provider config name: Required, no duplicate names
     * Url: required, valid Url
     * API key: required, Specific length
     * Timeout: required, long timeout warning, < 0 timeout error
     */
@Test
public void verifyValidConfiguration() {
    Map<String, FieldValueModel> defaultKeyToValues = createDefaultKeyToValues();
    FieldModel fieldModel = new FieldModel(new BlackDuckProviderKey().getUniversalKey(), ConfigContextEnum.GLOBAL.name(), defaultKeyToValues);
    BlackDuckGlobalConfigurationFieldModelValidator blackDuckGlobalConfigurationValidator = new BlackDuckGlobalConfigurationFieldModelValidator(createDefaultConfigurationAccessor());
    Set<AlertFieldStatus> alertFieldStatuses = blackDuckGlobalConfigurationValidator.validate(fieldModel);
    assertEquals(0, alertFieldStatuses.size());
}
Also used : BlackDuckProviderKey(com.synopsys.integration.alert.descriptor.api.BlackDuckProviderKey) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldValueModel(com.synopsys.integration.alert.common.rest.model.FieldValueModel) Test(org.junit.jupiter.api.Test)

Example 20 with FieldModel

use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-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.");
    }
}
Also used : OAuthEndpointResponse(com.synopsys.integration.alert.common.descriptor.config.field.endpoint.oauth.OAuthEndpointResponse) ConfigurationFieldModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel) FieldModel(com.synopsys.integration.alert.common.rest.model.FieldModel) FieldUtility(com.synopsys.integration.alert.common.persistence.accessor.FieldUtility) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Aggregations

FieldModel (com.synopsys.integration.alert.common.rest.model.FieldModel)73 ConfigurationFieldModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationFieldModel)43 FieldValueModel (com.synopsys.integration.alert.common.rest.model.FieldValueModel)31 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)28 Test (org.junit.jupiter.api.Test)26 HashMap (java.util.HashMap)25 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)21 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)21 ConfigurationFieldModelConverter (com.synopsys.integration.alert.common.persistence.util.ConfigurationFieldModelConverter)19 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)18 ConfigurationModelConfigurationAccessor (com.synopsys.integration.alert.common.persistence.accessor.ConfigurationModelConfigurationAccessor)18 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)15 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)14 FieldUtility (com.synopsys.integration.alert.common.persistence.accessor.FieldUtility)13 JobFieldModel (com.synopsys.integration.alert.common.rest.model.JobFieldModel)13 List (java.util.List)13 Autowired (org.springframework.beans.factory.annotation.Autowired)13 DescriptorAccessor (com.synopsys.integration.alert.common.persistence.accessor.DescriptorAccessor)12 JobProviderProjectFieldModel (com.synopsys.integration.alert.common.rest.model.JobProviderProjectFieldModel)12 MultiFieldModel (com.synopsys.integration.alert.common.rest.model.MultiFieldModel)12