a valid nuget local repo
This commit is contained in:
parent
1266dd54db
commit
61ba3b2bf8
3 changed files with 85 additions and 66 deletions
|
|
@ -31,7 +31,6 @@ test2:
|
||||||
script:
|
script:
|
||||||
- echo "Do another parallel test here"
|
- echo "Do another parallel test here"
|
||||||
- echo "For example run a lint test"
|
- echo "For example run a lint test"
|
||||||
- echo BUT DONO dotnet user-secrets list --project test/nuget.host.tests/
|
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
|
|
@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using NuGet.Packaging.Core;
|
using NuGet.Packaging.Core;
|
||||||
|
using NuGet.Versioning;
|
||||||
using nuget_host.Data;
|
using nuget_host.Data;
|
||||||
using nuget_host.Entities;
|
using nuget_host.Entities;
|
||||||
using nuget_host.Helpers;
|
using nuget_host.Helpers;
|
||||||
|
|
@ -72,21 +74,25 @@ namespace nuget_host.Controllers
|
||||||
{
|
{
|
||||||
var archive = new ZipArchive(fw);
|
var archive = new ZipArchive(fw);
|
||||||
|
|
||||||
foreach (var entry in archive.Entries)
|
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())
|
||||||
{
|
{
|
||||||
if (entry.FullName.EndsWith(".nuspec"))
|
|
||||||
{
|
|
||||||
var specstr = entry.Open();
|
|
||||||
NuspecCoreReader reader = new NuspecCoreReader(specstr);
|
NuspecCoreReader reader = new NuspecCoreReader(specstr);
|
||||||
|
|
||||||
string pkgdesc = reader.GetDescription();
|
string pkgdesc = reader.GetDescription();
|
||||||
string pkgid = reader.GetId();
|
pkgid = reader.GetId();
|
||||||
var version = reader.GetVersion();
|
version = reader.GetVersion();
|
||||||
string pkgidpath = Path.Combine(nugetSettings.PackagesRootDir,
|
string pkgidpath = Path.Combine(nugetSettings.PackagesRootDir,
|
||||||
pkgid);
|
pkgid);
|
||||||
string pkgpath = Path.Combine(pkgidpath, version.ToFullString());
|
pkgpath = Path.Combine(pkgidpath, version.ToFullString());
|
||||||
string name = $"{pkgid}-{version}.nupkg";
|
string name = $"{pkgid}-{version}.nupkg";
|
||||||
string fullpath = Path.Combine(pkgpath, name);
|
fullpath = Path.Combine(pkgpath, name);
|
||||||
|
|
||||||
var destpkgiddir = new DirectoryInfo(pkgidpath);
|
var destpkgiddir = new DirectoryInfo(pkgidpath);
|
||||||
Package package = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid);
|
Package package = dbContext.Packages.SingleOrDefault(p => p.Id == pkgid);
|
||||||
|
|
@ -135,11 +141,25 @@ namespace nuget_host.Controllers
|
||||||
};
|
};
|
||||||
dbContext.PackageVersions.Add(newversion);
|
dbContext.PackageVersions.Add(newversion);
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
logger.LogInformation($"new package : {entry.Name}");
|
logger.LogInformation($"new package : {nuspec.Name}");
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -153,21 +173,21 @@ namespace nuget_host.Controllers
|
||||||
{ StatusCode = 500 };
|
{ StatusCode = 500 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// dotnet add . package -s http://localhost:5000/packages nuget-cli
|
||||||
[HttpGet("packages/{spec}")]
|
// packages/FindPackagesById()?id='nuget-cli'&semVerLevel=2.0.0
|
||||||
public IActionResult Index(string spec)
|
[HttpGet("packages/FindPackagesById()")]
|
||||||
|
public IActionResult Index(string id, string semVerLevel)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(spec))
|
if (string.IsNullOrEmpty(id))
|
||||||
{
|
{
|
||||||
ViewData["warn"] = "no spec";
|
ViewData["warn"] = "no id";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ViewData["spec"] = spec;
|
ViewData["id"] = id;
|
||||||
// TODO Assert valid sem ver spec
|
// TODO Assert valid sem ver spec
|
||||||
var filelst = new DirectoryInfo(nugetSettings.PackagesRootDir);
|
var filelst = new DirectoryInfo(nugetSettings.PackagesRootDir);
|
||||||
var fi = new FileInfo(spec);
|
var lst = filelst.GetDirectories(id);
|
||||||
var lst = filelst.GetDirectories(spec);
|
|
||||||
ViewData["lst"] = lst.Select(entry => entry.Name);
|
ViewData["lst"] = lst.Select(entry => entry.Name);
|
||||||
}
|
}
|
||||||
return Ok(ViewData);
|
return Ok(ViewData);
|
||||||
|
|
|
||||||
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue