catalog impl

broken/ef
Paul Schneider 2 years ago
parent fa9a12ad49
commit 14206ac477
27 changed files with 320 additions and 44 deletions

5
.gitignore vendored

@ -17,5 +17,6 @@ appsettings.Development.json
/src/isn.abst/bin
/src/isn.abst/obj
/src/isnd/packages/
test/data/test-isn/bin/
test/data/test-isn/obj
/test/data/test-isn/bin/
/test/data/test-isn/obj
.fake

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<apikeys>
</apikeys>
<packageSources>
<add key="myIsnDev" value="http://localhost:5000/index.json" protocolVersion="3" />
</packageSources>
</configuration>

@ -0,0 +1,2 @@
nuget install -Verbosity detailed -Source http://localhost:5000/index.json -Prerelease Yavsc.Abstract
nuget locals all -clear

@ -0,0 +1,4 @@
= URL's
<http://localhost:5000/v3.4.0/registration/yavsc.abstract/index.json>

@ -1,11 +1,13 @@
#!/bin/bash
set -e
# compiler tout
dotnet publish -c Release
dotnet build -c Release
dotnet publish -c Release -f netcoreapp2.1 src/isnd
# MAJ du serveur
sudo systemctl stop isnd
sudo cp -a src/isnd/bin/Release/netcoreapp2.1/publish/* /srv/www/isnd
sudo systemctl start isnd
# MAJ du client
sudo cp -a src/isn/bin/Release/net472/* /usr/local/lib/isn
sudo chmod +x /usr/local/lib/isn/isn.exe
sudo cp -a src/isn/bin/Release/netcoreapp2.1/* /usr/local/lib/isn
sudo chown -R root.root /usr/local/lib/isn

@ -2,6 +2,7 @@ using System;
using System.Linq;
using System.Threading.Tasks;
using isnd.Data;
using isnd.Data.Catalog;
using isnd.Helpers;
using isnd.ViewModels;
using Microsoft.AspNetCore.Authorization;
@ -14,12 +15,14 @@ namespace isnd.Controllers
public partial class PackagesController
{
// Web search
public async Task<IActionResult> Index(PackageIndexViewModel model)
public async Task<IActionResult> Index(PackageRegistrationIndexViewModel model)
{
var applicationDbContext = dbContext.Packages.Include(p => p.Versions).Where(
var applicationDbContext = dbContext.Packages.Include(p => p.Versions)
.Include(p => p.Owner)
.Where(
p => (model.Prerelease || p.Versions.Any(v => !v.IsPrerelease))
&& ((model.Query == null) || p.Id.StartsWith(model.Query)));
model.Data = await applicationDbContext.ToArrayAsync();
model.Data = await applicationDbContext.Select(p => p.ToLeave()).ToArrayAsync();
return View(model);
}

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

@ -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; }
}
}

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

@ -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
}
}

@ -1,16 +1,14 @@
using isnd.Data;
using isnd.Data.Packages;
using Newtonsoft.Json;
namespace isnd.ViewModels
namespace isnd.Data.Catalog
{
public class PackageIndexViewModel
public class PackageRegistrationIndexViewModel
{
[JsonProperty("prerelease")]
public bool Prerelease { get; set; }
[JsonProperty("data")]
public Package[] Data {get; set;}
public RegistrationLeaf[] Data {get; set;}
[JsonProperty("query")]
public string Query { get; set; }

@ -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; }
}

@ -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; }
}
}

@ -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; }
}
}

@ -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
}
}

@ -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
{

@ -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;
}
}
}

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

@ -3,6 +3,7 @@ using System.Threading.Tasks;
using isn.Abstract;
using isnd.Controllers;
using isnd.Data;
using isnd.Data.Catalog;
using isnd.Data.Packages;
using isnd.Data.Packages.Catalog;
using isnd.Services;
@ -18,7 +19,7 @@ namespace isnd.Interfaces
CatalogIndex GetCatalogIndex();
string[] GetVersions(string pkgid, NuGetVersion parsedVersion, bool prerelease = false, string packageType = null, int skip = 0, int take = 25);
PackageIndexViewModel SearchByName(string query, int skip, int take, bool prerelease = false, string packageType = null);
PackageRegistrationIndexViewModel SearchByName(string query, int skip, int take, bool prerelease = false, string packageType = null);
IEnumerable<Resource> GetResources(IUnleash unleashĈlient);
void ÛpdateCatalogFor(Commit commit);
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);

@ -6,6 +6,7 @@ using System.Threading.Tasks;
using isn.Abstract;
using isnd.Controllers;
using isnd.Data;
using isnd.Data.Catalog;
using isnd.Data.Packages;
using isnd.Data.Packages.Catalog;
using isnd.Entities;
@ -121,13 +122,14 @@ namespace isnd.Services
return res;
}
public PackageIndexViewModel SearchByName(string query,
public PackageRegistrationIndexViewModel SearchByName(string query,
int skip, int take, bool prerelease = false,
string packageType = null)
{
var scope = dbContext.Packages
.Include(p=>p.Versions)
.Include(p => p.Owner)
.Where(
p => (PackageIdHelpers.CamelCaseMatch(p.Id, query) || PackageIdHelpers.SeparatedByMinusMatch(p.Id, query))
&& (prerelease || p.Versions.Any(v => !v.IsPrerelease))
@ -136,18 +138,11 @@ namespace isnd.Services
var total = scope.Count();
var pkgs = scope.Skip(skip).Take(take).ToArray();
return new PackageIndexViewModel
return new PackageRegistrationIndexViewModel
{
Query = query,
TotalHits = total,
Data = pkgs
};
}
private object PackageVersionToRegentry(Package v)
{
return new {
Data = pkgs.Select(p => p.ToLeave()).ToArray()
};
}
@ -326,17 +321,6 @@ namespace isnd.Services
);
}
public async Task<CatalogRegistration> GetPackageRegistrationAsync(string pkgid, string version, string type)
{
var pkgVersion = await GetPackageAsync(pkgid, version, type);
return new CatalogRegistration
{
Id = pkgVersion.PackageId,
CommitTimeStamp = pkgVersion.LatestCommit.CommitTimeStamp,
PackageContent = extUrl + pkgVersion.FullString
};
}
public IEnumerable<PackageVersion> GetCatalogLeaf(string id, string version, string lower)
{
return dbContext.PackageVersions

@ -0,0 +1,45 @@
using isnd.Data.Packages;
namespace isnd.ViewModels
{
public class RegistrationLeaf
{
/*
@id string yes The URL to the registration leaf
catalogEntry object yes The catalog entry containing the package metadata
packageContent string yes The URL to the package content (.nupkg)
*/
public static RegistrationLeaf FromPackage(Package p)
{
RegistrationLeaf v = new RegistrationLeaf
{
};
return v;
}
}
public class CatalogEntry
{
/*
@id string yes The URL to the document used to produce this object
authors string or array of strings no
dependencyGroups array of objects no The dependencies of the package, grouped by target framework
deprecation object no The deprecation associated with the package
description string no
iconUrl string no
id string yes The ID of the package
licenseUrl string no
licenseExpression string no
listed boolean no Should be considered as listed if absent
minClientVersion string no
projectUrl string no
published string no A string containing a ISO 8601 timestamp of when the package was published
requireLicenseAcceptance boolean no
summary string no
tags string or array of string no
title string no
version string yes The full version string after normalization
vulnerabilities array of objects no The security vulnerabilities of the package
*/
}
}

