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; } } } }));
public AzureAttachmentStorageServiceTests() { _globalSettings = new GlobalSettings(); _logger = Substitute.For <ILogger <AzureAttachmentStorageService> >(); _sut = new AzureAttachmentStorageService(_globalSettings, _logger); }
public AzureAttachmentStorageServiceTests() { _globalSettings = new GlobalSettings(); _sut = new AzureAttachmentStorageService(_globalSettings); }