TODO policy on existing zip from fs
This commit is contained in:
parent
e4511a8aaa
commit
e51da7f359
1 changed files with 39 additions and 5 deletions
|
|
@ -54,7 +54,10 @@ namespace nuget_host.Controllers
|
||||||
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.LogInformation("403 : no api-key");
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var file in Request.Form.Files)
|
foreach (var file in Request.Form.Files)
|
||||||
{
|
{
|
||||||
|
|
@ -94,7 +97,11 @@ namespace nuget_host.Controllers
|
||||||
var dest = new FileInfo(path);
|
var dest = new FileInfo(path);
|
||||||
var destdir = new DirectoryInfo(dest.DirectoryName);
|
var destdir = new DirectoryInfo(dest.DirectoryName);
|
||||||
if (dest.Exists)
|
if (dest.Exists)
|
||||||
return BadRequest(new { error = "existant" });
|
{
|
||||||
|
ViewData["error"] = "existe déjà";
|
||||||
|
logger.LogInformation("400 : existe déjà");
|
||||||
|
return BadRequest(ViewData);
|
||||||
|
}
|
||||||
|
|
||||||
if (!destdir.Exists)
|
if (!destdir.Exists)
|
||||||
{
|
{
|
||||||
|
|
@ -128,12 +135,39 @@ namespace nuget_host.Controllers
|
||||||
if (pkg == null)
|
if (pkg == null)
|
||||||
{
|
{
|
||||||
// TODO Choose an app policy to take ownership
|
// TODO Choose an app policy to take ownership
|
||||||
// on existing package on disk.
|
// and populate db with zip info
|
||||||
throw new Exception("Package directory exists, but don't have any owner");
|
// from either existing package on disk,
|
||||||
|
// or from request
|
||||||
|
logger.LogError("Package directory exists, but don't have any owner");
|
||||||
|
throw new NotImplementedException();
|
||||||
|
|
||||||
|
Package newpkgfromdisk = new Package{
|
||||||
|
Id = pkgid,
|
||||||
|
Description = pkgdesc,
|
||||||
|
OwnerId = apikey.UserId
|
||||||
|
};
|
||||||
|
dbContext.Packages.Add(newpkgfromdisk);
|
||||||
|
var newversionfromdisk = new PackageVersion
|
||||||
|
{
|
||||||
|
Package = newpkgfromdisk,
|
||||||
|
Major = version.Major,
|
||||||
|
Minor = version.Minor,
|
||||||
|
Patch = version.Patch,
|
||||||
|
IsPrerelease = version.IsPrerelease,
|
||||||
|
FullString = version.ToFullString()
|
||||||
|
};
|
||||||
|
dbContext.PackageVersions.Add(newversionfromdisk);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
logger.LogInformation($"new package : {entry.Name}");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apikey.UserId != pkg.OwnerId)
|
if (apikey.UserId != pkg.OwnerId)
|
||||||
|
{
|
||||||
|
logger.LogInformation("403 : not owner");
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
|
}
|
||||||
|
|
||||||
var newversion = new PackageVersion
|
var newversion = new PackageVersion
|
||||||
{
|
{
|
||||||
|
|
@ -155,9 +189,9 @@ namespace nuget_host.Controllers
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
logger.LogError($"400: {file.Name}");
|
logger.LogError($"400 en traitant {file.Name}:");
|
||||||
logger.LogError(ex.Message);
|
logger.LogError(ex.Message);
|
||||||
return new BadRequestObjectResult(ViewData);
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ok(ViewData);
|
return Ok(ViewData);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue