-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ticket #797 : Store the scim message in blob storage
- Loading branch information
Showing
20 changed files
with
195 additions
and
17 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/Scim/SimpleIdServer.Scim.Startup/Configurations/MassTransitStorageConfiguration.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,19 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
using MassTransit; | ||
|
||
namespace SimpleIdServer.Scim.Startup.Configurations; | ||
|
||
public class MassTransitStorageConfiguration | ||
{ | ||
public bool IsEnabled { get; set; } | ||
public MassTransitStorageTypes Type { get; set; } | ||
public string ConnectionString { get; set; } | ||
} | ||
|
||
public enum MassTransitStorageTypes | ||
{ | ||
INMEMORY = 0, | ||
DIRECTORY = 1, | ||
AZURESTORAGE = 2 | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Scim/SimpleIdServer.Scim.Startup/Consumers/BigMessageConsumer.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,33 @@ | ||
using MassTransit; | ||
using Newtonsoft.Json; | ||
using SimpleIdServer.Scim.ExternalEvents; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SimpleIdServer.Scim.Startup.Consumers | ||
{ | ||
public class BigMessageConsumer : IConsumer<BigMessage> | ||
{ | ||
private static List<Type> _types = new List<Type> | ||
{ | ||
typeof(RepresentationAddedEvent), | ||
typeof(RepresentationRemovedEvent), | ||
typeof(RepresentationUpdatedEvent), | ||
typeof(RepresentationRefAttributeAddedEvent), | ||
typeof(RepresentationRefAttributeRemovedEvent), | ||
typeof(RepresentationRefAttributeUpdatedEvent) | ||
}; | ||
|
||
|
||
public async Task Consume(ConsumeContext<BigMessage> context) | ||
{ | ||
var bigPayload = await context.Message.Payload.Value; | ||
var type = _types.Single(t => t.Name == context.Message.Name); | ||
var message = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(bigPayload), type); | ||
// CONTINUE... | ||
} | ||
} | ||
} |
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
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
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
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,12 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
using MassTransit; | ||
|
||
namespace SimpleIdServer.Scim.ExternalEvents | ||
{ | ||
public class BigMessage | ||
{ | ||
public string Name { get; set; } | ||
public MessageData<byte[]> Payload { get; set; } | ||
} | ||
} |
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,59 @@ | ||
// Copyright (c) SimpleIdServer. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
using MassTransit; | ||
using MassTransit.MessageData; | ||
using Microsoft.Extensions.Options; | ||
using Newtonsoft.Json; | ||
using SimpleIdServer.Scim.ExternalEvents; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace SimpleIdServer.Scim.Helpers | ||
{ | ||
public interface IBusHelper | ||
{ | ||
Task Publish<T>(T evt, CancellationToken cancellationToken = default) where T : IntegrationEvent; | ||
} | ||
|
||
public class BusHelper : IBusHelper | ||
{ | ||
private readonly SCIMHostOptions _options; | ||
private readonly IBusControl _busControl; | ||
private readonly IMessageDataRepository _messageDataRepository; | ||
|
||
public BusHelper( | ||
IOptionsMonitor<SCIMHostOptions> options, | ||
IBusControl busControl, | ||
IMessageDataRepository messageDataRepository) | ||
{ | ||
_options = options.CurrentValue; | ||
_busControl = busControl; | ||
_messageDataRepository = messageDataRepository; | ||
} | ||
|
||
public async Task Publish<T>(T evt, CancellationToken cancellationToken = default) where T : IntegrationEvent | ||
{ | ||
if (!_options.IsBigMessagePublished) | ||
{ | ||
await _busControl.Publish(evt); | ||
return; | ||
} | ||
|
||
var bigPayload = await _messageDataRepository.PutBytes(Serialize(evt), cancellationToken); | ||
var message = new BigMessage | ||
{ | ||
Name = typeof(T).Name, | ||
Payload = bigPayload | ||
}; | ||
await _busControl.Publish(message, cancellationToken); | ||
} | ||
|
||
public static byte[] Serialize(object obj) | ||
{ | ||
var json = JsonConvert.SerializeObject(obj); | ||
return Encoding.UTF8.GetBytes(json); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.