Skip to content

Commit

Permalink
add a JVM flag to disable local execution
Browse files Browse the repository at this point in the history
  • Loading branch information
ltamaster committed Oct 19, 2021
1 parent 446ec47 commit cd7510f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,11 @@
*/
public class LocalFileCopier extends BaseFileCopier implements FileCopier {
public static final String SERVICE_PROVIDER_TYPE = "local";
public static final String DISABLE_LOCAL_EXECUTOR_ENV = "RUNDECK_DISABLED_LOCAL_EXECUTOR";
private boolean disableLocalExecutor = false;

public LocalFileCopier(Framework framework) {
this.framework = framework;

String disableLocalExecutor = System.getenv(DISABLE_LOCAL_EXECUTOR_ENV);

if(disableLocalExecutor!=null && disableLocalExecutor.equals("true")){
this.disableLocalExecutor=true;
}

this.disableLocalExecutor = LocalNodeExecutor.getDisableLocalExecutorEnv();
}

public void setDisableLocalExecutor(boolean disableLocalExecutor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
public class LocalNodeExecutor implements NodeExecutor {
public static final String SERVICE_PROVIDER_TYPE = "local";
public static final String DISABLE_LOCAL_EXECUTOR_ENV = "RUNDECK_DISABLED_LOCAL_EXECUTOR";
public static final String DISABLE_LOCAL_EXECUTOR_PROP = "rundeck.localExecutor.disabled";

private Framework framework;
private ExecTaskParameterGenerator parameterGenerator;
Expand All @@ -66,13 +67,23 @@ public class LocalNodeExecutor implements NodeExecutor {
public LocalNodeExecutor(final Framework framework) {
this.framework = framework;
parameterGenerator = new ExecTaskParameterGeneratorImpl();
this.disableLocalExecutor = getDisableLocalExecutorEnv();
}

static Boolean getDisableLocalExecutorEnv(){
String disableLocalExecutor = System.getenv(DISABLE_LOCAL_EXECUTOR_ENV);

if(disableLocalExecutor!=null && disableLocalExecutor.equals("true")){
this.disableLocalExecutor=true;
return true;
}

disableLocalExecutor = System.getProperty(DISABLE_LOCAL_EXECUTOR_PROP);

if(disableLocalExecutor!=null && disableLocalExecutor.equals("true")){
return true;
}

return false;
}

public void setDisableLocalExecutor(boolean disableLocalExecutor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,27 @@ class LocalFileCopierSpec extends Specification{
e.message == "Local Executor is disabled"

}


def "disable local file copier jvm property"() {
given:
def node = Mock(INodeEntry)
def context = Mock(ExecutionContext){
getExecutionListener()>> Mock(ExecutionListener)
}
def framework = Mock(Framework)
System.setProperty("rundeck.localExecutor.disabled","true")

def plugin = new LocalFileCopier(framework)

File scriptFile = File.createTempFile("test","sh");

when:
def result = plugin.copyFile(context, scriptFile, node, "/tmp/inlinescript.sh" )

then:
FileCopierException e = thrown()
e.message == "Local Executor is disabled"

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,28 @@ class LocalNodeExecutorSpec extends Specification {
result.failureMessage == "Local Executor is disabled"

}

def "disable local executor jvm propertu"() {
given:
def node = Mock(INodeEntry)
def context = Mock(ExecutionContext){
getExecutionListener()>> Mock(ExecutionListener)
}
def command = ['a', 'command'] as String[]
def framework = Mock(Framework)

System.setProperty("rundeck.localExecutor.disabled","true")

def plugin = new LocalNodeExecutor(framework)

when:
def result = plugin.executeCommand(context, command, node)

then:
result != null
!result.success
result.failureReason != null
result.failureMessage == "Local Executor is disabled"

}
}

0 comments on commit cd7510f

Please sign in to comment.