refactorisation de la configuration
This commit is contained in:
@ -13,17 +13,16 @@ namespace nuget_host.Controllers
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
readonly IHostingEnvironment _environment;
|
||||
public IDataProtector DataProtector { get; }
|
||||
public SmtpSettings Options { get; } //set only via Secret Manager
|
||||
public SmtpSettings _smtpSettings { get; } //set only via Secret Manager
|
||||
|
||||
public HomeController(
|
||||
IOptions<SmtpSettings> smtpSettings,
|
||||
IDataProtectionProvider provider, Microsoft.AspNetCore.Hosting.IHostingEnvironment environment, ILogger<HomeController> logger)
|
||||
IHostingEnvironment environment,
|
||||
ILogger<HomeController> logger)
|
||||
{
|
||||
_environment = environment;
|
||||
_logger = logger;
|
||||
Options = smtpSettings.Value;
|
||||
DataProtector = provider.CreateProtector(Options.ProtectionTitle);
|
||||
_smtpSettings = smtpSettings.Value;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
|
@ -7,7 +7,9 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NuGet.Packaging;
|
||||
using nuget_host.Entities;
|
||||
|
||||
namespace nuget_host.Controllers
|
||||
{
|
||||
@ -16,10 +18,16 @@ namespace nuget_host.Controllers
|
||||
private readonly ILogger<PackagesController> logger;
|
||||
private readonly IDataProtector protector;
|
||||
|
||||
public PackagesController(ILoggerFactory loggerFactory, IDataProtectionProvider provider)
|
||||
private readonly NugetSettings nugetSettings;
|
||||
|
||||
public PackagesController(
|
||||
ILoggerFactory loggerFactory,
|
||||
IDataProtectionProvider provider,
|
||||
IOptions<NugetSettings> nugetOptions)
|
||||
{
|
||||
logger = loggerFactory.CreateLogger<PackagesController>();
|
||||
protector = provider.CreateProtector("Packages.v1");
|
||||
nugetSettings = nugetOptions.Value;
|
||||
protector = provider.CreateProtector(nugetSettings.ProtectionTitle);
|
||||
}
|
||||
|
||||
[HttpPut("packages/{*spec}")]
|
||||
@ -61,7 +69,7 @@ namespace nuget_host.Controllers
|
||||
var version = reader.GetVersion();
|
||||
|
||||
|
||||
path = Path.Combine(Startup.SourceDir,
|
||||
path = Path.Combine(nugetSettings.PackagesRootDir,
|
||||
Path.Combine(pkgid,
|
||||
Path.Combine(version.ToFullString(),
|
||||
$"{pkgid}-{version}.nupkg")));
|
||||
@ -85,12 +93,7 @@ namespace nuget_host.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewData["spec"] = spec;
|
||||
// TODO Assert valid sem ver spec
|
||||
var filelst = new DirectoryInfo(Startup.SourceDir);
|
||||
var fi = new FileInfo(spec);
|
||||
var lst = filelst.GetFiles(fi.Name + "*.nupkg");
|
||||
ViewData["lst"] = lst.Select(entry => entry.Name);
|
||||
return BadRequest();
|
||||
}
|
||||
return Ok(ViewData);
|
||||
}
|
||||
@ -101,18 +104,12 @@ namespace nuget_host.Controllers
|
||||
if (string.IsNullOrEmpty(spec))
|
||||
{
|
||||
ViewData["warn"] = "no spec";
|
||||
/*
|
||||
usr/lib/mono/msbuild/Current/bin/NuGet.targets(128,5): error : Failed to retrieve information about 'Microsoft.VisualStudio.Web.CodeGeneration.Tools' from remote source 'http://localhost:5000/Packages/FindPackagesById()?id='Microsoft.VisualStudio.Web.CodeGeneration.Tools'&semVerLevel=2.0.0'. [/home/paul/workspace/nuget-host/nuget-host.csproj]
|
||||
|
||||
|
||||
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
ViewData["spec"] = spec;
|
||||
// TODO Assert valid sem ver spec
|
||||
var filelst = new DirectoryInfo(Startup.SourceDir);
|
||||
var filelst = new DirectoryInfo(nugetSettings.PackagesRootDir);
|
||||
var fi = new FileInfo(spec);
|
||||
var lst = filelst.GetDirectories(spec);
|
||||
ViewData["lst"] = lst.Select(entry => entry.Name);
|
||||
@ -120,6 +117,8 @@ namespace nuget_host.Controllers
|
||||
return Ok(ViewData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Authorize]
|
||||
[HttpGet("api/get-key/{*apikey}")]
|
||||
public IActionResult GetApiKey(string apiKey)
|
||||
|
Reference in New Issue
Block a user