Search in sources :

Example 26 with TaskConfig

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

the class PluggableTaskPluginInfoBuilderTest method setUp.

@Before
public void setUp() throws Exception {
    extension = mock(TaskExtension.class);
    TaskConfig taskConfig = new TaskConfig();
    taskConfig.add(new TaskConfigProperty("username", null).with(Property.REQUIRED, true).with(Property.SECURE, false));
    taskConfig.add(new TaskConfigProperty("password", null).with(Property.REQUIRED, true).with(Property.SECURE, true));
    TaskView taskView = new TaskView() {

        @Override
        public String displayValue() {
            return "my task plugin";
        }

        @Override
        public String template() {
            return "some html";
        }
    };
    final Task task = mock(Task.class);
    when(task.config()).thenReturn(taskConfig);
    when(task.view()).thenReturn(taskView);
    final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
    String pluginId = "plugin1";
    when(descriptor.id()).thenReturn(pluginId);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            final Action<Task> action = (Action<Task>) invocation.getArguments()[1];
            action.execute(task, descriptor);
            return null;
        }
    }).when(extension).doOnTask(eq("plugin1"), any(Action.class));
}
Also used : TaskView(com.thoughtworks.go.plugin.api.task.TaskView) Task(com.thoughtworks.go.plugin.api.task.Task) Action(com.thoughtworks.go.plugin.infra.Action) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) TaskConfigProperty(com.thoughtworks.go.plugin.api.task.TaskConfigProperty) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Before(org.junit.Before)

Example 27 with TaskConfig

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

the class PluggableTaskPreferenceLoaderTest method shouldRemoveConfigForTheTaskCorrespondingToGivenPluginId.

@Test
public void shouldRemoveConfigForTheTaskCorrespondingToGivenPluginId() throws Exception {
    final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
    String pluginId = "test-plugin-id";
    when(descriptor.id()).thenReturn(pluginId);
    final Task task = mock(Task.class);
    TaskConfig config = new TaskConfig();
    TaskView taskView = mock(TaskView.class);
    when(task.config()).thenReturn(config);
    when(task.view()).thenReturn(taskView);
    PluggableTaskConfigStore.store().setPreferenceFor(pluginId, new TaskPreference(task));
    PluginManager pluginManager = mock(PluginManager.class);
    PluggableTaskPreferenceLoader pluggableTaskPreferenceLoader = new PluggableTaskPreferenceLoader(pluginManager, taskExtension);
    assertThat(PluggableTaskConfigStore.store().hasPreferenceFor(pluginId), is(true));
    pluggableTaskPreferenceLoader.pluginUnLoaded(descriptor);
    assertThat(PluggableTaskConfigStore.store().hasPreferenceFor(pluginId), is(false));
    verify(pluginManager).addPluginChangeListener(pluggableTaskPreferenceLoader);
}
Also used : PluginManager(com.thoughtworks.go.plugin.infra.PluginManager) Task(com.thoughtworks.go.plugin.api.task.Task) TaskView(com.thoughtworks.go.plugin.api.task.TaskView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) Test(org.junit.Test)

Example 28 with TaskConfig

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

the class PluggableTaskPluginInfoBuilder method pluginInfoFor.

public PluggableTaskPluginInfo pluginInfoFor(GoPluginDescriptor descriptor) {
    final TaskPreference[] tp = { null };
    extension.doOnTask(descriptor.id(), new Action<Task>() {

        @Override
        public void execute(Task task, GoPluginDescriptor pluginDescriptor) {
            tp[0] = new TaskPreference(task);
        }
    });
    TaskConfig config = tp[0].getConfig();
    TaskView view = tp[0].getView();
    if (config == null) {
        throw new RuntimeException(format("Plugin[%s] returned null task configuration", descriptor.id()));
    }
    if (view == null) {
        throw new RuntimeException(format("Plugin[%s] returned null task view", descriptor.id()));
    }
    String displayName = view.displayValue();
    PluggableInstanceSettings taskSettings = new PluggableInstanceSettings(configurations(config), new PluginView(view.template()));
    return new PluggableTaskPluginInfo(descriptor, displayName, taskSettings);
}
Also used : Task(com.thoughtworks.go.plugin.api.task.Task) TaskView(com.thoughtworks.go.plugin.api.task.TaskView) PluggableTaskPluginInfo(com.thoughtworks.go.plugin.domain.pluggabletask.PluggableTaskPluginInfo) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) PluggableInstanceSettings(com.thoughtworks.go.plugin.domain.common.PluggableInstanceSettings) PluginView(com.thoughtworks.go.plugin.domain.common.PluginView) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)

Example 29 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) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) GoCipher(com.thoughtworks.go.security.GoCipher) TaskConfig(com.thoughtworks.go.plugin.api.task.TaskConfig) 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)29 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)11 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)11 TaskProperty (com.thoughtworks.go.domain.TaskProperty)8 Task (com.thoughtworks.go.plugin.api.task.Task)8 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)8 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)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 Action (com.thoughtworks.go.plugin.infra.Action)3 Before (org.junit.Before)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Answer (org.mockito.stubbing.Answer)3