From 37c2f21835f4ea42dfd7e8def8997d62ea991073 Mon Sep 17 00:00:00 2001 From: Kim Ho Date: Fri, 8 Nov 2013 09:51:30 -0800 Subject: [PATCH 01/14] Remove job polling log noise --- .../java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin.java b/src/main/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin.java index 07e82c8..49b28a2 100644 --- a/src/main/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin.java +++ b/src/main/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin.java @@ -364,12 +364,13 @@ protected void validate(String user, String password, INodeEntry entry) throws S protected String waitForJidResponse(HttpClient client, String authToken, String jid, String minionId) throws IOException, InterruptedException, SaltApiException { ExponentialBackoffTimer timer = timerFactory.newTimer(delayStep, maximumRetryDelay); + String jidResource = String.format("%s%s/%s", saltEndpoint, JOBS_RESOURCE, jid); + logWrapper.info("Polling for job status with salt-api endpoint: [%s]", jidResource); do { String response = extractOutputForJid(client, authToken, jid, minionId); if (response != null) { return response; } - logWrapper.debug("No response received, waiting..."); timer.waitForNext(); } while (true); } @@ -390,14 +391,12 @@ protected String extractOutputForJid(HttpClient client, String authToken, String get.setHeader(SALT_AUTH_TOKEN_HEADER, authToken); get.setHeader(REQUEST_ACCEPT_HEADER_NAME, JSON_RESPONSE_ACCEPT_TYPE); - logWrapper.info("Polling for job status with salt-api endpoint: [%s]", get.getURI()); HttpResponse response = retryExecutor.execute(logWrapper, client, get, numRetries); try { if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); String entityResponse = extractBodyFromEntity(entity); - logWrapper.debug("Received response for jobs/%s = %s", jid, response); Gson gson = new Gson(); Map>> result = gson.fromJson(entityResponse, JOB_RESPONSE_TYPE); List> responses = result.get(SALT_OUTPUT_RETURN_KEY); @@ -406,6 +405,7 @@ protected String extractOutputForJid(HttpClient client, String authToken, String } else if (responses.size() == 1) { Map minionResponse = responses.get(0); if (minionResponse.containsKey(minionId)) { + logWrapper.debug("Received response for jobs/%s = %s", jid, response); Object responseObj = minionResponse.get(minionId); return gson.toJson(responseObj); } From 9aeea28e08cc7e8a7a3b105e26be78c89d6eac57 Mon Sep 17 00:00:00 2001 From: Kim Ho Date: Thu, 19 Dec 2013 11:30:26 -0800 Subject: [PATCH 02/14] Externalize BCP jars --- build.gradle | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b216682..f61f225 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ artifacts { } configurations { + provided pluginCompile compile { extendsFrom pluginCompile @@ -68,6 +69,9 @@ dependencies { 'org.apache.commons:commons-io:1.3.2', 'com.google.code.findbugs:jsr305:2.0.1' ) + provided ( + 'org.bouncycastle:bcpkix-jdk15on:1.48', + ) testCompile ( 'junit:junit:4.11', 'org.mockito:mockito-all:1.9.5', @@ -85,5 +89,5 @@ jar { 'Rundeck-Plugin-Classnames': pluginClassNames, 'Rundeck-Plugin-Libs': packagedJars } - from configurations.pluginCompile + from (configurations.pluginCompile - configurations.provided) } From 27fec37d659b3df4f879b3391accd4909f121d19 Mon Sep 17 00:00:00 2001 From: Kim Ho Date: Thu, 19 Dec 2013 16:00:30 -0800 Subject: [PATCH 03/14] Remove bcp dependency --- build.gradle | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index f61f225..b216682 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,6 @@ artifacts { } configurations { - provided pluginCompile compile { extendsFrom pluginCompile @@ -69,9 +68,6 @@ dependencies { 'org.apache.commons:commons-io:1.3.2', 'com.google.code.findbugs:jsr305:2.0.1' ) - provided ( - 'org.bouncycastle:bcpkix-jdk15on:1.48', - ) testCompile ( 'junit:junit:4.11', 'org.mockito:mockito-all:1.9.5', @@ -89,5 +85,5 @@ jar { 'Rundeck-Plugin-Classnames': pluginClassNames, 'Rundeck-Plugin-Libs': packagedJars } - from (configurations.pluginCompile - configurations.provided) + from configurations.pluginCompile } From 14fb3ddc933914727715b5d66ebbbbda6537e9ce Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Mon, 14 Jul 2014 18:45:36 -0700 Subject: [PATCH 04/14] Add file.touch to the list of commands that are always successful --- src/main/resources/defaultReturners.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/defaultReturners.yaml b/src/main/resources/defaultReturners.yaml index 5d993df..2ffeaa6 100644 --- a/src/main/resources/defaultReturners.yaml +++ b/src/main/resources/defaultReturners.yaml @@ -5,5 +5,6 @@ alwaysSuccessful: &alwaysSuccessful !!org.rundeck.plugin.salt.output.DefaultSalt handlerMappings: cmd.run_all: *defaultCommandParser + file.touch: *alwaysSuccessful file.append: *alwaysSuccessful file.remove: *alwaysSuccessful From 61b4dd6d3c32c4617ba5030fb61a58b5d2064d62 Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Thu, 17 Jul 2014 10:13:58 -0700 Subject: [PATCH 05/14] Make HTTP scheme configurable --- .../plugin/salt/SaltApiNodeStepPlugin.java | 12 +++++++--- src/main/resources/salt-api-plugin.properties | 3 ++- .../SaltApiNodeStepPlugin_ExecuteTest.java | 22 ++++++++++++++----- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin.java b/src/main/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin.java index 49b28a2..c892405 100644 --- a/src/main/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin.java +++ b/src/main/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin.java @@ -110,8 +110,6 @@ public enum SaltApiNodeStepFailureReason implements FailureReason { protected static final String SECURE_OPTION_VALUE = "****"; - protected static final String[] VALID_SALT_API_END_POINT_SCHEMES = { "http", "https" }; - protected static final String LOGIN_RESOURCE = "/login"; protected static final String MINION_RESOURCE = "/minions"; protected static final String JOBS_RESOURCE = "/jobs"; @@ -191,6 +189,9 @@ public enum SaltApiNodeStepFailureReason implements FailureReason { @Value("${saltApi.http.numRetries}") protected int numRetries; + // Supported API protocols + protected String[] endPointSchemes; + @Autowired protected ExponentialBackoffTimer.Factory timerFactory; @@ -198,6 +199,11 @@ public SaltApiNodeStepPlugin() { new DependencyInjectionUtil().inject(this); } + @Autowired + public void setEndPointSchemes(@Value("${saltApi.endPointSchemes}") String epSchemes) throws IllegalArgumentException { + endPointSchemes = epSchemes.split(","); + } + @Override public void executeNodeStep(PluginStepContext context, Map configuration, INodeEntry entry) throws NodeStepException { @@ -353,7 +359,7 @@ protected void validate(String user, String password, INodeEntry entry) throws S checkNotEmpty(SALT_USER_OPTION_NAME, user, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry); checkNotEmpty(SALT_PASSWORD_OPTION_NAME, password, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry); - UrlValidator urlValidator = new UrlValidator(VALID_SALT_API_END_POINT_SCHEMES, UrlValidator.ALLOW_LOCAL_URLS); + UrlValidator urlValidator = new UrlValidator(endPointSchemes, UrlValidator.ALLOW_LOCAL_URLS); if (!urlValidator.isValid(saltEndpoint)) { throw new SaltStepValidationException(SALT_API_END_POINT_OPTION_NAME, String.format( "%s is not a valid endpoint.", saltEndpoint), SaltApiNodeStepFailureReason.ARGUMENTS_INVALID, diff --git a/src/main/resources/salt-api-plugin.properties b/src/main/resources/salt-api-plugin.properties index 414b78b..b052067 100644 --- a/src/main/resources/salt-api-plugin.properties +++ b/src/main/resources/salt-api-plugin.properties @@ -5,4 +5,5 @@ retryingHttpClientExecutor.maximumRetryDelay=15000 retryingHttpClientExecutor.delayStep=500 saltJobPolling.maximumRetryDelay=15000 saltJobPolling.delayStep=500 -saltApi.http.numRetries=5 \ No newline at end of file +saltApi.http.numRetries=5 +saltApi.endPointSchemes=http,https \ No newline at end of file diff --git a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java index fa81646..37ed79d 100644 --- a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java +++ b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java @@ -26,8 +26,8 @@ package org.rundeck.plugin.salt; -import java.util.Set; - +import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException; +import com.google.common.collect.ImmutableSet; import org.apache.http.HttpException; import org.apache.http.client.HttpClient; import org.junit.Assert; @@ -39,10 +39,8 @@ import org.rundeck.plugin.salt.output.SaltReturnResponse; import org.rundeck.plugin.salt.output.SaltReturnResponseParseException; import org.rundeck.plugin.salt.validation.SaltStepValidationException; -import org.rundeck.plugin.salt.version.SaltApiCapability; -import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException; -import com.google.common.collect.ImmutableSet; +import java.util.Set; public class SaltApiNodeStepPlugin_ExecuteTest extends AbstractSaltApiNodeStepPluginTest { @@ -273,6 +271,20 @@ public void testExecuteWithHttpException() { } } + @Test + public void testExecuteWithUnsupportedEndPointScheme() { + setupAuthenticate(); + plugin.setEndPointSchemes("https"); + + try { + plugin.executeNodeStep(pluginContext, configuration, node); + Assert.fail("Expected node step failure."); + } catch (NodeStepException e) { + Assert.assertEquals("Expected failure reason to be set based on exception type", + SaltApiNodeStepFailureReason.ARGUMENTS_INVALID, e.getFailureReason()); + } + } + @Test public void testExecuteWithInterruptedException() throws Exception { setupAuthenticate(); From 0e2cfa6e212e5de56cecbd348e8ccd76e62481b0 Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Wed, 23 Jul 2014 15:42:44 -0700 Subject: [PATCH 06/14] Add missing unit test setup steps for prevent npe --- .../plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java index 37ed79d..72c5225 100644 --- a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java +++ b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java @@ -52,6 +52,9 @@ public void setup() throws Exception { @Test public void testExecuteWithAuthenticationFailure() { setupAuthenticate(null); + setupDoReturnJidWhenSubmitJob(); + setupDoReturnHostResponseWhenWaitForResponse(); + setupDoReturnSaltResponseWhenExtractResponse(0, new String[0], new String[0]); try { plugin.executeNodeStep(pluginContext, configuration, node); @@ -79,6 +82,9 @@ public void testExecuteWithValidationFailure() throws Exception { @Test public void testExecuteWithDataContextMissing() { + setupDoReturnJidWhenSubmitJob(); + setupDoReturnHostResponseWhenWaitForResponse(); + setupDoReturnSaltResponseWhenExtractResponse(0, new String[0], new String[0]); dataContext.clear(); try { plugin.executeNodeStep(pluginContext, configuration, node); @@ -274,6 +280,10 @@ public void testExecuteWithHttpException() { @Test public void testExecuteWithUnsupportedEndPointScheme() { setupAuthenticate(); + setupDoReturnJidWhenSubmitJob(); + setupDoReturnHostResponseWhenWaitForResponse(); + setupDoReturnSaltResponseWhenExtractResponse(0, new String[0], new String[0]); + plugin.setEndPointSchemes("https"); try { From f959459e711ba8c601f521fe556cdf8ff794eb86 Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Wed, 23 Jul 2014 15:59:46 -0700 Subject: [PATCH 07/14] Add setupAuth() for missing data context test --- .../rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java index 72c5225..0228f7f 100644 --- a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java +++ b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java @@ -82,6 +82,7 @@ public void testExecuteWithValidationFailure() throws Exception { @Test public void testExecuteWithDataContextMissing() { + setupAuthenticate(); setupDoReturnJidWhenSubmitJob(); setupDoReturnHostResponseWhenWaitForResponse(); setupDoReturnSaltResponseWhenExtractResponse(0, new String[0], new String[0]); From 69d40c2003e0e4f30239a8c0905a66b0def425a6 Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Thu, 24 Jul 2014 09:22:58 -0700 Subject: [PATCH 08/14] Restrict default http scheme to https only --- src/main/resources/salt-api-plugin.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/salt-api-plugin.properties b/src/main/resources/salt-api-plugin.properties index b052067..fef47f2 100644 --- a/src/main/resources/salt-api-plugin.properties +++ b/src/main/resources/salt-api-plugin.properties @@ -6,4 +6,4 @@ retryingHttpClientExecutor.delayStep=500 saltJobPolling.maximumRetryDelay=15000 saltJobPolling.delayStep=500 saltApi.http.numRetries=5 -saltApi.endPointSchemes=http,https \ No newline at end of file +saltApi.endPointSchemes=https \ No newline at end of file From 54cedb41fa73ac2cbc066dd83d23d295c1bbf610 Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Thu, 24 Jul 2014 09:37:34 -0700 Subject: [PATCH 09/14] Upgrade rundeck plugin version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 3ad0aea..a3081ee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ version = 0.2 -rundeckPluginVersion = 1.1 +rundeckPluginVersion = 1.2 mavenCentralUrl = http://repo1.maven.org/maven2 From 76f085861e0b2fb6ac37b0eeb54d154e8ad93604 Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Thu, 24 Jul 2014 13:05:46 -0700 Subject: [PATCH 10/14] Unit test fixes for configurable end point scheme --- .../AbstractSaltApiNodeStepPluginTest.java | 20 +++++++++---------- .../SaltApiNodeStepPlugin_ExecuteTest.java | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/test/java/org/rundeck/plugin/salt/AbstractSaltApiNodeStepPluginTest.java b/src/test/java/org/rundeck/plugin/salt/AbstractSaltApiNodeStepPluginTest.java index 51c2655..d83c29e 100644 --- a/src/test/java/org/rundeck/plugin/salt/AbstractSaltApiNodeStepPluginTest.java +++ b/src/test/java/org/rundeck/plugin/salt/AbstractSaltApiNodeStepPluginTest.java @@ -26,10 +26,11 @@ package org.rundeck.plugin.salt; -import java.net.URI; -import java.net.URLEncoder; -import java.util.Map; - +import com.dtolabs.rundeck.core.common.INodeEntry; +import com.dtolabs.rundeck.plugins.PluginLogger; +import com.dtolabs.rundeck.plugins.step.PluginStepContext; +import com.google.common.base.Predicate; +import com.google.common.collect.Maps; import org.apache.commons.io.IOUtils; import org.apache.http.Header; import org.apache.http.HttpEntity; @@ -54,15 +55,13 @@ import org.rundeck.plugin.salt.util.RetryingHttpClientExecutor; import org.rundeck.plugin.salt.version.SaltApiCapability; -import com.dtolabs.rundeck.core.common.INodeEntry; -import com.dtolabs.rundeck.plugins.PluginLogger; -import com.dtolabs.rundeck.plugins.step.PluginStepContext; -import com.google.common.base.Predicate; -import com.google.common.collect.Maps; +import java.net.URI; +import java.net.URLEncoder; +import java.util.Map; public abstract class AbstractSaltApiNodeStepPluginTest { - protected static final String PARAM_ENDPOINT = "http://localhost"; + protected static final String PARAM_ENDPOINT = "https://localhost"; protected static final String PARAM_EAUTH = "pam"; protected static final String PARAM_MINION_NAME = "minion"; protected static final String PARAM_FUNCTION = "some.function"; @@ -107,6 +106,7 @@ public void setUp() { plugin.saltEndpoint = PARAM_ENDPOINT; plugin.eAuth = PARAM_EAUTH; plugin.function = PARAM_FUNCTION; + plugin.setEndPointSchemes("https"); latestCapability = plugin.capabilityRegistry.getLatest(); client = Mockito.mock(HttpClient.class); post = Mockito.mock(HttpPost.class); diff --git a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java index 0228f7f..2b3d4cd 100644 --- a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java +++ b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ExecuteTest.java @@ -285,7 +285,7 @@ public void testExecuteWithUnsupportedEndPointScheme() { setupDoReturnHostResponseWhenWaitForResponse(); setupDoReturnSaltResponseWhenExtractResponse(0, new String[0], new String[0]); - plugin.setEndPointSchemes("https"); + plugin.setEndPointSchemes("http"); try { plugin.executeNodeStep(pluginContext, configuration, node); From 27a2977702868789cd1590c4f262b22e931726df Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Thu, 24 Jul 2014 13:37:23 -0700 Subject: [PATCH 11/14] Fix validation test http scheme --- .../plugin/salt/SaltApiNodeStepPlugin_ValidationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ValidationTest.java b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ValidationTest.java index ae2c467..4f7a19b 100644 --- a/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ValidationTest.java +++ b/src/test/java/org/rundeck/plugin/salt/SaltApiNodeStepPlugin_ValidationTest.java @@ -89,7 +89,7 @@ public void testValidateThrowsIfValidatorThrows() throws SaltStepValidationExcep @Test public void testValidateChecksValidEndpointHttpUrl() throws NodeStepException { - plugin.saltEndpoint = "http://some.machine.com"; + plugin.saltEndpoint = "https://some.machine.com"; plugin.validate(PARAM_USER, PARAM_PASSWORD, node); } From ffb4b9c18007e7512b9ba531655868e042e48d08 Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Thu, 24 Jul 2014 16:01:52 -0700 Subject: [PATCH 12/14] Update correct version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index a3081ee..cd34e83 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version = 0.2 +version = 0.3 rundeckPluginVersion = 1.2 mavenCentralUrl = http://repo1.maven.org/maven2 From 32724695054bd93c36e524998f6dd975672410ff Mon Sep 17 00:00:00 2001 From: mezbiderli Date: Thu, 24 Jul 2014 17:10:16 -0700 Subject: [PATCH 13/14] Re-down rundeck plugin version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index cd34e83..19cb58c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ version = 0.3 -rundeckPluginVersion = 1.2 +rundeckPluginVersion = 1.1 mavenCentralUrl = http://repo1.maven.org/maven2 From 4cbdc0354806d8f9601c527f8de63b75a2cb3ef4 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Thu, 24 Jul 2014 17:10:17 -0700 Subject: [PATCH 14/14] fix Rundeck-Plugin-Version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index cd34e83..19cb58c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ version = 0.3 -rundeckPluginVersion = 1.2 +rundeckPluginVersion = 1.1 mavenCentralUrl = http://repo1.maven.org/maven2