From c5dcb22c01b8b32bf0b9a8fa68a0ecf741bd50c0 Mon Sep 17 00:00:00 2001 From: bakerboy448 <55419169+bakerboy448@users.noreply.github.com> Date: Mon, 3 May 2021 16:14:06 -0500 Subject: [PATCH] New: DiscordNotifier is now Notifiarr Fixes #1014 --- .../CleanseLogMessageFixture.cs | 17 +++++++---- .../Instrumentation/CleanseLogMessage.cs | 5 +--- .../Migration/007_update_notifiarr.cs | 15 ++++++++++ .../DiscordNotifierException.cs | 18 ------------ .../DiscordNotifierSettings.cs | 28 ------------------- .../Notifiarr.cs} | 12 ++++---- .../Notifiarr/NotifiarrException.cs | 18 ++++++++++++ .../NotifiarrProxy.cs} | 26 ++++++++--------- .../Notifiarr/NotifiarrSettings.cs | 28 +++++++++++++++++++ 9 files changed, 92 insertions(+), 75 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/007_update_notifiarr.cs delete mode 100644 src/NzbDrone.Core/Notifications/DiscordNotifier/DiscordNotifierException.cs delete mode 100644 src/NzbDrone.Core/Notifications/DiscordNotifier/DiscordNotifierSettings.cs rename src/NzbDrone.Core/Notifications/{DiscordNotifier/DiscordNotifier.cs => Notifiarr/Notifiarr.cs} (92%) create mode 100644 src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrException.cs rename src/NzbDrone.Core/Notifications/{DiscordNotifier/DiscordNotifierProxy.cs => Notifiarr/NotifiarrProxy.cs} (73%) create mode 100644 src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrSettings.cs diff --git a/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs b/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs index 21c645b86..80abf09e6 100644 --- a/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs +++ b/src/NzbDrone.Common.Test/InstrumentationTests/CleanseLogMessageFixture.cs @@ -1,6 +1,6 @@ -using NUnit.Framework; -using NzbDrone.Common.Instrumentation; using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.Instrumentation; namespace NzbDrone.Common.Test.InstrumentationTests { @@ -17,9 +17,11 @@ namespace NzbDrone.Common.Test.InstrumentationTests [TestCase(@"https://baconbits.org/feeds.php?feed=torrents_tv&user=12345&auth=2b51db35e1910123321025a12b9933d2&passkey=mySecret&authkey=2b51db35e1910123321025a12b9933d2")] [TestCase(@"http://127.0.0.1:9117/dl/indexername?jackett_apikey=flwjiefewklfjacketmySecretsdfldskjfsdlk&path=we0re9f0sdfbase64sfdkfjsdlfjk&file=The+Torrent+File+Name.torrent")] [TestCase(@"http://nzb.su/getnzb/2b51db35e1912ffc138825a12b9933d2.nzb&i=37292&r=2b51db35e1910123321025a12b9933d2")] + // NzbGet [TestCase(@"{ ""Name"" : ""ControlUsername"", ""Value"" : ""mySecret"" }, { ""Name"" : ""ControlPassword"", ""Value"" : ""mySecret"" }, ")] [TestCase(@"{ ""Name"" : ""Server1.Username"", ""Value"" : ""mySecret"" }, { ""Name"" : ""Server1.Password"", ""Value"" : ""mySecret"" }, ")] + // Sabnzbd [TestCase(@"http://127.0.0.1:1234/api/call?vv=1&apikey=mySecret")] [TestCase(@"http://127.0.0.1:1234/api/call?vv=1&ma_username=mySecret&ma_password=mySecret")] @@ -30,6 +32,7 @@ namespace NzbDrone.Common.Test.InstrumentationTests [TestCase(@"""misc"":{""username"":""mySecret"",""api_key"":""mySecret"",""password"":""mySecret"",""nzb_key"":""mySecret""}")] [TestCase(@"""servers"":[{""username"":""mySecret"",""password"":""mySecret""}]")] [TestCase(@"""misc"":{""email_account"":""mySecret"",""email_to"":[],""email_from"":"""",""email_pwd"":""mySecret""}")] + // uTorrent [TestCase(@"http://localhost:9091/gui/?token=wThmph5l0ZXfH-a6WOA4lqiLvyjCP0FpMrMeXmySecret_VXBO11HoKL751MAAAAA&list=1")] [TestCase(@",[""boss_key"",0,""mySecret"",{""access"":""Y""}],[""boss_key_salt"",0,""mySecret"",{""access"":""W""}]")] @@ -37,23 +40,25 @@ namespace NzbDrone.Common.Test.InstrumentationTests [TestCase(@",[""webui.uconnect_username"",2,""mySecret"",{""access"":""Y""}],[""webui.uconnect_password"",2,""mySecret"",{""access"":""Y""}]")] [TestCase(@",[""proxy.proxy"",2,""mySecret"",{""access"":""Y""}]")] [TestCase(@",[""proxy.username"",2,""mySecret"",{""access"":""Y""}],[""proxy.password"",2,""mySecret"",{""access"":""Y""}]")] + // Deluge [TestCase(@",{""download_location"": ""C:\Users\\mySecret mySecret\\Downloads""}")] [TestCase(@",{""download_location"": ""/home/mySecret/Downloads""}")] [TestCase(@"auth.login(""mySecret"")")] + // Download Station [TestCase(@"webapi/entry.cgi?api=(removed)&version=2&method=login&account=01233210&passwd=mySecret&format=sid&session=DownloadStation")] + // BroadcastheNet [TestCase(@"method: ""getTorrents"", ""params"": [ ""mySecret"",")] [TestCase(@"getTorrents(""mySecret"", [asdfasdf], 100, 0)")] [TestCase(@"""DownloadURL"":""https:\/\/broadcasthe.net\/torrents.php?action=download&id=123&authkey=mySecret&torrent_pass=mySecret""")] - // Plex - [TestCase(@" http://localhost:32400/library/metadata/12345/refresh?X-Plex-Client-Identifier=1234530f-422f-4aac-b6b3-01233210aaaa&X-Plex-Product=Sonarr&X-Plex-Platform=Windows&X-Plex-Platform-Version=7&X-Plex-Device-Name=Sonarr&X-Plex-Version=3.0.3.833&X-Plex-Token=mySecret")] + // Internal [TestCase(@"OutputPath=/home/mySecret/Downloads")] [TestCase("Hardlinking episode file: /home/mySecret/Downloads to /media/abc.mkv")] [TestCase("Hardlink '/home/mySecret/Downloads/abs.mkv' to '/media/abc.mkv' failed.")] - [TestCase("https://discordnotifier.com/notifier.php: api=1234530f-422f-4aac-b6b3-01233210aaaa&radarr_health_issue_message=Download")] + [TestCase("https://notifiarr.com/notifier.php: api=1234530f-422f-4aac-b6b3-01233210aaaa&radarr_health_issue_message=Download")] // Announce URLs (passkeys) Magnet & Tracker [TestCase(@"magnet_uri"":""magnet:?xt=urn:btih:9pr04sgkillroyimaveql2tyu8xyui&dn=&tr=https%3a%2f%2fxxx.yyy%2f9pr04sg601233210imaveql2tyu8xyui%2fannounce""}")] @@ -73,7 +78,7 @@ namespace NzbDrone.Common.Test.InstrumentationTests } //GoodReads - [TestCase(@"{""signatureMethod"": ""hmacSha1"",""signatureTreatment"": ""escaped"",""type"": ""protectedResource"",""method"": ""GET"",""token"": ""mytoken"",""tokenSecret"": ""mytokensecret"",""requestUrl"": ""https://www.goodreads.com/review/list.xml"",""parameters"": { ""_nc"": ""1"", ""v"": ""2"", ""id"": ""999999999"", ""shelf"": ""currently-reading"", ""per_page"": ""200"", ""page"": ""1""}")] + [TestCase(@"{""signatureMethod"": ""hmacSha1"",""signatureTreatment"": ""escaped"",""type"": ""protectedResource"",""method"": ""GET"",""token"": ""mytoken"",""tokenSecret"": ""mytokensecret"",""requestUrl"": ""https://www.goodreads.com/review/list.xml"",""parameters"": { ""_nc"": ""1"", ""v"": ""2"", ""id"": ""999999999"", ""shelf"": ""currently-reading"", ""per_page"": ""200"", ""page"": ""1""}")] public void should_cleanGoodRead_message(string message) { var cleansedMessage = CleanseLogMessage.Cleanse(message); diff --git a/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs b/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs index 61ad2b715..7db118db4 100644 --- a/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs +++ b/src/NzbDrone.Common/Instrumentation/CleanseLogMessage.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Net; using System.Text.RegularExpressions; @@ -47,9 +47,6 @@ namespace NzbDrone.Common.Instrumentation // Good Reads new Regex(@"(?<=""(token|tokensecret)"":\s)""(?[^""]+?)""", RegexOptions.Compiled | RegexOptions.IgnoreCase) - - // Plex - new Regex(@"(?<=\?|&)(X-Plex-Client-Identifier|X-Plex-Token)=(?[^&=]+?)(?= |&|$)", RegexOptions.Compiled | RegexOptions.IgnoreCase) }; private static readonly Regex CleanseRemoteIPRegex = new Regex(@"(?:Auth-\w+(? - { - public DiscordNotifierSettingsValidator() - { - RuleFor(c => c.APIKey).NotEmpty(); - } - } - - public class DiscordNotifierSettings : IProviderConfig - { - private static readonly DiscordNotifierSettingsValidator Validator = new DiscordNotifierSettingsValidator(); - - [FieldDefinition(0, Label = "API Key", HelpText = "Your API key from your profile", HelpLink = "https://discordnotifier.com")] - public string APIKey { get; set; } - - public NzbDroneValidationResult Validate() - { - return new NzbDroneValidationResult(Validator.Validate(this)); - } - } -} diff --git a/src/NzbDrone.Core/Notifications/DiscordNotifier/DiscordNotifier.cs b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs similarity index 92% rename from src/NzbDrone.Core/Notifications/DiscordNotifier/DiscordNotifier.cs rename to src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs index e26e8ee14..4e4c38b08 100644 --- a/src/NzbDrone.Core/Notifications/DiscordNotifier/DiscordNotifier.cs +++ b/src/NzbDrone.Core/Notifications/Notifiarr/Notifiarr.cs @@ -4,19 +4,19 @@ using System.Linq; using FluentValidation.Results; using NzbDrone.Common.Extensions; -namespace NzbDrone.Core.Notifications.DiscordNotifier +namespace NzbDrone.Core.Notifications.Notifiarr { - public class DiscordNotifier : NotificationBase + public class Notifiarr : NotificationBase { - private readonly IDiscordNotifierProxy _proxy; + private readonly INotifiarrProxy _proxy; - public DiscordNotifier(IDiscordNotifierProxy proxy) + public Notifiarr(INotifiarrProxy proxy) { _proxy = proxy; } - public override string Link => "https://discordnotifier.com"; - public override string Name => "DiscordNotifier.com"; + public override string Link => "https://notifiarr.com"; + public override string Name => "Notifiarr"; public override void OnGrab(GrabMessage message) { diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrException.cs b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrException.cs new file mode 100644 index 000000000..283edda13 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrException.cs @@ -0,0 +1,18 @@ +using System; +using NzbDrone.Common.Exceptions; + +namespace NzbDrone.Core.Notifications.Notifiarr +{ + public class NotifiarrException : NzbDroneException + { + public NotifiarrException(string message) + : base(message) + { + } + + public NotifiarrException(string message, Exception innerException, params object[] args) + : base(message, innerException, args) + { + } + } +} diff --git a/src/NzbDrone.Core/Notifications/DiscordNotifier/DiscordNotifierProxy.cs b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs similarity index 73% rename from src/NzbDrone.Core/Notifications/DiscordNotifier/DiscordNotifierProxy.cs rename to src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs index bf237e20b..6038dc8bf 100644 --- a/src/NzbDrone.Core/Notifications/DiscordNotifier/DiscordNotifierProxy.cs +++ b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrProxy.cs @@ -7,40 +7,40 @@ using NLog; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Http; -namespace NzbDrone.Core.Notifications.DiscordNotifier +namespace NzbDrone.Core.Notifications.Notifiarr { - public interface IDiscordNotifierProxy + public interface INotifiarrProxy { - void SendNotification(StringDictionary message, DiscordNotifierSettings settings); - ValidationFailure Test(DiscordNotifierSettings settings); + void SendNotification(StringDictionary message, NotifiarrSettings settings); + ValidationFailure Test(NotifiarrSettings settings); } - public class DiscordNotifierProxy : IDiscordNotifierProxy + public class NotifiarrProxy : INotifiarrProxy { - private const string URL = "https://discordnotifier.com/notifier.php"; + private const string URL = "https://notifiarr.com/notifier.php"; private readonly IHttpClient _httpClient; private readonly Logger _logger; - public DiscordNotifierProxy(IHttpClient httpClient, Logger logger) + public NotifiarrProxy(IHttpClient httpClient, Logger logger) { _httpClient = httpClient; _logger = logger; } - public void SendNotification(StringDictionary message, DiscordNotifierSettings settings) + public void SendNotification(StringDictionary message, NotifiarrSettings settings) { try { ProcessNotification(message, settings); } - catch (DiscordNotifierException ex) + catch (NotifiarrException ex) { _logger.Error(ex, "Unable to send notification"); - throw new DiscordNotifierException("Unable to send notification"); + throw new NotifiarrException("Unable to send notification"); } } - public ValidationFailure Test(DiscordNotifierSettings settings) + public ValidationFailure Test(NotifiarrSettings settings) { try { @@ -68,7 +68,7 @@ namespace NzbDrone.Core.Notifications.DiscordNotifier } } - private void ProcessNotification(StringDictionary message, DiscordNotifierSettings settings) + private void ProcessNotification(StringDictionary message, NotifiarrSettings settings) { try { @@ -92,7 +92,7 @@ namespace NzbDrone.Core.Notifications.DiscordNotifier throw; } - throw new DiscordNotifierException("Unable to send notification", ex); + throw new NotifiarrException("Unable to send notification", ex); } } } diff --git a/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrSettings.cs b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrSettings.cs new file mode 100644 index 000000000..1a8bb06c9 --- /dev/null +++ b/src/NzbDrone.Core/Notifications/Notifiarr/NotifiarrSettings.cs @@ -0,0 +1,28 @@ +using FluentValidation; +using NzbDrone.Core.Annotations; +using NzbDrone.Core.ThingiProvider; +using NzbDrone.Core.Validation; + +namespace NzbDrone.Core.Notifications.Notifiarr +{ + public class NotifiarrSettingsValidator : AbstractValidator + { + public NotifiarrSettingsValidator() + { + RuleFor(c => c.APIKey).NotEmpty(); + } + } + + public class NotifiarrSettings : IProviderConfig + { + private static readonly NotifiarrSettingsValidator Validator = new NotifiarrSettingsValidator(); + + [FieldDefinition(0, Label = "API Key", Privacy = PrivacyLevel.ApiKey, HelpText = "Your API key from your profile", HelpLink = "https://notifiarr.com")] + public string APIKey { get; set; } + + public NzbDroneValidationResult Validate() + { + return new NzbDroneValidationResult(Validator.Validate(this)); + } + } +}