Skip to content

Commit 360900d

Browse files
authored
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 4f6c920 commit 360900d

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
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);
@@ -37,6 +39,9 @@ protected override void UpdateSettings()
3739
settings.RemoveIfRetired(ServiceControlSettings.AuditLogQueue, version);
3840
settings.RemoveIfRetired(ServiceControlSettings.ForwardAuditMessages, version);
3941
settings.RemoveIfRetired(ServiceControlSettings.InternalQueueName, version);
42+
settings.RemoveIfRetired(ServiceControlSettings.LicensingComponentRabbitMqManagementApiUrl, version);
43+
settings.RemoveIfRetired(ServiceControlSettings.LicensingComponentRabbitMqManagementApiUsername, version);
44+
settings.RemoveIfRetired(ServiceControlSettings.LicensingComponentRabbitMqManagementApiPassword, version);
4045

4146
RemoveRavenDB35Settings(settings, version);
4247
}
@@ -62,6 +67,43 @@ public override void SetTransportType(string transportTypeName)
6267
settings.Set(ServiceControlSettings.TransportType, transportTypeName, version);
6368
}
6469

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,23 @@ public static class ServiceControlSettings
8989
Name = "ServiceControl/EnableFullTextSearchOnBodies",
9090
SupportedFrom = new SemanticVersion(4, 17, 0)
9191
};
92+
93+
public static readonly SettingInfo LicensingComponentRabbitMqManagementApiUrl = new()
94+
{
95+
Name = "LicensingComponent/RabbitMQ/ApiUrl",
96+
RemovedFrom = new SemanticVersion(6, 5, 0)
97+
};
98+
99+
public static readonly SettingInfo LicensingComponentRabbitMqManagementApiUsername = new()
100+
{
101+
Name = "LicensingComponent/RabbitMQ/UserName",
102+
RemovedFrom = new SemanticVersion(6, 5, 0)
103+
};
104+
105+
public static readonly SettingInfo LicensingComponentRabbitMqManagementApiPassword = new()
106+
{
107+
Name = "LicensingComponent/RabbitMQ/Password",
108+
RemovedFrom = new SemanticVersion(6, 5, 0)
109+
};
92110
}
93111
}

0 commit comments

Comments
 (0)