catalog impl

This commit is contained in:
Paul Schneider 2022-08-20 12:54:24 +01:00
commit 14206ac477
27 changed files with 320 additions and 44 deletions

View file

@ -0,0 +1,11 @@
using NuGet.Versioning;
namespace isnd.Data.Catalog
{
public class AlternatePackage
{
public string id { get ; set; }
public VersionRange range { get ; set; }
}
}

View file

@ -0,0 +1,82 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace isnd.Data.Catalog
{
public class CatalogEntry
{
/// <summary>
/// The URL to the document used to produce this object
/// </summary>
/// <value></value>
[Key][Required]
[StringLength(1024)]
[JsonProperty("@id")]
public string Id { get; set; }
/// <summary>
/// Authors
/// </summary>
/// <value>string or array of strings</value>
public string authors { get; set; }
/// <summary>
/// The dependencies of the package, grouped by target framework
/// </summary>
/// <value>array of objects</value>
public DependencyGroup[] dependencyGroups { get; set; }
/// <summary>
/// The deprecation associated with the package
/// </summary>
/// <value></value>
public Deprecation deprecation { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
public string iconUrl { get; set; }
/// <summary>
/// The ID of the package
/// </summary>
/// <value></value>
public string idp { get; set; }
public string licenseUrl { get; set; }
public string licenseExpression { get; set; }
/// <summary>
/// Should be considered as listed if absent
/// </summary>
/// <value></value>
public bool listed { get; set; }
public string minClientVersion { get; set; }
public string projectUrl { get; set; }
/// <summary>
/// A string containing a ISO 8601 timestamp of when the package was published
/// </summary>
/// <value></value>
public string published { get; set; }
public bool requireLicenseAcceptance { get; set; }
public string summary { get; set; }
/// <summary>
/// The tags
/// </summary>
/// <value></value>
public string tags { get; set; }
public string title { get; set; }
/// <summary>
/// The full version string after normalization
/// </summary>
/// <value></value>
[Required]
public string version { get; set; } // string yes
/// <summary>
/// The security vulnerabilities of the package
/// </summary>
/// <value></value>
public Vulnerabilitie[] vulnerabilities { get; set; }
}
}

View file

@ -0,0 +1,6 @@
namespace isnd.Data.Catalog
{
public class DependencyGroup
{
}
}

View file

@ -0,0 +1,14 @@
namespace isnd.Data.Catalog
{
public class Deprecation
{
/*
Legacy The package is no longer maintained
CriticalBugs The package has bugs which make it unsuitable for usage
Other The package is deprecated due to a reason not on this list
*/
public string[] reasons { get; set; } // array of strings yes The reasons why the package was deprecated
public string message { get; set; } // The additional details about this deprecation
public AlternatePackage alternatePackage { get; set; } // object no The alternate package that should be used instead
}
}

View file

@ -0,0 +1,19 @@
using Newtonsoft.Json;
namespace isnd.Data.Catalog
{
public class PackageRegistrationIndexViewModel
{
[JsonProperty("prerelease")]
public bool Prerelease { get; set; }
[JsonProperty("data")]
public RegistrationLeaf[] Data {get; set;}
[JsonProperty("query")]
public string Query { get; set; }
[JsonProperty("totalHits")]
public int TotalHits { get; internal set; }
}
}

View file

@ -2,7 +2,7 @@ using System;
using isnd.Interfaces;
using Newtonsoft.Json;
namespace isnd.Data.Packages.Catalog
namespace isnd.Data.Catalog
{
public class PageRef : IObject
{
@ -19,7 +19,11 @@ namespace isnd.Data.Packages.Catalog
/// <value></value>
[JsonProperty("count")]
public int Count { get; set; }
[JsonProperty("commitId")]
public string CommitId { get; set; }
[JsonProperty("commitTimeStamp")]
public DateTime CommitTimeStamp { get; set; }
}

View file

@ -0,0 +1,36 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace isnd.Data.Catalog
{
public class RegistrationLeaf
{
/*
@id string yes
catalogEntry object yes
packageContent string yes
*/
[JsonProperty("@id")]
[Key][Required]
[StringLength(1024)]
/// <summary>
/// The URL to the registration leaf
/// </summary>
/// <value></value>
public string Id { get; set; }
/// <summary>
/// The catalog entry containing the package metadata
/// </summary>
/// <value></value>
[JsonProperty("catalogEntry")]
public CatalogEntry Entry { get; set; }
/// <summary>
/// The URL to the package content (.nupkg)
/// </summary>
/// <value></value>
[JsonProperty("packageContent")]
public string PackageContent { get; set; }
}
}

View file

@ -0,0 +1,34 @@
using System;
using Newtonsoft.Json;
namespace isnd.Data.Catalog
{
public class RegistrationPage
{
/*
@id string yes The URL to the registration page
count integer yes The number of registration leaves in the page
items array of objects no The array of registration leaves and their associate metadata
lower string yes The lowest SemVer 2.0.0 version in the page (inclusive)
parent string no The URL to the registration index
upper string yes The highest SemVer 2.0.0 version in the page (inclusive) */
[JsonProperty("@id")]
public string Id { get; set; }
[JsonProperty("count")]
public int Count { get; set; }
[JsonProperty("items")]
public RegistrationLeaf[] Items { get; set; }
[JsonProperty("upper")]
public Version Upper { get; set; }
[JsonProperty("lower")]
public Version Lower { get; set; }
[JsonProperty("parent")]
public string Parent { get; set; }
}
}

View file

@ -0,0 +1,9 @@
namespace isnd.Data.Catalog
{
public class Vulnerabilitie
{
public string advisoryUrl { get; set; } // string yes Location of security advisory for the package
public string severity { get; set; } // string yes Severity of advisory: "0" = Low, "1" = Moderate, "2" = High, "3" = Critical
}
}

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using isnd.Interfaces;
using isnd.Data.Catalog;
namespace isnd.Data.Packages.Catalog
{

View file

@ -2,6 +2,8 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using isnd.Data.Catalog;
using isnd.Interfaces;
using Newtonsoft.Json;
@ -44,5 +46,23 @@ namespace isnd.Data.Packages
public virtual Commit LatestVersion{ get; set; }
public DateTime CommitTimeStamp { get; set; }
internal RegistrationLeaf ToLeave()
{
if (!(Versions != null &&
Versions.Count > 0)) throw new Exception("NO VERSION");
var v = Versions.First();
RegistrationLeaf leave = new RegistrationLeaf
{
PackageContent = v.NugetLink,
Entry = new CatalogEntry
{
idp = Id,
version = v.FullString,
authors = $"{Owner.FullName} <${Owner.Email}>"
}
};
return leave;
}
}
}

View file

@ -12,6 +12,7 @@ namespace isnd.Data
[Required]
[ForeignKey("Package")]
[StringLength(1024)]
[JsonProperty("id")]
public string PackageId { get; set; }
[Required]