Search in sources :

Example 21 with ConfigurationValue

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

the class DeletePackageConfigCommandTest method setup.

@Before
public void setup() throws Exception {
    initMocks(this);
    currentUser = new Username(new CaseInsensitiveString("user"));
    cruiseConfig = new GoConfigMother().defaultCruiseConfig();
    packageUuid = "random-uuid";
    configuration = new Configuration(new ConfigurationProperty(new ConfigurationKey("PACKAGE_ID"), new ConfigurationValue("prettyjson")));
    packageDefinition = new PackageDefinition(packageUuid, "prettyjson", configuration);
    result = new HttpLocalizedOperationResult();
    PackageRepositories repositories = cruiseConfig.getPackageRepositories();
    PackageRepository repository = new PackageRepository();
    repository.addPackage(packageDefinition);
    repositories.add(repository);
    cruiseConfig.setPackageRepositories(repositories);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Configuration(com.thoughtworks.go.domain.config.Configuration) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) Username(com.thoughtworks.go.server.domain.Username) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) Before(org.junit.Before)

Example 22 with ConfigurationValue

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

the class ScheduledPipelineLoaderIntegrationTest method shouldUpdateScmConfigurationOfPluggableScmMaterialsOnPipeline.

@Test
public void shouldUpdateScmConfigurationOfPluggableScmMaterialsOnPipeline() {
    String jobName = "job-one";
    PipelineConfig pipelineConfig = setupPipelineWithScmMaterial("pipeline_with_pluggable_scm_mat", "stage", jobName);
    final Pipeline previousSuccessfulBuildWithOlderScmConfig = simulateSuccessfulPipelineRun(pipelineConfig);
    PipelineConfig updatedPipelineConfig = configHelper.updatePipeline(pipelineConfig.name(), new GoConfigFileHelper.Updater<PipelineConfig>() {

        @Override
        public void update(PipelineConfig config) {
            PluggableSCMMaterialConfig materialConfig = (PluggableSCMMaterialConfig) config.materialConfigs().first();
            materialConfig.getSCMConfig().getConfiguration().getProperty("password").setConfigurationValue(new ConfigurationValue("new_value"));
        }
    });
    final long jobId = rerunJob(jobName, pipelineConfig, previousSuccessfulBuildWithOlderScmConfig);
    Pipeline loadedPipeline = (Pipeline) transactionTemplate.execute(new TransactionCallback() {

        public Object doInTransaction(TransactionStatus status) {
            return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
        }
    });
    MaterialRevisions revisions = loadedPipeline.getBuildCause().getMaterialRevisions();
    Configuration updatedConfiguration = ((PluggableSCMMaterial) revisions.findRevisionFor(updatedPipelineConfig.materialConfigs().first()).getMaterial()).getScmConfig().getConfiguration();
    assertThat(updatedConfiguration.size(), is(2));
    assertThat(updatedConfiguration.getProperty("password").getConfigurationValue(), is(new ConfigurationValue("new_value")));
}
Also used : SCMPropertyConfiguration(com.thoughtworks.go.plugin.access.scm.SCMPropertyConfiguration) Configuration(com.thoughtworks.go.domain.config.Configuration) PackageConfiguration(com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) TransactionStatus(org.springframework.transaction.TransactionStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) TransactionCallback(org.springframework.transaction.support.TransactionCallback) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper) Test(org.junit.Test)

Example 23 with ConfigurationValue

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

the class PluggableTask method setTaskConfigAttributes.

@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);
        }
    }
}
Also used : ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Property(com.thoughtworks.go.plugin.api.config.Property) TaskProperty(com.thoughtworks.go.domain.TaskProperty) ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty)

Example 24 with ConfigurationValue

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

the class ConfigurationPropertyBuilder method create.

public ConfigurationProperty create(String key, String value, String encryptedValue, Boolean isSecure) {
    ConfigurationProperty configurationProperty = new ConfigurationProperty();
    configurationProperty.setConfigurationKey(new ConfigurationKey(key));
    if (isNotBlank(value) && isNotBlank(encryptedValue)) {
        configurationProperty.addError("configurationValue", "You may only specify `value` or `encrypted_value`, not both!");
        configurationProperty.addError("encryptedValue", "You may only specify `value` or `encrypted_value`, not both!");
        configurationProperty.setConfigurationValue(new ConfigurationValue(value));
        configurationProperty.setEncryptedConfigurationValue(new EncryptedConfigurationValue(encryptedValue));
        return configurationProperty;
    }
    if (isSecure) {
        if (isNotBlank(encryptedValue)) {
            configurationProperty.setEncryptedConfigurationValue(new EncryptedConfigurationValue(encryptedValue));
        }
        if (isNotBlank(value)) {
            configurationProperty.setEncryptedConfigurationValue(new EncryptedConfigurationValue(encrypt(value)));
        }
    } else {
        if (isNotBlank(encryptedValue)) {
            configurationProperty.addError("encryptedValue", "encrypted_value cannot be specified to a unsecured property.");
            configurationProperty.setEncryptedConfigurationValue(new EncryptedConfigurationValue(encryptedValue));
        }
        if (isNotBlank(value)) {
            configurationProperty.setConfigurationValue(new ConfigurationValue(value));
        }
    }
    return configurationProperty;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) EncryptedConfigurationValue(com.thoughtworks.go.domain.config.EncryptedConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey)

Example 25 with ConfigurationValue

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

the class JobAgentMetadata method elasticProfile.

public ElasticProfile elasticProfile() {
    Gson gson = new Gson();
    Map map = gson.fromJson(metadata, LinkedHashMap.class);
    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 = MapUtil.collect(properties, new ListUtil.Transformer<Map.Entry<String, String>, ConfigurationProperty>() {

        @Override
        public ConfigurationProperty transform(Map.Entry<String, String> entry) {
            return new ConfigurationProperty(new ConfigurationKey(entry.getKey()), new ConfigurationValue(entry.getValue()));
        }
    });
    return new ElasticProfile(id, pluginId, configProperties);
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) Gson(com.google.gson.Gson) ListUtil(com.thoughtworks.go.util.ListUtil) ConfigurationValue(com.thoughtworks.go.domain.config.ConfigurationValue) ConfigurationKey(com.thoughtworks.go.domain.config.ConfigurationKey) ElasticProfile(com.thoughtworks.go.config.elastic.ElasticProfile) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)34 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)28 ConfigurationKey (com.thoughtworks.go.domain.config.ConfigurationKey)27 Test (org.junit.Test)27 Configuration (com.thoughtworks.go.domain.config.Configuration)20 EncryptedConfigurationValue (com.thoughtworks.go.domain.config.EncryptedConfigurationValue)16 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)14 PackageConfiguration (com.thoughtworks.go.plugin.access.packagematerial.PackageConfiguration)9 GoCipher (com.thoughtworks.go.security.GoCipher)8 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)5 ElasticProfile (com.thoughtworks.go.config.elastic.ElasticProfile)4 SCMConfiguration (com.thoughtworks.go.plugin.access.scm.SCMConfiguration)4 ValidationError (com.thoughtworks.go.plugin.api.response.validation.ValidationError)4 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)4 SCM (com.thoughtworks.go.domain.scm.SCM)3 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)3 HashMap (java.util.HashMap)3 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)2 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)2 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)2