public async Task <HttpStatusCode> ProcessMessageAsync(WebhookCacheOperation webhookCacheOperation, Guid eventId, Guid contentId, string apiEndpoint) { if (_sharedContentId != contentId) { logger.LogInformation($"Event Id: {eventId}, is not a shared content item we are subscribed to, so no content has been processed"); return(HttpStatusCode.OK); } switch (webhookCacheOperation) { case WebhookCacheOperation.Delete: return(await webhookContentProcessor.DeleteContentAsync(contentId).ConfigureAwait(false)); case WebhookCacheOperation.CreateOrUpdate: if (!Uri.TryCreate(apiEndpoint, UriKind.Absolute, out Uri? url)) { throw new InvalidDataException($"Invalid Api url '{apiEndpoint}' received for Event Id: {eventId}"); } return(await webhookContentProcessor.ProcessContentAsync(url, contentId).ConfigureAwait(false)); default: logger.LogError($"Event Id: {eventId} got unknown cache operation - {webhookCacheOperation}"); return(HttpStatusCode.BadRequest); } }
public async Task <HttpStatusCode> ProcessMessageAsync(WebhookCacheOperation webhookCacheOperation, Guid eventId, Guid contentId, Uri url) { logger.LogInformation($"{nameof(ProcessMessageAsync)} called in {nameof(PagesWebhookService)}"); switch (webhookCacheOperation) { case WebhookCacheOperation.CreateOrUpdate: logger.LogInformation($"{nameof(WebhookCacheOperation.CreateOrUpdate)} called in {nameof(PagesWebhookService)} with Content Id {contentId}"); return(await pagesDataLoadService.CreateOrUpdateAsync(contentId).ConfigureAwait(false)); case WebhookCacheOperation.Delete: logger.LogInformation($"{nameof(WebhookCacheOperation.Delete)} called in {nameof(PagesWebhookService)} with Content Id {contentId}"); return(await pagesDataLoadService.RemoveAsync(contentId).ConfigureAwait(false)); default: return(HttpStatusCode.OK); } }
public async Task <HttpStatusCode> ProcessMessageAsync(WebhookCacheOperation webhookCacheOperation, Guid eventId, Guid contentId, string apiEndpoint) { switch (webhookCacheOperation) { case WebhookCacheOperation.Delete: return(await DeleteContentItemAsync(contentId).ConfigureAwait(false)); case WebhookCacheOperation.CreateOrUpdate: if (!Uri.TryCreate(apiEndpoint, UriKind.Absolute, out Uri? url)) { throw new InvalidDataException($"Invalid Api url '{apiEndpoint}' received for Event Id: {eventId}"); } return(await ProcessContentItemAsync(url).ConfigureAwait(false)); default: logger.LogError($"Event Id: {eventId} got unknown cache operation - {webhookCacheOperation}"); return(HttpStatusCode.BadRequest); } }
public async Task <HttpStatusCode> ProcessMessageAsync(bool isDraft, WebhookCacheOperation webhookCacheOperation, Guid eventId, Guid contentId, string?apiEndpoint) { var messageContentType = DetermineMessageContentType(apiEndpoint); if (messageContentType == MessageContentType.None) { logger.LogError($"Event Id: {eventId} got unknown message content type - {messageContentType} - {apiEndpoint}"); return(HttpStatusCode.BadRequest); } switch (webhookCacheOperation) { case WebhookCacheOperation.Delete: return(await webhooksDeleteService.ProcessDeleteAsync(eventId, contentId, messageContentType).ConfigureAwait(false)); case WebhookCacheOperation.CreateOrUpdate: return(await webhooksContentService.ProcessContentAsync(isDraft, eventId, contentId, apiEndpoint, messageContentType).ConfigureAwait(false)); } logger.LogError($"Event Id: {eventId} got unknown cache operation - {webhookCacheOperation}"); return(HttpStatusCode.BadRequest); }
public async Task SendEventAsync(WebhookCacheOperation webhookCacheOperation, ContentPageModel?updatedContentPageModel) { _ = updatedContentPageModel ?? throw new ArgumentNullException(nameof(updatedContentPageModel)); if (!IsValidEventGridPublishClientOptions(logger, eventGridPublishClientOptions)) { logger.LogWarning("Unable to send to event grid due to invalid EventGridPublishClientOptions options"); return; } var logMessage = $"{webhookCacheOperation} - {updatedContentPageModel.Id} - {updatedContentPageModel.CanonicalName}"; logger.LogInformation($"Sending Event Grid message for: {logMessage}"); var eventGridEvents = new List <EventGridEvent> { new EventGridEvent { Id = Guid.NewGuid().ToString(), Subject = $"{eventGridPublishClientOptions.SubjectPrefix}{updatedContentPageModel.Id}", Data = new EventGridEventData { ItemId = updatedContentPageModel.Id.ToString(), Api = $"{eventGridPublishClientOptions.ApiEndpoint}/{updatedContentPageModel.Id}", DisplayText = updatedContentPageModel.CanonicalName, VersionId = updatedContentPageModel.Version.ToString(), Author = eventGridPublishClientOptions.SubjectPrefix, }, EventType = webhookCacheOperation == WebhookCacheOperation.Delete ? "deleted" : "published", EventTime = DateTime.Now, DataVersion = "1.0", }, }; eventGridEvents.ForEach(f => f.Validate()); await eventGridClientService.SendEventAsync(eventGridEvents, eventGridPublishClientOptions.TopicEndpoint, eventGridPublishClientOptions.TopicKey, logMessage).ConfigureAwait(false); }
public void LmiWebhookReceiverServiceDetermineWebhookCommandReturnsExpected(MessageContentType messageContentType, WebhookCacheOperation webhookCacheOperation, WebhookCommand expectedResult) { // Arrange // Act var result = LmiWebhookReceiverService.DetermineWebhookCommand(messageContentType, webhookCacheOperation); // Assert Assert.Equal(expectedResult, result); }
public Task <HttpStatusCode> ProcessMessageAsync(WebhookCacheOperation webhookCacheOperation, Guid eventId, Guid contentId, string apiEndpoint) { return(Task.FromResult(HttpStatusCode.OK)); }
public static WebhookCommand DetermineWebhookCommand(MessageContentType messageContentType, WebhookCacheOperation webhookCacheOperation) { switch (webhookCacheOperation) { case WebhookCacheOperation.CreateOrUpdate: switch (messageContentType) { case MessageContentType.Publish: return(WebhookCommand.PublishFromDraft); } break; case WebhookCacheOperation.Delete: switch (messageContentType) { case MessageContentType.Publish: return(WebhookCommand.PurgeFromPublished); } break; } return(WebhookCommand.None); }
public static WebhookCommand DetermineWebhookCommand(MessageContentType messageContentType, WebhookCacheOperation webhookCacheOperation) { switch (webhookCacheOperation) { case WebhookCacheOperation.CreateOrUpdate: switch (messageContentType) { case MessageContentType.JobGroup: return(WebhookCommand.ReportDeltaForAll); case MessageContentType.JobGroupItem: return(WebhookCommand.ReportDeltaForSoc); } break; } return(WebhookCommand.None); }
public static WebhookCommand DetermineWebhookCommand(MessageContentType messageContentType, WebhookCacheOperation webhookCacheOperation) { switch (webhookCacheOperation) { case WebhookCacheOperation.CreateOrUpdate: switch (messageContentType) { case MessageContentType.LmiSocSummary: return(WebhookCommand.TransformAllSocToJobGroup); case MessageContentType.LmiSocItem: return(WebhookCommand.TransformSocToJobGroup); } break; case WebhookCacheOperation.Delete: switch (messageContentType) { case MessageContentType.LmiSocSummary: return(WebhookCommand.PurgeAllJobGroups); case MessageContentType.LmiSocItem: return(WebhookCommand.PurgeJobGroup); } break; } return(WebhookCommand.None); }