Search in sources :

Example 16 with ConfigurationProperty

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

the class PluginProfileCommand method isValidForCreateOrUpdate.

protected boolean isValidForCreateOrUpdate(CruiseConfig preprocessedConfig) {
    preprocessedProfile = findExistingProfile(preprocessedConfig);
    preprocessedProfile.validate(null);
    ValidationResult result = validateUsingExtension(preprocessedProfile.getPluginId(), profile.getConfigurationAsMap(true));
    if (!result.isSuccessful()) {
        for (ValidationError validationError : result.getErrors()) {
            ConfigurationProperty property = preprocessedProfile.getProperty(validationError.getKey());
            if (property == null) {
                profile.addNewConfiguration(validationError.getKey(), false);
                preprocessedProfile.addNewConfiguration(validationError.getKey(), false);
                property = preprocessedProfile.getProperty(validationError.getKey());
            }
            property.addError(validationError.getKey(), validationError.getMessage());
        }
    }
    if (preprocessedProfile.errors().isEmpty()) {
        getPluginProfiles(preprocessedConfig).validate(null);
        BasicCruiseConfig.copyErrors(preprocessedProfile, profile);
        return preprocessedProfile.getAllErrors().isEmpty() && profile.errors().isEmpty();
    }
    BasicCruiseConfig.copyErrors(preprocessedProfile, profile);
    return false;
}
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)

Example 17 with ConfigurationProperty

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

the class ConfigRepoPlugin method getCrConfigurations.

public static List<CRConfigurationProperty> getCrConfigurations(Configuration configuration) {
    List<CRConfigurationProperty> config = new ArrayList<>();
    for (ConfigurationProperty prop : configuration) {
        String configKeyName = prop.getConfigKeyName();
        if (!prop.isSecure())
            config.add(new CRConfigurationProperty(configKeyName, prop.getValue(), null));
        else {
            CRConfigurationProperty crProp = new CRConfigurationProperty(configKeyName, null, prop.getEncryptedValue());
            config.add(crProp);
        }
    }
    return config;
}
Also used : CRConfigurationProperty(com.thoughtworks.go.plugin.access.configrepo.contract.CRConfigurationProperty) CRConfigurationProperty(com.thoughtworks.go.plugin.access.configrepo.contract.CRConfigurationProperty) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ArrayList(java.util.ArrayList)

Example 18 with ConfigurationProperty

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

the class PluggableSCMMaterialPollerTest method assertConfiguration.

private void assertConfiguration(com.thoughtworks.go.plugin.api.config.Configuration configurationsSentToPlugin, Configuration configurationInMaterial) {
    assertThat(configurationsSentToPlugin.size(), is(configurationInMaterial.size()));
    for (ConfigurationProperty property : configurationInMaterial) {
        Property configuration = configurationsSentToPlugin.get(property.getConfigurationKey().getName());
        assertThat(configuration.getValue(), is(property.getValue()));
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Property(com.thoughtworks.go.plugin.api.config.Property) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty)

Example 19 with ConfigurationProperty

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

the class CruiseConfigTestBase method shouldAddPackageDefinitionToGivenRepository.

@Test
public void shouldAddPackageDefinitionToGivenRepository() throws Exception {
    String repoId = "repo-id";
    PackageRepository packageRepository = PackageRepositoryMother.create(repoId, "repo-name", "plugin-id", "1.0", new Configuration());
    PackageDefinition existing = PackageDefinitionMother.create("pkg-1", "pkg1-name", new Configuration(), packageRepository);
    packageRepository.setPackages(new Packages(existing));
    cruiseConfig.setPackageRepositories(new PackageRepositories(packageRepository));
    Configuration configuration = new Configuration();
    configuration.add(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value")));
    configuration.add(new ConfigurationProperty(new ConfigurationKey("key-with-no-value"), new ConfigurationValue("")));
    PackageDefinition packageDefinition = PackageDefinitionMother.create(null, "pkg2-name", configuration, packageRepository);
    cruiseConfig.savePackageDefinition(packageDefinition);
    assertThat(cruiseConfig.getPackageRepositories().size(), is(1));
    assertThat(cruiseConfig.getPackageRepositories().get(0).getId(), is(repoId));
    assertThat(cruiseConfig.getPackageRepositories().get(0).getPackages().size(), is(2));
    assertThat(cruiseConfig.getPackageRepositories().get(0).getPackages().get(0).getId(), is(existing.getId()));
    PackageDefinition createdPkgDef = cruiseConfig.getPackageRepositories().get(0).getPackages().get(1);
    assertThat(createdPkgDef.getId(), is(notNullValue()));
    assertThat(createdPkgDef.getConfiguration().getProperty("key"), is(Matchers.notNullValue()));
    assertThat(createdPkgDef.getConfiguration().getProperty("key-with-no-value"), is(nullValue()));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) Configuration(com.thoughtworks.go.domain.config.Configuration) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Test(org.junit.Test)

Example 20 with ConfigurationProperty

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

the class ConfigurationPropertyBuilderTest method shouldCreateWithErrorsInPresenceOfEncryptedTextInputForUnSecuredProperty.

@Test
public void shouldCreateWithErrorsInPresenceOfEncryptedTextInputForUnSecuredProperty() {
    Property key = new Property("key");
    key.with(Property.SECURE, false);
    ConfigurationProperty property = new ConfigurationPropertyBuilder().create("key", null, "enc_value", false);
    assertThat(property.errors().get("encryptedValue").get(0), is("encrypted_value cannot be specified to a unsecured property."));
    assertThat(property.getEncryptedValue(), is("enc_value"));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Property(com.thoughtworks.go.plugin.api.config.Property) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Test(org.junit.Test)

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