public File[] getFiles(File configRepoCheckoutDirectory, PartialConfigLoadContext context) { String pattern = defaultPattern; Configuration configuration = context.configuration(); if (configuration != null) { ConfigurationProperty explicitPattern = configuration.getProperty("pattern"); if (explicitPattern != null) { pattern = explicitPattern.getValue(); } } return getFiles(configRepoCheckoutDirectory, pattern); }
@Test public void shouldCheckForEqualityForConfiguration() { ConfigurationProperty configurationProperty = new ConfigurationProperty(); Configuration configuration = new Configuration(configurationProperty); assertThat(configuration, is(new Configuration(configurationProperty))); }
private Configuration toConfiguration(Collection<CRConfigurationProperty> properties) { Configuration configuration = new Configuration(); if (properties != null) { for (CRConfigurationProperty p : properties) { if (p.getValue() != null) configuration.addNewConfigurationWithValue(p.getKey(), p.getValue(), false); else configuration.addNewConfigurationWithValue(p.getKey(), p.getEncryptedValue(), true); } } return configuration; }
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); } }
if (configurationMetadata != null) { boolean isSecure = Boolean.parseBoolean(configurationMetadata.get("isSecure")); if (configuration.getProperty(key) == null) { configuration.addNewConfiguration(key, isSecure); configuration.getProperty(key).setEncryptedValue(new EncryptedConfigurationValue(configurationMetadata.get("value"))); } else { configuration.getProperty(key).setConfigurationValue(new ConfigurationValue(configurationMetadata.get("value"))); this.configuration.addNewConfigurationWithValue(configuration.getKey(), String.valueOf(configuration.getValue()), false);
@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")); }
private PackageMaterial createPackageMaterialWithSecureConfiguration() { PackageMaterial material = MaterialsMother.packageMaterial(); material.getPackageDefinition().getRepository().getConfiguration().get(1).handleSecureValueConfiguration(true); material.getPackageDefinition().getConfiguration().addNewConfigurationWithValue("k4", "package-v2", false); material.getPackageDefinition().getConfiguration().get(1).handleSecureValueConfiguration(true); return material; }
@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 shouldGetNullIfPropertyNotFoundForGivenKey() { Configuration config = new Configuration(); assertThat(config.getProperty("key2"), is(nullValue())); }
@Test public void shouldAddConfigurationPropertiesForAnyPlugin() { List<ConfigurationProperty> configurationProperties = Arrays.asList(ConfigurationPropertyMother.create("key", "value", "encValue")); Configuration configuration = new Configuration(); SCM scm = SCMMother.create("id", "name", "does_not_exist", "1.1", configuration); assertThat(configuration.size(), is(0)); scm.addConfigurations(configurationProperties); assertThat(configuration.size(), is(1)); }
@Test public void shouldLoadConfigWithConfigRepoAndConfiguration() throws Exception { CruiseConfig cruiseConfig = xmlLoader.loadConfigHolder(configWithConfigRepos( " <config-repos>\n" + " <config-repo id=\"id1\" pluginId=\"gocd-xml\">\n" + " <git url=\"https://github.com/tomzo/gocd-indep-config-part.git\" />\n" + " <configuration>\n" + " <property>\n" + " <key>pattern</key>\n" + " <value>*.gocd.xml</value>\n" + " </property>\n" + " </configuration>\n" + " </config-repo >\n" + " </config-repos>\n" )).config; assertThat(cruiseConfig.getConfigRepos().size(), is(1)); ConfigRepoConfig configRepo = cruiseConfig.getConfigRepos().get(0); assertThat(configRepo.getConfiguration().size(), is(1)); assertThat(configRepo.getConfiguration().getProperty("pattern").getValue(), is("*.gocd.xml")); }
@Test public void shouldHandleSecureConfigurations() throws Exception { TaskPreference taskPreference = mock(TaskPreference.class); Configuration configuration = new Configuration(); PluggableTaskConfigStore.store().setPreferenceFor("abc.def", taskPreference); PluggableTask task = new PluggableTask(new PluginConfiguration("abc.def", "1"), configuration); Map<String, String> attributeMap = DataStructureUtils.m("KEY1", "value1"); TaskConfig taskConfig = new TaskConfig(); taskConfig.addProperty("KEY1").with(Property.SECURE, true); when(taskPreference.getConfig()).thenReturn(taskConfig); task.setTaskConfigAttributes(attributeMap); assertThat(task.getConfiguration().size(), is(1)); assertTrue(task.getConfiguration().first().isSecure()); assertThat(task.getConfiguration().first().getValue(), is("value1")); }
@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())); }
@Test public void shouldWriteSCMConfiguration() throws Exception { CruiseConfig configToSave = new BasicCruiseConfig(); SCM scm = new SCM(); scm.setId("id"); scm.setName("name"); scm.setPluginConfiguration(new PluginConfiguration("plugin-id", "1.0")); scm.setConfiguration(new Configuration(getConfigurationProperty("url", false, "http://go"), getConfigurationProperty("secure", true, "secure"))); configToSave.getSCMs().add(scm); xmlWriter.write(configToSave, output, false); GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(output.toString()); SCMs scms = goConfigHolder.config.getSCMs(); assertThat(scms, is(configToSave.getSCMs())); assertThat(scms.get(0).getConfiguration().first().getConfigurationValue().getValue(), is("http://go")); assertThat(scms.get(0).getConfiguration().first().getEncryptedConfigurationValue(), is(nullValue())); assertThat(scms.get(0).getConfiguration().last().getEncryptedValue(), is(new GoCipher().encrypt("secure"))); assertThat(scms.get(0).getConfiguration().last().getConfigurationValue(), is(nullValue())); }
@Test public void validate_shouldValidateArtifactPropertiesConfigurationKeyUniqueness() { final ValidationContext validationContext = mock(ValidationContext.class); final PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID", create("Foo", false, "Bar"), create("Foo", true, "Bar")); final ArtifactStores artifactStores = mock(ArtifactStores.class); assertFalse(artifactConfig.hasErrors()); when(validationContext.artifactStores()).thenReturn(artifactStores); when(artifactStores.find("Store-ID")).thenReturn(new ArtifactStore("Store-ID", "pluginId")); artifactConfig.validate(validationContext); Configuration configuration = artifactConfig.getConfiguration(); assertThat(configuration.get(0).errors().getAllOn("configurationKey"), is(Arrays.asList("Duplicate key 'Foo' found for Pluggable Artifact"))); assertThat(configuration.get(1).errors().getAllOn("configurationKey"), is(Arrays.asList("Duplicate key 'Foo' found for Pluggable Artifact"))); }
@Override public String fetchArtifactMessage(ArtifactStore artifactStore, Configuration configuration, Map<String, Object> metadata, String agentWorkingDirectory) { final Map<String, Object> map = new HashMap<>(); map.put("store_configuration", artifactStore.getConfigurationAsMap(true)); map.put("fetch_artifact_configuration", configuration.getConfigurationAsMap(true)); map.put("artifact_metadata", metadata); map.put("agent_working_directory", agentWorkingDirectory); return GSON.toJson(map); }
@Override protected void setTaskConfigAttributes(Map attributes) { TaskConfig taskConfig = PluggableTaskConfigStore.store().preferenceFor(pluginConfiguration.getId()).getConfig(); for (Property property : taskConfig.list()) { String key = property.getKey(); if (attributes.containsKey(key)) { Boolean isSecure = property.getOption(Property.SECURE); if (configuration.getProperty(key) == null) { configuration.addNewConfiguration(property.getKey(), isSecure); } configuration.getProperty(key).setConfigurationValue(new ConfigurationValue((String) attributes.get(key))); configuration.getProperty(key).handleSecureValueConfiguration(isSecure); } } }
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); }
assertThat(task.getTypeForDisplay(), is("Pluggable Task")); final Configuration configuration = task.getConfiguration(); assertThat(configuration.listOfConfigKeys().size(), is(3)); assertThat(configuration.listOfConfigKeys(), is(asList("url", "username", "password"))); Collection<String> values = CollectionUtils.collect(configuration.listOfConfigKeys(), o -> { ConfigurationProperty property = configuration.getProperty(o); return property.getConfigurationValue().getValue(); });