public async Task <IEnumerable <WebHookFilter> > Get() { IWebHookFilterManager filterManager = HttpContext.RequestServices.GetFilterManager(); IDictionary <string, WebHookFilter> filters = await filterManager.GetAllWebHookFiltersAsync(); return(filters.Values); }
public async Task <IEnumerable <WebHookFilter> > Get() { IWebHookFilterManager filterManager = Configuration.DependencyResolver.GetFilterManager(); IDictionary <string, WebHookFilter> filters = await filterManager.GetAllWebHookFiltersAsync(); return(filters.Values); }
/// <summary> /// Ensure that the provided <paramref name="webHook"/> only has registered filters. /// </summary> protected virtual async Task VerifyFilters(WebHook webHook) { if (webHook == null) { throw new ArgumentNullException(nameof(webHook)); } // If there are no filters then add our wildcard filter. if (webHook.Filters.Count == 0) { webHook.Filters.Add(WildcardWebHookFilterProvider.Name); await InvokeRegistrars(webHook); return; } IWebHookFilterManager filterManager = Configuration.DependencyResolver.GetFilterManager(); IDictionary <string, WebHookFilter> filters = await filterManager.GetAllWebHookFiltersAsync(); HashSet <string> normalizedFilters = new HashSet <string>(); List <string> invalidFilters = new List <string>(); foreach (string filter in webHook.Filters) { WebHookFilter hookFilter; if (filters.TryGetValue(filter, out hookFilter)) { normalizedFilters.Add(hookFilter.Name); } else { invalidFilters.Add(filter); } } if (invalidFilters.Count > 0) { string invalidFiltersMsg = string.Join(", ", invalidFilters); string link = Url.Link(WebHookRouteNames.FiltersGetAction, routeValues: null); string msg = string.Format(CultureInfo.CurrentCulture, CustomApiResources.RegistrationController_InvalidFilters, invalidFiltersMsg, link); Configuration.DependencyResolver.GetLogger().Info(msg); HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, msg); throw new HttpResponseException(response); } else { webHook.Filters.Clear(); foreach (string filter in normalizedFilters) { webHook.Filters.Add(filter); } } await InvokeRegistrars(webHook); }
public async Task GetAllWebHookFilters_GetsAllFilters(int providerCount, int expectedFilterCount) { // Arrange IWebHookFilterManager manager = CreateWebHookFilterManager(providerCount); // Act IDictionary <string, WebHookFilter> actual = await manager.GetAllWebHookFiltersAsync(); // Assert Assert.Equal(expectedFilterCount, actual.Count); }
/// <summary> /// Ensure that the provided <paramref name="webHook"/> only has registered filters. /// </summary> protected virtual async Task VerifyFilters(WebHook webHook) { if (webHook == null) { throw new ArgumentNullException(nameof(webHook)); } // If there are no filters then add our wildcard filter. if (webHook.Filters.Count == 0) { webHook.Filters.Add(WildcardWebHookFilterProvider.Name); return; } IDictionary <string, WebHookFilter> filters = await _filterManager.GetAllWebHookFiltersAsync(); HashSet <string> normalizedFilters = new HashSet <string>(); List <string> invalidFilters = new List <string>(); foreach (string filter in webHook.Filters) { WebHookFilter hookFilter; if (filters.TryGetValue(filter, out hookFilter)) { normalizedFilters.Add(hookFilter.Name); } else { invalidFilters.Add(filter); } } if (invalidFilters.Count > 0) { string invalidFiltersMsg = string.Join(", ", invalidFilters); string link = Url.Link(WebHookNames.FiltersGetAction, null); string msg = string.Format(CultureInfo.CurrentCulture, LocalizationService.GetResource("Api.WebHooks.InvalidFilters"), invalidFiltersMsg, link); //Configuration.DependencyResolver.GetLogger().Info(msg); throw new VerificationException(msg); } else { webHook.Filters.Clear(); foreach (string filter in normalizedFilters) { webHook.Filters.Add(filter); } } }
/// <summary> /// Verifies that the <see cref="WebHook.Filters"/> for the given <paramref name="webHook"/> /// only contain registered filters provided by the <see cref="IWebHookFilterManager"/>. /// </summary> /// <param name="webHook">The <see cref="WebHook"/> to verify.</param> public virtual async Task VerifyFiltersAsync(WebHook webHook) { if (webHook == null) { throw new ArgumentNullException(nameof(webHook)); } // If there are no filters then add our wildcard filter. if (webHook.Filters.Count == 0) { webHook.Filters.Add(WildcardWebHookFilterProvider.Name); return; } IDictionary <string, WebHookFilter> filters = await _filterManager.GetAllWebHookFiltersAsync(); HashSet <string> normalizedFilters = new HashSet <string>(); List <string> invalidFilters = new List <string>(); foreach (string filter in webHook.Filters) { WebHookFilter hookFilter; if (filters.TryGetValue(filter, out hookFilter)) { normalizedFilters.Add(hookFilter.Name); } else { invalidFilters.Add(filter); } } if (invalidFilters.Count > 0) { string invalidFiltersMsg = string.Join(", ", invalidFilters); string msg = string.Format(CultureInfo.CurrentCulture, CustomResources.RegistrationsManager_InvalidFilters, invalidFiltersMsg); throw new InvalidOperationException(msg); } else { webHook.Filters.Clear(); foreach (string filter in normalizedFilters) { webHook.Filters.Add(filter); } } }
/// <summary> /// Verifies that the <see cref="WebHook.Filters"/> for the given <paramref name="webHook"/> /// only contain registered filters provided by the <see cref="IWebHookFilterManager"/>. /// </summary> /// <param name="webHook">The <see cref="WebHook"/> to verify.</param> public virtual async Task VerifyFiltersAsync(WebHook webHook) { if (webHook == null) { throw new ArgumentNullException(nameof(webHook)); } // If there are no filters then add our wildcard filter. if (webHook.Filters.Count == 0) { webHook.Filters.Add(WildcardWebHookFilterProvider.Name); return; } var filters = await _filterManager.GetAllWebHookFiltersAsync(); var normalizedFilters = new HashSet <string>(); var invalidFilters = new List <string>(); foreach (var filter in webHook.Filters) { if (filters.TryGetValue(filter, out var hookFilter)) { normalizedFilters.Add(hookFilter.Name); } else { invalidFilters.Add(filter); } } if (invalidFilters.Count > 0) { var invalidFiltersMessage = string.Join(", ", invalidFilters); var message = string.Format($"The following filters are not valid: '{invalidFiltersMessage}'."); throw new InvalidOperationException(message); } else { webHook.Filters.Clear(); foreach (var filter in normalizedFilters) { webHook.Filters.Add(filter); } } }
/// <summary> /// Ensure that the provided <paramref name="webHook"/> only has registered filters. /// </summary> protected virtual async Task VerifyFilters(WebHook webHook) { if (webHook == null) { throw new ArgumentNullException(nameof(webHook)); } if (webHook.Filters.Count == 0) { webHook.Filters.Add(WildcardWebHookFilterProvider.Name); return; } var filters = await _filterManager.GetAllWebHookFiltersAsync(); var normalizedFilters = new HashSet <string>(); var invalidFilters = new List <string>(); foreach (var filter in webHook.Filters) { if (filters.TryGetValue(filter, out var hookFilter)) { normalizedFilters.Add(hookFilter.Name); } else { invalidFilters.Add(filter); } } if (invalidFilters.Count > 0) { var invalidFiltersMsg = string.Join(", ", invalidFilters); var link = Url.Link(WebHookNames.FiltersGetAction, null); throw new VerificationException( $"The following filters are not valid: '{invalidFiltersMsg}'. A list of valid filters can be obtained from the path '{link}'."); } webHook.Filters.Clear(); foreach (var filter in normalizedFilters) { webHook.Filters.Add(filter); } }
public async Task <IEnumerable <WebHookFilter> > GetWebHookFilters() { IDictionary <string, WebHookFilter> filters = await _filterManager.GetAllWebHookFiltersAsync(); return(filters.Values); }
public async Task <IEnumerable <WebHookFilter> > Get() { var filters = await _filterManager.GetAllWebHookFiltersAsync(); return(filters.Values); }