diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fcac14089..97dc897339 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Features - [Netkan] Purge downloads that failed to index from Netkan cache (#2526 by: HebaruSan; reviewed: politas) - [Multiple] Add download count column to GUI (#2518 by: HebaruSan; reviewed: politas) +- [Netkan] Catch invalid $kref in Netkan (#2516 by: HebaruSan; reviewed: politas) ### Bugfixes - [GUI] Show innermost download exceptions (#2528 by: HebaruSan; reviewed: politas) diff --git a/Netkan/CKAN-netkan.csproj b/Netkan/CKAN-netkan.csproj index fa40f2496a..4ec0556df2 100644 --- a/Netkan/CKAN-netkan.csproj +++ b/Netkan/CKAN-netkan.csproj @@ -117,6 +117,7 @@ + diff --git a/Netkan/Model/RemoteRef.cs b/Netkan/Model/RemoteRef.cs index 05d4804a48..2b60b21e72 100644 --- a/Netkan/Model/RemoteRef.cs +++ b/Netkan/Model/RemoteRef.cs @@ -25,7 +25,9 @@ private RemoteRef(Arguments arguments) Source = arguments.Source; Id = arguments.Id; - _string = Id == null ? string.Format("#/{0}", Source) : string.Format("#/{0}/{1}", Source, Id); + _string = Id == null + ? $"#/ckan/{Source}" + : $"#/ckan/{Source}/{Id}"; } public override string ToString() diff --git a/Netkan/Validators/KrefValidator.cs b/Netkan/Validators/KrefValidator.cs new file mode 100644 index 0000000000..9afb139f2a --- /dev/null +++ b/Netkan/Validators/KrefValidator.cs @@ -0,0 +1,36 @@ +using log4net; +using CKAN.NetKAN.Model; +using CKAN.NetKAN.Services; + +namespace CKAN.NetKAN.Validators +{ + internal sealed class KrefValidator : IValidator + { + public KrefValidator() { } + + public void Validate(Metadata metadata) + { + Log.Info("Validating that metadata contains valid or null $kref"); + + switch (metadata.Kref?.Source) + { + case null: + case "curse": + case "github": + case "http": + case "jenkins": + case "netkan": + case "spacedock": + // We know this $kref, looks good + break; + + default: + // Anything not in the above list won't trigger a Transformer + throw new Kraken($"Invalid $kref: {metadata.Kref}"); + } + + } + + private static readonly ILog Log = LogManager.GetLogger(typeof(KrefValidator)); + } +} diff --git a/Netkan/Validators/NetkanValidator.cs b/Netkan/Validators/NetkanValidator.cs index b0022e037a..b480860953 100644 --- a/Netkan/Validators/NetkanValidator.cs +++ b/Netkan/Validators/NetkanValidator.cs @@ -11,7 +11,8 @@ public NetkanValidator() { _validators = new List { - new HasIdentifierValidator() + new HasIdentifierValidator(), + new KrefValidator() }; }