Search in sources :

Example 41 with ConfigurationKey

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

the class JobInstanceMother method jobPlanWithAssociatedEntities.

public static JobPlan jobPlanWithAssociatedEntities(String jobName, long id, List<ArtifactPlan> artifactPlans, List<ArtifactPropertiesGenerator> artifactPropertiesGenerators) {
    ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("image"), new ConfigurationValue("elastic-agent"));
    ElasticProfile elasticProfile = new ElasticProfile("elastic", "plugin", configurationProperty);
    EnvironmentVariables variables = new EnvironmentVariables();
    variables.add("some_var", "blah");
    return new DefaultJobPlan(new Resources(new Resource("foo"), new Resource("bar")), artifactPlans, artifactPropertiesGenerators, id, defaultJobIdentifier(jobName), null, variables, new EnvironmentVariables(), elasticProfile);
}
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)

Example 42 with ConfigurationKey

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

the class FetchPluggableArtifactTaskTest method encryptSecureProperties_shouldEncryptSecureProperties.

@Test
void encryptSecureProperties_shouldEncryptSecureProperties() throws CryptoException {
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("secure_property1", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("secure_property2", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("plain", new Metadata(true, false)));
    when(artifactPluginInfo.getFetchArtifactSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("pipeline", "stage", "job");
    PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("s3", "aws");
    pipelineConfig.getStage("stage").jobConfigByConfigName("job").artifactTypeConfigs().add(pluggableArtifactConfig);
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.addPipelineWithoutValidation("foo", pipelineConfig);
    cruiseConfig.getArtifactStores().add(new ArtifactStore("aws", artifactPluginInfo.getDescriptor().id()));
    FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"), new CaseInsensitiveString("job"), "s3");
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new ConfigurationValue("password")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
    ArrayList<ConfigurationProperty> expectedConfigurationProperties = new ArrayList<>();
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new EncryptedConfigurationValue(new GoCipher().encrypt("password"))));
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
    task.addConfigurations(configurationProperties);
    task.encryptSecureProperties(cruiseConfig, pipelineConfig, task);
    assertThat(task.getConfiguration().size()).isEqualTo(3);
    assertThat(task.getConfiguration()).isEqualTo(expectedConfigurationProperties);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 43 with ConfigurationKey

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

the class FetchPluggableArtifactTaskTest method encryptSecureProperties_shouldEncryptSecurePropertiesIfTheConfigIdentifersAreParams.

@Test
void encryptSecureProperties_shouldEncryptSecurePropertiesIfTheConfigIdentifersAreParams() throws CryptoException {
    ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
    pluginConfigurations.add(new PluginConfiguration("secure_property1", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("secure_property2", new Metadata(true, true)));
    pluginConfigurations.add(new PluginConfiguration("plain", new Metadata(true, false)));
    when(artifactPluginInfo.getFetchArtifactSettings()).thenReturn(new PluggableInstanceSettings(pluginConfigurations));
    PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("pipeline", "stage", "job");
    PluggableArtifactConfig pluggableArtifactConfig = new PluggableArtifactConfig("s3", "aws");
    pipelineConfig.getStage("stage").jobConfigByConfigName("job").artifactTypeConfigs().add(pluggableArtifactConfig);
    BasicCruiseConfig cruiseConfig = GoConfigMother.defaultCruiseConfig();
    cruiseConfig.addPipelineWithoutValidation("foo", pipelineConfig);
    cruiseConfig.getArtifactStores().add(new ArtifactStore("aws", artifactPluginInfo.getDescriptor().id()));
    FetchPluggableArtifactTask task = new FetchPluggableArtifactTask(new CaseInsensitiveString("#{pipeline}"), new CaseInsensitiveString("#{stage}"), new CaseInsensitiveString("#{job}"), "#{artifactId}");
    FetchPluggableArtifactTask preprocessedTask = new FetchPluggableArtifactTask(new CaseInsensitiveString("pipeline"), new CaseInsensitiveString("stage"), new CaseInsensitiveString("job"), "s3");
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new ConfigurationValue("password")));
    configurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
    ArrayList<ConfigurationProperty> expectedConfigurationProperties = new ArrayList<>();
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("plain"), new ConfigurationValue("plain")));
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property1"), new EncryptedConfigurationValue(new GoCipher().encrypt("password"))));
    expectedConfigurationProperties.add(new ConfigurationProperty(new ConfigurationKey("secure_property2"), new EncryptedConfigurationValue(new GoCipher().encrypt("secret"))));
    task.addConfigurations(configurationProperties);
    PipelineConfig pipelineWhichHasTheFetchTask = PipelineConfigMother.createPipelineConfigWithStage("p2", "anotherStage");
    pipelineWhichHasTheFetchTask.first().getJobs().first().addTask(task);
    pipelineWhichHasTheFetchTask.setParams(new ParamsConfig(new ParamConfig("pipeline", "pipeline"), new ParamConfig("stage", "stage"), new ParamConfig("job", "job"), new ParamConfig("artifactId", "s3")));
    task.encryptSecureProperties(cruiseConfig, pipelineWhichHasTheFetchTask, preprocessedTask);
    assertThat(task.getConfiguration().size()).isEqualTo(3);
    assertThat(task.getConfiguration()).isEqualTo(expectedConfigurationProperties);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) GoCipher(com.thoughtworks.go.security.GoCipher) ArrayList(java.util.ArrayList) Metadata(com.thoughtworks.go.plugin.domain.common.Metadata) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) PluginConfiguration(com.thoughtworks.go.plugin.domain.common.PluginConfiguration) Test(org.junit.jupiter.api.Test)

Example 44 with ConfigurationKey

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

the class ElasticProfileDTO method toDomainModel.

public ElasticProfile toDomainModel() {
    ArrayList<ConfigurationProperty> configurationProperties = new ArrayList<>();
    this.properties.forEach((key, value) -> {
        configurationProperties.add(new ConfigurationProperty(new ConfigurationKey(key), new ConfigurationValue(value)));
    });
    ElasticProfile elasticProfile = new ElasticProfile(this.id, this.clusterProfileId);
    elasticProfile.addConfigurations(configurationProperties);
    return elasticProfile;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ArrayList(java.util.ArrayList) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile)

Example 45 with ConfigurationKey

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

the class JobAgentMetadata method clusterProfile.

public ClusterProfile clusterProfile() {
    Map map = GSON.fromJson(clusterProfileMetadata, LinkedHashMap.class);
    if (map == null || map.isEmpty()) {
        return null;
    }
    String pluginId = (String) map.get("pluginId");
    String id = (String) map.get("id");
    Map<String, String> properties = (Map<String, String>) map.get("properties");
    Collection<ConfigurationProperty> configProperties = properties.entrySet().stream().map(entry -> new ConfigurationProperty(new ConfigurationKey(entry.getKey()), new ConfigurationValue(entry.getValue()))).collect(Collectors.toList());
    return new ClusterProfile(id, pluginId, configProperties);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) GsonBuilder(com.google.gson.GsonBuilder) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) LinkedHashMap(java.util.LinkedHashMap) Objects(java.util.Objects) FieldNamingPolicy(com.google.gson.FieldNamingPolicy) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) Gson(com.google.gson.Gson) Map(java.util.Map) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ClusterProfile(com.thoughtworks.go.config.elastic.ClusterProfile) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

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