Skip to content

Commit

Permalink
Added ability to "override" DryRun flag, allowing script or command t…
Browse files Browse the repository at this point in the history
…o support that functionality.
  • Loading branch information
Guy Waguespack committed May 31, 2017
1 parent db6e4e7 commit db8365c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Synapse.Handler.CommandLine/Classes/CommandHandlerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class CommandHandlerConfig
public List<String> ValidExitCodes { get; set; }
[XmlElement]
public bool ReturnStdout { get; set; } = true;

[XmlElement]
public bool SupportsDryRun { get; set; } = false;
}

}
2 changes: 2 additions & 0 deletions Synapse.Handler.CommandLine/Classes/ScriptHandlerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class ScriptHandlerConfig
public List<String> ValidExitCodes { get; set; }
[XmlElement]
public bool ReturnStdout { get; set; } = true;
[XmlElement]
public bool SupportsDryRun { get; set; } = false;

}

Expand Down
9 changes: 7 additions & 2 deletions Synapse.Handler.CommandLine/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Synapse.Handler.CommandLine/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) ]
8 changes: 6 additions & 2 deletions Synapse.Handler.CommandLine/ScriptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit db8365c

Please sign in to comment.