mirror of
https://github.com/bitwarden/server
synced 2025-12-23 11:43:23 +00:00
Migrate deprecated Microsoft.Azure.EventGrid to Azure.Messaging.EventGrid (#1731)
* Migrate from deprecated Microsoft.Azure.EventGrid to Azure.Messaging.EventGrid * Fixed retrieval/parsing of EventGridEvents * Fixed an issue where the events where not handled by the registered event handlers
This commit is contained in:
committed by
GitHub
parent
cc490a76de
commit
ad18adf471
@@ -1,8 +1,8 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Azure.EventGrid;
|
||||
using Microsoft.Azure.EventGrid.Models;
|
||||
using Azure.Messaging.EventGrid;
|
||||
using Azure.Messaging.EventGrid.SystemEvents;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -55,29 +55,25 @@ namespace Bit.Api.Utilities
|
||||
}
|
||||
|
||||
var response = string.Empty;
|
||||
var requestContent = await new StreamReader(request.Body).ReadToEndAsync();
|
||||
if (string.IsNullOrWhiteSpace(requestContent))
|
||||
{
|
||||
return new OkObjectResult(response);
|
||||
}
|
||||
|
||||
var eventGridSubscriber = new EventGridSubscriber();
|
||||
var eventGridEvents = eventGridSubscriber.DeserializeEventGridEvents(requestContent);
|
||||
|
||||
var requestData = await BinaryData.FromStreamAsync(request.Body);
|
||||
var eventGridEvents = EventGridEvent.ParseMany(requestData);
|
||||
foreach (var eventGridEvent in eventGridEvents)
|
||||
{
|
||||
if (eventGridEvent.Data is SubscriptionValidationEventData eventData)
|
||||
if (eventGridEvent.TryGetSystemEventData(out object systemEvent))
|
||||
{
|
||||
// Might want to enable additional validation: subject, topic etc.
|
||||
|
||||
var responseData = new SubscriptionValidationResponse()
|
||||
if (systemEvent is SubscriptionValidationEventData eventData)
|
||||
{
|
||||
ValidationResponse = eventData.ValidationCode
|
||||
};
|
||||
// Might want to enable additional validation: subject, topic etc.
|
||||
var responseData = new SubscriptionValidationResponse()
|
||||
{
|
||||
ValidationResponse = eventData.ValidationCode
|
||||
};
|
||||
|
||||
return new OkObjectResult(responseData);
|
||||
return new OkObjectResult(responseData);
|
||||
}
|
||||
}
|
||||
else if (eventTypeHandlers.ContainsKey(eventGridEvent.EventType))
|
||||
|
||||
if (eventTypeHandlers.ContainsKey(eventGridEvent.EventType))
|
||||
{
|
||||
await eventTypeHandlers[eventGridEvent.EventType](eventGridEvent);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user