From b7dae240cd513835226f0d338dde7154a32b7743 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 29 Aug 2021 00:08:34 +0100 Subject: [PATCH] Catalog packages --- src/isn/UploadFilesToServerUsingWebRequest.cs | 18 +- .../Controllers/PackagesController.Put.cs | 6 +- src/isnd/Controllers/PackagesController.cs | 9 +- src/isnd/Data/Catalog/Commit.cs | 2 +- src/isnd/Data/Catalog/PackageRef.cs | 6 +- src/isnd/Interfaces/IPackageManager.cs | 4 +- .../20210828220901_CommitNoPack.Designer.cs | 352 ++++++++++++++++++ .../Migrations/20210828220901_CommitNoPack.cs | 23 ++ .../ApplicationDbContextModelSnapshot.cs | 5 +- src/isnd/Services/PackageManager.cs | 29 +- 10 files changed, 413 insertions(+), 41 deletions(-) create mode 100644 src/isnd/Migrations/20210828220901_CommitNoPack.Designer.cs create mode 100644 src/isnd/Migrations/20210828220901_CommitNoPack.cs diff --git a/src/isn/UploadFilesToServerUsingWebRequest.cs b/src/isn/UploadFilesToServerUsingWebRequest.cs index a9c9b4c..70ea75d 100644 --- a/src/isn/UploadFilesToServerUsingWebRequest.cs +++ b/src/isn/UploadFilesToServerUsingWebRequest.cs @@ -93,13 +93,17 @@ namespace isn StreamReader re = new StreamReader(stream); if (resp is HttpWebResponse) { - String json = re.ReadToEnd(); - report.Message = json; - var hrep = resp as HttpWebResponse; - report.StatusCode = hrep.StatusCode.ToString(); - report.OK = hrep.StatusCode == HttpStatusCode.Accepted - || hrep.StatusCode == HttpStatusCode.OK; - return true; + if (resp.ContentType == "text/json") + { + String json = re.ReadToEnd(); + report.Message = json; + var hrep = resp as HttpWebResponse; + report.StatusCode = hrep.StatusCode.ToString(); + report.OK = hrep.StatusCode == HttpStatusCode.Accepted + || hrep.StatusCode == HttpStatusCode.OK; + return true; + + } } return false; } diff --git a/src/isnd/Controllers/PackagesController.Put.cs b/src/isnd/Controllers/PackagesController.Put.cs index 69b71e9..a8df81a 100644 --- a/src/isnd/Controllers/PackagesController.Put.cs +++ b/src/isnd/Controllers/PackagesController.Put.cs @@ -152,7 +152,8 @@ namespace isnd.Controllers Patch = version.Patch, IsPrerelease = version.IsPrerelease, FullString = version.ToFullString(), - Type = "" + Type = "", + LatestCommit = commit }); else foreach (var type in types) @@ -165,7 +166,8 @@ namespace isnd.Controllers Patch = version.Patch, IsPrerelease = version.IsPrerelease, FullString = version.ToFullString(), - Type = type.Name + Type = type.Name, + LatestCommit = commit }; _dbContext.PackageVersions.Add(pkgver); } diff --git a/src/isnd/Controllers/PackagesController.cs b/src/isnd/Controllers/PackagesController.cs index 2463d41..0799fb8 100644 --- a/src/isnd/Controllers/PackagesController.cs +++ b/src/isnd/Controllers/PackagesController.cs @@ -105,9 +105,16 @@ namespace isnd.Controllers [HttpGet(_pkgRootPrefix)] public IActionResult Index() { - // https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning + // https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning return Ok(PackageManager.CurrentCatalogIndex); } + + [HttpGet(_pkgRootPrefix + "/index-{id}")] + public IActionResult Index(string id) + { + // https://docs.microsoft.com/en-us/nuget/api/catalog-resource#versioning + return Ok(PackageManager.CurrentCatalogPages[int.Parse(id)]); + } // GET /autocomplete?id=isn.protocol&prerelease=true [HttpGet(_pkgRootPrefix + "/autocomplete")] diff --git a/src/isnd/Data/Catalog/Commit.cs b/src/isnd/Data/Catalog/Commit.cs index 594a42b..1f87670 100644 --- a/src/isnd/Data/Catalog/Commit.cs +++ b/src/isnd/Data/Catalog/Commit.cs @@ -26,7 +26,7 @@ namespace isnd.Data.Catalog public PackageAction Action { get; set; } [NotMapped] - public string CommitId { get => Id.ToString(); } + public string CommitId { get => Id.ToString(); } [NotMapped] public DateTime CommitTimeStamp { get => TimeStamp; } diff --git a/src/isnd/Data/Catalog/PackageRef.cs b/src/isnd/Data/Catalog/PackageRef.cs index 8dd3171..6895222 100644 --- a/src/isnd/Data/Catalog/PackageRef.cs +++ b/src/isnd/Data/Catalog/PackageRef.cs @@ -38,10 +38,14 @@ namespace isnd.Data.Catalog [JsonProperty("nuget:version")] public string Version { get; set; } + + [JsonProperty("commitId")] public string CommitId { get; set; } - [ForeignKey("CommitId")] + [ForeignKey("CommitId"), JsonIgnore] public virtual Commit LastCommit { get; set; } + + [JsonProperty("commitTimeStamp")] public DateTime CommitTimeStamp { get; set; } } } \ No newline at end of file diff --git a/src/isnd/Interfaces/IPackageManager.cs b/src/isnd/Interfaces/IPackageManager.cs index b807b4b..a7ad974 100644 --- a/src/isnd/Interfaces/IPackageManager.cs +++ b/src/isnd/Interfaces/IPackageManager.cs @@ -11,11 +11,9 @@ namespace isnd.Interfaces public interface IPackageManager { AutoCompleteResult AutoComplete(string id, int skip, int take, bool prerelease = false, string packageType = null); - Page CatalogPage(); - CatalogIndex GenerateCatalogIndex(string commitId); + CatalogIndex GetCatalogIndex(); string[] GetVersions(string id, NuGetVersion parsedVersion, bool prerelease = false, string packageType = null, int skip = 0, int take = 25); - void PublishCatalog(); PackageIndexViewModel SearchByName(string query, int skip, int take, bool prerelease = false, string packageType = null); IEnumerable GetResources(IUnleash unleashĈlient); } diff --git a/src/isnd/Migrations/20210828220901_CommitNoPack.Designer.cs b/src/isnd/Migrations/20210828220901_CommitNoPack.Designer.cs new file mode 100644 index 0000000..9837ec9 --- /dev/null +++ b/src/isnd/Migrations/20210828220901_CommitNoPack.Designer.cs @@ -0,0 +1,352 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using isnd.Data; + +namespace isndhost.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210828220901_CommitNoPack")] + partial class CommitNoPack + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Name") + .HasMaxLength(256); + + b.Property("NormalizedName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("RoleId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ClaimType"); + + b.Property("ClaimValue"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider"); + + b.Property("ProviderKey"); + + b.Property("ProviderDisplayName"); + + b.Property("UserId") + .IsRequired(); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId"); + + b.Property("RoleId"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId"); + + b.Property("LoginProvider"); + + b.Property("Name"); + + b.Property("Value"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("isnd.Data.ApiKeys.ApiKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CreationDate"); + + b.Property("Name"); + + b.Property("UserId") + .IsRequired(); + + b.Property("ValidityPeriodInDays"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("ApiKeys"); + }); + + modelBuilder.Entity("isnd.Data.ApplicationUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AccessFailedCount"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken(); + + b.Property("Email") + .HasMaxLength(256); + + b.Property("EmailConfirmed"); + + b.Property("FullName"); + + b.Property("LockoutEnabled"); + + b.Property("LockoutEnd"); + + b.Property("NormalizedEmail") + .HasMaxLength(256); + + b.Property("NormalizedUserName") + .HasMaxLength(256); + + b.Property("PasswordHash"); + + b.Property("PhoneNumber"); + + b.Property("PhoneNumberConfirmed"); + + b.Property("SecurityStamp"); + + b.Property("TwoFactorEnabled"); + + b.Property("UserName") + .HasMaxLength(256); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasName("UserNameIndex"); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("isnd.Data.Catalog.Commit", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Action"); + + b.Property("TimeStamp"); + + b.HasKey("Id"); + + b.ToTable("Commits"); + }); + + modelBuilder.Entity("isnd.Data.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CommitNId"); + + b.Property("CommitTimeStamp"); + + b.Property("Description") + .HasMaxLength(1024); + + b.Property("OwnerId") + .IsRequired(); + + b.Property("Public"); + + b.HasKey("Id"); + + b.HasIndex("CommitNId"); + + b.HasIndex("OwnerId"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("isnd.Data.PackageVersion", b => + { + b.Property("PackageId"); + + b.Property("FullString") + .HasMaxLength(256); + + b.Property("Type") + .HasMaxLength(256); + + b.Property("CommitNId"); + + b.Property("IsPrerelease"); + + b.Property("Major"); + + b.Property("Minor"); + + b.Property("Patch"); + + b.HasKey("PackageId", "FullString", "Type"); + + b.HasIndex("CommitNId"); + + b.ToTable("PackageVersions"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("isnd.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("isnd.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("isnd.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("isnd.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("isnd.Data.ApiKeys.ApiKey", b => + { + b.HasOne("isnd.Data.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("isnd.Data.Package", b => + { + b.HasOne("isnd.Data.Catalog.Commit", "LatestVersion") + .WithMany() + .HasForeignKey("CommitNId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("isnd.Data.ApplicationUser", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("isnd.Data.PackageVersion", b => + { + b.HasOne("isnd.Data.Catalog.Commit", "LatestCommit") + .WithMany("Versions") + .HasForeignKey("CommitNId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("isnd.Data.Package", "Package") + .WithMany("Versions") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/isnd/Migrations/20210828220901_CommitNoPack.cs b/src/isnd/Migrations/20210828220901_CommitNoPack.cs new file mode 100644 index 0000000..b84c807 --- /dev/null +++ b/src/isnd/Migrations/20210828220901_CommitNoPack.cs @@ -0,0 +1,23 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace isndhost.Migrations +{ + public partial class CommitNoPack : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "PackageVersionId", + table: "Commits"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "PackageVersionId", + table: "Commits", + nullable: false, + defaultValue: ""); + } + } +} diff --git a/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs b/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs index 8d885af..f7bebf6 100644 --- a/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/isnd/Migrations/ApplicationDbContextModelSnapshot.cs @@ -206,9 +206,6 @@ namespace isndhost.Migrations b.Property("Action"); - b.Property("PackageVersionId") - .IsRequired(); - b.Property("TimeStamp"); b.HasKey("Id"); @@ -338,7 +335,7 @@ namespace isndhost.Migrations modelBuilder.Entity("isnd.Data.PackageVersion", b => { b.HasOne("isnd.Data.Catalog.Commit", "LatestCommit") - .WithMany() + .WithMany("Versions") .HasForeignKey("CommitNId") .OnDelete(DeleteBehavior.Cascade); diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs index 852dd27..c93a625 100644 --- a/src/isnd/Services/PackageManager.cs +++ b/src/isnd/Services/PackageManager.cs @@ -79,23 +79,6 @@ namespace isnd.Services return catalog; } - public Page CatalogPage() - { - var scope = dbContext.Packages - .Where(P => P.Versions.Count > 0) - .Select( - p => new PackageRef { Id = p.Id, Version = p.Versions.Max().FullString }); - - return new Page - { - Items = scope.ToList() - }; - } - public void PublishCatalog() - { - - } - public AutoCompleteResult AutoComplete(string id, int skip, int take, bool prerelease = false, string packageType = null) @@ -157,7 +140,8 @@ namespace isnd.Services var oldPages = CurrentCatalogPages; CurrentCatalogIndex = new CatalogIndex { - Id = extApiUrl + Id = extApiUrl, + Items = new List() }; CurrentCatalogPages = new List(); @@ -175,8 +159,8 @@ namespace isnd.Services Parent = isndSettings.ExternalUrl + "/package", CommitId = commit.CommitId, CommitTimeStamp = commit.CommitTimeStamp, - Id = this.isndSettings.ExternalUrl + "/package/index-" + p++ - + Id = this.isndSettings.ExternalUrl + "/package/index-" + p++, + Items = new List() }; CurrentCatalogPages.Add(page); pageRef = new PageRef @@ -188,8 +172,9 @@ namespace isnd.Services } var validPkgs = dbContext.Packages .Include(pkg => pkg.Versions) + .Include(pkg => pkg.LatestVersion) .Where( - pkg => pkg.Versions.Count() > 0 + pkg => pkg.Versions.Count() > 0 && pkg.CommitId == commit.CommitId ); // pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString foreach (var pkg in validPkgs) @@ -202,7 +187,7 @@ namespace isnd.Services LastCommit = v.LatestCommit, CommitId = v.LatestCommit.CommitId, CommitTimeStamp = v.LatestCommit.CommitTimeStamp, - RefId = page.Id, + RefId = v.NugetLink, Id = v.PackageId }; page.Items.Add(pkgref);