Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch invalid $kref in Netkan #2516

Merged
merged 1 commit into from
Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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