@ -43,7 +43,7 @@
@foreach (var item in Model.Versions) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Package.Id)
@Html.DisplayFor(modelItem => item.PackageId)
<a href="@item.NugetLink">
nuget
</a>

@ -1,4 +1,4 @@
@model PackageIndexViewModel
@model PackageRegistrationIndexViewModel
@{
ViewData["Title"] = "Index";
@ -28,7 +28,7 @@
@Html.DisplayNameFor(model => model.Data[0].Id)
</th>
<th>
@Html.DisplayNameFor(model => model.Data[0].Description)
@Html.DisplayNameFor(model => model.Data[0].Entry.Description)
</th>
<th></th>
</tr>
@ -41,7 +41,7 @@
</td>
<td>
@Html.DisplayFor(modelItem => item.Description)
@Html.DisplayFor(modelItem => item.Entry.Description)
</td>
<td>
@Html.ActionLink("Details", "Details", new { pkgid = item.Id })

@ -6,6 +6,7 @@
<title>@ViewData["Title"] - isnd</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="~/css/site.css" />
<link rel="shortcut icon" href="favicon.ico#1" >
</head>
<body>
<header>

@ -1,4 +1,5 @@
@using isnd.Data
@using isnd.ViewModels
@using isnd.Helpers
@using isnd.Data.Catalog;
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@ -7848,3 +7848,6 @@ a.text-dark:hover, a.text-dark:focus {
.fa-copy {
cursor: copy; }
.border-top.footer.text-muted {
padding: 1em; }

@ -111,3 +111,8 @@ background-color: black;
.fa-copy {
cursor: copy;
}
.border-top.footer.text-muted {
padding: 1em;
}

Loading…