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.
* add local assets * Add Event Hub Sender * Adds more telemetry * Adds more telemetry * Remove encryption * Remove secret value saving * Add event hub storage * Add stroage to event hub on idops server * Add IdenttiyServer.Messaging.Azure * Add IdenttiyServer.Messaging.Azure * fixed build * Make cookies lax * Remove data conenction cache * Fixed login * Fixed login * Add login endpoint * Add fonts and redirect url --------- Co-authored-by: glucaci <[email protected]>
- Loading branch information
1 parent
1436740
commit ce232ed
Showing
40 changed files
with
454 additions
and
310 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
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,67 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Channels; | ||
using System.Threading.Tasks; | ||
using IdOps.IdentityServer.Abstractions; | ||
using IdOps.Messages; | ||
using MassTransit; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace IdOps.IdentityServer.Azure; | ||
|
||
public sealed class EventHubSender : BackgroundService, IEventSenderWorker | ||
{ | ||
private readonly IServiceProvider _serviceProvider; | ||
private readonly ChannelReader<IdentityEventMessage> _channelReader; | ||
|
||
public EventHubSender( | ||
IServiceProvider serviceProvider, | ||
ChannelReader<IdentityEventMessage> channelReader) | ||
{ | ||
_serviceProvider = serviceProvider; | ||
_channelReader = channelReader; | ||
} | ||
|
||
protected override async Task ExecuteAsync(CancellationToken stoppingToken) | ||
{ | ||
await Task.Yield(); | ||
await using AsyncServiceScope scope = _serviceProvider.CreateAsyncScope(); | ||
IEventHubProducerProvider provider = | ||
scope.ServiceProvider.GetRequiredService<IEventHubProducerProvider>(); | ||
|
||
IEventHubProducer producer = await provider.GetProducer("identity-events"); | ||
|
||
// we reuse the buffer to avoid allocations | ||
var buffer = new IdentityEventMessage[50]; | ||
try | ||
{ | ||
while (await _channelReader.WaitToReadAsync(stoppingToken)) | ||
{ | ||
// we read as many messages as we can | ||
for (var i = 0; i < buffer.Length; i++) | ||
{ | ||
if (!_channelReader.TryRead(out IdentityEventMessage? entity)) | ||
{ | ||
break; | ||
} | ||
|
||
buffer[i] = entity; | ||
} | ||
|
||
// create a batch of messages to send | ||
var batch = new IdentityEventMessage[buffer.Length]; | ||
Array.Copy(buffer, batch, buffer.Length); | ||
buffer.AsSpan().Clear(); | ||
|
||
IdOpsMeters.RecordSenderBatchSize(batch.Length); | ||
|
||
await producer.Produce<IdentityEventMessage>(batch, stoppingToken); | ||
} | ||
} | ||
catch | ||
{ | ||
// ignored | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
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,101 @@ | ||
using System; | ||
using Azure.Identity; | ||
using IdOps.IdentityServer.Abstractions; | ||
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."); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
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; | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
src/IdentityServer/Messaging.Azure/Options/EventHubOptions.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,8 @@ | ||
namespace IdOps.IdentityServer.Azure; | ||
|
||
public class EventHubOptions | ||
{ | ||
public string? ConnectionString { get; set; } | ||
|
||
public string? Namespace { get; set; } | ||
} |
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.
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
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,7 @@ | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace IdOps.IdentityServer.Abstractions; | ||
|
||
public interface IEventSenderWorker : IHostedService | ||
{ | ||
} |
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
16 changes: 0 additions & 16 deletions
16
src/IdentityServer/src/Abstractions/Stores/IUserDataConnectorDataRepository.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.