mirror of https://github.com/Radarr/Radarr
Merge 75e173b9ee
into db1fee8d8a
This commit is contained in:
commit
8bb6c1aeaf
|
@ -29,6 +29,7 @@ namespace NzbDrone.Common.Test
|
||||||
.AddNzbDroneLogger()
|
.AddNzbDroneLogger()
|
||||||
.AutoAddServices(Bootstrap.ASSEMBLIES)
|
.AutoAddServices(Bootstrap.ASSEMBLIES)
|
||||||
.AddDummyDatabase()
|
.AddDummyDatabase()
|
||||||
|
.AddDummyLogDatabase()
|
||||||
.AddStartupContext(new StartupContext("first", "second"));
|
.AddStartupContext(new StartupContext("first", "second"));
|
||||||
|
|
||||||
container.RegisterInstance(new Mock<IHostLifetime>().Object);
|
container.RegisterInstance(new Mock<IHostLifetime>().Object);
|
||||||
|
|
|
@ -61,6 +61,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
string PostgresMainDb { get; }
|
string PostgresMainDb { get; }
|
||||||
string PostgresLogDb { get; }
|
string PostgresLogDb { get; }
|
||||||
string Theme { get; }
|
string Theme { get; }
|
||||||
|
bool LogDbEnabled { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ConfigFileProvider : IConfigFileProvider
|
public class ConfigFileProvider : IConfigFileProvider
|
||||||
|
@ -202,6 +203,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
public string LogLevel => GetValue("LogLevel", "info").ToLowerInvariant();
|
public string LogLevel => GetValue("LogLevel", "info").ToLowerInvariant();
|
||||||
public string ConsoleLogLevel => GetValue("ConsoleLogLevel", string.Empty, persist: false);
|
public string ConsoleLogLevel => GetValue("ConsoleLogLevel", string.Empty, persist: false);
|
||||||
public string Theme => GetValue("Theme", "auto", persist: false);
|
public string Theme => GetValue("Theme", "auto", persist: false);
|
||||||
|
public bool LogDbEnabled => GetValueBoolean("LogDbEnabled", true, false);
|
||||||
public string PostgresHost => _postgresOptions?.Host ?? GetValue("PostgresHost", string.Empty, persist: false);
|
public string PostgresHost => _postgresOptions?.Host ?? GetValue("PostgresHost", string.Empty, persist: false);
|
||||||
public string PostgresUser => _postgresOptions?.User ?? GetValue("PostgresUser", string.Empty, persist: false);
|
public string PostgresUser => _postgresOptions?.User ?? GetValue("PostgresUser", string.Empty, persist: false);
|
||||||
public string PostgresPassword => _postgresOptions?.Password ?? GetValue("PostgresPassword", string.Empty, persist: false);
|
public string PostgresPassword => _postgresOptions?.Password ?? GetValue("PostgresPassword", string.Empty, persist: false);
|
||||||
|
|
|
@ -8,14 +8,24 @@ namespace NzbDrone.Core.Datastore.Extensions
|
||||||
public static IContainer AddDatabase(this IContainer container)
|
public static IContainer AddDatabase(this IContainer container)
|
||||||
{
|
{
|
||||||
container.RegisterDelegate<IDbFactory, IMainDatabase>(f => new MainDatabase(f.Create()), Reuse.Singleton);
|
container.RegisterDelegate<IDbFactory, IMainDatabase>(f => new MainDatabase(f.Create()), Reuse.Singleton);
|
||||||
container.RegisterDelegate<IDbFactory, ILogDatabase>(f => new LogDatabase(f.Create(MigrationType.Log)), Reuse.Singleton);
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IContainer AddLogDatabase(this IContainer container)
|
||||||
|
{
|
||||||
|
container.RegisterDelegate<IDbFactory, ILogDatabase>(f => new LogDatabase(f.Create(MigrationType.Log)), Reuse.Singleton);
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IContainer AddDummyDatabase(this IContainer container)
|
public static IContainer AddDummyDatabase(this IContainer container)
|
||||||
{
|
{
|
||||||
container.RegisterInstance<IMainDatabase>(new MainDatabase(null));
|
container.RegisterInstance<IMainDatabase>(new MainDatabase(null));
|
||||||
|
|
||||||
|
return container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IContainer AddDummyLogDatabase(this IContainer container)
|
||||||
|
{
|
||||||
container.RegisterInstance<ILogDatabase>(new LogDatabase(null));
|
container.RegisterInstance<ILogDatabase>(new LogDatabase(null));
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.Lifecycle;
|
using NzbDrone.Core.Lifecycle;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
using NzbDrone.Core.Update.History.Events;
|
using NzbDrone.Core.Update.History.Events;
|
||||||
|
@ -19,13 +20,15 @@ namespace NzbDrone.Core.Update.History
|
||||||
private readonly IUpdateHistoryRepository _repository;
|
private readonly IUpdateHistoryRepository _repository;
|
||||||
private readonly IEventAggregator _eventAggregator;
|
private readonly IEventAggregator _eventAggregator;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
private Version _prevVersion;
|
private Version _prevVersion;
|
||||||
|
|
||||||
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger)
|
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger, IConfigFileProvider configFileProvider)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_repository = repository;
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Version PreviouslyInstalled()
|
public Version PreviouslyInstalled()
|
||||||
|
@ -58,7 +61,7 @@ namespace NzbDrone.Core.Update.History
|
||||||
|
|
||||||
public void Handle(ApplicationStartedEvent message)
|
public void Handle(ApplicationStartedEvent message)
|
||||||
{
|
{
|
||||||
if (BuildInfo.Version.Major == 10)
|
if (BuildInfo.Version.Major == 10 || !_configFileProvider.LogDbEnabled)
|
||||||
{
|
{
|
||||||
// Don't save dev versions, they change constantly
|
// Don't save dev versions, they change constantly
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace NzbDrone.App.Test
|
||||||
.AutoAddServices(Bootstrap.ASSEMBLIES)
|
.AutoAddServices(Bootstrap.ASSEMBLIES)
|
||||||
.AddNzbDroneLogger()
|
.AddNzbDroneLogger()
|
||||||
.AddDummyDatabase()
|
.AddDummyDatabase()
|
||||||
|
.AddDummyLogDatabase()
|
||||||
.AddStartupContext(args);
|
.AddStartupContext(args);
|
||||||
|
|
||||||
// dummy lifetime and broadcaster so tests resolve
|
// dummy lifetime and broadcaster so tests resolve
|
||||||
|
|
|
@ -83,23 +83,31 @@ namespace NzbDrone.Host
|
||||||
// Utility mode
|
// Utility mode
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
new HostBuilder()
|
new HostBuilder()
|
||||||
.UseServiceProviderFactory(new DryIocServiceProviderFactory(new Container(rules => rules.WithNzbDroneRules())))
|
.UseServiceProviderFactory(new DryIocServiceProviderFactory(new Container(rules => rules.WithNzbDroneRules())))
|
||||||
.ConfigureContainer<IContainer>(c =>
|
.ConfigureContainer<IContainer>(c =>
|
||||||
{
|
{
|
||||||
c.AutoAddServices(Bootstrap.ASSEMBLIES)
|
c.AutoAddServices(Bootstrap.ASSEMBLIES)
|
||||||
.AddNzbDroneLogger()
|
.AddNzbDroneLogger()
|
||||||
.AddDatabase()
|
.AddDatabase()
|
||||||
.AddStartupContext(startupContext)
|
.AddStartupContext(startupContext)
|
||||||
.Resolve<UtilityModeRouter>()
|
.Resolve<UtilityModeRouter>()
|
||||||
.Route(appMode);
|
.Route(appMode);
|
||||||
})
|
if (config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true))
|
||||||
.ConfigureServices(services =>
|
{
|
||||||
{
|
c.AddLogDatabase();
|
||||||
services.Configure<PostgresOptions>(config.GetSection("Radarr:Postgres"));
|
}
|
||||||
}).Build();
|
else
|
||||||
|
{
|
||||||
|
c.AddDummyLogDatabase();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.ConfigureServices(services =>
|
||||||
|
{
|
||||||
|
services.Configure<PostgresOptions>(config.GetSection("Radarr:Postgres"));
|
||||||
|
}).Build();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,6 +138,7 @@ namespace NzbDrone.Host
|
||||||
var enableSsl = config.GetValue(nameof(ConfigFileProvider.EnableSsl), false);
|
var enableSsl = config.GetValue(nameof(ConfigFileProvider.EnableSsl), false);
|
||||||
var sslCertPath = config.GetValue<string>(nameof(ConfigFileProvider.SslCertPath));
|
var sslCertPath = config.GetValue<string>(nameof(ConfigFileProvider.SslCertPath));
|
||||||
var sslCertPassword = config.GetValue<string>(nameof(ConfigFileProvider.SslCertPassword));
|
var sslCertPassword = config.GetValue<string>(nameof(ConfigFileProvider.SslCertPassword));
|
||||||
|
var logDbEnabled = config.GetValue<bool>(nameof(ConfigFileProvider.LogDbEnabled), true);
|
||||||
|
|
||||||
var urls = new List<string> { BuildUrl("http", bindAddress, port) };
|
var urls = new List<string> { BuildUrl("http", bindAddress, port) };
|
||||||
|
|
||||||
|
@ -147,6 +156,14 @@ namespace NzbDrone.Host
|
||||||
.AddNzbDroneLogger()
|
.AddNzbDroneLogger()
|
||||||
.AddDatabase()
|
.AddDatabase()
|
||||||
.AddStartupContext(context);
|
.AddStartupContext(context);
|
||||||
|
if (logDbEnabled)
|
||||||
|
{
|
||||||
|
c.AddLogDatabase();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
c.AddDummyLogDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
SchemaBuilder.Initialize(c);
|
SchemaBuilder.Initialize(c);
|
||||||
})
|
})
|
||||||
|
|
|
@ -236,9 +236,12 @@ namespace NzbDrone.Host
|
||||||
|
|
||||||
// instantiate the databases to initialize/migrate them
|
// instantiate the databases to initialize/migrate them
|
||||||
_ = mainDatabaseFactory.Value;
|
_ = mainDatabaseFactory.Value;
|
||||||
_ = logDatabaseFactory.Value;
|
|
||||||
|
|
||||||
dbTarget.Register();
|
if (configFileProvider.LogDbEnabled)
|
||||||
|
{
|
||||||
|
_ = logDatabaseFactory.Value;
|
||||||
|
dbTarget.Register();
|
||||||
|
}
|
||||||
|
|
||||||
if (OsInfo.IsNotWindows)
|
if (OsInfo.IsNotWindows)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,10 +3,12 @@ using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.Instrumentation;
|
using NzbDrone.Core.Instrumentation;
|
||||||
using Radarr.Http;
|
using Radarr.Http;
|
||||||
using Radarr.Http.Extensions;
|
using Radarr.Http.Extensions;
|
||||||
|
using Radarr.Http.REST.Filters;
|
||||||
|
|
||||||
namespace Radarr.Api.V3.Logs
|
namespace Radarr.Api.V3.Logs
|
||||||
{
|
{
|
||||||
[V3ApiController]
|
[V3ApiController]
|
||||||
|
[LogDatabaseDisabledActionFilter]
|
||||||
public class LogController : Controller
|
public class LogController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogService _logService;
|
private readonly ILogService _logService;
|
||||||
|
|
|
@ -5,10 +5,12 @@ using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Core.Update;
|
using NzbDrone.Core.Update;
|
||||||
using NzbDrone.Core.Update.History;
|
using NzbDrone.Core.Update.History;
|
||||||
using Radarr.Http;
|
using Radarr.Http;
|
||||||
|
using Radarr.Http.REST.Filters;
|
||||||
|
|
||||||
namespace Radarr.Api.V3.Update
|
namespace Radarr.Api.V3.Update
|
||||||
{
|
{
|
||||||
[V3ApiController]
|
[V3ApiController]
|
||||||
|
[LogDatabaseDisabledActionFilter]
|
||||||
public class UpdateController : Controller
|
public class UpdateController : Controller
|
||||||
{
|
{
|
||||||
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
|
||||||
|
namespace Radarr.Http.REST.Filters;
|
||||||
|
|
||||||
|
public class LogDatabaseDisabledActionFilterAttribute : ActionFilterAttribute
|
||||||
|
{
|
||||||
|
public override void OnActionExecuting(ActionExecutingContext context)
|
||||||
|
{
|
||||||
|
var configFileProvider = context.HttpContext.RequestServices.GetService<IConfigFileProvider>();
|
||||||
|
if (!configFileProvider.LogDbEnabled)
|
||||||
|
{
|
||||||
|
context.Result = new NotFoundResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void OnActionExecuted(ActionExecutedContext context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue