use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.
the class PluggableTaskPluginInfoBuilder method configurations.
static List<PluginConfiguration> configurations(TaskConfig config) {
ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
for (Property property : config.list()) {
Map<String, Object> metaData = new HashMap<>();
metaData.put("required", property.getOption(Property.REQUIRED));
metaData.put("secure", property.getOption(Property.SECURE));
pluginConfigurations.add(new PluginConfiguration(property.getKey(), metaData));
}
return pluginConfigurations;
}
use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.
the class PluggableTaskViewModelBuilder method configurations.
private List<PluginConfiguration> configurations(TaskConfig config) {
ArrayList<PluginConfiguration> pluginConfigurations = new ArrayList<>();
for (Property property : config.list()) {
Map<String, Object> metaData = new HashMap<>();
metaData.put(REQUIRED_OPTION, property.getOption(Property.REQUIRED));
metaData.put(SECURE_OPTION, property.getOption(Property.SECURE));
pluginConfigurations.add(new PluginConfiguration(property.getKey(), metaData));
}
return pluginConfigurations;
}
use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.
the class PluggableTaskService method validate.
public boolean validate(final PluggableTask modifiedTask) {
final TaskConfig configuration = new TaskConfig();
for (ConfigurationProperty configurationProperty : modifiedTask.getConfiguration()) {
configuration.add(new TaskConfigProperty(configurationProperty.getConfigurationKey().getName(), configurationProperty.getValue()));
}
final String pluginId = modifiedTask.getPluginConfiguration().getId();
ValidationResult validationResult = taskExtension.validate(pluginId, configuration);
final TaskPreference preference = PluggableTaskConfigStore.store().preferenceFor(pluginId);
if (PluggableTaskConfigStore.store().hasPreferenceFor(pluginId)) {
for (ConfigurationProperty configurationProperty : modifiedTask.getConfiguration()) {
String key = configurationProperty.getConfigurationKey().getName();
final Property property = preference.getConfig().get(key);
if (property != null) {
final Boolean required = property.getOption(Property.REQUIRED);
if (required && StringUtils.isBlank(configurationProperty.getConfigValue()))
validationResult.addError(new ValidationError(property.getKey(), localizer.localize("MANDATORY_CONFIGURATION_FIELD")));
}
}
}
for (ValidationError validationError : validationResult.getErrors()) {
modifiedTask.getConfiguration().getProperty(validationError.getKey()).addError(validationError.getKey(), validationError.getMessage());
}
return validationResult.isSuccessful();
}
use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.
the class TaskViewServiceTest method shouldStoreDefaultValuesGivenForPropertiesInAPluginWhenInitializingANewTaskPlugin.
@Test
public void shouldStoreDefaultValuesGivenForPropertiesInAPluginWhenInitializingANewTaskPlugin() throws Exception {
String plugin = "task-plugin";
when(pluginManager.getPluginDescriptorFor(plugin)).thenReturn(new GoPluginDescriptor(plugin, "1", null, null, null, false));
Property taskConfigProperty1 = new TaskConfigProperty("key1", null);
Property taskConfigProperty2 = new TaskConfigProperty("key2", null);
Property taskConfigProperty3 = new TaskConfigProperty("key3", null);
storeTaskPreferences(plugin, taskConfigProperty1.withDefault("default1"), taskConfigProperty2.withDefault("default2"), taskConfigProperty3);
when(registry.implementersOf(Task.class)).thenReturn(Arrays.<Class<? extends Task>>asList(PluggableTask.class));
PluggableTask pluggableTask = (PluggableTask) taskViewService.taskInstanceFor(new PluggableTask(new PluginConfiguration(plugin, "1"), new Configuration()).getTaskType());
assertThat(pluggableTask.getConfiguration().getProperty("key1").getValue(), is("default1"));
assertThat(pluggableTask.getConfiguration().getProperty("key2").getValue(), is("default2"));
assertNull(pluggableTask.getConfiguration().getProperty("key3").getValue());
}
use of com.thoughtworks.go.plugin.api.config.Property in project gocd by gocd.
the class TaskViewServiceTest method shouldFetchPluggableTasksWithSecureConfigurations.
@Test
public void shouldFetchPluggableTasksWithSecureConfigurations() throws Exception {
String plugin = "task-plugin";
when(pluginManager.getPluginDescriptorFor(plugin)).thenReturn(new GoPluginDescriptor(plugin, "1", null, null, null, false));
Property taskConfigProperty = new TaskConfigProperty("key1", null).with(Property.SECURE, true);
storeTaskPreferences(plugin, taskConfigProperty);
when(registry.implementersOf(Task.class)).thenReturn(Arrays.<Class<? extends Task>>asList(PluggableTask.class));
PluggableTask pluggableTask = (PluggableTask) taskViewService.taskInstanceFor(new PluggableTask(new PluginConfiguration(plugin, "1"), null).getTaskType());
assertTrue(pluggableTask.getConfiguration().first().isSecure());
}
Aggregations