Skip to content

Commit

Permalink
Merge #2516 Catch invalid in Netkan
Browse files Browse the repository at this point in the history
  • Loading branch information
politas committed Oct 7, 2018
2 parents b97842d + bb57c84 commit fc0fa20
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Netkan/CKAN-netkan.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<Compile Include="Validators\InstallsFilesValidator.cs" />
<Compile Include="Validators\IsCkanModuleValidator.cs" />
<Compile Include="Validators\IValidator.cs" />
<Compile Include="Validators\KrefValidator.cs" />
<Compile Include="Validators\MatchingIdentifiersValidator.cs" />
<Compile Include="Validators\NetkanValidator.cs" />
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion Netkan/Model/RemoteRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
36 changes: 36 additions & 0 deletions Netkan/Validators/KrefValidator.cs
Original file line number Diff line number Diff line change
@@ -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));
}
}
3 changes: 2 additions & 1 deletion Netkan/Validators/NetkanValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public NetkanValidator()
{
_validators = new List<IValidator>
{
new HasIdentifierValidator()
new HasIdentifierValidator(),
new KrefValidator()
};
}

Expand Down

0 comments on commit fc0fa20

Please sign in to comment.