TODO policy on existing zip from fs
This commit is contained in:
@ -54,7 +54,10 @@ namespace nuget_host.Controllers
|
||||
var clearkey = protector.Unprotect(apiKey);
|
||||
var apikey = dbContext.ApiKeys.SingleOrDefault(k => k.Id == clearkey);
|
||||
if (apikey == null)
|
||||
{
|
||||
logger.LogInformation("403 : no api-key");
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
foreach (var file in Request.Form.Files)
|
||||
{
|
||||
@ -94,7 +97,11 @@ namespace nuget_host.Controllers
|
||||
var dest = new FileInfo(path);
|
||||
var destdir = new DirectoryInfo(dest.DirectoryName);
|
||||
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)
|
||||
{
|
||||
@ -128,12 +135,39 @@ namespace nuget_host.Controllers
|
||||
if (pkg == null)
|
||||
{
|
||||
// TODO Choose an app policy to take ownership
|
||||
// on existing package on disk.
|
||||
throw new Exception("Package directory exists, but don't have any owner");
|
||||
// and populate db with zip info
|
||||
// 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)
|
||||
{
|
||||
logger.LogInformation("403 : not owner");
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
var newversion = new PackageVersion
|
||||
{
|
||||
@ -155,9 +189,9 @@ namespace nuget_host.Controllers
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError($"400: {file.Name}");
|
||||
logger.LogError($"400 en traitant {file.Name}:");
|
||||
logger.LogError(ex.Message);
|
||||
return new BadRequestObjectResult(ViewData);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return Ok(ViewData);
|
||||
|
Reference in New Issue
Block a user