Search in sources :

Example 71 with ConfigurationProperty

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

the class SCMTest method shouldValidateUniqueKeysInConfiguration.

@Test
public void shouldValidateUniqueKeysInConfiguration() {
    ConfigurationProperty one = create("one", false, "value1");
    ConfigurationProperty duplicate1 = create("ONE", false, "value2");
    ConfigurationProperty duplicate2 = create("ONE", false, "value3");
    ConfigurationProperty two = create("two", false, null);
    SCM scm = new SCM();
    scm.setConfiguration(new Configuration(one, duplicate1, duplicate2, two));
    scm.setName("git");
    scm.validate(null);
    assertThat(one.errors().isEmpty(), is(false));
    assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for SCM 'git'"), is(true));
    assertThat(duplicate1.errors().isEmpty(), is(false));
    assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for SCM 'git'"), is(true));
    assertThat(duplicate2.errors().isEmpty(), is(false));
    assertThat(one.errors().getAllOn(ConfigurationProperty.CONFIGURATION_KEY).contains("Duplicate key 'ONE' found for SCM 'git'"), is(true));
    assertThat(two.errors().isEmpty(), is(true));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Configuration(com.thoughtworks.go.domain.config.Configuration) PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) SCMConfiguration(com.thoughtworks.go.plugin.access.scm.SCMConfiguration) Test(org.junit.Test)

Example 72 with ConfigurationProperty

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

the class RoleConfigCommand method validate.

private void validate(CruiseConfig preprocessedConfig) {
    if (role instanceof PluginRoleConfig) {
        PluginRoleConfig role = (PluginRoleConfig) this.role;
        PluginRoleConfig preprocessedRole = (PluginRoleConfig) this.preprocessedRole;
        SecurityAuthConfig securityAuthConfig = preprocessedConfig.server().security().securityAuthConfigs().find(role.getAuthConfigId());
        if (securityAuthConfig == null) {
            role.addError("authConfigId", "No such security auth configuration present " + role.getAuthConfigId());
            return;
        }
        try {
            ValidationResult result = extension.validateRoleConfiguration(securityAuthConfig.getPluginId(), role.getConfigurationAsMap(true));
            if (!result.isSuccessful()) {
                for (ValidationError validationError : result.getErrors()) {
                    ConfigurationProperty property = preprocessedRole.getProperty(validationError.getKey());
                    if (property == null) {
                        role.addNewConfiguration(validationError.getKey(), false);
                        preprocessedRole.addNewConfiguration(validationError.getKey(), false);
                        property = preprocessedRole.getProperty(validationError.getKey());
                    }
                    property.addError(validationError.getKey(), validationError.getMessage());
                }
            }
        } catch (PluginNotFoundException e) {
            role.addError("authConfigId", "Could not find a security authorization config with id '" + role.getAuthConfigId() + "'.");
        }
    }
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) PluginNotFoundException(com.thoughtworks.go.plugin.access.PluginNotFoundException) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult)

Example 73 with ConfigurationProperty

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

the class PackageMaterialPollerTest 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 74 with ConfigurationProperty

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

the class PluggableSCMMaterialPollerTest method setup.

@Before
public void setup() {
    initMocks(this);
    ConfigurationProperty k1 = ConfigurationPropertyMother.create("k1", false, "v1");
    ConfigurationProperty k2 = ConfigurationPropertyMother.create("k2", true, "v2");
    SCM scmConfig = SCMMother.create("scm-id", "scm-name", "plugin-id", "1.0", new Configuration(k1, k2));
    material = new PluggableSCMMaterial();
    material.setSCMConfig(scmConfig);
    MaterialInstance materialInstance = material.createMaterialInstance();
    Map<String, String> data = new HashMap<>();
    data.put("mk-1", "mv-1");
    materialInstance.setAdditionalData(JsonHelper.toJsonString(data));
    when(materialRepository.findMaterialInstance(material)).thenReturn(materialInstance);
    poller = new PluggableSCMMaterialPoller(materialRepository, scmExtension, transactionTemplate);
    scmConfiguration = ArgumentCaptor.forClass(SCMPropertyConfiguration.class);
    materialData = ArgumentCaptor.forClass(Map.class);
    flyweightFolderPath = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) SCM(com.thoughtworks.go.domain.scm.SCM) MaterialInstance(com.thoughtworks.go.domain.MaterialInstance) ModifiedFile(com.thoughtworks.go.plugin.access.scm.revision.ModifiedFile) File(java.io.File) Before(org.junit.Before)

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