From a92bee32e1c090e85b0fec8dd47e048311e890c4 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Thu, 2 Sep 2021 23:37:28 +0100 Subject: [PATCH] CQ --- README.md | 9 +- src/isnd/ApiConfig.cs | 14 +++ .../Controllers/PackagesController.Put.cs | 2 +- src/isnd/Controllers/PackagesController.cs | 19 ++-- src/isnd/Services/PackageManager.cs | 104 +++++++++--------- 5 files changed, 81 insertions(+), 67 deletions(-) create mode 100644 src/isnd/ApiConfig.cs diff --git a/README.md b/README.md index ec5324b..5bfbdf6 100644 --- a/README.md +++ b/README.md @@ -81,12 +81,7 @@ sudo chmod +x /usr/local/lib/isn/isn.exe ## TODO ````bash +nuget list +The V2 feed at 'http://isn.pschneider.fr/package/Search()?$filter=IsLatestVersion&$orderby=Id&searchTerm=''&targetFramework=''&includePrerelease=false&$skip=0&$top=30&semVerLevel=2.0.0' returned an unexpected status code '404 Not Found'. -Failed to retrieve information about 'Yavsc.Abstract' from remote source 'http://isn.pschneider.fr/package/FindPackagesById()?id='Yavsc.Abstract'&semVerLevel=2.0.0'. - Response status code does not indicate success: 404 (Not Found). - - -isn set-api-key -isn add -isn sources ```` diff --git a/src/isnd/ApiConfig.cs b/src/isnd/ApiConfig.cs new file mode 100644 index 0000000..5013e6a --- /dev/null +++ b/src/isnd/ApiConfig.cs @@ -0,0 +1,14 @@ +namespace isnd +{ + public static class ApiConfig + { + public const string BaseApiPath = "/"; + public const string Publish = "put"; + public const string Base = "index"; + public const string Catalog = "catalog"; + public const string Get = "get"; + public const string Search = "search"; + public const string AutoComplete = "autocomplete"; + + } +} \ No newline at end of file diff --git a/src/isnd/Controllers/PackagesController.Put.cs b/src/isnd/Controllers/PackagesController.Put.cs index 67708b2..a41b409 100644 --- a/src/isnd/Controllers/PackagesController.Put.cs +++ b/src/isnd/Controllers/PackagesController.Put.cs @@ -22,7 +22,7 @@ namespace isnd.Controllers public partial class PackagesController { - [HttpPut(_pkgRootPrefix)] + [HttpPut(_pkgRootPrefix + ApiConfig.Publish)] public async Task Put() { try diff --git a/src/isnd/Controllers/PackagesController.cs b/src/isnd/Controllers/PackagesController.cs index 0799fb8..5c1edbe 100644 --- a/src/isnd/Controllers/PackagesController.cs +++ b/src/isnd/Controllers/PackagesController.cs @@ -24,7 +24,6 @@ namespace isnd.Controllers { const int maxTake = 100; - const string _pkgRootPrefix = "~/package"; const string defaultSemVer = "2.0.0"; private readonly Resource[] _ressources; private readonly ILogger _logger; @@ -94,22 +93,24 @@ namespace isnd.Controllers } + const string _pkgRootPrefix = "~" + ApiConfig.BaseApiPath; - [HttpGet("~/index.json")] + + [HttpGet(_pkgRootPrefix + ApiConfig.Base)] public IActionResult ApiIndex() { return Ok(_ressources); } // - [HttpGet(_pkgRootPrefix)] - public IActionResult Index() + [HttpGet(_pkgRootPrefix + ApiConfig.Catalog)] + public IActionResult CatalogIndex() { // https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning return Ok(PackageManager.CurrentCatalogIndex); } - [HttpGet(_pkgRootPrefix + "/index-{id}")] + [HttpGet(_pkgRootPrefix + ApiConfig.Catalog + "-{id}")] public IActionResult Index(string id) { // https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning @@ -117,7 +118,7 @@ namespace isnd.Controllers } // GET /autocomplete?id=isn.protocol&prerelease=true - [HttpGet(_pkgRootPrefix + "/autocomplete")] + [HttpGet(_pkgRootPrefix + ApiConfig.AutoComplete)] public IActionResult AutoComplete( string id, string semVerLevel, @@ -141,7 +142,7 @@ namespace isnd.Controllers // TODO GET {@id}/{LOWER_ID}/index.json // LOWER_ID URL string yes The package ID, lowercased // response : versions array of strings yes The versions available - [HttpGet(_pkgRootPrefix + "/{id}/{lower}/index.json")] + [HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/index.json")] public IActionResult GetVersions( string id, string lower, @@ -174,7 +175,7 @@ namespace isnd.Controllers // LOWER_ID URL string yes The package ID, lowercase // LOWER_VERSION URL string yes The package version, normalized and lowercased // response 200 : the package - [HttpGet(_pkgRootPrefix + "/{id}/{lower}/{idf}-{lowerf}.nupkg")] + [HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nupkg")] public IActionResult GetPackage( [FromRoute] string id, [FromRoute] string lower, [FromRoute] string idf, [FromRoute] string lowerf) @@ -194,7 +195,7 @@ namespace isnd.Controllers // TODO GET {@id}/{LOWER_ID}/{LOWER_VERSION}/{LOWER_ID}.nuspec // response 200 : the nuspec - [HttpGet(_pkgRootPrefix + "/{id}/{lower}/{idf}-{lowerf}.nuspec")] + [HttpGet(_pkgRootPrefix + ApiConfig.Get + "/{id}/{lower}/{idf}-{lowerf}.nuspec")] public IActionResult GetNuspec( [FromRoute][SafeName][Required] string id, [FromRoute][SafeName][Required] string lower, diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs index 5d07757..cb435c6 100644 --- a/src/isnd/Services/PackageManager.cs +++ b/src/isnd/Services/PackageManager.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using isnd.Controllers; @@ -14,20 +13,65 @@ using Unleash; namespace isnd.Services { - - public class PackageManager : IPackageManager { ApplicationDbContext dbContext; + public PackageManager(ApplicationDbContext dbContext, IOptions siteConfigOptionsOptions) { this.dbContext = dbContext; isndSettings = siteConfigOptionsOptions.Value; - extApiUrl = isndSettings.ExternalUrl + "/package"; + extUrl = isndSettings.ExternalUrl ; CurrentCatalogIndex = GetCatalogIndex(); } + public IEnumerable GetResources(IUnleash unleashClient) + { + bool defaultActivation = false; + #if DEBUG + defaultActivation = true; + #endif + + var res = new List(); + + // stable + if (unleashClient.IsEnabled("pkg-push", true)) + res.Add( + new Resource + { + id = extUrl + ApiConfig.Publish, + type = "PackagePublish/2.0.0", + comment = "Package Publish service" + }); + // under dev, only leash in release mode + if (defaultActivation || unleashClient.IsEnabled("pkg-get", false)) + res.Add( + new Resource + { + id = extUrl + ApiConfig.Base, + type = "PackageBaseAddress/3.0.0", + comment = "Package Base Address service" + }); + if (defaultActivation || unleashClient.IsEnabled("pkg-autocomplete", false)) + res.Add( + new Resource + { + id = extUrl + ApiConfig.AutoComplete, + type = "SearchAutocompleteService/3.5.0", + comment = "Auto complete service" + }); + if (defaultActivation || unleashClient.IsEnabled("pkg-search", false)) + res.Add( + new Resource + { + id = extUrl + ApiConfig.Search, + type = "SearchQueryService/3.5.0", + comment = "Search Query service" + }); + return res; + + } public PackageIndexViewModel SearchByName(string query, int skip, int take, bool prerelease = false, @@ -51,9 +95,6 @@ namespace isnd.Services data = pkgs }; } - const int maxPageLen = 512; - - public AutoCompleteResult AutoComplete(string id, int skip, int take, bool prerelease = false, string packageType = null) @@ -96,7 +137,7 @@ namespace isnd.Services public static CatalogIndex CurrentCatalogIndex { get; protected set; } public static List CurrentCatalogPages { get; protected set; } private IsndSettings isndSettings; - private string extApiUrl; + private string extUrl; public virtual CatalogIndex GetCatalogIndex() { @@ -114,7 +155,7 @@ namespace isnd.Services var oldPages = CurrentCatalogPages; CurrentCatalogIndex = new CatalogIndex { - Id = extApiUrl, + Id = extUrl, Items = new List() }; CurrentCatalogPages = new List(); @@ -148,12 +189,14 @@ namespace isnd.Services .Include(pkg => pkg.Versions) .Include(pkg => pkg.LatestVersion) .Where( - pkg => pkg.Versions.Count() > 0 && pkg.CommitId == commit.CommitId + pkg => pkg.Versions.Count(v => v.CommitId == commit.CommitId) > 0 ); // pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString foreach (var pkg in validPkgs) { - var v = pkg.Versions.OrderByDescending(vc => vc.CommitNId).First(); + var v = pkg.Versions. + Where (cv => cv.CommitId == commit.CommitId) + .OrderByDescending(vc => vc.CommitNId).First(); var pkgref = new PackageRef { @@ -204,44 +247,5 @@ namespace isnd.Services return false; } - public IEnumerable GetResources(IUnleash unleashClient) - { - var res = new List(); - if (unleashClient.IsEnabled("pkg-push", true)) - res.Add( - new Resource - { - id = extApiUrl, - type = "PackagePublish/2.0.0", - comment = "Package Publish service" - }); - if (unleashClient.IsEnabled("pkg-get", false)) - res.Add( - new Resource - { - id = extApiUrl, - type = "PackageBaseAddress/3.0.0", - comment = "Package Base Address service" - }); - if (unleashClient.IsEnabled("pkg-autocomplete", false)) - res.Add( - new Resource - { - id = extApiUrl, - type = "SearchAutocompleteService/3.5.0", - comment = "Auto complete service" - }); - if (unleashClient.IsEnabled("pkg-search", false)) - res.Add( - new Resource - { - id = extApiUrl, - type = "SearchQueryService/3.5.0", - comment = "Search Query service" - }); - return res; - - } - } } \ No newline at end of file