public FileGlobalConfigurationFluentValidator(QosDelegatingHandlerDelegate qosDelegatingHandlerDelegate) { _qosDelegatingHandlerDelegate = qosDelegatingHandlerDelegate; RuleFor(configuration => configuration.QoSOptions) .SetValidator(new FileQoSOptionsFluentValidator(_qosDelegatingHandlerDelegate)); }
public DelegatingHandlerHandlerProviderFactoryTests() { _qosDelegate = (a, b) => new FakeQoSHandler(); _tracingFactory = new Mock <ITracingHandlerFactory>(); _qosFactory = new Mock <IQoSFactory>(); _loggerFactory = new Mock <IOcelotLoggerFactory>(); _services = new ServiceCollection(); _services.AddSingleton(_qosDelegate); }
public FileQoSOptionsFluentValidator(QosDelegatingHandlerDelegate qosDelegatingHandlerDelegate) { _qosDelegatingHandlerDelegate = qosDelegatingHandlerDelegate; When(qosOptions => qosOptions.TimeoutValue > 0 && qosOptions.ExceptionsAllowedBeforeBreaking > 0, () => { RuleFor(qosOptions => qosOptions) .Must(HaveQosHandlerRegistered) .WithMessage("Unable to start Ocelot because either a ReRoute or GlobalConfiguration are using QoSOptions but no QosDelegatingHandlerDelegate has been registered in dependency injection container. Are you missing a package like Ocelot.Provider.Polly and services.AddPolly()?"); }); }
public DelegatingHandlerHandlerProviderFactoryTests() { _qosDelegate = (a, b) => new FakeQoSHandler(); _tracingFactory = new Mock <ITracingHandlerFactory>(); _qosFactory = new Mock <IQoSFactory>(); _loggerFactory = new Mock <IOcelotLoggerFactory>(); _logger = new Mock <IOcelotLogger>(); _loggerFactory.Setup(x => x.CreateLogger <DelegatingHandlerHandlerFactory>()).Returns(_logger.Object); _services = new ServiceCollection(); _services.AddSingleton(_qosDelegate); }
private void GivenAQosDelegate() { QosDelegatingHandlerDelegate fake = (a, b) => { return(null); }; _services.AddSingleton <QosDelegatingHandlerDelegate>(fake); var provider = _services.BuildServiceProvider(); _validator = new FileQoSOptionsFluentValidator(provider); }
public ReRouteFluentValidator(IAuthenticationSchemeProvider authenticationSchemeProvider, QosDelegatingHandlerDelegate qosDelegatingHandlerDelegate) { _authenticationSchemeProvider = authenticationSchemeProvider; _qosDelegatingHandlerDelegate = qosDelegatingHandlerDelegate; RuleFor(reRoute => reRoute.QoSOptions) .SetValidator(new FileQoSOptionsFluentValidator(_qosDelegatingHandlerDelegate)); RuleFor(reRoute => reRoute.DownstreamPathTemplate) .Must(path => path.StartsWith("/")) .WithMessage("{PropertyName} {PropertyValue} doesnt start with forward slash"); RuleFor(reRoute => reRoute.UpstreamPathTemplate) .Must(path => !path.Contains("//")) .WithMessage("{PropertyName} {PropertyValue} contains double forward slash, Ocelot does not support this at the moment. Please raise an issue in GitHib if you need this feature."); RuleFor(reRoute => reRoute.DownstreamPathTemplate) .Must(path => !path.Contains("//")) .WithMessage("{PropertyName} {PropertyValue} contains double forward slash, Ocelot does not support this at the moment. Please raise an issue in GitHib if you need this feature."); RuleFor(reRoute => reRoute.UpstreamPathTemplate) .Must(path => path.StartsWith("/")) .WithMessage("{PropertyName} {PropertyValue} doesnt start with forward slash"); RuleFor(reRoute => reRoute.DownstreamPathTemplate) .Must(path => !path.Contains("https://") && !path.Contains("http://")) .WithMessage("{PropertyName} {PropertyValue} contains scheme"); RuleFor(reRoute => reRoute.UpstreamPathTemplate) .Must(path => !path.Contains("https://") && !path.Contains("http://")) .WithMessage("{PropertyName} {PropertyValue} contains scheme"); RuleFor(reRoute => reRoute.RateLimitOptions) .Must(IsValidPeriod) .WithMessage("RateLimitOptions.Period does not contains (s,m,h,d)"); RuleFor(reRoute => reRoute.AuthenticationOptions) .MustAsync(IsSupportedAuthenticationProviders) .WithMessage("{PropertyValue} is unsupported authentication provider"); When(reRoute => string.IsNullOrEmpty(reRoute.ServiceName), () => { RuleFor(r => r.DownstreamHostAndPorts).NotEmpty() .WithMessage("When not using service discovery DownstreamHostAndPorts must be set and not empty or Ocelot cannot find your service!"); }); When(reRoute => string.IsNullOrEmpty(reRoute.ServiceName), () => { RuleFor(reRoute => reRoute.DownstreamHostAndPorts) .SetCollectionValidator(new HostAndPortValidator()); }); }
public FileConfigurationFluentValidator(IAuthenticationSchemeProvider authenticationSchemeProvider, IServiceProvider provider) { _qosDelegatingHandlerDelegate = provider.GetService <QosDelegatingHandlerDelegate>(); _serviceDiscoveryFinderDelegates = provider .GetServices <ServiceDiscoveryFinderDelegate>() .ToList(); RuleFor(configuration => configuration.ReRoutes) .SetCollectionValidator(new ReRouteFluentValidator(authenticationSchemeProvider, _qosDelegatingHandlerDelegate)); RuleFor(configuration => configuration.GlobalConfiguration) .SetValidator(new FileGlobalConfigurationFluentValidator(_qosDelegatingHandlerDelegate)); RuleForEach(configuration => configuration.ReRoutes) .Must((config, reRoute) => IsNotDuplicateIn(reRoute, config.ReRoutes)) .WithMessage((config, reRoute) => $"{nameof(reRoute)} {reRoute.UpstreamPathTemplate} has duplicate"); RuleForEach(configuration => configuration.ReRoutes) .Must((config, reRoute) => HaveServiceDiscoveryProviderRegitered(reRoute, config.GlobalConfiguration.ServiceDiscoveryProvider)) .WithMessage((config, reRoute) => $"Unable to start Ocelot, errors are: Unable to start Ocelot because either a ReRoute or GlobalConfiguration are using ServiceDiscoveryOptions but no ServiceDiscoveryFinderDelegate has been registered in dependency injection container. Are you missing a package like Ocelot.Provider.Consul and services.AddConsul() or Ocelot.Provider.Eureka and services.AddEureka()?"); RuleFor(configuration => configuration.GlobalConfiguration.ServiceDiscoveryProvider) .Must((config) => HaveServiceDiscoveryProviderRegitered(config)) .WithMessage((config, reRoute) => $"Unable to start Ocelot, errors are: Unable to start Ocelot because either a ReRoute or GlobalConfiguration are using ServiceDiscoveryOptions but no ServiceDiscoveryFinderDelegate has been registered in dependency injection container. Are you missing a package like Ocelot.Provider.Consul and services.AddConsul() or Ocelot.Provider.Eureka and services.AddEureka()?"); RuleForEach(configuration => configuration.ReRoutes) .Must((config, reRoute) => IsNotDuplicateIn(reRoute, config.Aggregates)) .WithMessage((config, reRoute) => $"{nameof(reRoute)} {reRoute.UpstreamPathTemplate} has duplicate aggregate"); RuleForEach(configuration => configuration.Aggregates) .Must((config, aggregateReRoute) => IsNotDuplicateIn(aggregateReRoute, config.Aggregates)) .WithMessage((config, aggregate) => $"{nameof(aggregate)} {aggregate.UpstreamPathTemplate} has duplicate aggregate"); RuleForEach(configuration => configuration.Aggregates) .Must((config, aggregateReRoute) => AllReRoutesForAggregateExist(aggregateReRoute, config.ReRoutes)) .WithMessage((config, aggregateReRoute) => $"ReRoutes for {nameof(aggregateReRoute)} {aggregateReRoute.UpstreamPathTemplate} either do not exist or do not have correct ServiceName property"); RuleForEach(configuration => configuration.Aggregates) .Must((config, aggregateReRoute) => DoesNotContainReRoutesWithSpecificRequestIdKeys(aggregateReRoute, config.ReRoutes)) .WithMessage((config, aggregateReRoute) => $"{nameof(aggregateReRoute)} {aggregateReRoute.UpstreamPathTemplate} contains ReRoute with specific RequestIdKey, this is not possible with Aggregates"); }