Search in sources :

Example 6 with ConfigurationProperty

use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.

the class PluggableTaskTest method postConstructShouldDoNothingForAInvalidConfigurationProperty.

@Test
public void postConstructShouldDoNothingForAInvalidConfigurationProperty() throws Exception {
    TaskPreference taskPreference = mock(TaskPreference.class);
    ConfigurationProperty configurationProperty = ConfigurationPropertyMother.create("KEY1");
    Configuration configuration = new Configuration(configurationProperty);
    PluggableTaskConfigStore.store().setPreferenceFor("abc.def", taskPreference);
    TaskConfig taskConfig = new TaskConfig();
    when(taskPreference.getConfig()).thenReturn(taskConfig);
    PluggableTask task = new PluggableTask(new PluginConfiguration("abc.def", "1"), configuration);
    assertFalse(configurationProperty.isSecure());
    task.applyPluginMetadata();
    assertFalse(configurationProperty.isSecure());
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 7 with ConfigurationProperty

use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.

the class PluggableTaskTest method postConstructShouldDoNothingForPluggableTaskWithoutCorrespondingPlugin.

@Test
public void postConstructShouldDoNothingForPluggableTaskWithoutCorrespondingPlugin() throws Exception {
    ConfigurationProperty configurationProperty = ConfigurationPropertyMother.create("KEY1");
    Configuration configuration = new Configuration(configurationProperty);
    PluggableTask task = new PluggableTask(new PluginConfiguration("abc.def", "1"), configuration);
    assertFalse(configurationProperty.isSecure());
    task.applyPluginMetadata();
    assertFalse(configurationProperty.isSecure());
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Test(org.junit.Test)

Example 8 with ConfigurationProperty

use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.

the class PluggableTaskTest method testConfigAsMap.

@Test
public void testConfigAsMap() throws Exception {
    PluginConfiguration pluginConfiguration = new PluginConfiguration("test-plugin-id", "13.4");
    GoCipher cipher = new GoCipher();
    List<String> keys = Arrays.asList("Avengers 1", "Avengers 2", "Avengers 3", "Avengers 4");
    List<String> values = Arrays.asList("Iron man", "Hulk", "Thor", "Captain America");
    Configuration configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey(keys.get(0)), new ConfigurationValue(values.get(0))), new ConfigurationProperty(new ConfigurationKey(keys.get(1)), new ConfigurationValue(values.get(1))), new ConfigurationProperty(new ConfigurationKey(keys.get(2)), new ConfigurationValue(values.get(2))), new ConfigurationProperty(new ConfigurationKey(keys.get(3)), null, new EncryptedConfigurationValue(cipher.encrypt(values.get(3))), cipher));
    PluggableTask task = new PluggableTask(pluginConfiguration, configuration);
    Map<String, Map<String, String>> configMap = task.configAsMap();
    assertThat(configMap.keySet().size(), is(keys.size()));
    assertThat(configMap.values().size(), is(values.size()));
    assertThat(configMap.keySet().containsAll(keys), is(true));
    for (int i = 0; i < keys.size(); i++) {
        assertThat(configMap.get(keys.get(i)).get(PluggableTask.VALUE_KEY), is(values.get(i)));
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) Map(java.util.Map) Test(org.junit.Test)

Example 9 with ConfigurationProperty

use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.

the class PluggableTaskTest method shouldAddConfigurationProperties.

@Test
public void shouldAddConfigurationProperties() {
    List<ConfigurationProperty> configurationProperties = Arrays.asList(ConfigurationPropertyMother.create("key", "value", "encValue"), new ConfigurationProperty());
    PluginConfiguration pluginConfiguration = new PluginConfiguration("github.pr", "1.1");
    TaskPreference taskPreference = mock(TaskPreference.class);
    TaskConfig taskConfig = new TaskConfig();
    Configuration configuration = new Configuration();
    Property property = new Property("key");
    property.with(Property.SECURE, false);
    PluggableTaskConfigStore.store().setPreferenceFor(pluginConfiguration.getId(), taskPreference);
    TaskConfigProperty taskConfigProperty = taskConfig.addProperty("key");
    when(taskPreference.getConfig()).thenReturn(taskConfig);
    PluggableTask pluggableTask = new PluggableTask(pluginConfiguration, configuration);
    pluggableTask.addConfigurations(configurationProperties);
    assertThat(configuration.size(), is(2));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) TaskProperty(com.thoughtworks.go.domain.TaskProperty) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 10 with ConfigurationProperty

use of com.thoughtworks.go.domain.config.ConfigurationProperty in project gocd by gocd.

the class PackageRepositoryService method performPluginValidationsFor.

void performPluginValidationsFor(final PackageRepository packageRepository) {
    if (!validatePluginId(packageRepository)) {
        return;
    }
    for (ConfigurationProperty configurationProperty : packageRepository.getConfiguration()) {
        String key = configurationProperty.getConfigurationKey().getName();
        String pluginId = packageRepository.getPluginConfiguration().getId();
        if (repositoryMetadataStore.hasOption(pluginId, key, PackageConfiguration.REQUIRED)) {
            if (configurationProperty.getValue().isEmpty()) {
                configurationProperty.addErrorAgainstConfigurationValue(localizer.localize("MANDATORY_CONFIGURATION_FIELD"));
            }
        }
    }
    ValidationResult validationResult = packageRepositoryExtension.isRepositoryConfigurationValid(packageRepository.getPluginConfiguration().getId(), populateConfiguration(packageRepository.getConfiguration()));
    for (ValidationError error : validationResult.getErrors()) {
        packageRepository.addConfigurationErrorFor(error.getKey(), error.getMessage());
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Aggregations

ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)74 Test (org.junit.Test)41 Configuration (com.thoughtworks.go.domain.config.Configuration)28 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)27 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)27 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)20 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)16 Property (com.thoughtworks.go.plugin.api.config.Property)12 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)10 GoCipher (com.thoughtworks.go.security.GoCipher)9 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)8 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)8 HashMap (java.util.HashMap)6 Map (java.util.Map)6 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)5 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)5 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)4 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 ArrayList (java.util.ArrayList)4