Trying and find a package from API
This commit is contained in:
@ -12,5 +12,7 @@ namespace isnd.Entities
|
|||||||
|
|
||||||
public const string Nuspec = "/nuspec";
|
public const string Nuspec = "/nuspec";
|
||||||
public const string Nuget = "/nuget";
|
public const string Nuget = "/nuget";
|
||||||
|
|
||||||
|
public const string Find = "/index/FindPackagesById()"; // /FindPackagesById()?id='isn.abst'&semVerLevel=2.0.0
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,6 @@ using Microsoft.Extensions.Logging;
|
|||||||
using isnd.Data;
|
using isnd.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using isnd.ViewModels;
|
using isnd.ViewModels;
|
||||||
using Unleash;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
@ -16,19 +15,14 @@ namespace isnd.Controllers
|
|||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly ApplicationDbContext _dbContext;
|
private readonly ApplicationDbContext _dbContext;
|
||||||
private readonly IUnleash _unleashĈlient;
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Home controller ctor
|
/// Home controller ctor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="dbContext"></param>
|
/// <param name="dbContext"></param>
|
||||||
/// <param name="unleashĈlient"></param>
|
|
||||||
|
|
||||||
public HomeController(
|
public HomeController(
|
||||||
ApplicationDbContext dbContext,
|
ApplicationDbContext dbContext)
|
||||||
IUnleash unleashĈlient)
|
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
_unleashĈlient = unleashĈlient;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
@ -36,9 +30,7 @@ namespace isnd.Controllers
|
|||||||
return View(new HomeIndexViewModel{
|
return View(new HomeIndexViewModel{
|
||||||
PkgCount = _dbContext.Packages
|
PkgCount = _dbContext.Packages
|
||||||
.Where(p => p.Versions.Count > 0)
|
.Where(p => p.Versions.Count > 0)
|
||||||
.Count(),
|
.Count()});
|
||||||
UnleashClient = _unleashĈlient
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult About()
|
public IActionResult About()
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using isnd.Entities;
|
|
||||||
using isnd.Services;
|
using isnd.Services;
|
||||||
using isn.Abstract;
|
using isn.Abstract;
|
||||||
using isn.abst;
|
using isn.abst;
|
||||||
using isnd.Interfaces;
|
using isnd.Interfaces;
|
||||||
using Unleash;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
|
||||||
@ -22,11 +20,10 @@ namespace isnd.Controllers
|
|||||||
/// Api Controller Constructor
|
/// Api Controller Constructor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pm"></param>
|
/// <param name="pm"></param>
|
||||||
/// <param name="unleashĈlient"></param>
|
public ApiController(IPackageManager pm)
|
||||||
public ApiController(IPackageManager pm, IUnleash unleashĈlient)
|
|
||||||
{
|
{
|
||||||
packageManager = pm;
|
packageManager = pm;
|
||||||
resources = packageManager.GetResources(unleashĈlient).ToArray();
|
resources = packageManager.GetResources().ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -44,8 +44,5 @@ namespace isnd.Controllers
|
|||||||
if (null == leaf) return NotFound(new { id, version });
|
if (null == leaf) return NotFound(new { id, version });
|
||||||
return Ok(leaf);
|
return Ok(leaf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,9 +1,11 @@
|
|||||||
|
using System.Linq;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using isnd.Entities;
|
using isnd.Entities;
|
||||||
using isn.abst;
|
using isn.abst;
|
||||||
|
using isnd.Data.Catalog;
|
||||||
|
|
||||||
namespace isnd.Controllers
|
namespace isnd.Controllers
|
||||||
{
|
{
|
||||||
@ -11,18 +13,32 @@ namespace isnd.Controllers
|
|||||||
public partial class PackagesController
|
public partial class PackagesController
|
||||||
{
|
{
|
||||||
// GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
|
// GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
|
||||||
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Search)]
|
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Find)]
|
||||||
public IActionResult Search(
|
[HttpPost("~" + Constants.ApiVersionPrefix + ApiConfig.Find)]
|
||||||
string q,
|
public async Task<IActionResult> Search(
|
||||||
int skip = 0,
|
string id,
|
||||||
int take = 25,
|
|
||||||
bool prerelease = false,
|
bool prerelease = false,
|
||||||
|
// string packageType = null,
|
||||||
string semVerLevel = null,
|
string semVerLevel = null,
|
||||||
string packageType = null
|
int skip = 0,
|
||||||
|
int take = 25
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
id = id.Trim('\'');
|
||||||
|
if (semVerLevel == "2.0.0") prerelease = true;
|
||||||
|
|
||||||
throw new NotImplementedException();
|
//packageManager.SearchCatalogEntriesById(id, semVerLevel, packageType, prerelease);
|
||||||
|
var regs = await packageManager.SearchPackageAsync(
|
||||||
|
|
||||||
|
new PackageRegistrationQuery
|
||||||
|
{
|
||||||
|
Query = id,
|
||||||
|
Prerelease = prerelease,
|
||||||
|
Take = take,
|
||||||
|
Skip = skip
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return Ok(new { totalHits = regs.Count(), data = regs });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,19 +1,11 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using NuGet.Versioning;
|
|
||||||
using isnd.Data;
|
using isnd.Data;
|
||||||
using isnd.Entities;
|
using isnd.Entities;
|
||||||
using Unleash;
|
|
||||||
using isnd.Services;
|
|
||||||
using isnd.ViewModels;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using isnd.Interfaces;
|
using isnd.Interfaces;
|
||||||
using isn.Abstract;
|
using isn.Abstract;
|
||||||
|
|
||||||
@ -30,13 +22,11 @@ namespace isnd.Controllers
|
|||||||
private readonly IsndSettings isndSettings;
|
private readonly IsndSettings isndSettings;
|
||||||
readonly ApplicationDbContext dbContext;
|
readonly ApplicationDbContext dbContext;
|
||||||
private readonly IPackageManager packageManager;
|
private readonly IPackageManager packageManager;
|
||||||
private readonly IUnleash unleashĈlient;
|
|
||||||
|
|
||||||
public PackagesController(
|
public PackagesController(
|
||||||
ILoggerFactory loggerFactory,
|
ILoggerFactory loggerFactory,
|
||||||
IDataProtectionProvider provider,
|
IDataProtectionProvider provider,
|
||||||
IOptions<IsndSettings> isndOptions,
|
IOptions<IsndSettings> isndOptions,
|
||||||
IUnleash unleashĈlient,
|
|
||||||
ApplicationDbContext dbContext,
|
ApplicationDbContext dbContext,
|
||||||
IPackageManager pm)
|
IPackageManager pm)
|
||||||
{
|
{
|
||||||
@ -45,8 +35,7 @@ namespace isnd.Controllers
|
|||||||
protector = provider.CreateProtector(isndSettings.ProtectionTitle);
|
protector = provider.CreateProtector(isndSettings.ProtectionTitle);
|
||||||
this.dbContext = dbContext;
|
this.dbContext = dbContext;
|
||||||
packageManager = pm;
|
packageManager = pm;
|
||||||
this.unleashĈlient = unleashĈlient;
|
resources = packageManager.GetResources().ToArray();
|
||||||
resources = packageManager.GetResources(unleashĈlient).ToArray();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ namespace isnd.Data
|
|||||||
.HasKey( v => new { v.PackageId, v.FullString } );
|
.HasKey( v => new { v.PackageId, v.FullString } );
|
||||||
_ = builder.Entity<PackageVersion>()
|
_ = builder.Entity<PackageVersion>()
|
||||||
.HasOne(v => v.Package).WithMany(p => p.Versions).HasForeignKey(x => x.PackageId);
|
.HasOne(v => v.Package).WithMany(p => p.Versions).HasForeignKey(x => x.PackageId);
|
||||||
// _ = builder.Entity<Package>().HasMany(p => p.Versions).WithOne(V => V.Package).HasForeignKey(x => new { x.PackageId, x.FullString });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
@ -6,10 +7,15 @@ using NuGet.Versioning;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System;
|
using System;
|
||||||
using isnd.Interfaces;
|
using isnd.Interfaces;
|
||||||
|
using NuGet.Protocol.Core.Types;
|
||||||
|
using NuGet.Protocol;
|
||||||
|
using NuGet.Packaging;
|
||||||
|
using NuGet.Packaging.Core;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace isnd.Data.Catalog
|
namespace isnd.Data.Catalog
|
||||||
{
|
{
|
||||||
public class PackageDetails : Permalink, IObject
|
public class PackageDetails : Permalink, IObject, IPackageSearchMetadata
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a catalog entry
|
/// Creates a catalog entry
|
||||||
@ -20,11 +26,12 @@ namespace isnd.Data.Catalog
|
|||||||
{
|
{
|
||||||
PackageId = pkg.Package.Id;
|
PackageId = pkg.Package.Id;
|
||||||
Version = pkg.FullString;
|
Version = pkg.FullString;
|
||||||
authors = $"{pkg.Package.Owner.FullName} <${pkg.Package.Owner.Email}>";
|
Authors = $"{pkg.Package.Owner.FullName} <${pkg.Package.Owner.Email}>";
|
||||||
packageContent = apiBase + pkg.NugetLink;
|
packageContent = apiBase + pkg.NugetLink;
|
||||||
CommitId = pkg.CommitId;
|
CommitId = pkg.CommitId;
|
||||||
CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
|
CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
|
||||||
|
IsListed = !pkg.IsDeleted && pkg.Package.Public;
|
||||||
|
// TODO Licence Project Urls, Summary, Title, etc ...
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty("@type")]
|
[JsonProperty("@type")]
|
||||||
@ -40,7 +47,8 @@ namespace isnd.Data.Catalog
|
|||||||
/// Authors
|
/// Authors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>string or array of strings</value>
|
/// <value>string or array of strings</value>
|
||||||
public string authors { get; set; }
|
[JsonProperty("authors")]
|
||||||
|
public string Authors { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The dependencies of the package, grouped by target framework
|
/// The dependencies of the package, grouped by target framework
|
||||||
@ -56,36 +64,45 @@ namespace isnd.Data.Catalog
|
|||||||
|
|
||||||
[JsonProperty("description")]
|
[JsonProperty("description")]
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
public string iconUrl { get; set; }
|
|
||||||
|
[JsonProperty("iconUrl")]
|
||||||
|
public Uri IconUrl { get; set; }
|
||||||
|
|
||||||
public string language { get; set; }
|
public string language { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public string licenseUrl { get; set; }
|
[JsonProperty("licenseUrl")]
|
||||||
public string licenseExpression { get; set; }
|
public Uri LicenseUrl { 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; }
|
|
||||||
|
|
||||||
public bool requireLicenseAcceptance { get; set; }
|
public string licenseExpression { get; set; }
|
||||||
public string summary { get; set; }
|
|
||||||
|
public string minClientVersion { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("projectUrl")]
|
||||||
|
public Uri ProjectUrl { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[JsonProperty("requireLicenseAcceptance")]
|
||||||
|
public bool RequireLicenseAcceptance { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("summary")]
|
||||||
|
public string Summary { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The tags
|
/// The tags
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public string tags { get; set; }
|
[JsonProperty("tags")]
|
||||||
public string title { get; set; }
|
public string Tags { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
[JsonProperty("title")]
|
||||||
|
public string Title { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The security vulnerabilities of the package
|
/// The security vulnerabilities of the package
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public Vulnerabilitie[] vulnerabilities { get; set; }
|
public IEnumerable<PackageVulnerabilityMetadata> Vulnerabilities { get; }
|
||||||
|
|
||||||
public string packageContent { get; set; }
|
public string packageContent { get; set; }
|
||||||
|
|
||||||
@ -94,7 +111,7 @@ namespace isnd.Data.Catalog
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
[JsonProperty("published")]
|
[JsonProperty("published")]
|
||||||
public DateTime Published { get; set; }
|
public DateTimeOffset? Published { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The full version string after normalization
|
/// The full version string after normalization
|
||||||
@ -107,5 +124,36 @@ namespace isnd.Data.Catalog
|
|||||||
[Required,JsonRequired]
|
[Required,JsonRequired]
|
||||||
[JsonProperty("id")]
|
[JsonProperty("id")]
|
||||||
public string PackageId { get; set; }
|
public string PackageId { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<PackageDependencyGroup> DependencySets { get; set; }
|
||||||
|
|
||||||
|
public long? DownloadCount { get; set; }
|
||||||
|
|
||||||
|
public PackageIdentity Identity{ get; set; }
|
||||||
|
|
||||||
|
public Uri ReadmeUrl { get; set; }
|
||||||
|
|
||||||
|
public Uri ReportAbuseUrl { get; set; }
|
||||||
|
|
||||||
|
public Uri PackageDetailsUrl { get; set; }
|
||||||
|
|
||||||
|
public string Owners { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("isListed")]
|
||||||
|
public bool IsListed { get; set; }
|
||||||
|
|
||||||
|
public bool PrefixReserved { get; set; }
|
||||||
|
|
||||||
|
public LicenseMetadata LicenseMetadata { get; set; }
|
||||||
|
|
||||||
|
public Task<PackageDeprecationMetadata> GetDeprecationMetadataAsync()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<VersionInfo>> GetVersionsAsync()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,8 +20,6 @@ namespace isnd.Data.Catalog
|
|||||||
{
|
{
|
||||||
new CatalogPage(bid, pkg.Id, apiBase, pkg.Versions)
|
new CatalogPage(bid, pkg.Id, apiBase, pkg.Versions)
|
||||||
};
|
};
|
||||||
CommitId = pkg.LatestCommit.CommitId;
|
|
||||||
CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty("count")]
|
[JsonProperty("count")]
|
||||||
@ -29,10 +27,6 @@ namespace isnd.Data.Catalog
|
|||||||
|
|
||||||
[JsonProperty("items")]
|
[JsonProperty("items")]
|
||||||
public List<CatalogPage> Items { get; set; }
|
public List<CatalogPage> Items { get; set; }
|
||||||
|
|
||||||
public string CommitId { get; set; }
|
|
||||||
public DateTimeOffset CommitTimeStamp { get; internal set; }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -71,11 +71,6 @@ namespace isnd.Data.Catalog
|
|||||||
}
|
}
|
||||||
Upper = upper.ToFullString();
|
Upper = upper.ToFullString();
|
||||||
Lower = lower.ToFullString();
|
Lower = lower.ToFullString();
|
||||||
if (latest != null && latest.LatestCommit !=null)
|
|
||||||
{
|
|
||||||
CommitId = latest.CommitId;
|
|
||||||
CommitTimeStamp = latest.LatestCommit.CommitTimeStamp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -100,7 +95,5 @@ namespace isnd.Data.Catalog
|
|||||||
|
|
||||||
[JsonProperty("count")]
|
[JsonProperty("count")]
|
||||||
public int Count { get => items.Count; }
|
public int Count { get => items.Count; }
|
||||||
public string CommitId { get; internal set; }
|
|
||||||
public DateTimeOffset CommitTimeStamp { get; internal set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,8 +0,0 @@
|
|||||||
namespace isnd.Entities
|
|
||||||
{
|
|
||||||
public class UnleashClientSettings
|
|
||||||
{
|
|
||||||
public string ClientApiKey { get; set; }
|
|
||||||
public string ApiUrl { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using isnd.Entities;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Unleash;
|
|
||||||
using Unleash.ClientFactory;
|
|
||||||
|
|
||||||
namespace isnd.Helpers
|
|
||||||
{
|
|
||||||
public static class UnleashHelpers
|
|
||||||
{
|
|
||||||
|
|
||||||
public static IUnleash CreateUnleahClient(this IHostingEnvironment env,
|
|
||||||
UnleashClientSettings unleashClientSettings)
|
|
||||||
{
|
|
||||||
var unleashSettings = new UnleashSettings
|
|
||||||
{
|
|
||||||
UnleashApi = new Uri(unleashClientSettings.ApiUrl),
|
|
||||||
AppName = "isnd",
|
|
||||||
Environment = env.EnvironmentName,
|
|
||||||
CustomHttpHeaders = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "Authorization", unleashClientSettings.ClientApiKey }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
UnleashClientFactory unleashClientFactory = new UnleashClientFactory();
|
|
||||||
return unleashClientFactory.CreateClient(unleashSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using isn.Abstract;
|
using isn.Abstract;
|
||||||
using isnd.Controllers;
|
|
||||||
using isnd.Data;
|
using isnd.Data;
|
||||||
using isnd.Data.Catalog;
|
using isnd.Data.Catalog;
|
||||||
using isnd.Data.Packages;
|
using isnd.Data.Packages;
|
||||||
using isnd.Data.Packages.Catalog;
|
|
||||||
using isnd.Services;
|
using isnd.Services;
|
||||||
using isnd.ViewModels;
|
using isnd.ViewModels;
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using Unleash;
|
|
||||||
|
|
||||||
namespace isnd.Interfaces
|
namespace isnd.Interfaces
|
||||||
{
|
{
|
||||||
@ -19,13 +16,13 @@ namespace isnd.Interfaces
|
|||||||
AutoCompleteResult AutoComplete(string pkgid, int skip, int take, bool prerelease = false, string packageType = null);
|
AutoCompleteResult AutoComplete(string pkgid, int skip, int take, bool prerelease = false, string packageType = null);
|
||||||
|
|
||||||
string[] GetVersions(string pkgid, NuGetVersion parsedVersion, bool prerelease = false, string packageType = null, int skip = 0, int take = 25);
|
string[] GetVersions(string pkgid, NuGetVersion parsedVersion, bool prerelease = false, string packageType = null, int skip = 0, int take = 25);
|
||||||
IEnumerable<Resource> GetResources(IUnleash unleashĈlient);
|
IEnumerable<Resource> GetResources();
|
||||||
Task<PackageRegistration> ÛpdateCatalogForAsync(Commit commit);
|
Task<PackageRegistration> ÛpdateCatalogForAsync(Commit commit);
|
||||||
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);
|
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);
|
||||||
Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, string type);
|
Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, string type);
|
||||||
Task<PackageVersion> GetPackageAsync(string pkgid, string version, string type);
|
Task<PackageVersion> GetPackageAsync(string pkgid, string version, string type);
|
||||||
Task<Data.Catalog.Package> GetCatalogEntryAsync(string pkgId, string version, string pkgType);
|
Task<Data.Catalog.Package> GetCatalogEntryAsync(string pkgId, string version, string pkgType);
|
||||||
IEnumerable<Data.Catalog.Package> SearchCatalogEntriesById(string pkgId, string semver, string pkgType);
|
IEnumerable<Data.Catalog.Package> SearchCatalogEntriesById(string pkgId, string semver, string pkgType, bool preRelease);
|
||||||
|
|
||||||
Task<PackageRegistration> GetCatalogIndexAsync();
|
Task<PackageRegistration> GetCatalogIndexAsync();
|
||||||
Task<PackageRegistration> GetPackageRegistrationIndexAsync(PackageRegistrationQuery query);
|
Task<PackageRegistration> GetPackageRegistrationIndexAsync(PackageRegistrationQuery query);
|
||||||
|
@ -13,7 +13,6 @@ using isnd.ViewModels;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using Unleash;
|
|
||||||
|
|
||||||
namespace isnd.Services
|
namespace isnd.Services
|
||||||
{
|
{
|
||||||
@ -30,25 +29,25 @@ namespace isnd.Services
|
|||||||
apiBase = isndSettings.ExternalUrl + Constants.ApiVersionPrefix;
|
apiBase = isndSettings.ExternalUrl + Constants.ApiVersionPrefix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Resource> GetResources(IUnleash unleashClient)
|
public IEnumerable<Resource> GetResources()
|
||||||
{
|
{
|
||||||
|
|
||||||
var res = new List<Resource>
|
var res = new List<Resource>
|
||||||
{
|
{
|
||||||
new Resource(apiBase + ApiConfig.Package,
|
new Resource(apiBase + ApiConfig.Package,
|
||||||
"PackagePublish/2.0.0")
|
"PackagePublish/2.0.0")
|
||||||
{
|
{
|
||||||
Comment = "Package Publish service"
|
Comment = "Package Publish service"
|
||||||
},
|
},
|
||||||
// under dev, only leash in release mode
|
// under dev, only leash in release mode
|
||||||
|
|
||||||
new Resource(apiBase + ApiConfig.Package + "/{id}/{version}",
|
new Resource(apiBase + ApiConfig.Package + "/{id}/{version}",
|
||||||
"PackageDetailsUriTemplate/5.1.0")
|
"PackageDetailsUriTemplate/5.1.0")
|
||||||
{
|
{
|
||||||
Comment = "URI template used by NuGet Client to construct details URL for packages"
|
Comment = "URI template used by NuGet Client to construct details URL for packages"
|
||||||
},
|
},
|
||||||
|
|
||||||
new Resource(apiBase + ApiConfig.Nuget,
|
new Resource(apiBase + ApiConfig.Nuget,
|
||||||
"PackageBaseAddress/3.0.0")
|
"PackageBaseAddress/3.0.0")
|
||||||
{
|
{
|
||||||
Comment = "Package Base Address service - " +
|
Comment = "Package Base Address service - " +
|
||||||
@ -56,7 +55,7 @@ namespace isnd.Services
|
|||||||
"https://<host>/nupkg/{id-lower}/{version-lower}/{id-lower}.{version-lower}.nupkg"
|
"https://<host>/nupkg/{id-lower}/{version-lower}/{id-lower}.{version-lower}.nupkg"
|
||||||
},
|
},
|
||||||
|
|
||||||
new Resource(apiBase + ApiConfig.AutoComplete,
|
new Resource(apiBase + ApiConfig.AutoComplete,
|
||||||
"SearchAutocompleteService/" + BASE_API_LEVEL)
|
"SearchAutocompleteService/" + BASE_API_LEVEL)
|
||||||
{
|
{
|
||||||
Comment = "Auto complete service"
|
Comment = "Auto complete service"
|
||||||
@ -86,7 +85,7 @@ namespace isnd.Services
|
|||||||
string packageType = null)
|
string packageType = null)
|
||||||
{
|
{
|
||||||
var scope = dbContext.PackageVersions.Where(
|
var scope = dbContext.PackageVersions.Where(
|
||||||
v => v.PackageId == id
|
v => v.PackageId.StartsWith(id)
|
||||||
&& (prerelease || !v.IsPrerelease)
|
&& (prerelease || !v.IsPrerelease)
|
||||||
&& (packageType == null || v.Type == packageType)
|
&& (packageType == null || v.Type == packageType)
|
||||||
)
|
)
|
||||||
@ -173,17 +172,6 @@ namespace isnd.Services
|
|||||||
reason = commit;
|
reason = commit;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reason != null)
|
|
||||||
{
|
|
||||||
index.CommitId = reason.CommitId;
|
|
||||||
index.CommitTimeStamp = reason.CommitTimeStamp;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// From a fresh db
|
|
||||||
index.CommitId = "none";
|
|
||||||
}
|
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -246,7 +234,7 @@ namespace isnd.Services
|
|||||||
|
|
||||||
|
|
||||||
public IEnumerable<Data.Catalog.Package> SearchCatalogEntriesById
|
public IEnumerable<Data.Catalog.Package> SearchCatalogEntriesById
|
||||||
(string pkgId, string semver, string pkgType)
|
(string pkgId, string semver, string pkgType, bool preRelease)
|
||||||
{
|
{
|
||||||
|
|
||||||
return dbContext.PackageVersions
|
return dbContext.PackageVersions
|
||||||
@ -254,7 +242,8 @@ namespace isnd.Services
|
|||||||
.Include(v => v.Package.Owner)
|
.Include(v => v.Package.Owner)
|
||||||
.Include(v => v.LatestCommit)
|
.Include(v => v.LatestCommit)
|
||||||
.Where(v => v.PackageId == pkgId && semver == v.FullString
|
.Where(v => v.PackageId == pkgId && semver == v.FullString
|
||||||
&& (pkgType == null || pkgType == v.Type))
|
&& (pkgType == null || pkgType == v.Type)
|
||||||
|
&& (preRelease || !v.IsPrerelease))
|
||||||
.OrderByDescending(p => p.CommitNId)
|
.OrderByDescending(p => p.CommitNId)
|
||||||
.Select(p => p.ToPackage(apiBase))
|
.Select(p => p.ToPackage(apiBase))
|
||||||
;
|
;
|
||||||
@ -277,8 +266,9 @@ namespace isnd.Services
|
|||||||
var scope = await dbContext.Packages
|
var scope = await dbContext.Packages
|
||||||
.Include(p => p.Versions)
|
.Include(p => p.Versions)
|
||||||
.Include(p => p.Owner)
|
.Include(p => p.Owner)
|
||||||
.Include(p=>p.LatestCommit)
|
.Include(p => p.LatestCommit)
|
||||||
.SingleAsync(p => p.Id.ToLower() == query.Query);
|
.SingleOrDefaultAsync(p => p.Id.ToLower() == query.Query);
|
||||||
|
if (scope==null) return null;
|
||||||
if (scope.Versions.Count==0) return null;
|
if (scope.Versions.Count==0) return null;
|
||||||
string bid = $"{apiBase}{ApiConfig.Registration}";
|
string bid = $"{apiBase}{ApiConfig.Registration}";
|
||||||
foreach (var version in scope.Versions)
|
foreach (var version in scope.Versions)
|
||||||
@ -300,13 +290,12 @@ namespace isnd.Services
|
|||||||
.Skip(query.Skip).Take(query.Take)
|
.Skip(query.Skip).Take(query.Take)
|
||||||
.ToListAsync()
|
.ToListAsync()
|
||||||
);
|
);
|
||||||
var pkgs = scope;
|
scope.ForEach(pkg =>
|
||||||
foreach (var pkg in pkgs)
|
pkg.Versions.ForEach (version =>
|
||||||
{
|
version.LatestCommit = dbContext.Commits.Single(c => c.Id == version.CommitNId))
|
||||||
foreach (var version in pkg.Versions)
|
);
|
||||||
version.LatestCommit = dbContext.Commits.Single(c=>c.Id == version.CommitNId);
|
|
||||||
}
|
return scope.Select(p => new PackageRegistration(bid, apiBase, p));
|
||||||
return pkgs.Select(p => new PackageRegistration(bid, apiBase, p));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System.Linq;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using System.Collections.Generic;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@ -15,19 +13,11 @@ using isnd.Entities;
|
|||||||
using isnd.Authorization;
|
using isnd.Authorization;
|
||||||
using isnd.Data.Roles;
|
using isnd.Data.Roles;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Unleash;
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using isnd.Helpers;
|
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System;
|
using System;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
using isnd.Data.Catalog;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Microsoft.AspNetCore.HttpOverrides;
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
|
||||||
namespace isnd
|
namespace isnd
|
||||||
@ -49,7 +39,6 @@ namespace isnd
|
|||||||
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
||||||
var isndSettingsconf = Configuration.GetSection("Isn");
|
var isndSettingsconf = Configuration.GetSection("Isn");
|
||||||
var adminStartupListConf = Configuration.GetSection("AdminList");
|
var adminStartupListConf = Configuration.GetSection("AdminList");
|
||||||
var unleashConf = Configuration.GetSection("Unleash");
|
|
||||||
|
|
||||||
services.Configure<ForwardedHeadersOptions>(options =>
|
services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
{
|
{
|
||||||
@ -60,7 +49,6 @@ namespace isnd
|
|||||||
services.Configure<SmtpSettings>(smtpSettingsconf)
|
services.Configure<SmtpSettings>(smtpSettingsconf)
|
||||||
.Configure<IsndSettings>(isndSettingsconf)
|
.Configure<IsndSettings>(isndSettingsconf)
|
||||||
.Configure<AdminStartupList>(adminStartupListConf)
|
.Configure<AdminStartupList>(adminStartupListConf)
|
||||||
.Configure<UnleashClientSettings>(unleashConf)
|
|
||||||
.Configure<MigrationsEndPointOptions>(o => o.Path = "~/migrate")
|
.Configure<MigrationsEndPointOptions>(o => o.Path = "~/migrate")
|
||||||
.AddDbContext<ApplicationDbContext>(options =>
|
.AddDbContext<ApplicationDbContext>(options =>
|
||||||
options.UseNpgsql(
|
options.UseNpgsql(
|
||||||
@ -88,18 +76,7 @@ namespace isnd
|
|||||||
.AddTransient<IMailer, EmailSender>()
|
.AddTransient<IMailer, EmailSender>()
|
||||||
.AddTransient<IEmailSender, EmailSender>()
|
.AddTransient<IEmailSender, EmailSender>()
|
||||||
.AddTransient<IPackageManager, PackageManager>()
|
.AddTransient<IPackageManager, PackageManager>()
|
||||||
.AddSingleton<IAuthorizationHandler, ValidApiKeyRequirementHandler>()
|
.AddSingleton<IAuthorizationHandler, ValidApiKeyRequirementHandler>();
|
||||||
.AddSingleton(s =>
|
|
||||||
{
|
|
||||||
var config = s.GetRequiredService<IOptions<UnleashClientSettings>>();
|
|
||||||
if (config.Value == null)
|
|
||||||
throw new System.Exception("No unleash client settings");
|
|
||||||
if (config.Value.ApiUrl == null)
|
|
||||||
throw new System.Exception("No unleash client ApiUrl");
|
|
||||||
if (config.Value.ClientApiKey == null)
|
|
||||||
throw new System.Exception("No unleash client ClientApiKey");
|
|
||||||
return s.GetRequiredService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().CreateUnleahClient(config.Value);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
services.AddAuthentication("Bearer")
|
services.AddAuthentication("Bearer")
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
using Unleash;
|
|
||||||
|
|
||||||
namespace isnd.ViewModels
|
namespace isnd.ViewModels
|
||||||
{
|
{
|
||||||
public class HomeIndexViewModel
|
public class HomeIndexViewModel
|
||||||
{
|
{
|
||||||
public int PkgCount { get; set; }
|
public int PkgCount { get; set; }
|
||||||
public IUnleash UnleashClient;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,17 +1 @@
|
|||||||
@model HomeIndexViewModel
|
@model HomeIndexViewModel
|
||||||
@{
|
|
||||||
foreach (string leashed in new string[] { "pkg-push", "pkg-get",
|
|
||||||
"pkg-autocomplete","pkg-search","pkg-catalog"})
|
|
||||||
{
|
|
||||||
if (Model.UnleashClient.IsEnabled(leashed))
|
|
||||||
{
|
|
||||||
//do some magic
|
|
||||||
<p>@leashed</p>
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//do old boring stuff
|
|
||||||
<p>No @leashed (disabled)</p>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +1,4 @@
|
|||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System;
|
using System;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
@ -12,6 +13,8 @@ using NuGet.Configuration;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NuGet.Protocol.Core.Types;
|
using NuGet.Protocol.Core.Types;
|
||||||
using isn.abst;
|
using isn.abst;
|
||||||
|
using NuGet.Common;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace isnd.host.tests
|
namespace isnd.host.tests
|
||||||
{
|
{
|
||||||
@ -107,5 +110,62 @@ namespace isnd.host.tests
|
|||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
public string SPIIndexURI {
|
||||||
|
get => server.Addresses.First() + "/v3/index";
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task TestGetMetadataAsync()
|
||||||
|
{
|
||||||
|
ILogger logger = NullLogger.Instance;
|
||||||
|
CancellationToken cancellationToken = CancellationToken.None;
|
||||||
|
|
||||||
|
SourceCacheContext cache = new SourceCacheContext();
|
||||||
|
SourceRepository repository = Repository.Factory.GetCoreV3(SPIIndexURI);
|
||||||
|
PackageMetadataResource resource = await repository.GetResourceAsync<PackageMetadataResource>();
|
||||||
|
|
||||||
|
IEnumerable<IPackageSearchMetadata> packages = await resource.GetMetadataAsync(
|
||||||
|
"isn.abst",
|
||||||
|
includePrerelease: true,
|
||||||
|
includeUnlisted: true,
|
||||||
|
cache,
|
||||||
|
logger,
|
||||||
|
cancellationToken);
|
||||||
|
|
||||||
|
Assert.NotEmpty(packages);
|
||||||
|
|
||||||
|
foreach (IPackageSearchMetadata package in packages)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Version: {package.Identity.Version}");
|
||||||
|
Console.WriteLine($"Listed: {package.IsListed}");
|
||||||
|
Console.WriteLine($"Tags: {package.Tags}");
|
||||||
|
Console.WriteLine($"Description: {package.Description}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task TestFindPackageAsync()
|
||||||
|
{
|
||||||
|
ILogger logger = NullLogger.Instance;
|
||||||
|
CancellationToken cancellationToken = CancellationToken.None;
|
||||||
|
|
||||||
|
SourceRepository repository = Repository.Factory.GetCoreV3(SPIIndexURI);
|
||||||
|
PackageSearchResource resource = await repository.GetResourceAsync<PackageSearchResource>();
|
||||||
|
SearchFilter searchFilter = new SearchFilter(includePrerelease: true);
|
||||||
|
|
||||||
|
IEnumerable<IPackageSearchMetadata> results = await resource.SearchAsync(
|
||||||
|
"isn",
|
||||||
|
searchFilter,
|
||||||
|
skip: 0,
|
||||||
|
take: 20,
|
||||||
|
logger,
|
||||||
|
cancellationToken);
|
||||||
|
|
||||||
|
foreach (IPackageSearchMetadata result in results)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Found package {result.Identity.Id} {result.Identity.Version}");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ namespace isnd.tests
|
|||||||
{
|
{
|
||||||
|
|
||||||
[CollectionDefinition("Web server collection")]
|
[CollectionDefinition("Web server collection")]
|
||||||
|
|
||||||
|
|
||||||
public class WebServerFixture : IDisposable
|
public class WebServerFixture : IDisposable
|
||||||
{
|
{
|
||||||
public IWebHost Host { get; private set;}
|
public IWebHost Host { get; private set;}
|
||||||
@ -43,20 +41,11 @@ namespace isnd.tests
|
|||||||
});
|
});
|
||||||
|
|
||||||
Host = webhostBuilder.Build();
|
Host = webhostBuilder.Build();
|
||||||
|
|
||||||
Host.Start(); //Starts listening on the configured addresses.
|
Host.Start(); //Starts listening on the configured addresses.
|
||||||
PrintAddresses(Host.Services);
|
var server = Host.Services.GetRequiredService<IServer>();
|
||||||
}
|
|
||||||
|
|
||||||
void PrintAddresses(IServiceProvider services)
|
|
||||||
{
|
|
||||||
Addresses.Clear();
|
|
||||||
Console.WriteLine("Checking addresses...");
|
|
||||||
var server = services.GetRequiredService<IServer>();
|
|
||||||
var addressFeature = server.Features.Get<IServerAddressesFeature>();
|
var addressFeature = server.Features.Get<IServerAddressesFeature>();
|
||||||
foreach (var address in addressFeature.Addresses)
|
foreach (var address in addressFeature.Addresses)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Listing on address: " + address);
|
|
||||||
Addresses.Add(address);
|
Addresses.Add(address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user