Skip to content

Commit e5b39ce

Browse files
abparticularbording
authored andcommitted
Migrate RabbitMQ management API settings into connection string
* Migrate RabbitMQ management API settings from separate app.config entries into the connection string * Renamed settings related to Licensing component's use of RabbitMQ management API Removed unnecessary LINQ usage when working with DbConnectionStringBuilder in ServiceControlAppConfig
1 parent 32a9d68 commit e5b39ce

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

src/ServiceControlInstaller.Engine/Configuration/ServiceControl/ServiceControlAppConfig.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace ServiceControlInstaller.Engine.Configuration.ServiceControl
22
{
3+
using System;
4+
using System.Data.Common;
35
using System.IO;
46
using Instances;
57

@@ -12,7 +14,7 @@ public ServiceControlAppConfig(IServiceControlInstance instance) : base(Path.Com
1214

1315
protected override void UpdateSettings()
1416
{
15-
Config.ConnectionStrings.ConnectionStrings.Set("NServiceBus/Transport", details.ConnectionString);
17+
Config.ConnectionStrings.ConnectionStrings.Set("NServiceBus/Transport", UpdateConnectionString());
1618
var settings = Config.AppSettings.Settings;
1719
var version = details.Version;
1820
settings.Set(ServiceControlSettings.InstanceName, details.InstanceName, version);
@@ -43,6 +45,9 @@ protected override void UpdateSettings()
4345
settings.RemoveIfRetired(ServiceControlSettings.AuditLogQueue, version);
4446
settings.RemoveIfRetired(ServiceControlSettings.ForwardAuditMessages, version);
4547
settings.RemoveIfRetired(ServiceControlSettings.InternalQueueName, version);
48+
settings.RemoveIfRetired(ServiceControlSettings.LicensingComponentRabbitMqManagementApiUrl, version);
49+
settings.RemoveIfRetired(ServiceControlSettings.LicensingComponentRabbitMqManagementApiUsername, version);
50+
settings.RemoveIfRetired(ServiceControlSettings.LicensingComponentRabbitMqManagementApiPassword, version);
4651

4752
RemoveRavenDB35Settings(settings, version);
4853
}
@@ -68,6 +73,43 @@ public override void SetTransportType(string transportTypeName)
6873
settings.Set(ServiceControlSettings.TransportType, transportTypeName, version);
6974
}
7075

71-
IServiceControlInstance details;
76+
string UpdateConnectionString()
77+
{
78+
var connectionStringBuilder = new DbConnectionStringBuilder { ConnectionString = details.ConnectionString };
79+
80+
MigrateLicensingComponentRabbitMqManagementApiSettings(connectionStringBuilder);
81+
82+
return connectionStringBuilder.ConnectionString;
83+
}
84+
85+
void MigrateLicensingComponentRabbitMqManagementApiSettings(DbConnectionStringBuilder connectionStringBuilder)
86+
{
87+
if (!details.TransportPackage.Name.Contains("rabbitmq", StringComparison.OrdinalIgnoreCase))
88+
{
89+
return;
90+
}
91+
92+
var settings = Config.AppSettings.Settings;
93+
94+
var legacySetting = settings[ServiceControlSettings.LicensingComponentRabbitMqManagementApiUrl.Name];
95+
if (legacySetting is not null && !connectionStringBuilder.ContainsKey("ManagementApiUrl"))
96+
{
97+
connectionStringBuilder.Add("ManagementApiUrl", legacySetting.Value);
98+
}
99+
100+
legacySetting = settings[ServiceControlSettings.LicensingComponentRabbitMqManagementApiUsername.Name];
101+
if (legacySetting is not null && !connectionStringBuilder.ContainsKey("ManagementApiUserName"))
102+
{
103+
connectionStringBuilder.Add("ManagementApiUserName", legacySetting.Value);
104+
}
105+
106+
legacySetting = settings[ServiceControlSettings.LicensingComponentRabbitMqManagementApiPassword.Name];
107+
if (legacySetting is not null && !connectionStringBuilder.ContainsKey("ManagementApiPassword"))
108+
{
109+
connectionStringBuilder.Add("ManagementApiPassword", legacySetting.Value);
110+
}
111+
}
112+
113+
readonly IServiceControlInstance details;
72114
}
73115
}

src/ServiceControlInstaller.Engine/Configuration/ServiceControl/SettingsList.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,23 @@ public static class ServiceControlSettings
9595
Name = "ServiceControl/ShutdownTimeout",
9696
SupportedFrom = new SemanticVersion(6, 4, 1)
9797
};
98+
99+
public static readonly SettingInfo LicensingComponentRabbitMqManagementApiUrl = new()
100+
{
101+
Name = "LicensingComponent/RabbitMQ/ApiUrl",
102+
RemovedFrom = new SemanticVersion(6, 5, 0)
103+
};
104+
105+
public static readonly SettingInfo LicensingComponentRabbitMqManagementApiUsername = new()
106+
{
107+
Name = "LicensingComponent/RabbitMQ/UserName",
108+
RemovedFrom = new SemanticVersion(6, 5, 0)
109+
};
110+
111+
public static readonly SettingInfo LicensingComponentRabbitMqManagementApiPassword = new()
112+
{
113+
Name = "LicensingComponent/RabbitMQ/Password",
114+
RemovedFrom = new SemanticVersion(6, 5, 0)
115+
};
98116
}
99-
}
117+
}

0 commit comments

Comments
 (0)