New: Command line arguments for Custom Scripts are no longer supported

This commit is contained in:
Mark McDowall
2019-06-29 15:33:49 -07:00
committed by ta264
parent b8b8f064c7
commit b9d240924f
15 changed files with 170 additions and 126 deletions
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
@@ -5,6 +6,7 @@ using System.Linq;
using FluentValidation.Results;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Common.Processes;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Music;
@@ -160,6 +162,35 @@ namespace NzbDrone.Core.Notifications.CustomScript
failures.Add(new NzbDroneValidationFailure("Path", "File does not exist"));
}
foreach (var systemFolder in SystemFolders.GetSystemFolders())
{
if (systemFolder.IsParentPath(Settings.Path))
{
failures.Add(new NzbDroneValidationFailure("Path", $"Must not be a descendant of '{systemFolder}'"));
}
}
if (failures.Empty())
{
try
{
var environmentVariables = new StringDictionary();
environmentVariables.Add("Sonarr_EventType", "Test");
var processOutput = ExecuteScript(environmentVariables);
if (processOutput.ExitCode != 0)
{
failures.Add(new NzbDroneValidationFailure(string.Empty, $"Script exited with code: {processOutput.ExitCode}"));
}
}
catch (Exception ex)
{
_logger.Error(ex);
failures.Add(new NzbDroneValidationFailure(string.Empty, ex.Message));
}
}
return new ValidationResult(failures);
}
@@ -172,5 +203,10 @@ namespace NzbDrone.Core.Notifications.CustomScript
_logger.Debug("Executed external script: {0} - Status: {1}", Settings.Path, process.ExitCode);
_logger.Debug($"Script Output: {System.Environment.NewLine}{string.Join(System.Environment.NewLine, process.Lines)}");
}
private bool ValidatePathParent(string possibleParent, string path)
{
return possibleParent.IsParentPath(path);
}
}
}
@@ -11,6 +11,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
public CustomScriptSettingsValidator()
{
RuleFor(c => c.Path).IsValidPath();
RuleFor(c => c.Arguments).Empty().WithMessage("Arguments are no longer supported for custom scripts");
}
}
@@ -21,7 +22,7 @@ namespace NzbDrone.Core.Notifications.CustomScript
[FieldDefinition(0, Label = "Path", Type = FieldType.FilePath)]
public string Path { get; set; }
[FieldDefinition(1, Label = "Arguments", HelpText = "Arguments to pass to the script")]
[FieldDefinition(1, Label = "Arguments", HelpText = "Arguments to pass to the script", Hidden = HiddenType.HiddenIfNotSet)]
public string Arguments { get; set; }
public NzbDroneValidationResult Validate()
@@ -13,22 +13,22 @@ namespace NzbDrone.Core.Notifications.Plex.HomeTheater
//These need to be kept in the same order as XBMC Settings, but we don't want them displayed
[FieldDefinition(2, Label = "Username", Type = FieldType.Hidden)]
[FieldDefinition(2, Label = "Username", Hidden = HiddenType.Hidden)]
public new string Username { get; set; }
[FieldDefinition(3, Label = "Password", Type = FieldType.Hidden)]
[FieldDefinition(3, Label = "Password", Hidden = HiddenType.Hidden)]
public new string Password { get; set; }
[FieldDefinition(5, Label = "GUI Notification", Type = FieldType.Hidden)]
[FieldDefinition(5, Label = "GUI Notification", Type = FieldType.Checkbox, Hidden = HiddenType.Hidden)]
public new bool Notify { get; set; }
[FieldDefinition(6, Label = "Update Library", HelpText = "Update Library on Download & Rename?", Type = FieldType.Hidden)]
[FieldDefinition(6, Label = "Update Library", HelpText = "Update Library on Download & Rename?", Type = FieldType.Checkbox, Hidden = HiddenType.Hidden)]
public new bool UpdateLibrary { get; set; }
[FieldDefinition(7, Label = "Clean Library", HelpText = "Clean Library after update?", Type = FieldType.Hidden)]
[FieldDefinition(7, Label = "Clean Library", HelpText = "Clean Library after update?", Type = FieldType.Checkbox, Hidden = HiddenType.Hidden)]
public new bool CleanLibrary { get; set; }
[FieldDefinition(8, Label = "Always Update", HelpText = "Update Library even when a video is playing?", Type = FieldType.Hidden)]
[FieldDefinition(8, Label = "Always Update", HelpText = "Update Library even when a video is playing?", Type = FieldType.Checkbox, Hidden = HiddenType.Hidden)]
public new bool AlwaysUpdate { get; set; }
}
}
@@ -70,15 +70,15 @@ namespace NzbDrone.Core.Notifications.PushBullet
var devices = _proxy.GetDevices(Settings);
return new
{
devices = devices.Where(d => d.Nickname.IsNotNullOrWhiteSpace())
.OrderBy(d => d.Nickname, StringComparer.InvariantCultureIgnoreCase)
.Select(d => new
{
id = d.Id,
name = d.Nickname
})
};
{
options = devices.Where(d => d.Nickname.IsNotNullOrWhiteSpace())
.OrderBy(d => d.Nickname, StringComparer.InvariantCultureIgnoreCase)
.Select(d => new
{
id = d.Id,
name = d.Nickname
})
};
}
return new { };