diff --git a/src/nuget-host/Controllers/HomeController.cs b/src/nuget-host/Controllers/HomeController.cs index e325409..fa9346b 100644 --- a/src/nuget-host/Controllers/HomeController.cs +++ b/src/nuget-host/Controllers/HomeController.cs @@ -48,7 +48,7 @@ namespace nuget_host.Controllers { ViewData["Message"] = "Your Privacy page."; - return Ok(ViewData); + return View(ViewData); } public IActionResult Error() diff --git a/src/nuget-host/Controllers/PackageVersionController.cs b/src/nuget-host/Controllers/PackageVersionController.cs index 153e494..aa64b03 100644 --- a/src/nuget-host/Controllers/PackageVersionController.cs +++ b/src/nuget-host/Controllers/PackageVersionController.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.EntityFrameworkCore; using nuget_host.Data; using nuget_host.ViewModels; diff --git a/src/nuget-host/Controllers/PackagesController.Put.cs b/src/nuget-host/Controllers/PackagesController.Put.cs new file mode 100644 index 0000000..a27912b --- /dev/null +++ b/src/nuget-host/Controllers/PackagesController.Put.cs @@ -0,0 +1,172 @@ + +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.DataProtection; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using NuGet.Packaging.Core; +using NuGet.Versioning; +using nuget_host.Data; +using nuget_host.Helpers; + +namespace nuget_host.Controllers +{ + + public partial class PackagesController + { + + [HttpPut("packages")] + public async Task Put() + { + try + { + var clientVersionId = Request.Headers["X-NuGet-Client-Version"]; + var apiKey = Request.Headers["X-NuGet-ApiKey"]; + ViewData["versionId"] = typeof(PackagesController).Assembly.FullName; + var files = new List(); + ViewData["files"] = files; + + var clearkey = protector.Unprotect(apiKey); + var apikey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey); + if (apikey == null) + { + logger.LogError("403 : no api-key"); + return Unauthorized(); + } + + foreach (var file in Request.Form.Files) + { + string initpath = Path.Combine(Environment.GetEnvironmentVariable("TEMP") ?? + Environment.GetEnvironmentVariable("TMP") ?? "/tmp", + $"nuget_host-{Guid.NewGuid()}.nupkg"); + + using (FileStream fw = new FileStream(initpath, FileMode.Create)) + { + file.CopyTo(fw); + } + + using (FileStream fw = new FileStream(initpath, FileMode.Open)) + { + var archive = new ZipArchive(fw); + + var nuspec = archive.Entries.FirstOrDefault(e => e.FullName.EndsWith(".nuspec")); + if (nuspec == null) return BadRequest("no nuspec from archive"); + string pkgpath; + NuGetVersion version; + string pkgid; + string fullpath; + + using (var specstr = nuspec.Open()) + { + NuspecCoreReader reader = new NuspecCoreReader(specstr); + + string pkgdesc = reader.GetDescription(); + var types = reader.GetPackageTypes(); + pkgid = reader.GetId(); + version = reader.GetVersion(); + string pkgidpath = Path.Combine(nugetSettings.PackagesRootDir, + pkgid); + pkgpath = Path.Combine(pkgidpath, version.ToFullString()); + string name = $"{pkgid}-{version}.nupkg"; + fullpath = Path.Combine(pkgpath, name); + + var destpkgiddir = new DirectoryInfo(pkgidpath); + Package package = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid); + if (package != null) + { + if (package.OwnerId != apikey.UserId) + { + return new ForbidResult(); + } + package.Description = pkgdesc; + } + else + { + package = new Package + { + Id = pkgid, + Description = pkgdesc, + OwnerId = apikey.UserId + }; + dbContext.Packages.Add(package); + } + if (!destpkgiddir.Exists) destpkgiddir.Create(); + + var source = new FileInfo(initpath); + var dest = new FileInfo(fullpath); + var destdir = new DirectoryInfo(dest.DirectoryName); + if (dest.Exists) + { + ViewData["msg"] = "existant"; + ViewData["ecode"] = 1; + logger.LogWarning("400 : existant"); + return BadRequest(ViewData); + } + else + { + destdir.Create(); + source.MoveTo(fullpath); + files.Add(name); + string fullstringversion = version.ToFullString(); + var pkgvers = dbContext.PackageVersions.Where + (v => v.PackageId == package.Id && v.FullString == fullstringversion); + if (pkgvers.Count() > 0) + { + foreach (var v in pkgvers.ToArray()) + dbContext.PackageVersions.Remove(v); + } + foreach (var type in types) + { + var pkgver = new PackageVersion + { + Package = package, + Major = version.Major, + Minor = version.Minor, + Patch = version.Patch, + IsPrerelease = version.IsPrerelease, + FullString = version.ToFullString(), + Type = type.Name + }; + dbContext.PackageVersions.Add(pkgver); + } + await dbContext.SaveChangesAsync(); + + logger.LogInformation($"new package : {nuspec.Name}"); + } + } + using (var shacrypto = System.Security.Cryptography.SHA512.Create()) + { + using (var stream = System.IO.File.OpenRead(fullpath)) + { + var hash = shacrypto.ComputeHash(stream); + var shafullname = fullpath + ".sha512"; + var hashtext = Convert.ToBase64String(hash); + var hashtextbytes = Encoding.ASCII.GetBytes(hashtext); + + using (var shafile = System.IO.File.OpenWrite(shafullname)) + { + shafile.Write(hashtextbytes, 0, hashtextbytes.Length); + } + } + } + nuspec.ExtractToFile(Path.Combine(pkgpath, pkgid + ".nuspec")); + } + + } + return Ok(ViewData); + } + catch (Exception ex) + { + logger.LogError(ex.Message); + logger.LogError("Stack Trace: " + ex.StackTrace); + return new ObjectResult(new { ViewData, ex.Message }) + { StatusCode = 500 }; + } + } + } +} diff --git a/src/nuget-host/Controllers/PackagesController.cs b/src/nuget-host/Controllers/PackagesController.cs index 6f0fc09..760f768 100644 --- a/src/nuget-host/Controllers/PackagesController.cs +++ b/src/nuget-host/Controllers/PackagesController.cs @@ -1,26 +1,19 @@ -using System; -using System.Collections.Generic; using System.IO; -using System.IO.Compression; using System.Linq; -using System.Text; -using System.Threading.Tasks; 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.Packaging.Core; -using NuGet.Versioning; using nuget_host.Data; using nuget_host.Entities; -using nuget_host.Helpers; namespace nuget_host.Controllers { [AllowAnonymous] - public class PackagesController : Controller + public partial class PackagesController : Controller { private readonly ILogger logger; private readonly IDataProtector protector; @@ -40,180 +33,67 @@ namespace nuget_host.Controllers this.dbContext = dbContext; } - [HttpPut("packages")] - public async Task Put() - { - try - { - var clientVersionId = Request.Headers["X-NuGet-Client-Version"]; - var apiKey = Request.Headers["X-NuGet-ApiKey"]; - ViewData["versionId"] = typeof(PackagesController).Assembly.FullName; - var files = new List(); - ViewData["files"] = files; - - var clearkey = protector.Unprotect(apiKey); - var apikey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey); - if (apikey == null) - { - logger.LogError("403 : no api-key"); - return Unauthorized(); - } - - foreach (var file in Request.Form.Files) - { - string initpath = Path.Combine(Environment.GetEnvironmentVariable("TEMP") ?? - Environment.GetEnvironmentVariable("TMP") ?? "/tmp", - $"nuget_host-{Guid.NewGuid()}.nupkg"); - - using (FileStream fw = new FileStream(initpath, FileMode.Create)) - { - file.CopyTo(fw); - } - - using (FileStream fw = new FileStream(initpath, FileMode.Open)) - { - var archive = new ZipArchive(fw); - - var nuspec = archive.Entries.FirstOrDefault(e => e.FullName.EndsWith(".nuspec")); - if (nuspec==null) return BadRequest("no nuspec from archive"); - string pkgpath; - NuGetVersion version; - string pkgid; - string fullpath; - - using (var specstr = nuspec.Open()) - { - NuspecCoreReader reader = new NuspecCoreReader(specstr); - - string pkgdesc = reader.GetDescription(); - pkgid = reader.GetId(); - version = reader.GetVersion(); - string pkgidpath = Path.Combine(nugetSettings.PackagesRootDir, - pkgid); - pkgpath = Path.Combine(pkgidpath, version.ToFullString()); - string name = $"{pkgid}-{version}.nupkg"; - fullpath = Path.Combine(pkgpath, name); - - var destpkgiddir = new DirectoryInfo(pkgidpath); - Package package = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid); - if (package != null) - { - if (package.OwnerId != apikey.UserId) - { - return new ForbidResult(); - } - package.Description = pkgdesc; - } - else - { - package = new Package - { - Id = pkgid, - Description = pkgdesc, - OwnerId = apikey.UserId - }; - dbContext.Packages.Add(package); - } - if (!destpkgiddir.Exists) destpkgiddir.Create(); - - var source = new FileInfo(initpath); - var dest = new FileInfo(fullpath); - var destdir = new DirectoryInfo(dest.DirectoryName); - if (dest.Exists) - { - ViewData["msg"] = "existant"; - ViewData["ecode"] = 1; - logger.LogWarning("400 : existant"); - return BadRequest(ViewData); - } - else - { - destdir.Create(); - - source.MoveTo(fullpath); - files.Add(name); - string fullstringversion = version.ToFullString(); - PackageVersion pkgver = dbContext.PackageVersions.FirstOrDefault - (v => v.PackageId == package.Id && v.FullString == fullstringversion); - if (pkgver == null) - { - pkgver = new PackageVersion - { - Package = package, - Major = version.Major, - Minor = version.Minor, - Patch = version.Patch, - IsPrerelease = version.IsPrerelease, - FullString = version.ToFullString() - }; - dbContext.PackageVersions.Add(pkgver); - await dbContext.SaveChangesAsync(); - } - else - { - // existant en db mais pas sur le disque - // TODO prise en charge de ce cas anormal - } - - logger.LogInformation($"new package : {nuspec.Name}"); - } - } - using (var shacrypto = System.Security.Cryptography.SHA512.Create()) - { - using (var stream = System.IO.File.OpenRead(fullpath)) - { - var hash = shacrypto.ComputeHash(stream); - var shafullname = fullpath + ".sha512"; - var hashtext = Convert.ToBase64String(hash); - var hashtextbytes = Encoding.ASCII.GetBytes(hashtext); - - using (var shafile = System.IO.File.OpenWrite(shafullname)) - { - shafile.Write(hashtextbytes, 0, hashtextbytes.Length); - } - } - } - nuspec.ExtractToFile(Path.Combine(pkgpath, pkgid + ".nuspec")); - } - } - return Ok(ViewData); - } - catch (Exception ex) - { - logger.LogError(ex.Message); - logger.LogError("Stack Trace: "+ ex.StackTrace); - return new ObjectResult(new { ViewData, ex.Message}) - { StatusCode = 500 }; - } - } // dotnet add . package -s http://localhost:5000/packages nuget-cli // packages/FindPackagesById()?id='nuget-cli'&semVerLevel=2.0.0 - [HttpGet("packages/FindPackagesById()")] - public IActionResult Index(string id, string semVerLevel) + + // Search + // GET {@id}?q={QUERY}&skip={SKIP}&take={TAKE}&prerelease={PRERELEASE}&semVerLevel={SEMVERLEVEL}&packageType={PACKAGETYPE} + + [HttpGet("~/search/index.json")] + public IActionResult Index( + string q, + bool prerelease = false, + string packageType = null, + int skip = 0, + int take = 25, + string semVerLevel = "2.0.0") { - if (string.IsNullOrEmpty(id)) + if (string.IsNullOrEmpty(q)) { - ViewData["msg"] = "no id"; + ModelState.AddModelError("q", "no value"); + return NotFound(ModelState); } else { - ViewData["id"] = id; - // TODO Assert valid sem ver spec - var filelst = new DirectoryInfo(nugetSettings.PackagesRootDir); - var lst = filelst.GetDirectories(id); - ViewData["lst"] = lst.Select(entry => entry.Name); + var scope = dbContext.Packages + .Include(p => p.Versions) + .Where( + p => (CamelCaseMatch(p.Id, q) || SeparatedByMinusMatch(p.Id, q)) + && (prerelease || p.Versions.Any(v => !v.IsPrerelease)) + && (packageType == null || p.Versions.Any(v => v.Type == packageType)) + ); + var result = new { + totalHits = scope.Count(), + data = scope.Skip(skip).Take(take).ToArray() + }; + return Ok(result); } - return Ok(ViewData); } + protected static bool CamelCaseMatch(string id, string q) + { + // Assert.False (q==null); + string query = q; + if (query.Length==0) return false; - - [Authorize] - [HttpGet("api/get-key/{*apikey}")] - public IActionResult GetApiKey(string apiKey) + while (id.Length > 0) + { + int i = 0; + while (id.Length > i && char.IsLower(id[i])) i++; + if (i==0) break; + id = id.Substring(i); + if (id.StartsWith(q, System.StringComparison.OrdinalIgnoreCase)) return true; + } + return false; + } + protected static bool SeparatedByMinusMatch(string id, string q) { - return Ok(protector.Protect(apiKey)); + foreach (var part in id.Split('-')) + { + if (part.StartsWith(q, System.StringComparison.OrdinalIgnoreCase)) return true; + } + return false; } } } \ No newline at end of file diff --git a/src/nuget-host/Data/ApplicationDbContext.cs b/src/nuget-host/Data/ApplicationDbContext.cs index 01671c0..764c708 100644 --- a/src/nuget-host/Data/ApplicationDbContext.cs +++ b/src/nuget-host/Data/ApplicationDbContext.cs @@ -18,10 +18,11 @@ namespace nuget_host.Data protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); - modelBuilder.Entity().HasKey(v => new + modelBuilder.Entity().HasKey(v => new { - v.PackageId, - v.FullString + v.PackageId, + v.FullString, + v.Type }); } public DbSet ApiKeys { get; set; } diff --git a/src/nuget-host/Data/Package.cs b/src/nuget-host/Data/Package.cs index 6e7f1b2..150a2c5 100644 --- a/src/nuget-host/Data/Package.cs +++ b/src/nuget-host/Data/Package.cs @@ -1,5 +1,7 @@ +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using Newtonsoft.Json; namespace nuget_host.Data { @@ -12,7 +14,14 @@ namespace nuget_host.Data [ForeignKey("Owner")] public string OwnerId { get; set; } + [StringLength(1024)] public string Description { get; set; } + + [JsonIgnore] virtual public ApplicationUser Owner { get; set; } + + [JsonIgnore] + + public virtual List Versions { get; set; } } } \ No newline at end of file diff --git a/src/nuget-host/Data/PackageVersion.cs b/src/nuget-host/Data/PackageVersion.cs index 8b1b6ff..550ce69 100644 --- a/src/nuget-host/Data/PackageVersion.cs +++ b/src/nuget-host/Data/PackageVersion.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using Newtonsoft.Json; namespace nuget_host.Data { @@ -23,8 +24,11 @@ namespace nuget_host.Data public string FullString { get; set; } public bool IsPrerelease { get; set; } - public virtual Package Package { get; set; } + [StringLength(256)] + public string Type { get; set; } + [JsonIgnore] + public virtual Package Package { get; set; } } } \ No newline at end of file diff --git a/src/nuget-host/Migrations/20210621214109_version-types.Designer.cs b/src/nuget-host/Migrations/20210621214109_version-types.Designer.cs new file mode 100644 index 0000000..4c65b2d --- /dev/null +++ b/src/nuget-host/Migrations/20210621214109_version-types.Designer.cs @@ -0,0 +1,316 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using nuget_host.Data; + +namespace nugethost.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20210621214109_version-types")] + partial class versiontypes + { + 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("nuget_host.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("nuget_host.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("nuget_host.Data.Package", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description") + .HasMaxLength(1024); + + b.Property("OwnerId") + .IsRequired(); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("Packages"); + }); + + modelBuilder.Entity("nuget_host.Data.PackageVersion", b => + { + b.Property("PackageId"); + + b.Property("FullString") + .HasMaxLength(256); + + b.Property("Type") + .HasMaxLength(256); + + b.Property("IsPrerelease"); + + b.Property("Major"); + + b.Property("Minor"); + + b.Property("Patch"); + + b.HasKey("PackageId", "FullString", "Type"); + + 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("nuget_host.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("nuget_host.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("nuget_host.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("nuget_host.Data.ApplicationUser") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("nuget_host.Data.ApiKeys.ApiKey", b => + { + b.HasOne("nuget_host.Data.ApplicationUser", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("nuget_host.Data.Package", b => + { + b.HasOne("nuget_host.Data.ApplicationUser", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("nuget_host.Data.PackageVersion", b => + { + b.HasOne("nuget_host.Data.Package", "Package") + .WithMany("Versions") + .HasForeignKey("PackageId") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/nuget-host/Migrations/20210621214109_version-types.cs b/src/nuget-host/Migrations/20210621214109_version-types.cs new file mode 100644 index 0000000..dd4b8d5 --- /dev/null +++ b/src/nuget-host/Migrations/20210621214109_version-types.cs @@ -0,0 +1,58 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace nugethost.Migrations +{ + public partial class versiontypes : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_PackageVersions", + table: "PackageVersions"); + + migrationBuilder.AddColumn( + name: "Type", + table: "PackageVersions", + maxLength: 256, + nullable: false, + defaultValue: ""); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Packages", + maxLength: 1024, + nullable: true, + oldClrType: typeof(string), + oldNullable: true); + + migrationBuilder.AddPrimaryKey( + name: "PK_PackageVersions", + table: "PackageVersions", + columns: new[] { "PackageId", "FullString", "Type" }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_PackageVersions", + table: "PackageVersions"); + + migrationBuilder.DropColumn( + name: "Type", + table: "PackageVersions"); + + migrationBuilder.AlterColumn( + name: "Description", + table: "Packages", + nullable: true, + oldClrType: typeof(string), + oldMaxLength: 1024, + oldNullable: true); + + migrationBuilder.AddPrimaryKey( + name: "PK_PackageVersions", + table: "PackageVersions", + columns: new[] { "PackageId", "FullString" }); + } + } +} diff --git a/src/nuget-host/Migrations/ApplicationDbContextModelSnapshot.cs b/src/nuget-host/Migrations/ApplicationDbContextModelSnapshot.cs index eba417d..db4197b 100644 --- a/src/nuget-host/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/nuget-host/Migrations/ApplicationDbContextModelSnapshot.cs @@ -204,7 +204,8 @@ namespace nugethost.Migrations b.Property("Id") .ValueGeneratedOnAdd(); - b.Property("Description"); + b.Property("Description") + .HasMaxLength(1024); b.Property("OwnerId") .IsRequired(); @@ -223,6 +224,9 @@ namespace nugethost.Migrations b.Property("FullString") .HasMaxLength(256); + b.Property("Type") + .HasMaxLength(256); + b.Property("IsPrerelease"); b.Property("Major"); @@ -231,7 +235,7 @@ namespace nugethost.Migrations b.Property("Patch"); - b.HasKey("PackageId", "FullString"); + b.HasKey("PackageId", "FullString", "Type"); b.ToTable("PackageVersions"); }); @@ -300,7 +304,7 @@ namespace nugethost.Migrations modelBuilder.Entity("nuget_host.Data.PackageVersion", b => { b.HasOne("nuget_host.Data.Package", "Package") - .WithMany() + .WithMany("Versions") .HasForeignKey("PackageId") .OnDelete(DeleteBehavior.Cascade); }); diff --git a/src/nuget-host/Startup.cs b/src/nuget-host/Startup.cs index ca458ce..4251ed6 100644 --- a/src/nuget-host/Startup.cs +++ b/src/nuget-host/Startup.cs @@ -64,6 +64,7 @@ namespace nuget_host services.Configure(nugetSettingsconf); var adminStartupListConf = Configuration.GetSection("AdminList"); services.Configure(adminStartupListConf); + services.Configure(o => o.Path = "~/migrate"); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/src/nuget-host/nuget-host.csproj b/src/nuget-host/nuget-host.csproj index 33a62de..cb2eb7f 100644 --- a/src/nuget-host/nuget-host.csproj +++ b/src/nuget-host/nuget-host.csproj @@ -12,7 +12,6 @@ - @@ -22,10 +21,12 @@ + +