From 4a2f120bc1b212031f50093380be7469dc295a36 Mon Sep 17 00:00:00 2001
From: Robin Dadswell <19610103+RobinDadswell@users.noreply.github.com>
Date: Thu, 12 May 2022 17:10:10 +0100
Subject: [PATCH] New: Set Instance Name
---
.../src/Settings/General/GeneralSettings.js | 1 +
frontend/src/Settings/General/HostSettings.js | 17 +++++++++++++++++
.../Configuration/ConfigFileProvider.cs | 15 ++++++++++++++-
.../Validation/RuleBuilderExtensions.cs | 6 ++++++
src/Sonarr.Api.V3/Config/HostConfigModule.cs | 1 +
src/Sonarr.Api.V3/Config/HostConfigResource.cs | 2 ++
6 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/frontend/src/Settings/General/GeneralSettings.js b/frontend/src/Settings/General/GeneralSettings.js
index 1fd14b924..25cef72a6 100644
--- a/frontend/src/Settings/General/GeneralSettings.js
+++ b/frontend/src/Settings/General/GeneralSettings.js
@@ -20,6 +20,7 @@ const requiresRestartKeys = [
'bindAddress',
'port',
'urlBase',
+ 'instanceName',
'enableSsl',
'sslPort',
'sslCertHash',
diff --git a/frontend/src/Settings/General/HostSettings.js b/frontend/src/Settings/General/HostSettings.js
index 73ca53520..7133d926e 100644
--- a/frontend/src/Settings/General/HostSettings.js
+++ b/frontend/src/Settings/General/HostSettings.js
@@ -19,6 +19,7 @@ function HostSettings(props) {
bindAddress,
port,
urlBase,
+ instanceName,
enableSsl,
sslPort,
sslCertHash,
@@ -71,6 +72,22 @@ function HostSettings(props) {
/>
+
+ Instance Name
+
+
+
+
GetValue("UiFolder", "UI", false);GetValue("UiFolder", "UI", false);
public string UiFolder => "UI";
+ public string InstanceName
+ {
+ get
+ {
+ var instanceName = GetValue("InstanceName", BuildInfo.AppName);
+
+ if (instanceName.StartsWith(BuildInfo.AppName) || instanceName.EndsWith(BuildInfo.AppName) )
+ {
+ return instanceName;
+ }
+ return BuildInfo.AppName;
+ }
+ }
public bool UpdateAutomatically => GetValueBoolean("UpdateAutomatically", false, false);
@@ -218,7 +232,6 @@ namespace NzbDrone.Core.Configuration
public string SyslogLevel => GetValue("SyslogLevel", LogLevel, persist: false).ToLowerInvariant();
-
public int GetValueInt(string key, int defaultValue, bool persist = true)
{
return Convert.ToInt32(GetValue(key, defaultValue));
diff --git a/src/NzbDrone.Core/Validation/RuleBuilderExtensions.cs b/src/NzbDrone.Core/Validation/RuleBuilderExtensions.cs
index df9043fd0..8699d156c 100644
--- a/src/NzbDrone.Core/Validation/RuleBuilderExtensions.cs
+++ b/src/NzbDrone.Core/Validation/RuleBuilderExtensions.cs
@@ -62,5 +62,11 @@ namespace NzbDrone.Core.Validation
{
return ruleBuilder.WithState(v => NzbDroneValidationState.Warning);
}
+
+ public static IRuleBuilderOptions StartsOrEndsWithSonarr(this IRuleBuilder ruleBuilder)
+ {
+ ruleBuilder.SetValidator(new NotEmptyValidator(null));
+ return ruleBuilder.SetValidator(new RegularExpressionValidator("^Sonarr|Sonarr$")).WithMessage("Must start or end with Sonarr");
+ }
}
}
diff --git a/src/Sonarr.Api.V3/Config/HostConfigModule.cs b/src/Sonarr.Api.V3/Config/HostConfigModule.cs
index eb9021929..10d74562c 100644
--- a/src/Sonarr.Api.V3/Config/HostConfigModule.cs
+++ b/src/Sonarr.Api.V3/Config/HostConfigModule.cs
@@ -38,6 +38,7 @@ namespace Sonarr.Api.V3.Config
SharedValidator.RuleFor(c => c.Port).ValidPort();
SharedValidator.RuleFor(c => c.UrlBase).ValidUrlBase();
+ SharedValidator.RuleFor(c => c.InstanceName).StartsOrEndsWithSonarr();
SharedValidator.RuleFor(c => c.Username).NotEmpty().When(c => c.AuthenticationMethod != AuthenticationType.None);
SharedValidator.RuleFor(c => c.Password).NotEmpty().When(c => c.AuthenticationMethod != AuthenticationType.None);
diff --git a/src/Sonarr.Api.V3/Config/HostConfigResource.cs b/src/Sonarr.Api.V3/Config/HostConfigResource.cs
index 8fd147dac..ff3bc777f 100644
--- a/src/Sonarr.Api.V3/Config/HostConfigResource.cs
+++ b/src/Sonarr.Api.V3/Config/HostConfigResource.cs
@@ -24,6 +24,7 @@ namespace Sonarr.Api.V3.Config
public string ApiKey { get; set; }
public string SslCertHash { get; set; }
public string UrlBase { get; set; }
+ public string InstanceName { get; set; }
public bool UpdateAutomatically { get; set; }
public UpdateMechanism UpdateMechanism { get; set; }
public string UpdateScriptPath { get; set; }
@@ -63,6 +64,7 @@ namespace Sonarr.Api.V3.Config
ApiKey = model.ApiKey,
SslCertHash = model.SslCertHash,
UrlBase = model.UrlBase,
+ InstanceName = model.InstanceName,
UpdateAutomatically = model.UpdateAutomatically,
UpdateMechanism = model.UpdateMechanism,
UpdateScriptPath = model.UpdateScriptPath,