mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 08:32:50 -05:00
Reference event service implementation (#811)
* Reference event service implementation * Fix IReferenceable implementation of Id * add structure to event body
This commit is contained in:
@ -0,0 +1,49 @@
|
||||
using System.Threading.Tasks;
|
||||
using Azure.Storage.Queues;
|
||||
using Bit.Core.Models.Business;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
public class AzureQueueReferenceEventService : IReferenceEventService
|
||||
{
|
||||
private const string _queueName = "reference-events";
|
||||
|
||||
private readonly QueueClient _queueClient;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
private readonly JsonSerializerSettings _jsonSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
};
|
||||
|
||||
public AzureQueueReferenceEventService (
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
_queueClient = new QueueClient(globalSettings.Storage.ConnectionString, _queueName);
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
public async Task RaiseEventAsync(ReferenceEvent referenceEvent)
|
||||
{
|
||||
await SendMessageAsync(referenceEvent);
|
||||
}
|
||||
|
||||
private async Task SendMessageAsync(ReferenceEvent referenceEvent)
|
||||
{
|
||||
if (_globalSettings.SelfHosted || string.IsNullOrWhiteSpace(referenceEvent.ReferenceId))
|
||||
{
|
||||
// Ignore for self-hosted, OR, where there is no ReferenceId
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var message = JsonConvert.SerializeObject(referenceEvent, _jsonSerializerSettings);
|
||||
await _queueClient.SendMessageAsync(message);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Ignore failure
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user