use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.
the class PackageRepository method getSecureKeyInfoProvider.
private SecureKeyInfoProvider getSecureKeyInfoProvider() {
final RepositoryMetadataStore repositoryMetadataStore = RepositoryMetadataStore.getInstance();
final PackageConfigurations metadata = repositoryMetadataStore.getMetadata(pluginConfiguration.getId());
if (metadata == null) {
return null;
}
return new SecureKeyInfoProvider() {
@Override
public boolean isSecure(String key) {
PackageConfiguration packageConfiguration = metadata.get(key);
return packageConfiguration.getOption(PackageConfiguration.SECURE);
}
};
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.
the class PackageDefinitionTest method shouldOnlyDisplayFieldsWhichAreNonSecureAndPartOfIdentityInGetConfigForDisplayWhenPluginExists.
@Test
public void shouldOnlyDisplayFieldsWhichAreNonSecureAndPartOfIdentityInGetConfigForDisplayWhenPluginExists() {
String pluginId = "plugin-id";
PackageConfigurations repositoryConfigurations = new PackageConfigurations();
repositoryConfigurations.add(new PackageConfiguration("rk1", "rv1").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, false));
repositoryConfigurations.add(new PackageConfiguration("rk2", "rv2").with(PackageConfiguration.PART_OF_IDENTITY, false).with(PackageConfiguration.SECURE, false));
repositoryConfigurations.add(new PackageConfiguration("rk3", "rv3").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, true));
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfigurations);
PackageConfigurations packageConfigurations = new PackageConfigurations();
packageConfigurations.add(new PackageConfiguration("pk1", "pv1").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, false));
packageConfigurations.add(new PackageConfiguration("pk2", "pv2").with(PackageConfiguration.PART_OF_IDENTITY, false).with(PackageConfiguration.SECURE, false));
packageConfigurations.add(new PackageConfiguration("pk3", "pv3").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, true));
packageConfigurations.add(new PackageConfiguration("pk4", "pv4").with(PackageConfiguration.PART_OF_IDENTITY, false).with(PackageConfiguration.SECURE, true));
packageConfigurations.add(new PackageConfiguration("pk5", "pv5").with(PackageConfiguration.PART_OF_IDENTITY, true).with(PackageConfiguration.SECURE, false));
PackageMetadataStore.getInstance().addMetadataFor(pluginId, packageConfigurations);
PackageRepository repository = PackageRepositoryMother.create("repo-id", "repo", pluginId, "version", new Configuration(create("rk1", false, "rv1"), create("rk2", false, "rv2"), create("rk3", true, "rv3")));
Configuration packageConfig = new Configuration(create("pk1", false, "pv1"), create("pk2", false, "pv2"), create("pk3", true, "pv3"), create("pk4", true, "pv4"), create("pk5", false, "pv5"));
PackageDefinition packageDefinition = PackageDefinitionMother.create("p-id", "name", packageConfig, repository);
packageDefinition.setRepository(repository);
assertThat(packageDefinition.getConfigForDisplay(), is("Repository: [rk1=rv1] - Package: [pk1=pv1, pk5=pv5]"));
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.
the class PackageDefinitionTest method shouldSetConfigAttributes.
@Test
public void shouldSetConfigAttributes() throws Exception {
PackageDefinition definition = new PackageDefinition();
String pluginId = "plugin";
Map config = createPackageDefinitionConfiguration("package-name", pluginId, new ConfigurationHolder("key1", "value1"), new ConfigurationHolder("key2", "value2", "encrypted-value", true, "1"), new ConfigurationHolder("key3", "test", "encrypted-value", true, "0"));
PackageConfigurations metadata = new PackageConfigurations();
metadata.addConfiguration(new PackageConfiguration("key1"));
metadata.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, true));
metadata.addConfiguration(new PackageConfiguration("key3").with(PackageConfiguration.SECURE, true));
PackageMetadataStore.getInstance().addMetadataFor(pluginId, metadata);
definition.setRepository(PackageRepositoryMother.create("1"));
definition.setConfigAttributes(config);
String encryptedValue = new GoCipher().encrypt("value2");
assertThat(definition.getName(), is("package-name"));
assertThat(definition.getConfiguration().size(), is(3));
assertThat(definition.getConfiguration().getProperty("key1").getConfigurationValue().getValue(), is("value1"));
assertThat(definition.getConfiguration().getProperty("key1").getEncryptedConfigurationValue(), is(nullValue()));
assertThat(definition.getConfiguration().getProperty("key2").getEncryptedValue(), is(encryptedValue));
assertThat(definition.getConfiguration().getProperty("key2").getConfigurationValue(), is(nullValue()));
assertThat(definition.getConfiguration().getProperty("key3").getEncryptedValue(), is("encrypted-value"));
assertThat(definition.getConfiguration().getProperty("key3").getConfigurationValue(), is(nullValue()));
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.
the class PackageDefinitionTest method shouldMakeConfigurationSecureBasedOnMetadata.
@Test
public void shouldMakeConfigurationSecureBasedOnMetadata() throws Exception {
/*secure property is set based on metadata*/
ConfigurationProperty secureProperty = new ConfigurationProperty(new ConfigurationKey("key1"), new ConfigurationValue("value1"), null, new GoCipher());
ConfigurationProperty nonSecureProperty = new ConfigurationProperty(new ConfigurationKey("key2"), new ConfigurationValue("value2"), null, new GoCipher());
PackageDefinition packageDefinition = new PackageDefinition("go", "name", new Configuration(secureProperty, nonSecureProperty));
PackageRepository packageRepository = new PackageRepository();
packageRepository.setPluginConfiguration(new PluginConfiguration("plugin-id", "1.0"));
packageDefinition.setRepository(packageRepository);
PackageConfigurations packageConfigurations = new PackageConfigurations();
packageConfigurations.addConfiguration(new PackageConfiguration("key1").with(PackageConfiguration.SECURE, true));
packageConfigurations.addConfiguration(new PackageConfiguration("key2").with(PackageConfiguration.SECURE, false));
PackageMetadataStore.getInstance().addMetadataFor("plugin-id", packageConfigurations);
packageDefinition.applyPackagePluginMetadata("plugin-id");
assertThat(secureProperty.isSecure(), is(true));
assertThat(nonSecureProperty.isSecure(), is(false));
}
use of com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration in project gocd by gocd.
the class PackageRepositoryTest method shouldSetConfigAttributesAsAvailable.
@Test
public void shouldSetConfigAttributesAsAvailable() throws Exception {
//metadata setup
PackageConfigurations repositoryConfiguration = new PackageConfigurations();
repositoryConfiguration.add(new PackageConfiguration("url"));
repositoryConfiguration.add(new PackageConfiguration("username"));
repositoryConfiguration.add(new PackageConfiguration("password").with(SECURE, true));
repositoryConfiguration.add(new PackageConfiguration("secureKeyNotChanged").with(SECURE, true));
RepositoryMetadataStore.getInstance().addMetadataFor("yum", repositoryConfiguration);
String name = "go-server";
String repoId = "repo-id";
String pluginId = "yum";
ConfigurationHolder url = new ConfigurationHolder("url", "http://test.com");
ConfigurationHolder username = new ConfigurationHolder("username", "user");
String oldEncryptedValue = "oldEncryptedValue";
ConfigurationHolder password = new ConfigurationHolder("password", "pass", oldEncryptedValue, true, "1");
ConfigurationHolder secureKeyNotChanged = new ConfigurationHolder("secureKeyNotChanged", "pass", oldEncryptedValue, true, "0");
Map attributes = createPackageRepositoryConfiguration(name, pluginId, repoId, url, username, password, secureKeyNotChanged);
PackageRepository packageRepository = new PackageRepository();
Packages packages = new Packages();
packageRepository.setPackages(packages);
packageRepository.setConfigAttributes(attributes);
assertThat(packageRepository.getName(), is(name));
assertThat(packageRepository.getId(), is(repoId));
assertThat(packageRepository.getPluginConfiguration().getId(), is(pluginId));
assertThat(packageRepository.getConfiguration().get(0).getConfigurationKey().getName(), is(url.name));
assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().getValue(), is(url.value));
assertThat(packageRepository.getConfiguration().get(1).getConfigurationKey().getName(), is(username.name));
assertThat(packageRepository.getConfiguration().get(1).getConfigurationValue().getValue(), is(username.value));
assertThat(packageRepository.getConfiguration().get(2).getConfigurationKey().getName(), is(password.name));
assertThat(packageRepository.getConfiguration().get(2).getEncryptedValue(), is(new GoCipher().encrypt(password.value)));
assertThat(packageRepository.getConfiguration().get(2).getConfigurationValue(), is(nullValue()));
assertThat(packageRepository.getConfiguration().get(3).getConfigurationKey().getName(), is(secureKeyNotChanged.name));
assertThat(packageRepository.getConfiguration().get(3).getEncryptedValue(), is(oldEncryptedValue));
assertThat(packageRepository.getConfiguration().get(3).getConfigurationValue(), is(nullValue()));
assertSame(packageRepository.getPackages(), packages);
}
Aggregations