|
1 | 1 | using System;
|
2 |
| -using System.Linq; |
3 | 2 | using Arcus.BackgroundJobs.KeyVault;
|
4 |
| -using Arcus.BackgroundJobs.KeyVault.Events; |
5 | 3 | using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling;
|
6 |
| -using Arcus.Messaging.Pumps.ServiceBus; |
7 | 4 | using Arcus.Messaging.Pumps.ServiceBus.Configuration;
|
8 | 5 | using Arcus.Security.Core.Caching;
|
9 |
| -using Azure.Messaging; |
10 | 6 | using GuardNet;
|
11 | 7 | using Microsoft.Extensions.Hosting;
|
12 | 8 | using Microsoft.Extensions.Logging;
|
@@ -233,116 +229,5 @@ private static void WithInvalidateKeyVaultSecretHandler(this ServiceBusMessageHa
|
233 | 229 | return new InvalidateKeyVaultSecretHandler(cachedSecretProvider, logger);
|
234 | 230 | });
|
235 | 231 | }
|
236 |
| - |
237 |
| - /// <summary> |
238 |
| - /// Adds a background job to the <see cref="IServiceCollection"/> to automatically restart a <see cref="AzureServiceBusMessagePump"/> with a specific <paramref name="jobId"/> |
239 |
| - /// when the Azure Key Vault secret that holds the Azure Service Bus connection string was updated. |
240 |
| - /// </summary> |
241 |
| - /// <remarks> |
242 |
| - /// Make sure that the application has the Arcus secret store configured correctly. |
243 |
| - /// For on the Arcus secret store: <a href="https://security.arcus-azure.net/features/secret-store" />. |
244 |
| - /// </remarks> |
245 |
| - /// <param name="services">The collection of services to add the job to.</param> |
246 |
| - /// <param name="jobId">The unique background job ID to identify which message pump to restart.</param> |
247 |
| - /// <param name="subscriptionNamePrefix">The name of the Azure Service Bus subscription that will be created to receive <see cref="CloudEvent"/>'s.</param> |
248 |
| - /// <param name="serviceBusTopicConnectionStringSecretKey">The secret key that points to the Azure Service Bus Topic connection string.</param> |
249 |
| - /// <param name="messagePumpConnectionStringKey"> |
250 |
| - /// The secret key where the connection string credentials are located for the target message pump that needs to be auto-restarted. |
251 |
| - /// </param> |
252 |
| - /// <exception cref="ArgumentNullException"> |
253 |
| - /// Thrown when the <paramref name="services"/> or the searched for <see cref="AzureServiceBusMessagePump"/> based on the given <paramref name="jobId"/> is <c>null</c>. |
254 |
| - /// </exception> |
255 |
| - /// <exception cref="ArgumentException"> |
256 |
| - /// Thrown when the <paramref name="subscriptionNamePrefix"/> or <paramref name="serviceBusTopicConnectionStringSecretKey"/> is blank. |
257 |
| - /// </exception> |
258 |
| -#pragma warning disable CS0436 // Type conflicts with imported type |
259 |
| - [Obsolete("Consider using the " + nameof(ServiceBusMessageHandlerCollectionExtensions.WithAutoRestartOnRotatedCredentials) + " extension instead when configuring the message pump/router/handlers")] |
260 |
| -#pragma warning restore CS0436 // Type conflicts with imported type |
261 |
| - public static IServiceCollection AddAutoRestartServiceBusMessagePumpOnRotatedCredentialsBackgroundJob( |
262 |
| - this IServiceCollection services, |
263 |
| - string jobId, |
264 |
| - string subscriptionNamePrefix, |
265 |
| - string serviceBusTopicConnectionStringSecretKey, |
266 |
| - string messagePumpConnectionStringKey) |
267 |
| - { |
268 |
| - Guard.NotNull(services, nameof(services), "Requires a collection of services to add the re-authentication background job"); |
269 |
| - Guard.NotNullOrWhitespace(jobId, nameof(jobId), "Requires a non-blank job ID to identify the Azure Service Bus message pump which needs to restart"); |
270 |
| - Guard.NotNullOrWhitespace(subscriptionNamePrefix, nameof(subscriptionNamePrefix), "Requires a non-blank subscription name of the Azure Service Bus Topic subscription, to receive Azure Key Vault events"); |
271 |
| - Guard.NotNullOrWhitespace(serviceBusTopicConnectionStringSecretKey, nameof(serviceBusTopicConnectionStringSecretKey), "Requires a non-blank secret key that points to a Azure Service Bus Topic"); |
272 |
| - Guard.NotNullOrWhitespace(messagePumpConnectionStringKey, nameof(messagePumpConnectionStringKey), "Requires a non-blank secret key that points to the credentials that holds the connection string of the target message pump"); |
273 |
| - |
274 |
| - return AddAutoRestartServiceBusMessagePumpOnRotatedCredentialsBackgroundJob( |
275 |
| - services, |
276 |
| - jobId, |
277 |
| - subscriptionNamePrefix, |
278 |
| - serviceBusTopicConnectionStringSecretKey, |
279 |
| - messagePumpConnectionStringKey, |
280 |
| - configureBackgroundJob: null); |
281 |
| - } |
282 |
| - |
283 |
| - /// <summary> |
284 |
| - /// Adds a background job to the <see cref="IServiceCollection"/> to automatically restart a <see cref="AzureServiceBusMessagePump"/> with a specific <paramref name="jobId"/> |
285 |
| - /// when the Azure Key Vault secret that holds the Azure Service Bus connection string was updated. |
286 |
| - /// </summary> |
287 |
| - /// <remarks> |
288 |
| - /// Make sure that the application has the Arcus secret store configured correctly. |
289 |
| - /// For on the Arcus secret store: <a href="https://security.arcus-azure.net/features/secret-store" />. |
290 |
| - /// </remarks> |
291 |
| - /// <param name="services">The collection of services to add the job to.</param> |
292 |
| - /// <param name="jobId">The unique background job ID to identify which message pump to restart.</param> |
293 |
| - /// <param name="subscriptionNamePrefix">The name of the Azure Service Bus subscription that will be created to receive <see cref="CloudEvent"/>'s.</param> |
294 |
| - /// <param name="serviceBusTopicConnectionStringSecretKey">The secret key that points to the Azure Service Bus Topic connection string.</param> |
295 |
| - /// <param name="messagePumpConnectionStringKey"> |
296 |
| - /// The secret key where the connection string credentials are located for the target message pump that needs to be auto-restarted. |
297 |
| - /// </param> |
298 |
| - /// <param name="configureBackgroundJob"> |
299 |
| - /// The capability to configure additional options on how the auto-restart Azure Service Bus message pump |
300 |
| - /// on rotated Azure Key Vault credentials background job should behave. |
301 |
| - /// </param> |
302 |
| - /// <exception cref="ArgumentNullException"> |
303 |
| - /// Thrown when the <paramref name="services"/> or the searched for <see cref="AzureServiceBusMessagePump"/> based on the given <paramref name="jobId"/> is <c>null</c>. |
304 |
| - /// </exception> |
305 |
| - /// <exception cref="ArgumentException"> |
306 |
| - /// Thrown when the <paramref name="subscriptionNamePrefix"/> or <paramref name="serviceBusTopicConnectionStringSecretKey"/> is blank. |
307 |
| - /// </exception> |
308 |
| -#pragma warning disable CS0436 // Type conflicts with imported type |
309 |
| - [Obsolete("Consider using the " + nameof(Microsoft.Extensions.DependencyInjection.ServiceBusMessageHandlerCollectionExtensions.WithAutoRestartOnRotatedCredentials) + " extension instead when configuring the message pump/router/handlers")] |
310 |
| -#pragma warning restore CS0436 // Type conflicts with imported type |
311 |
| - public static IServiceCollection AddAutoRestartServiceBusMessagePumpOnRotatedCredentialsBackgroundJob( |
312 |
| - this IServiceCollection services, |
313 |
| - string jobId, |
314 |
| - string subscriptionNamePrefix, |
315 |
| - string serviceBusTopicConnectionStringSecretKey, |
316 |
| - string messagePumpConnectionStringKey, |
317 |
| - Action<IAzureServiceBusTopicMessagePumpOptions> configureBackgroundJob) |
318 |
| - { |
319 |
| - Guard.NotNull(services, nameof(services), "Requires a collection of services to add the re-authentication background job"); |
320 |
| - Guard.NotNullOrWhitespace(jobId, nameof(jobId), "Requires a non-blank job ID to identify the Azure Service Bus message pump which needs to restart"); |
321 |
| - Guard.NotNullOrWhitespace(subscriptionNamePrefix, nameof(subscriptionNamePrefix), "Requires a non-blank subscription name of the Azure Service Bus Topic subscription, to receive Azure Key Vault events"); |
322 |
| - Guard.NotNullOrWhitespace(serviceBusTopicConnectionStringSecretKey, nameof(serviceBusTopicConnectionStringSecretKey), "Requires a non-blank secret key that points to a Azure Service Bus Topic"); |
323 |
| - Guard.NotNullOrWhitespace(messagePumpConnectionStringKey, nameof(messagePumpConnectionStringKey), "Requires a non-blank secret key that points to the credentials that holds the connection string of the target message pump"); |
324 |
| - |
325 |
| - services.AddCloudEventBackgroundJob(subscriptionNamePrefix, serviceBusTopicConnectionStringSecretKey, configureBackgroundJob) |
326 |
| - .WithServiceBusMessageHandler<ReAuthenticateOnRotatedCredentialsMessageHandler, CloudEvent>( |
327 |
| - messageBodyFilter: cloudEvent => cloudEvent?.Type == SecretNewVersionCreatedEventType, |
328 |
| - implementationFactory: serviceProvider => |
329 |
| - { |
330 |
| - AzureServiceBusMessagePump messagePump = |
331 |
| - serviceProvider.GetServices<IHostedService>() |
332 |
| - .OfType<AzureServiceBusMessagePump>() |
333 |
| - .FirstOrDefault(pump => pump.JobId == jobId); |
334 |
| - |
335 |
| - if (messagePump is null) |
336 |
| - { |
337 |
| - throw new InvalidOperationException( |
338 |
| - $"Cannot register re-authentication without a '{nameof(AzureServiceBusMessagePump)}' with job id {jobId}"); |
339 |
| - } |
340 |
| - |
341 |
| - var messageHandlerLogger = serviceProvider.GetRequiredService<ILogger<ReAuthenticateOnRotatedCredentialsMessageHandler>>(); |
342 |
| - return new ReAuthenticateOnRotatedCredentialsMessageHandler(messagePumpConnectionStringKey, messagePump, messageHandlerLogger); |
343 |
| - }); |
344 |
| - |
345 |
| - return services; |
346 |
| - } |
347 | 232 | }
|
348 | 233 | }
|
0 commit comments