public void setConfigAttributes(Object attributes, SecureKeyInfoProvider secureKeyInfoProvider) { this.clear(); Map attributesMap = (Map) attributes; for (Object o : attributesMap.values()) { Map configurationAttributeMap = (Map) o; ConfigurationProperty configurationProperty = new ConfigurationProperty(); configurationProperty.setConfigAttributes(configurationAttributeMap, secureKeyInfoProvider); this.add(configurationProperty); } }
public void addNewConfigurationWithValue(String key, String value, boolean isSecure) { if (isSecure) { add(new ConfigurationProperty(new ConfigurationKey(key), new EncryptedConfigurationValue(value))); } else { add(new ConfigurationProperty(new ConfigurationKey(key), new ConfigurationValue(value))); } }
public void addConfigurations(List<ConfigurationProperty> configurations) { ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurations) { if(isValidPluginConfiguration(property.getConfigKeyName())) { configuration.add(builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), pluginConfigurationFor(property.getConfigKeyName()).getOption(Property.SECURE))); } else { configuration.add(property); } } }
public void addConfigurations(List<ConfigurationProperty> configurations) { ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurations) { if (doesPluginExist()) { com.thoughtworks.go.plugin.api.material.packagerepository.PackageConfiguration packageMetadata = PackageMetadataStore.getInstance().getPackageMetadata(pluginId()); if (isValidConfiguration(property.getConfigKeyName(), packageMetadata)) { configuration.add(builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), packagePropertyFor(property.getConfigKeyName(), packageMetadata).getOption(Property.SECURE))); } else { configuration.add(property); } } else { configuration.add(property); } } }
public void addConfigurations(List<ConfigurationProperty> configurations) { ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurations) { SCMConfigurations scmConfigurations = SCMMetadataStore.getInstance().getConfigurationMetadata(getPluginId()); if (isValidPluginConfiguration(property.getConfigKeyName(), scmConfigurations)) { configuration.add(builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), scmConfigurationFor(property.getConfigKeyName(), scmConfigurations).getOption(SCMConfiguration.SECURE))); } else { configuration.add(property); } } }
public void addConfigurations(List<ConfigurationProperty> configurations) { ConfigurationPropertyBuilder builder = new ConfigurationPropertyBuilder(); for (ConfigurationProperty property : configurations) { RepositoryConfiguration repositoryMetadata = RepositoryMetadataStore.getInstance().getRepositoryMetadata(pluginConfiguration.getId()); if (isValidPluginConfiguration(property.getConfigKeyName(), repositoryMetadata)) { configuration.add(builder.create(property.getConfigKeyName(), property.getConfigValue(), property.getEncryptedValue(), repositoryPropertyFor(property.getConfigKeyName(), repositoryMetadata).getOption(Property.SECURE))); } else { configuration.add(property); } } }
@Test public void shouldTestEqualsBasedOnConfiguration() { PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial("scm-id", "scm-name", ConfigurationPropertyMother.create("key1", false, "value1")); MaterialInstance materialInstance = material.createMaterialInstance(); MaterialInstance materialInstanceCopy = material.createMaterialInstance(); material.getScmConfig().getConfiguration().add(ConfigurationPropertyMother.create("key2", false, "value2")); MaterialInstance newMaterialInstance = material.createMaterialInstance(); assertThat(materialInstance, is(materialInstanceCopy)); assertThat(materialInstance, is(not(newMaterialInstance))); }
@Test public void shouldTestEqualsBasedOnConfiguration() { PackageMaterial material = MaterialsMother.packageMaterial("repo-id", "repo-name", "pkg-id", "pkg-name", ConfigurationPropertyMother.create("key1", false, "value1")); MaterialInstance materialInstance = material.createMaterialInstance(); MaterialInstance materialInstanceCopy = material.createMaterialInstance(); material.getPackageDefinition().getConfiguration().add(ConfigurationPropertyMother.create("key2", false, "value2")); MaterialInstance newMaterialInstance = material.createMaterialInstance(); assertThat(materialInstance, is(materialInstanceCopy)); assertThat(materialInstance, is(not(newMaterialInstance))); }
@Test public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception { Configuration configuration = new Configuration(); configuration.add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue())); configuration.add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue())); configuration.add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null)); ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null); configurationProperty.addErrorAgainstConfigurationValue("error"); configuration.add(configurationProperty); configuration.clearEmptyConfigurations(); assertThat(configuration.size(), is(1)); assertThat(configuration.get(0).getConfigurationKey().getName(), is("name-four")); }
@Test public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception { SCM scm = new SCM(); scm.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue())); scm.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue())); scm.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null)); ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null); configurationProperty.addErrorAgainstConfigurationValue("error"); scm.getConfiguration().add(configurationProperty); scm.clearEmptyConfigurations(); assertThat(scm.getConfiguration().size(), is(1)); assertThat(scm.getConfiguration().get(0).getConfigurationKey().getName(), is("name-four")); }
@Test public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception { PackageRepository packageRepository = new PackageRepository(); packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue())); packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue())); packageRepository.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null)); ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null); configurationProperty.addErrorAgainstConfigurationValue("error"); packageRepository.getConfiguration().add(configurationProperty); packageRepository.clearEmptyConfigurations(); assertThat(packageRepository.getConfiguration().size(), is(1)); assertThat(packageRepository.getConfiguration().get(0).getConfigurationKey().getName(), is("name-four")); }
@Test public void shouldCorrectlyCheckIfUpgradeIsNecessary() { PluggableSCMMaterial material = MaterialsMother.pluggableSCMMaterial("scm-id", "scm-name", ConfigurationPropertyMother.create("key1", false, "value1")); PluggableSCMMaterialInstance materialInstance = (PluggableSCMMaterialInstance) material.createMaterialInstance(); materialInstance.setId(10L); PluggableSCMMaterialInstance materialInstanceCopy = (PluggableSCMMaterialInstance) material.createMaterialInstance(); material.getScmConfig().getConfiguration().add(ConfigurationPropertyMother.create("key2", false, "value2")); PluggableSCMMaterialInstance newMaterialInstance = (PluggableSCMMaterialInstance) material.createMaterialInstance(); assertThat(materialInstance.shouldUpgradeTo(materialInstanceCopy), is(false)); assertThat(materialInstance.shouldUpgradeTo(newMaterialInstance), is(true)); }
@Test public void shouldCorrectlyCheckIfUpgradeIsNecessary() { PackageMaterial material = MaterialsMother.packageMaterial("repo-id", "repo-name", "pkg-id", "pkg-name", ConfigurationPropertyMother.create("key1", false, "value1")); PackageMaterialInstance materialInstance = (PackageMaterialInstance) material.createMaterialInstance(); materialInstance.setId(10L); PackageMaterialInstance materialInstanceCopy = (PackageMaterialInstance) material.createMaterialInstance(); material.getPackageDefinition().getConfiguration().add(ConfigurationPropertyMother.create("key2", false, "value2")); PackageMaterialInstance newMaterialInstance = (PackageMaterialInstance) material.createMaterialInstance(); assertThat(materialInstance.shouldUpgradeTo(materialInstanceCopy), is(false)); assertThat(materialInstance.shouldUpgradeTo(newMaterialInstance), is(true)); }
@Test public void shouldClearConfigurationsWhichAreEmptyAndNoErrors() throws Exception { PackageDefinition packageDefinition = new PackageDefinition(); packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-one"), new ConfigurationValue())); packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-two"), new EncryptedConfigurationValue())); packageDefinition.getConfiguration().add(new ConfigurationProperty(new ConfigurationKey("name-three"), null, new EncryptedConfigurationValue(), null)); ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("name-four"), null, new EncryptedConfigurationValue(), null); configurationProperty.addErrorAgainstConfigurationValue("error"); packageDefinition.getConfiguration().add(configurationProperty); packageDefinition.clearEmptyConfigurations(); assertThat(packageDefinition.getConfiguration().size(), is(1)); assertThat(packageDefinition.getConfiguration().get(0).getConfigurationKey().getName(), is("name-four")); }
public static PluggableSCMMaterialConfig pluggableSCMMaterialConfigWithConfigProperties(String... properties) { SCM scmConfig = SCMMother.create("scm-id"); Configuration configuration = new Configuration(); for (String property : properties) { ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey(property), new ConfigurationValue(property+"-value")); configuration.add(configurationProperty); } scmConfig.setConfiguration(configuration); return new PluggableSCMMaterialConfig(null, scmConfig, "des-folder", null); }
@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())); }