public async Task <ObjectResult> AzureValidateFile() { return(await ApiHelpers.HandleAzureEvents(Request, new Dictionary <string, Func <EventGridEvent, Task> > { { "Microsoft.Storage.BlobCreated", async(eventGridEvent) => { try { var blobName = eventGridEvent.Subject.Split($"{AzureSendFileStorageService.FilesContainerName}/blobs/")[1]; var sendId = AzureSendFileStorageService.SendIdFromBlobName(blobName); var send = await _sendRepository.GetByIdAsync(new Guid(sendId)); if (send == null) { if (_sendFileStorageService is AzureSendFileStorageService azureSendFileStorageService) { await azureSendFileStorageService.DeleteBlobAsync(blobName); } return; } await _sendService.ValidateSendFile(send); } catch (Exception e) { _logger.LogError(e, $"Uncaught exception occurred while handling event grid event: {JsonConvert.SerializeObject(eventGridEvent)}"); return; } } } }));
public async Task <ObjectResult> AzureValidateFile() { return(await ApiHelpers.HandleAzureEvents(Request, new Dictionary <string, Func <EventGridEvent, Task> > { { "Microsoft.Storage.BlobCreated", async(eventGridEvent) => { try { var blobName = eventGridEvent.Subject.Split($"{AzureAttachmentStorageService.EventGridEnabledContainerName}/blobs/")[1]; var(cipherId, organizationId, attachmentId) = AzureAttachmentStorageService.IdentifiersFromBlobName(blobName); var cipher = await _cipherRepository.GetByIdAsync(new Guid(cipherId)); var attachments = cipher?.GetAttachments() ?? new Dictionary <string, CipherAttachment.MetaData>(); if (cipher == null || !attachments.ContainsKey(attachmentId) || attachments[attachmentId].Validated) { if (_attachmentStorageService is AzureSendFileStorageService azureFileStorageService) { await azureFileStorageService.DeleteBlobAsync(blobName); } return; } await _cipherService.ValidateCipherAttachmentFile(cipher, attachments[attachmentId]); } catch (Exception e) { _logger.LogError(e, $"Uncaught exception occurred while handling event grid event: {JsonSerializer.Serialize(eventGridEvent)}"); return; } } } }));