Search in sources :

Example 1 with SettingsProxyModel

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

the class ProxyManager method createProxyInfoForHost.

public ProxyInfo createProxyInfoForHost(String proxyHostCandidate) throws IllegalArgumentException {
    Optional<SettingsProxyModel> optionalSettingsConfiguration = settingsUtility.getConfiguration();
    if (optionalSettingsConfiguration.isPresent()) {
        SettingsProxyModel settingsProxyModel = optionalSettingsConfiguration.get();
        List<String> nonProxyHosts = settingsProxyModel.getNonProxyHosts().orElse(List.of());
        NonProxyHostChecker nonProxyHostChecker = new NonProxyHostChecker(nonProxyHosts);
        if (StringUtils.isNotBlank(proxyHostCandidate) && nonProxyHostChecker.isNonProxyHost(proxyHostCandidate)) {
            return ProxyInfo.NO_PROXY_INFO;
        }
        return createProxyInfo(settingsProxyModel);
    }
    return ProxyInfo.NO_PROXY_INFO;
}
Also used : SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)

Example 2 with SettingsProxyModel

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

the class SettingsProxyConfigAccessor method createConfigModel.

private SettingsProxyModel createConfigModel(SettingsProxyConfigurationEntity proxyConfiguration) {
    SettingsProxyModel newModel = new SettingsProxyModel();
    String createdAtFormatted = null;
    String lastUpdatedFormatted = null;
    if (null != proxyConfiguration) {
        createdAtFormatted = DateUtils.formatDate(proxyConfiguration.getCreatedAt(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
        if (null != proxyConfiguration.getLastUpdated()) {
            lastUpdatedFormatted = DateUtils.formatDate(proxyConfiguration.getLastUpdated(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
        }
        newModel.setId(String.valueOf(proxyConfiguration.getConfigurationId()));
        newModel.setName(proxyConfiguration.getName());
        newModel.setProxyHost(proxyConfiguration.getHost());
        newModel.setProxyPort(proxyConfiguration.getPort());
        newModel.setProxyUsername(proxyConfiguration.getUsername());
        String proxyPassword = proxyConfiguration.getPassword();
        boolean doesPasswordExist = StringUtils.isNotBlank(proxyPassword);
        newModel.setIsProxyPasswordSet(doesPasswordExist);
        if (doesPasswordExist) {
            newModel.setProxyPassword(encryptionUtility.decrypt(proxyPassword));
        }
        newModel.setNonProxyHosts(getNonProxyHosts(proxyConfiguration.getNonProxyHosts()));
    }
    newModel.setCreatedAt(createdAtFormatted);
    newModel.setLastUpdated(lastUpdatedFormatted);
    return newModel;
}
Also used : SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)

Example 3 with SettingsProxyModel

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

the class ProxyConfigurationModelSaveActions method convertModelAndPerformAction.

private void convertModelAndPerformAction(ConfigurationModel configurationModel, Function<SettingsProxyModel, ActionResponse<SettingsProxyModel>> configAction) {
    Optional<SettingsProxyModel> settingsProxyModel = proxyFieldModelConverter.convert(configurationModel);
    if (settingsProxyModel.isPresent()) {
        SettingsProxyModel model = settingsProxyModel.get();
        model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
        configAction.apply(model);
    }
}
Also used : SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)

Example 4 with SettingsProxyModel

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

the class SettingsProxyControllerTestIT method testValidate.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testValidate() throws Exception {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    String url = AlertRestConstants.SETTINGS_PROXY_PATH + "/validate";
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(new URI(url)).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(settingsProxyModel)).contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) URI(java.net.URI) WithMockUser(org.springframework.security.test.context.support.WithMockUser) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with SettingsProxyModel

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

the class SettingsProxyControllerTestIT method createSettingsProxyModel.

private SettingsProxyModel createSettingsProxyModel(String configurationName) {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    settingsProxyModel.setName(configurationName);
    settingsProxyModel.setProxyHost(HOST);
    settingsProxyModel.setProxyPort(PORT);
    settingsProxyModel.setProxyUsername(USERNAME);
    settingsProxyModel.setProxyPassword(PASSWORD);
    settingsProxyModel.setNonProxyHosts(List.of("hosts"));
    return settingsProxyModel;
}
Also used : SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)

Aggregations

SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)44 Test (org.junit.jupiter.api.Test)32 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)18 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)12 SettingsProxyTestAction (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction)8 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)7 URI (java.net.URI)6 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)6 SettingsProxyCrudActions (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions)5 SettingsProxyConfigAccessor (com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor)5 NonProxyHostsConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository)5 SettingsProxyConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository)5 UUID (java.util.UUID)5 WithMockUser (org.springframework.security.test.context.support.WithMockUser)5 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 SettingsProxyConfigurationEntity (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity)2 AssertionFailedError (org.opentest4j.AssertionFailedError)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 SettingsUtility (com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility)1 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)1