Skip to content

Commit

Permalink
adding property resolver to both plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jsboak committed May 24, 2024
1 parent 966510e commit b47ec15
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 33 deletions.
22 changes: 22 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 Down Expand Up @@ -108,6 +109,9 @@ public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws Ce
httpClientBuilder.setSSLContext(sslContextBuilder.build());
}
if(options.containsKey("proxySettings") && Boolean.parseBoolean(options.get("proxySettings").toString())){
log.log(5, "using proxy IP: " + options.get("proxyIP").toString());
log.log(5, "using proxy Port: " + options.get("proxyPort").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 +464,23 @@ public void setHeaders(String headers, RequestBuilder request){
}
}

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

String projectPrefix = "project.plugin.WorkflowNodeStep." + SERVICE_PROVIDER_NAME + ".";
String frameworkPrefix = "framework.plugin.WorkflowNodeStep" + 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));

}
}

}
36 changes: 3 additions & 33 deletions src/main/java/edu/ohio/ais/rundeck/HttpWorkflowNodeStepPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,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 @@ -44,13 +46,6 @@ public class HttpWorkflowNodeStepPlugin implements NodeStepPlugin, Describable,
*/
public static final Integer DEFAULT_TIMEOUT = 30*1000;

// @PluginProperty(
// title = "Proxy URL",
// description = "HTTP URL to which to make the request.",
// required = true
// )
// String proxyURL;

/**
* 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 @@ -70,13 +65,8 @@ public void executeNodeStep(PluginStepContext context, Map<String, Object> confi

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(prop.getName(), configuration, context)
propertyResolver(prop.getName(), configuration, context, SERVICE_PROVIDER_NAME)
);
// propertyResolver("proxyIP", configuration, context);
// propertyResolver("proxyPort", configuration, context);

System.out.println("post-resolver proxyIp: " + configuration.get("proxyIP"));
// System.out.println("proxySettings: " + configuration.get("proxySettings"));

// Parse out the options
String remoteUrl = configuration.containsKey("remoteUrl") ? configuration.get("remoteUrl").toString() : null;
Expand Down Expand Up @@ -167,24 +157,4 @@ public List<String> listSecretsPathWorkflowNodeStep(ExecutionContext context, IN
return SecretBundleUtil.getListSecrets(configuration);
}

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

String projectPrefix = "project.plugin.WorkflowNodeStep." + SERVICE_PROVIDER_NAME + ".";
String frameworkPrefix = "framework.plugin.WorkflowNodeStep" + 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));

}
System.out.println("resolver: " + property + Configuration.get(property));
}

}
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(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

0 comments on commit b47ec15

Please sign in to comment.