diff --git a/Synapse.Handler.CommandLine/Classes/CommandHandlerConfig.cs b/Synapse.Handler.CommandLine/Classes/CommandHandlerConfig.cs index 0310e22..9b0ccda 100644 --- a/Synapse.Handler.CommandLine/Classes/CommandHandlerConfig.cs +++ b/Synapse.Handler.CommandLine/Classes/CommandHandlerConfig.cs @@ -33,7 +33,8 @@ public class CommandHandlerConfig public List ValidExitCodes { get; set; } [XmlElement] public bool ReturnStdout { get; set; } = true; - + [XmlElement] + public bool SupportsDryRun { get; set; } = false; } } diff --git a/Synapse.Handler.CommandLine/Classes/ScriptHandlerConfig.cs b/Synapse.Handler.CommandLine/Classes/ScriptHandlerConfig.cs index 34968c3..a30a4f7 100644 --- a/Synapse.Handler.CommandLine/Classes/ScriptHandlerConfig.cs +++ b/Synapse.Handler.CommandLine/Classes/ScriptHandlerConfig.cs @@ -35,6 +35,8 @@ public class ScriptHandlerConfig public List ValidExitCodes { get; set; } [XmlElement] public bool ReturnStdout { get; set; } = true; + [XmlElement] + public bool SupportsDryRun { get; set; } = false; } diff --git a/Synapse.Handler.CommandLine/CommandHandler.cs b/Synapse.Handler.CommandLine/CommandHandler.cs index 05e8a58..319470a 100644 --- a/Synapse.Handler.CommandLine/CommandHandler.cs +++ b/Synapse.Handler.CommandLine/CommandHandler.cs @@ -79,16 +79,21 @@ override public ExecuteResult Execute(HandlerStartInfo startInfo) expression.ReplaceWith = HandlerUtils.ReplaceHandlerVariables(expression.ReplaceWith, variables); String args = RegexArguments.Parse(parameters.Arguments, parameters.Expressions); + + bool isDryRun = startInfo.IsDryRun && !(config.SupportsDryRun); + if (startInfo.IsDryRun && config.SupportsDryRun) + OnLogMessage("Execute", "DryRun Flag is set, but plan config indicates the command supports DryRun. Command will execute."); + if (String.IsNullOrEmpty(config.RunOn)) { SecurityContext runAs = startInfo.RunAs; if (runAs != null && runAs.HasCrypto) runAs = startInfo.RunAs.GetCryptoValues(startInfo.RunAs.Crypto, false); - result = LocalProcess.RunCommand(config.Command, args, config.WorkingDirectory, config.TimeoutMills, config.TimeoutStatus, SynapseLogger, null, startInfo.IsDryRun, config.ReturnStdout, runAs?.Domain, runAs?.UserName, runAs?.Password); + result = LocalProcess.RunCommand(config.Command, args, config.WorkingDirectory, config.TimeoutMills, config.TimeoutStatus, SynapseLogger, null, isDryRun, config.ReturnStdout, runAs?.Domain, runAs?.UserName, runAs?.Password); } else { - result = WMIUtil.RunCommand(config.Command, args, config.RunOn, config.WorkingDirectory, config.TimeoutMills, config.TimeoutStatus, config.KillRemoteProcessOnTimeout, SynapseLogger, config.RunOn, startInfo.IsDryRun, config.ReturnStdout); + result = WMIUtil.RunCommand(config.Command, args, config.RunOn, config.WorkingDirectory, config.TimeoutMills, config.TimeoutStatus, config.KillRemoteProcessOnTimeout, SynapseLogger, config.RunOn, isDryRun, config.ReturnStdout); } if (result.Status == StatusType.None) diff --git a/Synapse.Handler.CommandLine/Properties/AssemblyInfo.cs b/Synapse.Handler.CommandLine/Properties/AssemblyInfo.cs index e3f6acf..a2bf43b 100644 --- a/Synapse.Handler.CommandLine/Properties/AssemblyInfo.cs +++ b/Synapse.Handler.CommandLine/Properties/AssemblyInfo.cs @@ -33,4 +33,4 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion( "0.1.0.0" ) ] -[assembly: AssemblyFileVersion( "0.1.17145.0" ) ] +[assembly: AssemblyFileVersion( "0.1.17151.0" ) ] diff --git a/Synapse.Handler.CommandLine/ScriptHandler.cs b/Synapse.Handler.CommandLine/ScriptHandler.cs index 291f804..0bea3f1 100644 --- a/Synapse.Handler.CommandLine/ScriptHandler.cs +++ b/Synapse.Handler.CommandLine/ScriptHandler.cs @@ -128,16 +128,20 @@ override public ExecuteResult Execute(HandlerStartInfo startInfo) throw new Exception("Unknown ScriptType [" + config.Type.ToString() + "] Received."); } + bool isDryRun = startInfo.IsDryRun && !(config.SupportsDryRun); + if (startInfo.IsDryRun && config.SupportsDryRun) + OnLogMessage("Execute", "DryRun Flag is set, but plan config indicates the script supports DryRun. Script will execute."); + if (String.IsNullOrEmpty(config.RunOn)) { SecurityContext runAs = startInfo.RunAs; if (runAs!= null && runAs.HasCrypto) runAs = startInfo.RunAs.GetCryptoValues(startInfo.RunAs.Crypto, false); - result = LocalProcess.RunCommand(command, args, config.WorkingDirectory, config.TimeoutMills, config.TimeoutStatus, SynapseLogger, null, startInfo.IsDryRun, config.ReturnStdout, runAs?.Domain, runAs?.UserName, runAs?.Password); + result = LocalProcess.RunCommand(command, args, config.WorkingDirectory, config.TimeoutMills, config.TimeoutStatus, SynapseLogger, null, isDryRun, config.ReturnStdout, runAs?.Domain, runAs?.UserName, runAs?.Password); } else { - result = WMIUtil.RunCommand(command, args, config.RunOn, config.WorkingDirectory, config.TimeoutMills, config.TimeoutStatus, config.KillRemoteProcessOnTimeout, SynapseLogger, config.RunOn, startInfo.IsDryRun, config.ReturnStdout); + result = WMIUtil.RunCommand(command, args, config.RunOn, config.WorkingDirectory, config.TimeoutMills, config.TimeoutStatus, config.KillRemoteProcessOnTimeout, SynapseLogger, config.RunOn, isDryRun, config.ReturnStdout); } if (result.Status == StatusType.None)