Search in sources :

Example 16 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.

the class PluggableTaskPluginInfoBuilderTest method allPluginInfos_ShouldReturnAListOfAllPluginInfos.

@Test
public void allPluginInfos_ShouldReturnAListOfAllPluginInfos() throws Exception {
    GoPluginDescriptor.About about = new GoPluginDescriptor.About("Plugin Descriptor Validator", "1.0.1", "12.4", "Validates its own plugin descriptor", new GoPluginDescriptor.Vendor("ThoughtWorks Go Team", "www.thoughtworks.com"), Arrays.asList("Linux", "Windows", "Mac OS X"));
    GoPluginDescriptor plugin = new GoPluginDescriptor("docker-plugin", "1.0", about, null, null, false);
    PluginManager pluginManager = mock(PluginManager.class);
    PluggableTaskConfigStore packageMetadataStore = mock(PluggableTaskConfigStore.class);
    when(packageMetadataStore.pluginIds()).thenReturn(Collections.singleton(plugin.id()));
    when(pluginManager.getPluginDescriptorFor(plugin.id())).thenReturn(plugin);
    JsonBasedPluggableTask jsonBasedPluggableTask = mock(JsonBasedPluggableTask.class);
    TaskView taskView = new TaskView() {

        @Override
        public String displayValue() {
            return "task display value";
        }

        @Override
        public String template() {
            return "pluggable task view template";
        }
    };
    TaskConfig taskConfig = new TaskConfig();
    taskConfig.add(new TaskConfigProperty("key1", null));
    taskConfig.add(new TaskConfigProperty("key2", null));
    when(jsonBasedPluggableTask.config()).thenReturn(taskConfig);
    when(jsonBasedPluggableTask.view()).thenReturn(taskView);
    TaskPreference taskPreference = new TaskPreference(jsonBasedPluggableTask);
    when(packageMetadataStore.preferenceFor(plugin.id())).thenReturn(taskPreference);
    PluggableTaskPluginInfoBuilder builder = new PluggableTaskPluginInfoBuilder(pluginManager, packageMetadataStore);
    Collection<PluggableTaskPluginInfo> pluginInfos = builder.allPluginInfos();
    PluggableTaskPluginInfo expectedPluginInfo = new PluggableTaskPluginInfo(plugin, taskView.displayValue(), new PluggableInstanceSettings(configurations(taskConfig), new PluginView(taskView.template())));
    assertEquals(Arrays.asList(expectedPluginInfo), pluginInfos);
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) JsonBasedPluggableTask(com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask) PluggableTaskPluginInfo(com.thoughtworks.go.server.ui.plugins.PluggableTaskPluginInfo) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) PluggableInstanceSettings(com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings) PluginView(com.thoughtworks.go.server.ui.plugins.PluginView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) PluggableTaskConfigStore(com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Example 17 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.

the class PluggableTaskServiceTest method isValidShouldValidateTaskAgainstPlugin.

@Test
public void isValidShouldValidateTaskAgainstPlugin() {
    TaskConfig taskConfig = mock(TaskConfig.class);
    ValidationResult validationResult = mock(ValidationResult.class);
    PluggableTask pluggableTask = mock(PluggableTask.class);
    PluginConfiguration pluginConfiguration = new PluginConfiguration("plugin_id", "version");
    when(pluggableTask.isValid()).thenReturn(true);
    when(pluggableTask.getPluginConfiguration()).thenReturn(pluginConfiguration);
    when(pluggableTask.toTaskConfig()).thenReturn(taskConfig);
    when(taskExtension.validate(pluginConfiguration.getId(), taskConfig)).thenReturn(validationResult);
    when(validationResult.isSuccessful()).thenReturn(true);
    assertTrue(pluggableTaskService.isValid(pluggableTask));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) Test(org.junit.Test)

Example 18 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.

the class PluggableTaskServiceTest method setUp.

@Before
public void setUp() throws Exception {
    taskExtension = mock(TaskExtension.class);
    localizer = mock(Localizer.class);
    pluggableTaskService = new PluggableTaskService(taskExtension, localizer);
    final TaskPreference preference = mock(TaskPreference.class);
    final TaskConfig taskConfig = new TaskConfig();
    final TaskConfigProperty key1 = taskConfig.addProperty("KEY1");
    key1.with(Property.REQUIRED, true);
    taskConfig.addProperty("KEY2");
    when(preference.getConfig()).thenReturn(taskConfig);
    PluggableTaskConfigStore.store().setPreferenceFor(pluginId, preference);
}
Also used : TaskExtension(com.thoughtworks.go.plugin.access.pluggabletask.TaskExtension) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Localizer(com.thoughtworks.go.i18n.Localizer) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Before(org.junit.Before)

Example 19 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig 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 20 with TaskConfig

use of com.thoughtworks.go.plugin.api.task.TaskConfig in project gocd by gocd.

the class MagicalGoConfigXmlLoaderTest method shouldBeAbleToResolveSecureConfigPropertiesForPluggableTasks.

@Test
public void shouldBeAbleToResolveSecureConfigPropertiesForPluggableTasks() throws Exception {
    String encryptedValue = new GoCipher().encrypt("password");
    String configString = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'>\n" + " <pipelines>" + "<pipeline name='pipeline1'>" + "    <materials>" + "      <svn url='svnurl' username='admin' password='%s'/>" + "    </materials>" + "  <stage name='mingle'>" + "    <jobs>" + "      <job name='do-something'><tasks>" + "        <task>" + "          <pluginConfiguration id='plugin-id-1' version='1.0'/>" + "          <configuration>" + "            <property><key>username</key><value>godev</value></property>" + "            <property><key>password</key><value>password</value></property>" + "          </configuration>" + "        </task> </tasks>" + "      </job>" + "    </jobs>" + "  </stage>" + "</pipeline></pipelines>" + "</cruise>";
    //meta data of package
    PluggableTaskConfigStore.store().setPreferenceFor("plugin-id-1", new TaskPreference(new com.thoughtworks.go.plugin.api.task.Task() {

        @Override
        public TaskConfig config() {
            TaskConfig taskConfig = new TaskConfig();
            taskConfig.addProperty("username").with(Property.SECURE, false);
            taskConfig.addProperty("password").with(Property.SECURE, true);
            return taskConfig;
        }

        @Override
        public TaskExecutor executor() {
            return null;
        }

        @Override
        public TaskView view() {
            return null;
        }

        @Override
        public ValidationResult validate(TaskConfig configuration) {
            return null;
        }
    }));
    GoConfigHolder goConfigHolder = xmlLoader.loadConfigHolder(configString);
    PipelineConfig pipelineConfig = goConfigHolder.config.pipelineConfigByName(new CaseInsensitiveString("pipeline1"));
    PluggableTask task = (PluggableTask) pipelineConfig.getStage("mingle").getJobs().getJob(new CaseInsensitiveString("do-something")).getTasks().first();
    assertFalse(task.getConfiguration().getProperty("username").isSecure());
    assertTrue(task.getConfiguration().getProperty("password").isSecure());
}
Also used : PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) GoCipher(com.thoughtworks.go.security.GoCipher) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) PluggableTask(com.thoughtworks.go.config.pluggabletask.PluggableTask) TaskPreference(com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference) Test(org.junit.Test)

Aggregations

TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)27 Test (org.junit.Test)22 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)16 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)12 Configuration (com.thoughtworks.go.domain.config.Configuration)11 TaskConfigProperty (com.thoughtworks.go.plugin.api.task.TaskConfigProperty)10 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)9 TaskProperty (com.thoughtworks.go.domain.TaskProperty)8 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)6 Task (com.thoughtworks.go.plugin.api.task.Task)6 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)6 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)5 Property (com.thoughtworks.go.plugin.api.config.Property)4 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)4 JsonBasedPluggableTask (com.thoughtworks.go.plugin.access.pluggabletask.JsonBasedPluggableTask)3 GoPluginApiRequest (com.thoughtworks.go.plugin.api.request.GoPluginApiRequest)3 AntTask (com.thoughtworks.go.config.AntTask)2 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)2 PluggableTaskConfigStore (com.thoughtworks.go.plugin.access.pluggabletask.PluggableTaskConfigStore)2 Action (com.thoughtworks.go.plugin.infra.Action)2