Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.

Commit f99905e

Browse files
committed
chore: remove deprecated functionality
1 parent 55e5b8a commit f99905e

File tree

5 files changed

+37
-363
lines changed

5 files changed

+37
-363
lines changed

src/Arcus.BackgroundJobs.CloudEvents/CloudEventBackgroundJob.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/Arcus.BackgroundJobs.CloudEvents/CloudEventBackgroundJobOptions.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Arcus.BackgroundJobs.KeyVault/Extensions/IServiceCollectionExtensions.cs

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
using System;
2-
using System.Linq;
32
using Arcus.BackgroundJobs.KeyVault;
4-
using Arcus.BackgroundJobs.KeyVault.Events;
53
using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling;
6-
using Arcus.Messaging.Pumps.ServiceBus;
74
using Arcus.Messaging.Pumps.ServiceBus.Configuration;
85
using Arcus.Security.Core.Caching;
9-
using Azure.Messaging;
106
using GuardNet;
117
using Microsoft.Extensions.Hosting;
128
using Microsoft.Extensions.Logging;
@@ -233,116 +229,5 @@ private static void WithInvalidateKeyVaultSecretHandler(this ServiceBusMessageHa
233229
return new InvalidateKeyVaultSecretHandler(cachedSecretProvider, logger);
234230
});
235231
}
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-
}
347232
}
348233
}

src/Arcus.BackgroundJobs.KeyVault/Extensions/ServiceBusMessageHandlerCollectionExtensions.cs

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
using System;
2+
using System.Linq;
3+
using Arcus.BackgroundJobs.KeyVault;
24
using Arcus.Messaging.Abstractions.ServiceBus.MessageHandling;
35
using Arcus.Messaging.Pumps.ServiceBus;
46
using Arcus.Messaging.Pumps.ServiceBus.Configuration;
5-
using Azure.Messaging;
67
using GuardNet;
8+
using Microsoft.Extensions.Hosting;
9+
using Microsoft.Extensions.Logging;
10+
#if NET6_0
11+
using CloudEvent = Azure.Messaging.CloudEvent;
12+
#else
13+
using CloudEvent = CloudNative.CloudEvents.CloudEvent;
14+
#endif
715

816
// ReSharper disable once CheckNamespace
917
namespace Microsoft.Extensions.DependencyInjection
@@ -13,6 +21,8 @@ namespace Microsoft.Extensions.DependencyInjection
1321
/// </summary>
1422
public static class ServiceBusMessageHandlerCollectionExtensions
1523
{
24+
private const string SecretNewVersionCreatedEventType = "Microsoft.KeyVault.SecretNewVersionCreated";
25+
1626
/// <summary>
1727
/// Adds a background job to the <see cref="IServiceCollection"/> to automatically restart a <see cref="AzureServiceBusMessagePump"/> with a specific <paramref name="jobId"/>
1828
/// when the Azure Key Vault secret that holds the Azure Service Bus connection string was updated.
@@ -84,16 +94,32 @@ public static ServiceBusMessageHandlerCollection WithAutoRestartOnRotatedCredent
8494
Guard.NotNullOrWhitespace(serviceBusTopicConnectionStringSecretKey, nameof(serviceBusTopicConnectionStringSecretKey), "Requires a non-blank secret key that points to a Azure Service Bus Topic");
8595
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");
8696

87-
#pragma warning disable CS0618 // Deprecated version still has the actual implementation, it can be moved to here once the next major version deletes the deprecated version.
88-
services.Services.AddAutoRestartServiceBusMessagePumpOnRotatedCredentialsBackgroundJob(
89-
#pragma warning restore CS0618
90-
jobId,
91-
subscriptionNamePrefix,
92-
serviceBusTopicConnectionStringSecretKey,
93-
messagePumpConnectionStringKey,
94-
configureBackgroundJob);
97+
return services.Services.AddCloudEventBackgroundJob(
98+
subscriptionNamePrefix,
99+
serviceBusTopicConnectionStringSecretKey,
100+
configureBackgroundJob)
101+
.WithServiceBusMessageHandler<ReAuthenticateOnRotatedCredentialsMessageHandler, CloudEvent>(
102+
messageBodyFilter: cloudEvent => cloudEvent?.Type == SecretNewVersionCreatedEventType,
103+
implementationFactory: serviceProvider =>
104+
{
105+
AzureServiceBusMessagePump messagePump =
106+
serviceProvider.GetServices<IHostedService>()
107+
.OfType<AzureServiceBusMessagePump>()
108+
.FirstOrDefault(pump => pump.JobId == jobId);
109+
110+
if (messagePump is null)
111+
{
112+
throw new InvalidOperationException(
113+
$"Cannot register re-authentication without a '{nameof(AzureServiceBusMessagePump)}' with job id {jobId}");
114+
}
115+
116+
var messageHandlerLogger = serviceProvider.GetRequiredService<ILogger<ReAuthenticateOnRotatedCredentialsMessageHandler>>();
117+
return new ReAuthenticateOnRotatedCredentialsMessageHandler(
118+
messagePumpConnectionStringKey,
119+
messagePump,
120+
messageHandlerLogger);
95121

96-
return services;
122+
});
123+
}
97124
}
98-
}
99125
}

0 commit comments

Comments
 (0)