WIP page leaf

broken/ef
Paul Schneider 2 years ago
parent 2dcf1a2806
commit 7f9984b059
28 changed files with 164 additions and 75 deletions

@ -1,6 +1,6 @@
{
"omnisharp.msbuild": false,
"dotnet-test-explorer.testProjectPath": "**/*.sln",
"omnisharp.msbuild": true,
"dotnet-test-explorer.testProjectPath": "**/*Tests.csproj",
"dotnet-test-explorer.runInParallel": false,
"dotnet-test-explorer.showCodeLens": true,
"dotnet-test-explorer.testArguments": "",
@ -46,5 +46,7 @@
"database": "isnd",
"username": "paul"
}
]
],
"omnisharp.disableMSBuildDiagnosticWarning": true,
"omnisharp.enableRoslynAnalyzers": false
}

@ -76,3 +76,50 @@ sudo chown -R root.root /usr/local/lib/isn
````
## TODO
```json
{
"@id": "https://api.nuget.org/v3/registration5-semver1/",
"@type": "RegistrationsBaseUrl",
"comment": "Base URL of Azure storage where NuGet package registration info is stored"
},
{
"@id": "https://api.nuget.org/v3-flatcontainer/",
"@type": "PackageBaseAddress/3.0.0",
"comment": "Base URL of where NuGet packages are stored, in the format https://api.nuget.org/v3-flatcontainer/{id-lower}/{version-lower}/{id-lower}.{version-lower}.nupkg"
},
{
"@id": "https://api.nuget.org/v3/registration5-semver1/",
"@type": "RegistrationsBaseUrl/3.0.0-rc",
"comment": "Base URL of Azure storage where NuGet package registration info is stored used by RC clients. This base URL does not include SemVer 2.0.0 packages."
},
{
"@id": "https://api.nuget.org/v3/registration5-semver1/",
"@type": "RegistrationsBaseUrl/3.0.0-beta",
"comment": "Base URL of Azure storage where NuGet package registration info is stored used by Beta clients. This base URL does not include SemVer 2.0.0 packages."
},
{
"@id": "https://www.nuget.org/packages/{id}/{version}?_src=template",
"@type": "PackageDetailsUriTemplate/5.1.0",
"comment": "URI template used by NuGet Client to construct details URL for packages"
},
{
"@id": "https://api.nuget.org/v3/registration5-gz-semver2/",
"@type": "RegistrationsBaseUrl/3.6.0",
"comment": "Base URL of Azure storage where NuGet package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
},
````

@ -25,10 +25,8 @@ namespace isnd.Controllers
public IActionResult Index()
{
return View(new HomeIndexViewModel{
PkgCount = _dbContext.Packages
.Include(p => p.Versions)
.Where(p => p.Versions.Count > 0)
.Count(),
UnleashClient = _unleashĈlient

@ -1,6 +1,5 @@
using System.Linq;
using System.Threading.Tasks;
using isnd.Data.Catalog;
using isnd.Helpers;
using isnd.Services;
using isnd.Entities;
@ -28,19 +27,18 @@ namespace isnd.Controllers
return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]);
}
[HttpGet(_pkgRootPrefix + ApiConfig.Registration + "/{id}/{*lower}")]
public async Task<IActionResult> CatalogRegistrationAsync(string id, string lower)
[HttpGet(_pkgRootPrefix + "{apiVersion}/" + ApiConfig.Registration + "/{id}/{*lower}")]
public async Task<IActionResult> CatalogRegistrationAsync(string apiVersion, string id, string lower)
{
bool askForindex = lower != null && lower.EndsWith(ApiConfig.Base);
if (askForindex)
{
lower = lower.Substring(0, lower.Length - ApiConfig.Base.Length);
}
string pkgType = ParamHelpers.Optional(ref lower);
var pkgVersion = await dbContext.PackageVersions
.Include(v => v.LatestCommit)
.SingleOrDefaultAsync(
v => v.PackageId == id &&
v.FullString == lower &&
v.Type == pkgType
);
if (pkgVersion == null) return NotFound();
return Ok();
var pkgFromname = packageManager.SearchByName(id, 0, 1);
if (pkgFromname == null) return NotFound();
return Ok(pkgFromname);
}
@ -50,22 +48,24 @@ namespace isnd.Controllers
var pkgvs = this.packageManager.GetCatalogLeaf(id, version, lower)
.ToArray();
if (pkgvs.Count()==0) return NotFound();
if (pkgvs.Count() == 0) return NotFound();
List <string> types = pkgvs.Select(
List<string> types = pkgvs.Select(
v => v.Type ?? "Dependency"
).Distinct().ToList();
if (!types.Contains("PackageDelete"))
types.Add("PackageDetails");
var pub = pkgvs.Last().Package.CommitTimeStamp;
var last = pkgvs.Last();
var pub = last.Package.CommitTimeStamp;
var firstpub = pkgvs.First().Package.CommitTimeStamp;
return Ok(new CatalogLeaf
return Ok(new Data.Packages.Catalog.CatalogLeaf
{
CommitId = id,
CommitId = last.CommitId,
Id = id,
CommitTimeStamp = firstpub,
Version = version,
CommitTimeStamp = pub,
Version = last.FullString,
Published = pub,
RefType = types.ToArray(),

@ -32,7 +32,7 @@ namespace isnd.Controllers
}
// Web get spec
[HttpGet(_pkgRootPrefix + ApiConfig.GetNuspec + "/{id}/{lower}/{idf}-{lowerf}."
[HttpGet(_pkgRootPrefix + Constants.SpecFileEstension + "/{id}/{lower}/{idf}-{lowerf}."
+ Constants.SpecFileEstension)]
public IActionResult GetNuspec(
[FromRoute][SafeName][Required] string id,

@ -6,7 +6,7 @@ namespace isnd.Controllers
{
public partial class PackagesController
{
[HttpGet(_pkgRootPrefix + ApiConfig.GetVersion + "/{id}/{lower}/index.json")]
[HttpGet(_pkgRootPrefix + ApiConfig.GetVersion + "/{id}/{lower}/" + ApiConfig.Base)]
public IActionResult GetVersions(
string id,
string lower,

@ -15,8 +15,8 @@ using isnd.Data;
using isnd.Helpers;
using isnd.Entities;
using Microsoft.AspNetCore.Http;
using isnd.Data.Catalog;
using isn.abst;
using isnd.Data.Packages;
namespace isnd.Controllers
{

@ -6,8 +6,7 @@ using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using isnd.Data;
using isnd.Data.ApiKeys;
using isnd.Data.Catalog;
using isnd.Data.Historic;
using isnd.Data.Packages;
namespace isnd.Data
{

@ -1,7 +1,8 @@
using System;
using isnd.Interfaces;
using Newtonsoft.Json;
namespace isnd.Data.Catalog
namespace isnd.Data.Packages.Catalog
{
public class PageRef : IObject
{

@ -1,6 +1,7 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using isnd.Data.Catalog;
using isnd.Data.Packages;
using isnd.Data.Packages.Catalog;
namespace isnd.Data.Historic
{

@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using isnd.Interfaces;
namespace isnd.Data.Catalog
namespace isnd.Data.Packages.Catalog
{
public class CatalogIndex : IObject
{

@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using isnd.Interfaces;
using Newtonsoft.Json;
namespace isnd.Data.Catalog
namespace isnd.Data.Packages.Catalog
{
public class CatalogLeaf : IObject
{

@ -1,7 +1,7 @@
using System;
using Newtonsoft.Json;
namespace isnd.Data.Catalog
namespace isnd.Interfaces
{
public interface IObject
{

@ -1,4 +1,4 @@
namespace isnd.Data.Catalog
namespace isnd.Data.Packages.Catalog
{
public class PackageDetail : CatalogLeaf
{

@ -1,8 +1,9 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using isnd.Interfaces;
using Newtonsoft.Json;
namespace isnd.Data.Catalog
namespace isnd.Data.Packages.Catalog
{
/// <summary>
/// An presence of package in a catalog,

@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;
using isnd.Interfaces;
using Newtonsoft.Json;
namespace isnd.Data.Catalog
namespace isnd.Data.Packages.Catalog
{
public class Page : IObject
{

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
using isnd.Interfaces;
namespace isnd.Data.Catalog
namespace isnd.Data.Packages
{
public enum PackageAction
{

@ -2,10 +2,10 @@ using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using isnd.Data.Catalog;
using isnd.Interfaces;
using Newtonsoft.Json;
namespace isnd.Data
namespace isnd.Data.Packages
{
public class Package : IObject
{

@ -1,7 +1,8 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using isn.abst;
using isnd.Data.Catalog;
using isnd.Data.Packages;
using isnd.Data.Packages.Catalog;
using Newtonsoft.Json;
namespace isnd.Data

@ -3,7 +3,8 @@ 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;
using isnd.ViewModels;
using NuGet.Versioning;

@ -6,7 +6,8 @@ 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;
using isnd.Helpers;
using isnd.Interfaces;
@ -48,15 +49,15 @@ namespace isnd.Services
Comment = "Package Publish service"
});
// under dev, only leash in release mode
if (unleashClient.IsEnabled("pkg-get", false))
if (unleashClient.IsEnabled("pkg-get", true))
res.Add(
new Resource
{
Id = extUrl + ApiConfig.GetPackage,
Type = "PackageBaseAddress/3.0.0" ,
Type = "PackageBaseAddress/3.0.0",
Comment = "Package Base Address service"
});
if (unleashClient.IsEnabled("pkg-autocomplete", false))
if (unleashClient.IsEnabled("pkg-autocomplete", true))
res.Add(
new Resource
{
@ -72,22 +73,51 @@ namespace isnd.Services
Type = "SearchQueryService/" + BASE_API_LEVEL,
Comment = "Search Query service"
});
if (unleashClient.IsEnabled("pkg-catalog", false))
if (unleashClient.IsEnabled("pkg-catalog", true))
res.Add(
new Resource
{
Id = extUrl + ApiConfig.Catalog,
Type = "Catalog/"+ BASE_API_LEVEL,
Type = "Catalog/" + BASE_API_LEVEL,
Comment = "Package Catalog Index"
});
/* FIXME res.Add(
/* FIXME */
res.Add(
new Resource
{
Id = extUrl + ApiConfig.Registration,
Id = extUrl + "v" + BASE_API_LEVEL + "/" + ApiConfig.Registration,
Type = "RegistrationsBaseUrl",
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
});
res.Add(
new Resource
{
Id = extUrl + "v3.0.0-beta/" + ApiConfig.Registration,
Type = "RegistrationsBaseUrl/3.0.0-beta",
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
});
res.Add(
new Resource
{
Id = extUrl + "v3.0.0-rc/" + ApiConfig.Registration,
Type = "RegistrationsBaseUrl/3.0.0-rc",
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
});
res.Add(new Resource
{
Id = extUrl + "v3.4.0/" + ApiConfig.Registration,
Type = "RegistrationsBaseUrl/3.4.0",
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
});
res.Add(new Resource
{
Id = extUrl + "v3.6.0/" + ApiConfig.Registration,
Type = "RegistrationsBaseUrl/3.6.0",
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
}); */
});
return res;
}
@ -97,7 +127,6 @@ namespace isnd.Services
{
var scope = dbContext.Packages
.Include(p => p.Versions)
.Where(
p => (PackageIdHelpers.CamelCaseMatch(p.Id, query) || PackageIdHelpers.SeparatedByMinusMatch(p.Id, query))
&& (prerelease || p.Versions.Any(v => !v.IsPrerelease))
@ -171,8 +200,8 @@ namespace isnd.Services
int p = 0;
var oldIndex = CurrentCatalogIndex;
var oldPages = CurrentCatalogPages;
string baseid= extUrl + ApiConfig.Catalog;
string basepageid= extUrl + ApiConfig.CatalogPage;
string baseid = extUrl + ApiConfig.Catalog;
string basepageid = extUrl + ApiConfig.CatalogPage;
CurrentCatalogIndex = new CatalogIndex
{
Id = baseid,
@ -217,14 +246,14 @@ namespace isnd.Services
foreach (var pkg in validPkgs)
{
var v = pkg.Versions.
Where (cv => cv.CommitId == commit.CommitId)
Where(cv => cv.CommitId == commit.CommitId)
.OrderByDescending(vc => vc.CommitNId).First();
StringBuilder refid = new StringBuilder(extUrl);
refid.AppendFormat("{0}/{1}/{2}",ApiConfig.CatalogLeaf, v.PackageId
refid.AppendFormat("{0}/{1}/{2}", ApiConfig.CatalogLeaf, v.PackageId
, v.FullString);
if (v.Type!=null)
refid.AppendFormat("/{0}",v.Type);
if (v.Type != null)
refid.AppendFormat("/{0}", v.Type);
var pkgref = new PackageRef
{
@ -258,7 +287,8 @@ namespace isnd.Services
public async Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type)
{
// TODO deletion on disk
var commit = new Commit{
var commit = new Commit
{
Action = PackageAction.DeletePackage,
TimeStamp = DateTime.Now
};
@ -270,12 +300,12 @@ namespace isnd.Services
);
if (pkg == null)
{
return new PackageDeletionReport{ Deleted = false };
return new PackageDeletionReport { Deleted = false };
}
dbContext.PackageVersions.Remove(pkg);
await dbContext.SaveChangesAsync();
ÛpdateCatalogFor(commit);
return new PackageDeletionReport{ Deleted = true, DeletedVersion = pkg };
return new PackageDeletionReport { Deleted = true, DeletedVersion = pkg };
}
public async Task<PackageVersion> GetPackageAsync(string pkgid, string version, string type)
@ -301,7 +331,7 @@ namespace isnd.Services
public IEnumerable<PackageVersion> GetCatalogLeaf(string id, string version, string lower)
{
return dbContext.PackageVersions
.Include(v=>v.Package)
.Include(v => v.Package)
.Where(v => v.PackageId == id && v.FullString == version
&& (lower == null || lower == v.Type));
}

@ -109,13 +109,14 @@ namespace isnd
Microsoft.AspNetCore.Hosting.IHostingEnvironment env,
ApplicationDbContext dbContext)
{
// app.UseForwardedHeaders();
// .UseHttpsRedirection();
app.UseForwardedHeaders();
// if have a cert : app.UseHttpsRedirection();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseMigrationsEndPoint();
app.UseBrowserLink();
}
else
{

@ -1,4 +1,5 @@
using isnd.Data;
using isnd.Data.Packages;
using Newtonsoft.Json;
namespace isnd.ViewModels

@ -1,4 +1,5 @@
using isnd.Data;
using isnd.Data.Packages;
namespace isnd.Services
{

@ -10,6 +10,7 @@ using isn.Abstract;
using System.Linq;
using Xunit;
using isn.abst;
using isnd.Entities;
namespace isn.tests
{
@ -47,7 +48,7 @@ dataTable.Rows.Add(dataRow);
[Fact]
public async Task TestHttpClient()
{
string url = "http://isn.pschneider.fr/index.json";
string url = "http://isn.pschneider.fr/" + ApiConfig.Base;
HttpClient client = new HttpClient();
// var json = await client.GetStringAsync(new System.Uri(url));
var response = await client.GetAsync(url);

Loading…