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 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 System.Linq;
|
||||
using isnd.ViewModels;
|
||||
using Unleash;
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@ -16,19 +15,14 @@ namespace isnd.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ApplicationDbContext _dbContext;
|
||||
private readonly IUnleash _unleashĈlient;
|
||||
/// <summary>
|
||||
/// Home controller ctor
|
||||
/// </summary>
|
||||
/// <param name="dbContext"></param>
|
||||
/// <param name="unleashĈlient"></param>
|
||||
|
||||
public HomeController(
|
||||
ApplicationDbContext dbContext,
|
||||
IUnleash unleashĈlient)
|
||||
ApplicationDbContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_unleashĈlient = unleashĈlient;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
@ -36,9 +30,7 @@ namespace isnd.Controllers
|
||||
return View(new HomeIndexViewModel{
|
||||
PkgCount = _dbContext.Packages
|
||||
.Where(p => p.Versions.Count > 0)
|
||||
.Count(),
|
||||
UnleashClient = _unleashĈlient
|
||||
});
|
||||
.Count()});
|
||||
}
|
||||
|
||||
public IActionResult About()
|
||||
|
@ -1,10 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using isnd.Entities;
|
||||
using isnd.Services;
|
||||
using isn.Abstract;
|
||||
using isn.abst;
|
||||
using isnd.Interfaces;
|
||||
using Unleash;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
@ -22,11 +20,10 @@ namespace isnd.Controllers
|
||||
/// Api Controller Constructor
|
||||
/// </summary>
|
||||
/// <param name="pm"></param>
|
||||
/// <param name="unleashĈlient"></param>
|
||||
public ApiController(IPackageManager pm, IUnleash unleashĈlient)
|
||||
public ApiController(IPackageManager pm)
|
||||
{
|
||||
packageManager = pm;
|
||||
resources = packageManager.GetResources(unleashĈlient).ToArray();
|
||||
resources = packageManager.GetResources().ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -44,8 +44,5 @@ namespace isnd.Controllers
|
||||
if (null == leaf) return NotFound(new { id, version });
|
||||
return Ok(leaf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
using System.Linq;
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using isnd.Entities;
|
||||
using isn.abst;
|
||||
using isnd.Data.Catalog;
|
||||
|
||||
namespace isnd.Controllers
|
||||
{
|
||||
@ -11,18 +13,32 @@ namespace isnd.Controllers
|
||||
public partial class PackagesController
|
||||
{
|
||||
// GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE}
|
||||
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Search)]
|
||||
public IActionResult Search(
|
||||
string q,
|
||||
int skip = 0,
|
||||
int take = 25,
|
||||
[HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Find)]
|
||||
[HttpPost("~" + Constants.ApiVersionPrefix + ApiConfig.Find)]
|
||||
public async Task<IActionResult> Search(
|
||||
string id,
|
||||
bool prerelease = false,
|
||||
// string packageType = 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 Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NuGet.Versioning;
|
||||
using isnd.Data;
|
||||
using isnd.Entities;
|
||||
using Unleash;
|
||||
using isnd.Services;
|
||||
using isnd.ViewModels;
|
||||
using System.Threading.Tasks;
|
||||
using isnd.Interfaces;
|
||||
using isn.Abstract;
|
||||
|
||||
@ -30,13 +22,11 @@ namespace isnd.Controllers
|
||||
private readonly IsndSettings isndSettings;
|
||||
readonly ApplicationDbContext dbContext;
|
||||
private readonly IPackageManager packageManager;
|
||||
private readonly IUnleash unleashĈlient;
|
||||
|
||||
public PackagesController(
|
||||
ILoggerFactory loggerFactory,
|
||||
IDataProtectionProvider provider,
|
||||
IOptions<IsndSettings> isndOptions,
|
||||
IUnleash unleashĈlient,
|
||||
ApplicationDbContext dbContext,
|
||||
IPackageManager pm)
|
||||
{
|
||||
@ -45,8 +35,7 @@ namespace isnd.Controllers
|
||||
protector = provider.CreateProtector(isndSettings.ProtectionTitle);
|
||||
this.dbContext = dbContext;
|
||||
packageManager = pm;
|
||||
this.unleashĈlient = unleashĈlient;
|
||||
resources = packageManager.GetResources(unleashĈlient).ToArray();
|
||||
resources = packageManager.GetResources().ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ namespace isnd.Data
|
||||
.HasKey( v => new { v.PackageId, v.FullString } );
|
||||
_ = builder.Entity<PackageVersion>()
|
||||
.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.ComponentModel.DataAnnotations;
|
||||
using Newtonsoft.Json;
|
||||
@ -6,10 +7,15 @@ using NuGet.Versioning;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
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
|
||||
{
|
||||
public class PackageDetails : Permalink, IObject
|
||||
public class PackageDetails : Permalink, IObject, IPackageSearchMetadata
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a catalog entry
|
||||
@ -20,11 +26,12 @@ namespace isnd.Data.Catalog
|
||||
{
|
||||
PackageId = pkg.Package.Id;
|
||||
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;
|
||||
CommitId = pkg.CommitId;
|
||||
CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
|
||||
|
||||
IsListed = !pkg.IsDeleted && pkg.Package.Public;
|
||||
// TODO Licence Project Urls, Summary, Title, etc ...
|
||||
}
|
||||
|
||||
[JsonProperty("@type")]
|
||||
@ -40,7 +47,8 @@ namespace isnd.Data.Catalog
|
||||
/// Authors
|
||||
/// </summary>
|
||||
/// <value>string or array of strings</value>
|
||||
public string authors { get; set; }
|
||||
[JsonProperty("authors")]
|
||||
public string Authors { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The dependencies of the package, grouped by target framework
|
||||
@ -56,36 +64,45 @@ namespace isnd.Data.Catalog
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
public string iconUrl { get; set; }
|
||||
|
||||
[JsonProperty("iconUrl")]
|
||||
public Uri IconUrl { get; set; }
|
||||
|
||||
public string language { 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; }
|
||||
[JsonProperty("licenseUrl")]
|
||||
public Uri LicenseUrl { get; set; }
|
||||
|
||||
public bool requireLicenseAcceptance { get; set; }
|
||||
public string summary { get; set; }
|
||||
public string licenseExpression { 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>
|
||||
/// The tags
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public string tags { get; set; }
|
||||
public string title { get; set; }
|
||||
|
||||
[JsonProperty("tags")]
|
||||
public string Tags { get; set; }
|
||||
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The security vulnerabilities of the package
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public Vulnerabilitie[] vulnerabilities { get; set; }
|
||||
public IEnumerable<PackageVulnerabilityMetadata> Vulnerabilities { get; }
|
||||
|
||||
public string packageContent { get; set; }
|
||||
|
||||
@ -94,7 +111,7 @@ namespace isnd.Data.Catalog
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("published")]
|
||||
public DateTime Published { get; set; }
|
||||
public DateTimeOffset? Published { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The full version string after normalization
|
||||
@ -107,5 +124,36 @@ namespace isnd.Data.Catalog
|
||||
[Required,JsonRequired]
|
||||
[JsonProperty("id")]
|
||||
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)
|
||||
};
|
||||
CommitId = pkg.LatestCommit.CommitId;
|
||||
CommitTimeStamp = pkg.LatestCommit.CommitTimeStamp;
|
||||
}
|
||||
|
||||
[JsonProperty("count")]
|
||||
@ -29,10 +27,6 @@ namespace isnd.Data.Catalog
|
||||
|
||||
[JsonProperty("items")]
|
||||
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();
|
||||
Lower = lower.ToFullString();
|
||||
if (latest != null && latest.LatestCommit !=null)
|
||||
{
|
||||
CommitId = latest.CommitId;
|
||||
CommitTimeStamp = latest.LatestCommit.CommitTimeStamp;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -100,7 +95,5 @@ namespace isnd.Data.Catalog
|
||||
|
||||
[JsonProperty("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.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;
|
||||
using Unleash;
|
||||
|
||||
namespace isnd.Interfaces
|
||||
{
|
||||
@ -19,13 +16,13 @@ namespace isnd.Interfaces
|
||||
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);
|
||||
IEnumerable<Resource> GetResources(IUnleash unleashĈlient);
|
||||
IEnumerable<Resource> GetResources();
|
||||
Task<PackageRegistration> ÛpdateCatalogForAsync(Commit commit);
|
||||
Task<PackageDeletionReport> DeletePackageAsync(string pkgid, string version, string type);
|
||||
Task<PackageDeletionReport> UserAskForPackageDeletionAsync(string userid, string pkgId, string lower, string type);
|
||||
Task<PackageVersion> GetPackageAsync(string pkgid, string version, string type);
|
||||
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> GetPackageRegistrationIndexAsync(PackageRegistrationQuery query);
|
||||
|
@ -13,7 +13,6 @@ using isnd.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NuGet.Versioning;
|
||||
using Unleash;
|
||||
|
||||
namespace isnd.Services
|
||||
{
|
||||
@ -30,25 +29,25 @@ namespace isnd.Services
|
||||
apiBase = isndSettings.ExternalUrl + Constants.ApiVersionPrefix;
|
||||
}
|
||||
|
||||
public IEnumerable<Resource> GetResources(IUnleash unleashClient)
|
||||
public IEnumerable<Resource> GetResources()
|
||||
{
|
||||
|
||||
var res = new List<Resource>
|
||||
{
|
||||
new Resource(apiBase + ApiConfig.Package,
|
||||
new Resource(apiBase + ApiConfig.Package,
|
||||
"PackagePublish/2.0.0")
|
||||
{
|
||||
Comment = "Package Publish service"
|
||||
},
|
||||
// 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")
|
||||
{
|
||||
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")
|
||||
{
|
||||
Comment = "Package Base Address service - " +
|
||||
@ -56,7 +55,7 @@ namespace isnd.Services
|
||||
"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)
|
||||
{
|
||||
Comment = "Auto complete service"
|
||||
@ -86,7 +85,7 @@ namespace isnd.Services
|
||||
string packageType = null)
|
||||
{
|
||||
var scope = dbContext.PackageVersions.Where(
|
||||
v => v.PackageId == id
|
||||
v => v.PackageId.StartsWith(id)
|
||||
&& (prerelease || !v.IsPrerelease)
|
||||
&& (packageType == null || v.Type == packageType)
|
||||
)
|
||||
@ -173,17 +172,6 @@ namespace isnd.Services
|
||||
reason = commit;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (reason != null)
|
||||
{
|
||||
index.CommitId = reason.CommitId;
|
||||
index.CommitTimeStamp = reason.CommitTimeStamp;
|
||||
}
|
||||
else
|
||||
{
|
||||
// From a fresh db
|
||||
index.CommitId = "none";
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
@ -246,7 +234,7 @@ namespace isnd.Services
|
||||
|
||||
|
||||
public IEnumerable<Data.Catalog.Package> SearchCatalogEntriesById
|
||||
(string pkgId, string semver, string pkgType)
|
||||
(string pkgId, string semver, string pkgType, bool preRelease)
|
||||
{
|
||||
|
||||
return dbContext.PackageVersions
|
||||
@ -254,7 +242,8 @@ namespace isnd.Services
|
||||
.Include(v => v.Package.Owner)
|
||||
.Include(v => v.LatestCommit)
|
||||
.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)
|
||||
.Select(p => p.ToPackage(apiBase))
|
||||
;
|
||||
@ -277,8 +266,9 @@ namespace isnd.Services
|
||||
var scope = await dbContext.Packages
|
||||
.Include(p => p.Versions)
|
||||
.Include(p => p.Owner)
|
||||
.Include(p=>p.LatestCommit)
|
||||
.SingleAsync(p => p.Id.ToLower() == query.Query);
|
||||
.Include(p => p.LatestCommit)
|
||||
.SingleOrDefaultAsync(p => p.Id.ToLower() == query.Query);
|
||||
if (scope==null) return null;
|
||||
if (scope.Versions.Count==0) return null;
|
||||
string bid = $"{apiBase}{ApiConfig.Registration}";
|
||||
foreach (var version in scope.Versions)
|
||||
@ -300,13 +290,12 @@ namespace isnd.Services
|
||||
.Skip(query.Skip).Take(query.Take)
|
||||
.ToListAsync()
|
||||
);
|
||||
var pkgs = scope;
|
||||
foreach (var pkg in pkgs)
|
||||
{
|
||||
foreach (var version in pkg.Versions)
|
||||
version.LatestCommit = dbContext.Commits.Single(c=>c.Id == version.CommitNId);
|
||||
}
|
||||
return pkgs.Select(p => new PackageRegistration(bid, apiBase, p));
|
||||
scope.ForEach(pkg =>
|
||||
pkg.Versions.ForEach (version =>
|
||||
version.LatestCommit = dbContext.Commits.Single(c => c.Id == version.CommitNId))
|
||||
);
|
||||
|
||||
return scope.Select(p => new PackageRegistration(bid, apiBase, p));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -15,19 +13,11 @@ using isnd.Entities;
|
||||
using isnd.Authorization;
|
||||
using isnd.Data.Roles;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Unleash;
|
||||
using Microsoft.Extensions.Options;
|
||||
using isnd.Helpers;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System;
|
||||
using Microsoft.OpenApi.Models;
|
||||
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;
|
||||
|
||||
namespace isnd
|
||||
@ -49,7 +39,6 @@ namespace isnd
|
||||
var smtpSettingsconf = Configuration.GetSection("Smtp");
|
||||
var isndSettingsconf = Configuration.GetSection("Isn");
|
||||
var adminStartupListConf = Configuration.GetSection("AdminList");
|
||||
var unleashConf = Configuration.GetSection("Unleash");
|
||||
|
||||
services.Configure<ForwardedHeadersOptions>(options =>
|
||||
{
|
||||
@ -60,7 +49,6 @@ namespace isnd
|
||||
services.Configure<SmtpSettings>(smtpSettingsconf)
|
||||
.Configure<IsndSettings>(isndSettingsconf)
|
||||
.Configure<AdminStartupList>(adminStartupListConf)
|
||||
.Configure<UnleashClientSettings>(unleashConf)
|
||||
.Configure<MigrationsEndPointOptions>(o => o.Path = "~/migrate")
|
||||
.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseNpgsql(
|
||||
@ -88,18 +76,7 @@ namespace isnd
|
||||
.AddTransient<IMailer, EmailSender>()
|
||||
.AddTransient<IEmailSender, EmailSender>()
|
||||
.AddTransient<IPackageManager, PackageManager>()
|
||||
.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);
|
||||
});
|
||||
.AddSingleton<IAuthorizationHandler, ValidApiKeyRequirementHandler>();
|
||||
|
||||
|
||||
services.AddAuthentication("Bearer")
|
||||
|
@ -1,11 +1,9 @@
|
||||
using Unleash;
|
||||
|
||||
namespace isnd.ViewModels
|
||||
{
|
||||
public class HomeIndexViewModel
|
||||
{
|
||||
public int PkgCount { get; set; }
|
||||
public IUnleash UnleashClient;
|
||||
|
||||
}
|
||||
}
|
@ -1,17 +1 @@
|
||||
@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;
|
||||
using Xunit;
|
||||
@ -12,6 +13,8 @@ using NuGet.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using NuGet.Protocol.Core.Types;
|
||||
using isn.abst;
|
||||
using NuGet.Common;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace isnd.host.tests
|
||||
{
|
||||
@ -107,5 +110,62 @@ namespace isnd.host.tests
|
||||
{
|
||||
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")]
|
||||
|
||||
|
||||
public class WebServerFixture : IDisposable
|
||||
{
|
||||
public IWebHost Host { get; private set;}
|
||||
@ -43,20 +41,11 @@ namespace isnd.tests
|
||||
});
|
||||
|
||||
Host = webhostBuilder.Build();
|
||||
|
||||
Host.Start(); //Starts listening on the configured addresses.
|
||||
PrintAddresses(Host.Services);
|
||||
}
|
||||
|
||||
void PrintAddresses(IServiceProvider services)
|
||||
{
|
||||
Addresses.Clear();
|
||||
Console.WriteLine("Checking addresses...");
|
||||
var server = services.GetRequiredService<IServer>();
|
||||
var server = Host.Services.GetRequiredService<IServer>();
|
||||
var addressFeature = server.Features.Get<IServerAddressesFeature>();
|
||||
foreach (var address in addressFeature.Addresses)
|
||||
{
|
||||
Console.WriteLine("Listing on address: " + address);
|
||||
Addresses.Add(address);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user