upgrade notes

broken/ef
Paul Schneider 3 years ago
parent 82cec8eece
commit 1aef7ce614
4 changed files with 41 additions and 37 deletions

@ -12,7 +12,7 @@ isnd&
# get an api-key from <http://localhost:5000/ApkKeys> # get an api-key from <http://localhost:5000/ApkKeys>
isn push -k <lame-api-key> -s http://localhost:5000/packages your-lame-versionned.nupkg isn push -k <lame-api-key> -s http://localhost:5000/index.json your-lame-versionned.nupkg
```` ````
@ -65,8 +65,13 @@ sudo chown root.root /usr/local/bin/isn
### Mises à jour ### Mises à jour
````bash ````bash
# compiler tout
dotnet publish -c Release
# MAJ du serveur
sudo systemctl stop isnd
sudo cp -a src/isnd/bin/Release/netcoreapp2.1/publish/* /srv/www/isnd sudo cp -a src/isnd/bin/Release/netcoreapp2.1/publish/* /srv/www/isnd
sudo systemctl restart isnd sudo systemctl start isnd
# MAJ du client
sudo cp -a src/isn/bin/Release/net472/* /usr/local/lib/isn sudo cp -a src/isn/bin/Release/net472/* /usr/local/lib/isn
sudo chmod +x /usr/local/lib/isn/isn.exe sudo chmod +x /usr/local/lib/isn/isn.exe
```` ````

@ -20,7 +20,7 @@ namespace isn.Controllers
public partial class PackagesController public partial class PackagesController
{ {
[HttpPut("packages")] [HttpPut(_pkgRootPrefix)]
public async Task<IActionResult> Put() public async Task<IActionResult> Put()
{ {
try try
@ -31,11 +31,11 @@ namespace isn.Controllers
var files = new List<string>(); var files = new List<string>();
ViewData["files"] = files; ViewData["files"] = files;
var clearkey = protector.Unprotect(apiKey); var clearkey = _protector.Unprotect(apiKey);
var apikey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey); var apikey = _dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey);
if (apikey == null) if (apikey == null)
{ {
logger.LogError("403 : no api-key"); _logger.LogError("403 : no api-key");
return Unauthorized(); return Unauthorized();
} }
@ -70,14 +70,14 @@ namespace isn.Controllers
pkgid = reader.GetId(); pkgid = reader.GetId();
version = reader.GetVersion(); version = reader.GetVersion();
string pkgidpath = Path.Combine(nugetSettings.PackagesRootDir, string pkgidpath = Path.Combine(_nugetSettings.PackagesRootDir,
pkgid); pkgid);
pkgpath = Path.Combine(pkgidpath, version.ToFullString()); pkgpath = Path.Combine(pkgidpath, version.ToFullString());
string name = $"{pkgid}-{version}.nupkg"; string name = $"{pkgid}-{version}.nupkg";
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);
if (package != null) if (package != null)
{ {
if (package.OwnerId != apikey.UserId) if (package.OwnerId != apikey.UserId)
@ -94,7 +94,7 @@ namespace isn.Controllers
Description = pkgdesc, Description = pkgdesc,
OwnerId = apikey.UserId OwnerId = apikey.UserId
}; };
dbContext.Packages.Add(package); _dbContext.Packages.Add(package);
} }
if (!destpkgiddir.Exists) destpkgiddir.Create(); if (!destpkgiddir.Exists) destpkgiddir.Create();
@ -105,7 +105,7 @@ namespace isn.Controllers
{ {
ViewData["msg"] = "existant"; ViewData["msg"] = "existant";
ViewData["ecode"] = 1; ViewData["ecode"] = 1;
logger.LogWarning("400 : existant"); _logger.LogWarning("400 : existant");
return base.BadRequest(new { error = ModelState }); return base.BadRequest(new { error = ModelState });
} }
else else
@ -114,12 +114,12 @@ namespace isn.Controllers
source.MoveTo(fullpath); source.MoveTo(fullpath);
files.Add(name); files.Add(name);
string fullstringversion = version.ToFullString(); string fullstringversion = version.ToFullString();
var pkgvers = dbContext.PackageVersions.Where var pkgvers = _dbContext.PackageVersions.Where
(v => v.PackageId == package.Id && v.FullString == fullstringversion); (v => v.PackageId == package.Id && v.FullString == fullstringversion);
if (pkgvers.Count() > 0) if (pkgvers.Count() > 0)
{ {
foreach (var v in pkgvers.ToArray()) foreach (var v in pkgvers.ToArray())
dbContext.PackageVersions.Remove(v); _dbContext.PackageVersions.Remove(v);
} }
foreach (var type in types) foreach (var type in types)
{ {
@ -133,11 +133,11 @@ namespace isn.Controllers
FullString = version.ToFullString(), FullString = version.ToFullString(),
Type = type.Name Type = type.Name
}; };
dbContext.PackageVersions.Add(pkgver); _dbContext.PackageVersions.Add(pkgver);
} }
await dbContext.SaveChangesAsync(); await _dbContext.SaveChangesAsync();
logger.LogInformation($"new package : {nuspec.Name}"); _logger.LogInformation($"new package : {nuspec.Name}");
} }
} }
using (var shacrypto = System.Security.Cryptography.SHA512.Create()) using (var shacrypto = System.Security.Cryptography.SHA512.Create())
@ -163,8 +163,8 @@ namespace isn.Controllers
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex.Message); _logger.LogError(ex.Message);
logger.LogError("Stack Trace: " + ex.StackTrace); _logger.LogError("Stack Trace: " + ex.StackTrace);
return new ObjectResult(new { ViewData, ex.Message }) return new ObjectResult(new { ViewData, ex.Message })
{ StatusCode = 500 }; { StatusCode = 500 };
} }

@ -28,30 +28,29 @@ namespace isn.Controllers
const string _pkgRootPrefix = "~/package"; const string _pkgRootPrefix = "~/package";
const string defaultSemVer = "2.0.0"; const string defaultSemVer = "2.0.0";
private readonly Resource[] ressources; private readonly Resource[] _ressources;
private readonly ILogger<PackagesController> logger; private readonly ILogger<PackagesController> _logger;
private readonly IDataProtector protector; private readonly IDataProtector _protector;
private readonly NugetSettings nugetSettings; private readonly NugetSettings _nugetSettings;
readonly ApplicationDbContext dbContext; readonly ApplicationDbContext _dbContext;
private readonly PackageManager packageManager; private readonly PackageManager _packageManager;
private readonly IUnleash _unleashĈlient; private readonly IUnleash _unleashĈlient;
public PackagesController( public PackagesController(
PackageManager packageManager,
ILoggerFactory loggerFactory, ILoggerFactory loggerFactory,
IDataProtectionProvider provider, IDataProtectionProvider provider,
IOptions<NugetSettings> nugetOptions, IOptions<NugetSettings> nugetOptions,
IUnleash unleashĈlient, IUnleash unleashĈlient,
ApplicationDbContext dbContext) ApplicationDbContext dbContext)
{ {
logger = loggerFactory.CreateLogger<PackagesController>(); _logger = loggerFactory.CreateLogger<PackagesController>();
nugetSettings = nugetOptions.Value; _nugetSettings = nugetOptions.Value;
protector = provider.CreateProtector(nugetSettings.ProtectionTitle); _protector = provider.CreateProtector(_nugetSettings.ProtectionTitle);
this.dbContext = dbContext; _dbContext = dbContext;
this.packageManager = packageManager; _packageManager = new PackageManager(dbContext);
_unleashĈlient = unleashĈlient; _unleashĈlient = unleashĈlient;
ressources = packageManager.GetResources(_unleashĈlient).ToArray(); _ressources = _packageManager.GetResources(_unleashĈlient).ToArray();
} }
// dotnet add . package -s http://localhost:5000/packages isn // dotnet add . package -s http://localhost:5000/packages isn
@ -64,7 +63,7 @@ namespace isn.Controllers
[HttpGet("~/index.json")] [HttpGet("~/index.json")]
public IActionResult ApiIndex() public IActionResult ApiIndex()
{ {
return Ok(ressources); return Ok(_ressources);
} }
@ -91,7 +90,7 @@ namespace isn.Controllers
} }
if (ModelState.IsValid) if (ModelState.IsValid)
{ {
return Ok(packageManager.SearchByName(q,skip,take,prerelease,packageType)); return Ok(_packageManager.SearchByName(q,skip,take,prerelease,packageType));
} }
return BadRequest(new { error = ModelState }); return BadRequest(new { error = ModelState });
} }
@ -116,7 +115,7 @@ namespace isn.Controllers
ModelState.AddModelError("semVerLevel", defaultSemVer + " expected"); ModelState.AddModelError("semVerLevel", defaultSemVer + " expected");
} }
return Ok(packageManager.AutoComplete(id,skip,take,prerelease,packageType)); return Ok(_packageManager.AutoComplete(id,skip,take,prerelease,packageType));
} }
// TODO GET {@id}/{LOWER_ID}/index.json // TODO GET {@id}/{LOWER_ID}/index.json
// LOWER_ID URL string yes The package ID, lowercased // LOWER_ID URL string yes The package ID, lowercased
@ -145,7 +144,7 @@ namespace isn.Controllers
} }
return Ok(new return Ok(new
{ {
versions = packageManager.GetVersions( versions = _packageManager.GetVersions(
id, parsedVersion, prerelease, packageType, skip, take) id, parsedVersion, prerelease, packageType, skip, take)
}); });
} }
@ -159,7 +158,7 @@ namespace isn.Controllers
[FromRoute] string id, [FromRoute] string lower, [FromRoute] string id, [FromRoute] string lower,
[FromRoute] string idf, [FromRoute] string lowerf) [FromRoute] string idf, [FromRoute] string lowerf)
{ {
var pkgpath = Path.Combine(nugetSettings.PackagesRootDir, var pkgpath = Path.Combine(_nugetSettings.PackagesRootDir,
id, lower, $"{idf}.{lowerf}.nupkg" id, lower, $"{idf}.{lowerf}.nupkg"
); );
@ -176,7 +175,7 @@ namespace isn.Controllers
[FromRoute][SafeName][Required] string idf, [FromRoute][SafeName][Required] string idf,
[FromRoute][SafeName][Required] string lowerf) [FromRoute][SafeName][Required] string lowerf)
{ {
var pkgpath = Path.Combine(nugetSettings.PackagesRootDir, var pkgpath = Path.Combine(_nugetSettings.PackagesRootDir,
id, lower, $"{idf}.{lowerf}.nuspec"); id, lower, $"{idf}.{lowerf}.nuspec");
FileInfo pkgfi = new FileInfo(pkgpath); FileInfo pkgfi = new FileInfo(pkgpath);

@ -20,6 +20,7 @@ using Unleash.ClientFactory;
using isnd.Entities; using isnd.Entities;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using isnd.Helpers; using isnd.Helpers;
using isnd.Services;
namespace isn namespace isn
{ {
@ -70,7 +71,6 @@ namespace isn
var config = s.GetRequiredService<IOptions<UnleashClientSettings>>(); var config = s.GetRequiredService<IOptions<UnleashClientSettings>>();
return s.GetRequiredService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().CreateUnleahClient(config.Value); return s.GetRequiredService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().CreateUnleahClient(config.Value);
}); });
// _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value); // _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value);
var smtpSettingsconf = Configuration.GetSection("Smtp"); var smtpSettingsconf = Configuration.GetSection("Smtp");
services.Configure<SmtpSettings>(smtpSettingsconf); services.Configure<SmtpSettings>(smtpSettingsconf);

Loading…