generated from SwissLife-OSS/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2dcf002
commit 9c12f84
Showing
14 changed files
with
144 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/IdentityServer/Messaging.Azure/Extensions/AzureServiceBusIdOpsBuilderExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
using System; | ||
using Azure.Identity; | ||
using IdOps.IdentityServer.Abstractions; | ||
using IdOps.IdentityServer.Azure; | ||
using MassTransit; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using static IdOps.IdentityServer.Wellknown.ConfigSections; | ||
|
||
namespace IdOps.IdentityServer.Azure | ||
{ | ||
public static class AzureServiceBusIdOpsBuilderExtensions | ||
{ | ||
public static IIdOpsIdentityServerBuilder UseAzure(this BusBuilder builder) | ||
{ | ||
AzureOptions? options = builder | ||
.IdOpsBuilder.Configuration?.GetSection($"{Messaging}:Azure") | ||
.Get<AzureOptions>(); | ||
|
||
if (options == null) | ||
{ | ||
throw new ApplicationException( | ||
"Could not get AzureOptions configuration from " | ||
+ $"{Messaging}:Azure." | ||
+ "Please check you configuration"); | ||
} | ||
|
||
return builder.UseAzure(options); | ||
} | ||
|
||
private static IIdOpsIdentityServerBuilder UseAzure( | ||
this BusBuilder builder, | ||
AzureOptions options) | ||
{ | ||
if (options.EventHub is not null) | ||
{ | ||
builder.IdOpsBuilder.Services.AddSingleton<IEventSenderWorker, EventHubSender>(); | ||
} | ||
|
||
builder.IdOpsBuilder.Services.AddMassTransit(s => | ||
{ | ||
builder.BusSetup?.Invoke(s); | ||
|
||
if (options.ServiceBus is { }) | ||
{ | ||
s.RegisterServiceBus(options.ServiceBus, builder); | ||
} | ||
|
||
if (options.EventHub is { } eventHub) | ||
{ | ||
s.RegisterEventHub(eventHub); | ||
} | ||
}); | ||
|
||
return builder.IdOpsBuilder; | ||
} | ||
|
||
private static void RegisterEventHub( | ||
this IBusRegistrationConfigurator configurator, | ||
EventHubOptions eventHub) | ||
{ | ||
configurator.AddRider(x => | ||
x.UsingEventHub((_, k) => | ||
{ | ||
if (eventHub.Namespace is { } @namespace) | ||
{ | ||
k.Host(@namespace, new DefaultAzureCredential()); | ||
} | ||
else if (eventHub.ConnectionString is not null) | ||
{ | ||
k.Host(eventHub.ConnectionString); | ||
} | ||
else | ||
{ | ||
throw new ApplicationException( | ||
"EventHub configuration is missing. Please check your settings."); | ||
} | ||
|
||
if (eventHub.Storage is { } storageOption) | ||
{ | ||
if (storageOption.Url is { } url) | ||
{ | ||
k.Storage(new Uri(url), new DefaultAzureCredential()); | ||
} | ||
else if (storageOption.ConnectionString is { } connectionString) | ||
{ | ||
k.Storage(connectionString); | ||
} | ||
else | ||
{ | ||
throw new ApplicationException( | ||
"EventHub storage configuration is missing. Please check your settings."); | ||
} | ||
} | ||
}) | ||
); | ||
} | ||
|
||
private static void RegisterServiceBus( | ||
this IBusRegistrationConfigurator configurator, | ||
AzureServiceBusOptions options, | ||
BusBuilder builder) | ||
{ | ||
configurator.UsingAzureServiceBus((provider, cfg) => | ||
{ | ||
var serverGroup = builder.IdOpsBuilder.Options!.ServerGroup.ToLower(); | ||
var environmentName = builder.IdOpsBuilder.Options!.EnvironmentName.ToLower(); | ||
cfg.Host(options.ConnectionString); | ||
cfg.ReceiveEndpoint( | ||
$"id-{serverGroup}-{environmentName}", | ||
e => | ||
{ | ||
e.ConfigureConsumers(provider); | ||
e.PrefetchCount = options.PrefetchCount; | ||
}); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace IdOps.IdentityServer.Azure; | ||
|
||
public sealed class AzureOptions | ||
{ | ||
public AzureServiceBusOptions? ServiceBus { get; set; } = default!; | ||
public EventHubOptions? EventHub { get; set; } = default!; | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
src/IdentityServer/Messaging.Azure/Options/AzureServiceBusOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace IdOps.IdentityServer.Azure; | ||
|
||
public class AzureServiceBusOptions | ||
{ | ||
public string ConnectionString { get; set; } = default!; | ||
|
||
public int PrefetchCount { get; set; } = 10; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...g.AzureEventHub/EventStorageHubOptions.cs → ...g.Azure/Options/EventStorageHubOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 0 additions & 85 deletions
85
src/IdentityServer/Messaging.AzureEventHub/EventHubIdOpsBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
src/IdentityServer/Messaging.AzureEventHub/Messaging.AzureEventHub.csproj
This file was deleted.
Oops, something went wrong.
62 changes: 0 additions & 62 deletions
62
src/IdentityServer/Messaging.AzureServiceBus/AzureServiceBusIdOpsBuilderExtensions.cs
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
src/IdentityServer/Messaging.AzureServiceBus/AzureServiceBusOptions.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.