Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/main/java/edu/ohio/ais/rundeck/HttpBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.dtolabs.rundeck.core.execution.workflow.steps.StepException;
import com.dtolabs.rundeck.core.execution.workflow.steps.StepFailureReason;
import com.dtolabs.rundeck.core.storage.ResourceMeta;
import com.dtolabs.rundeck.core.utils.IPropertyLookup;
import com.dtolabs.rundeck.plugins.PluginLogger;
import com.dtolabs.rundeck.plugins.step.PluginStepContext;
import com.google.gson.Gson;
Expand All @@ -22,6 +23,7 @@
import org.apache.http.entity.ContentType;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.SystemDefaultRoutePlanner;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.dom4j.DocumentHelper;
Expand All @@ -33,6 +35,7 @@
import org.yaml.snakeyaml.constructor.SafeConstructor;

import java.io.*;
import java.net.ProxySelector;
import java.security.GeneralSecurityException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -107,7 +110,16 @@ public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws Ce
httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
httpClientBuilder.setSSLContext(sslContextBuilder.build());
}
if(options.get("useSystemProxySettings").equals("true") && !Boolean.parseBoolean(options.get("proxySettings").toString())) {

log.log(5, "Using proxy settings set on system");

httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()));

}
if(options.containsKey("proxySettings") && Boolean.parseBoolean(options.get("proxySettings").toString())){
log.log(5, "proxy IP set in job: " + options.get("proxyIP").toString());

HttpHost proxy = new HttpHost(options.get("proxyIP").toString(), Integer.valueOf((String)options.get("proxyPort")), "http");
httpClientBuilder.setProxy(proxy);
}
Expand Down Expand Up @@ -460,5 +472,23 @@ public void setHeaders(String headers, RequestBuilder request){
}
}

