Search in sources :

Example 26 with ConfigurationKey

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

the class JobInstanceSqlMapDaoIntegrationTest method shouldSaveJobAgentMetadata_WhenClusterProfileIsAssociatedWithElasticAgentProfile.

@Test
public void shouldSaveJobAgentMetadata_WhenClusterProfileIsAssociatedWithElasticAgentProfile() {
    JobInstance instance = jobInstanceDao.save(stageId, new JobInstance(JOB_NAME));
    instance.setIdentifier(new JobIdentifier(savedPipeline, savedStage, instance));
    ElasticProfile elasticProfile = new ElasticProfile("foo", "clusterId", Arrays.asList(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"))));
    ClusterProfile clusterProfile = new ClusterProfile("clusterId", "cd.go.elastic-agent:docker", Arrays.asList(new ConfigurationProperty(new ConfigurationKey("key"), new ConfigurationValue("value"))));
    JobPlan plan = new DefaultJobPlan(new Resources("something"), new ArrayList<>(), instance.getId(), instance.getIdentifier(), null, new EnvironmentVariables(), new EnvironmentVariables(), elasticProfile, clusterProfile);
    jobInstanceDao.save(instance.getId(), plan);
    JobPlan retrieved = jobInstanceDao.loadPlan(plan.getJobId());
    assertThat(retrieved.getElasticProfile(), is(elasticProfile));
    assertThat(retrieved.getClusterProfile(), is(clusterProfile));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Test(org.junit.jupiter.api.Test)

Example 27 with ConfigurationKey

use of com.thoughtworks.go.domain.config.ConfigurationKey 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.jupiter.api.Test)

Example 28 with ConfigurationKey

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

the class FetchPluggableArtifactTaskTest method shouldSetConfiguration_whenPluginIsProvided.

@Test
void shouldSetConfiguration_whenPluginIsProvided() {
    final HashMap<Object, Object> configAttrs = new HashMap<>();
    configAttrs.put(FetchPluggableArtifactTask.ARTIFACT_ID, "installers");
    configAttrs.put(FetchPluggableArtifactTask.CONFIGURATION, Collections.singletonMap("NAME", "gocd.zip"));
    configAttrs.put("pluginId", "cd.go.artifact.s3");
    FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("#{pipeline}"), new CaseInsensitiveString("#{stage}"), new CaseInsensitiveString("#{job}"), "#{artifactId}");
    task.setFetchTaskAttributes(configAttrs);
    Assertions.assertThat(task.getArtifactId()).isEqualTo("installers");
    Assertions.assertThat(task.getConfiguration()).hasSize(1).contains(new ConfigurationProperty(new ConfigurationKey("NAME"), new ConfigurationValue("gocd.zip")));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 29 with ConfigurationKey

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

the class FetchPluggableArtifactTaskTest method shouldSetConfiguration_whenPluginIsNotProvided.

@Test
void shouldSetConfiguration_whenPluginIsNotProvided() throws CryptoException {
    final HashMap<Object, Object> configAttrs = new HashMap<>();
    configAttrs.put(FetchPluggableArtifactTask.ARTIFACT_ID, "installers");
    configAttrs.put(FetchPluggableArtifactTask.CONFIGURATION, Collections.singletonMap("NAME", new HashMap<String, String>() {

        {
            put("value", new GoCipher().encrypt("gocd.zip"));
            put("isSecure", "true");
        }
    }));
    FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("#{pipeline}"), new CaseInsensitiveString("#{stage}"), new CaseInsensitiveString("#{job}"), "#{artifactId}");
    task.setFetchTaskAttributes(configAttrs);
    Assertions.assertThat(task.getArtifactId()).isEqualTo("installers");
    Assertions.assertThat(task.getConfiguration()).hasSize(1).contains(new ConfigurationProperty(new ConfigurationKey("NAME"), new EncryptedConfigurationValue(new GoCipher().encrypt("gocd.zip"))));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) GoCipher(com.thoughtworks.go.security.GoCipher) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test)

Example 30 with ConfigurationKey

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

the class PluginSettingsTest method shouldValidateThatEncryptedVariablesAreEncryptedWithTheCorrectCipher.

@Test
public void shouldValidateThatEncryptedVariablesAreEncryptedWithTheCorrectCipher() {
    final PluginInfo pluginInfo = mock(PluginInfo.class);
    String secureKey = "supposedly-secure-key";
    when(pluginInfo.isSecure(secureKey)).thenReturn(true);
    PluginSettings pluginSettings = new PluginSettings(PLUGIN_ID);
    pluginSettings.addConfigurations(pluginInfo, Arrays.asList(new ConfigurationProperty(new ConfigurationKey(secureKey), new EncryptedConfigurationValue("value_encrypted_by_a_different_cipher"))));
    pluginSettings.validateTree();
    assertThat(pluginSettings.hasErrors(), is(true));
    assertThat(pluginSettings.getPluginSettingsProperties().get(0).errors().firstError(), is("Encrypted value for property with key 'supposedly-secure-key' is invalid. This usually happens when the cipher text is modified to have an invalid value."));
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ElasticAgentPluginInfo(com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo) PluginInfo(com.thoughtworks.go.plugin.domain.common.PluginInfo) ConfigRepoPluginInfo(com.thoughtworks.go.plugin.domain.configrepo.ConfigRepoPluginInfo) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)71 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)71 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)65 Test (org.junit.jupiter.api.Test)49 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)29 PluginConfiguration (com.thoughtworks.go.plugin.domain.common.PluginConfiguration)13 GoCipher (com.thoughtworks.go.security.GoCipher)13 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)12 PluggableInstanceSettings (com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings)12 ClusterProfile (com.thoughtworks.go.config.elastic.ClusterProfile)11 Metadata (com.thoughtworks.go.plugin.domain.common.Metadata)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)9 ArrayList (java.util.ArrayList)9 Configuration (com.thoughtworks.go.domain.config.Configuration)8 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)8 Test (org.junit.Test)7 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)5 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)5 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)4 PluginRoleConfig (com.thoughtworks.go.config.PluginRoleConfig)4