static void propertyResolver(String pluginType, String property, Map<String,Object> Configuration, PluginStepContext context, String SERVICE_PROVIDER_NAME) {

String projectPrefix = "project.plugin." + pluginType + "." + SERVICE_PROVIDER_NAME + ".";
String frameworkPrefix = "framework.plugin." + pluginType + "." + SERVICE_PROVIDER_NAME + ".";

Map<String,String> projectProperties = context.getFramework().getFrameworkProjectMgr().getFrameworkProject(context.getFrameworkProject()).getProperties();
IPropertyLookup frameworkProperties = context.getFramework().getPropertyLookup();

if(!Configuration.containsKey(property) && projectProperties.containsKey(projectPrefix + property)) {

Configuration.put(property, projectProperties.get(projectPrefix + property));

} else if (!Configuration.containsKey(property) && frameworkProperties.hasProperty(frameworkPrefix + property)) {

Configuration.put(property, frameworkProperties.getProperty(frameworkPrefix + property));

}
}

}
7 changes: 7 additions & 0 deletions src/main/java/edu/ohio/ais/rundeck/HttpDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dtolabs.rundeck.core.plugins.configuration.Describable;
import com.dtolabs.rundeck.core.plugins.configuration.Description;
import com.dtolabs.rundeck.core.plugins.configuration.PropertyScope;
import com.dtolabs.rundeck.core.plugins.configuration.StringRenderingConstants;
import com.dtolabs.rundeck.plugins.util.DescriptionBuilder;
import com.dtolabs.rundeck.plugins.util.PropertyBuilder;
Expand Down Expand Up @@ -165,6 +166,12 @@ public Description getDescription() {
.defaultValue("false")
.renderingOption(StringRenderingConstants.GROUP_NAME,"Print")
.build())
.property(PropertyBuilder.builder()
.booleanType("useSystemProxySettings")
.description("Choose whether to use proxy settings set on the JVM.")
.defaultValue("false")
.scope(PropertyScope.Project)
.build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
import com.dtolabs.rundeck.core.execution.ExecutionContext;
import com.dtolabs.rundeck.core.execution.proxy.ProxySecretBundleCreator;
import com.dtolabs.rundeck.core.execution.proxy.SecretBundle;
import com.dtolabs.rundeck.core.execution.utils.ResolverUtil;
import com.dtolabs.rundeck.core.execution.workflow.steps.StepException;
import com.dtolabs.rundeck.core.execution.workflow.steps.StepFailureReason;
import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException;
import com.dtolabs.rundeck.core.plugins.Plugin;
import com.dtolabs.rundeck.core.plugins.configuration.Describable;
import com.dtolabs.rundeck.core.plugins.configuration.Description;
import com.dtolabs.rundeck.core.utils.IPropertyLookup;
import com.dtolabs.rundeck.plugins.PluginLogger;
import com.dtolabs.rundeck.plugins.ServiceNameConstants;
import com.dtolabs.rundeck.plugins.descriptions.PluginProperty;
import com.dtolabs.rundeck.plugins.step.NodeStepPlugin;
import com.dtolabs.rundeck.plugins.step.PluginStepContext;
import com.dtolabs.rundeck.plugins.util.DescriptionBuilder;
import edu.ohio.ais.rundeck.util.OAuthClient;
import edu.ohio.ais.rundeck.util.SecretBundleUtil;
import org.apache.http.HttpEntity;
Expand All @@ -25,6 +29,8 @@
import java.io.UnsupportedEncodingException;
import java.util.*;

import static edu.ohio.ais.rundeck.HttpBuilder.propertyResolver;

@Plugin(name = HttpWorkflowNodeStepPlugin.SERVICE_PROVIDER_NAME, service = ServiceNameConstants.WorkflowNodeStep)
public class HttpWorkflowNodeStepPlugin implements NodeStepPlugin, Describable, ProxySecretBundleCreator {
public static final String SERVICE_PROVIDER_NAME = "edu.ohio.ais.rundeck.HttpWorkflowNodeStepPlugin";
Expand All @@ -40,7 +46,6 @@ public class HttpWorkflowNodeStepPlugin implements NodeStepPlugin, Describable,
*/
public static final Integer DEFAULT_TIMEOUT = 30*1000;


/**
* Synchronized map of all existing OAuth clients. This is indexed by
* the Client ID and the token URL so that we can store and re-use access tokens.
Expand All @@ -58,6 +63,11 @@ public Description getDescription() {
public void executeNodeStep(PluginStepContext context, Map<String, Object> configuration, INodeEntry entry) throws NodeStepException {
PluginLogger log = context.getLogger();

Description description = new HttpDescription(SERVICE_PROVIDER_NAME, "HTTP Request Node Step", "Performs an HTTP request with or without authentication (per node)").getDescription();
description.getProperties().forEach(prop->
propertyResolver("WorkflowNodeStep", prop.getName(), configuration, context, SERVICE_PROVIDER_NAME)
);

// Parse out the options
String remoteUrl = configuration.containsKey("remoteUrl") ? configuration.get("remoteUrl").toString() : null;
String method = configuration.containsKey("method") ? configuration.get("method").toString() : null;
Expand Down Expand Up @@ -146,4 +156,5 @@ public SecretBundle prepareSecretBundleWorkflowNodeStep(ExecutionContext context
public List<String> listSecretsPathWorkflowNodeStep(ExecutionContext context, INodeEntry node, Map<String, Object> configuration) {
return SecretBundleUtil.getListSecrets(configuration);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.*;
import java.util.*;

import static edu.ohio.ais.rundeck.HttpBuilder.propertyResolver;


/**
* Main implementation of the plugin. This will handle fetching
Expand Down Expand Up @@ -69,6 +71,11 @@ public Description getDescription() {
public void executeStep(PluginStepContext pluginStepContext, Map<String, Object> options) throws StepException {
PluginLogger log = pluginStepContext.getLogger();

Description description = new HttpDescription(SERVICE_PROVIDER_NAME, "HTTP Request Node Step", "Performs an HTTP request with or without authentication (per node)").getDescription();
description.getProperties().forEach(prop->
propertyResolver("WorkflowStep",prop.getName(), options, pluginStepContext, SERVICE_PROVIDER_NAME)
);

// Parse out the options
String remoteUrl = options.containsKey("remoteUrl") ? options.get("remoteUrl").toString() : null;
String method = options.containsKey("method") ? options.get("method").toString() : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package edu.ohio.ais.rundeck;

import com.dtolabs.rundeck.core.common.Framework;
import com.dtolabs.rundeck.core.common.FrameworkProject;
import com.dtolabs.rundeck.core.common.FrameworkProjectMgr;
import com.dtolabs.rundeck.core.common.INodeEntry;
import com.dtolabs.rundeck.core.execution.ExecutionContext;
import com.dtolabs.rundeck.core.execution.ExecutionLogger;
import com.dtolabs.rundeck.core.execution.workflow.steps.StepFailureReason;
import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException;
import com.dtolabs.rundeck.core.plugins.configuration.Description;
import com.dtolabs.rundeck.core.utils.IPropertyLookup;
import com.dtolabs.rundeck.plugins.PluginLogger;
import com.dtolabs.rundeck.plugins.step.PluginStepContext;
import com.github.tomakehurst.wiremock.client.WireMock;
Expand All @@ -27,6 +31,7 @@
import java.util.Map;

import static org.junit.Assert.*;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;

public class HttpWorkflowNodeStepPluginTest {
Expand Down Expand Up @@ -176,6 +181,20 @@ public void setUp() {
when(pluginContext.getLogger()).thenReturn(pluginLogger);
when(pluginContext.getExecutionContext()).thenReturn(executionContext);

// Mock the necessary objects
Framework framework = Mockito.mock(Framework.class);
FrameworkProjectMgr frameworkProjectMgr = Mockito.mock(FrameworkProjectMgr.class);
FrameworkProject frameworkProject = Mockito.mock(FrameworkProject.class);
IPropertyLookup frameworkProperties = Mockito.mock(IPropertyLookup.class);

// Mock the interactions
when(pluginContext.getFramework()).thenReturn(framework);
when(framework.getFrameworkProjectMgr()).thenReturn(frameworkProjectMgr);
when(frameworkProjectMgr.getFrameworkProject(anyString())).thenReturn(frameworkProject);
when(frameworkProject.getProperties()).thenReturn(new HashMap<String, String>());
when(framework.getPropertyLookup()).thenReturn(frameworkProperties);
when(frameworkProperties.hasProperty(anyString())).thenReturn(true);

dataContext =new HashMap<>();
when(pluginContext.getDataContext()).thenReturn(dataContext);

Expand Down
Loading