Ejemplo n.º 1
0
        public static IReverseProxyBuilder AddInMemoryRepos(this IReverseProxyBuilder builder)
        {
            builder.Services.TryAddSingleton <IBackendsRepo, InMemoryBackendsRepo>();
            builder.Services.TryAddSingleton <IRoutesRepo, InMemoryRoutesRepo>();

            return(builder);
        }
Ejemplo n.º 2
0
 public static IReverseProxyBuilder LoadFromEFCore(this IReverseProxyBuilder builder)
 {
     builder.Services.AddSingleton <ICertificateConfigLoader, CertificateConfigLoader>();
     builder.Services.AddSingleton <IReverseProxyStore, EFCoreReverseProxyStore>();
     builder.LoadFromStore();
     return(builder);
 }
Ejemplo n.º 3
0
 public static IReverseProxyBuilder AddProxy(this IReverseProxyBuilder builder)
 {
     builder.Services.AddSingleton <IProxyHttpClientFactoryFactory, ProxyHttpClientFactoryFactory>();
     builder.Services.AddSingleton <ILoadBalancer, LoadBalancer>();
     builder.Services.AddSingleton <IHttpProxy, HttpProxy>();
     return(builder);
 }
 public static IReverseProxyBuilder AddConfigBuilder(this IReverseProxyBuilder builder)
 {
     builder.Services.TryAddSingleton <IConfigValidator, ConfigValidator>();
     builder.Services.TryAddSingleton <IRuntimeRouteBuilder, RuntimeRouteBuilder>();
     builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <MatcherPolicy, HeaderMatcherPolicy>());
     return(builder);
 }
Ejemplo n.º 5
0
 public static IReverseProxyBuilder AddTelemetryShims(this IReverseProxyBuilder builder)
 {
     // NOTE: Consumers of ReverseProxy are expected to replace these with their own classes
     builder.Services.TryAddSingleton <IMetricCreator, NullMetricCreator>();
     builder.Services.TryAddSingleton <IOperationLogger, TextOperationLogger>();
     return(builder);
 }
Ejemplo n.º 6
0
        public static IReverseProxyBuilder AddProxy(this IReverseProxyBuilder builder)
        {
            builder.Services.TryAddSingleton <IProxyHttpClientFactory, ProxyHttpClientFactory>();

            builder.Services.AddHttpProxy();
            return(builder);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Loads routes and endpoints from config.
        /// </summary>
        public static IReverseProxyBuilder LoadFromConfig(this IReverseProxyBuilder builder, IConfiguration config)
        {
            builder.Services.Configure <ProxyConfigOptions>(config);
            builder.Services.AddHostedService <ProxyConfigLoader>();

            return(builder);
        }
Ejemplo n.º 8
0
 public static IReverseProxyBuilder AddRuntimeStateManagers(this IReverseProxyBuilder builder)
 {
     builder.Services.TryAddSingleton <IDestinationManagerFactory, DestinationManagerFactory>();
     builder.Services.TryAddSingleton <IClusterManager, ClusterManager>();
     builder.Services.TryAddSingleton <IRouteManager, RouteManager>();
     return(builder);
 }
Ejemplo n.º 9
0
 public static IReverseProxyBuilder AddRuntimeStateManagers(this IReverseProxyBuilder builder)
 {
     builder.Services.TryAddSingleton <IEndpointManagerFactory, EndpointManagerFactory>();
     builder.Services.TryAddSingleton <IBackendManager, BackendManager>();
     builder.Services.TryAddSingleton <IRouteManager, RouteManager>();
     return(builder);
 }
Ejemplo n.º 10
0
 public static IReverseProxyBuilder AddConfigBuilder(this IReverseProxyBuilder builder)
 {
     builder.Services.TryAddSingleton <IDynamicConfigBuilder, DynamicConfigBuilder>();
     builder.Services.TryAddSingleton <IRouteValidator, RouteValidator>();
     builder.Services.TryAddSingleton <IRuntimeRouteBuilder, RuntimeRouteBuilder>();
     return(builder);
 }
 public static IReverseProxyBuilder LoadFromStore(this IReverseProxyBuilder builder)
 {
     builder.Services.AddSingleton <IProxyConfigProvider>(sp =>
     {
         return(new InStoreConfigProvider(sp.GetService <ILogger <InStoreConfigProvider> >(), sp.GetRequiredService <IReverseProxyStore>()));
     });
     return(builder);
 }
        /// <summary>
        /// Loads routes and endpoints from config.
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="config"></param>
        /// <param name="reloadOnChange"></param>
        /// <returns></returns>
        public static IReverseProxyBuilder LoadFromConfig(this IReverseProxyBuilder builder, IConfiguration config, bool reloadOnChange = true)
        {
            builder.Services.Configure <ProxyConfigOptions>(config);
            builder.Services.Configure <ProxyConfigOptions>(options => options.ReloadOnChange = reloadOnChange);
            builder.Services.AddHostedService <ProxyConfigLoader>();

            return(builder);
        }
        /// <summary>
        /// Loads routes and endpoints from config.
        /// </summary>
        public static IReverseProxyBuilder LoadFromConfig(this IReverseProxyBuilder builder, IConfiguration config)
        {
            builder.Services.Configure <ConfigurationData>(config);
            builder.Services.AddSingleton <ICertificateConfigLoader, CertificateConfigLoader>();
            builder.Services.AddSingleton <IProxyConfigProvider, ConfigurationConfigProvider>();

            return(builder);
        }
Ejemplo n.º 14
0
    public static IReverseProxyBuilder AddHttpSysDelegation(this IReverseProxyBuilder builder)
    {
        builder.Services.AddSingleton <HttpSysDelegator>();
        builder.Services.TryAddSingleton <IHttpSysDelegator>(p => p.GetRequiredService <HttpSysDelegator>());
        builder.Services.AddSingleton <IClusterChangeListener>(p => p.GetRequiredService <HttpSysDelegator>());

        return(builder);
    }
 public static IReverseProxyBuilder AddProxy(this IReverseProxyBuilder builder)
 {
     builder.Services.TryAddSingleton <ITransformBuilder, TransformBuilder>();
     builder.Services.TryAddSingleton <IProxyHttpClientFactory, ProxyHttpClientFactory>();
     builder.Services.TryAddSingleton <ILoadBalancer, LoadBalancer>();
     builder.Services.TryAddSingleton <IRandomFactory, RandomFactory>();
     builder.Services.AddHttpProxy();
     return(builder);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Provides a callback to customize <see cref="SocketsHttpHandler"/> settings used for proxying requests.
 /// This will be called each time a cluster is added or changed. Cluster settings are applied to the handler before
 /// the callback. Custom data can be provided in the cluster metadata.
 /// </summary>
 public static IReverseProxyBuilder ConfigureClient(this IReverseProxyBuilder builder, Action <ProxyHttpClientContext, SocketsHttpHandler> configure)
 {
     builder.Services.AddSingleton <IProxyHttpClientFactory>(services =>
     {
         var logger = services.GetRequiredService <ILogger <ProxyHttpClientFactory> >();
         return(new CallbackProxyHttpClientFactory(logger, configure));
     });
     return(builder);
 }
Ejemplo n.º 17
0
        public static IReverseProxyBuilder LoadFromKubernetes(this IReverseProxyBuilder builder, IConfiguration configuration)
        {
            _ = configuration ?? throw new ArgumentNullException(nameof(configuration));

            AddServices(builder);

            builder.Services.Configure <KubernetesDiscoveryOptions>(configuration);

            return(builder);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Registers a singleton IProxyConfigFilter service. Multiple filters are allowed and they will be run in registration order.
        /// </summary>
        /// <typeparam name="TService">A class that implements IProxyConfigFilter.</typeparam>
        public static IReverseProxyBuilder AddProxyConfigFilter <TService>(this IReverseProxyBuilder builder) where TService : class, IProxyConfigFilter
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddSingleton <IProxyConfigFilter, TService>();
            return(builder);
        }
Ejemplo n.º 19
0
        public static IReverseProxyBuilder LoadFromMemory(
            this IReverseProxyBuilder builder,
            IReadOnlyList <ProxyRoute> routes,
            IReadOnlyList <Cluster> clusters)
        {
            builder.Services.AddSingleton <IProxyConfigProvider>(
                new InMemoryConfigProvider(routes, clusters));

            return(builder);
        }
        /// <summary>
        /// Provides a callback that will be run for each route to conditionally add transforms.
        /// <see cref="AddTransforms(IReverseProxyBuilder, Action{TransformBuilderContext})"/> can be called multiple times to
        /// provide multiple callbacks.
        /// </summary>
        public static IReverseProxyBuilder AddTransforms(this IReverseProxyBuilder builder, Action <TransformBuilderContext> action)
        {
            if (action is null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            builder.Services.AddSingleton <ITransformProvider>(new ActionTransformProvider(action));
            return(builder);
        }
Ejemplo n.º 21
0
    /// <summary>
    /// Uses Service Fabric dynamic service discovery as the configuration source for the Proxy
    /// via a specific implementation of <see cref="IProxyConfigProvider" />.
    /// </summary>
    public static IReverseProxyBuilder LoadFromServiceFabric(this IReverseProxyBuilder builder, Action <ServiceFabricDiscoveryOptions> configureOptions)
    {
        _ = configureOptions ?? throw new ArgumentNullException(nameof(configureOptions));

        AddServices(builder);

        builder.Services.Configure(configureOptions);

        return(builder);
    }
Ejemplo n.º 22
0
        /// <summary>
        /// Loads routes and endpoints from config.
        /// </summary>
        public static IReverseProxyBuilder LoadFromConfig(this IReverseProxyBuilder builder, IConfiguration config)
        {
            builder.Services.AddSingleton <ICertificateConfigLoader, CertificateConfigLoader>();
            builder.Services.AddSingleton <IProxyConfigProvider>(sp =>
            {
                // This is required because we're capturing the configuration via a closure
                return(new ConfigurationConfigProvider(sp.GetService <ILogger <ConfigurationConfigProvider> >(), config, sp.GetService <ICertificateConfigLoader>()));
            });

            return(builder);
        }
Ejemplo n.º 23
0
 private static void AddServices(IReverseProxyBuilder builder)
 {
     builder.Services.AddSingleton <IFabricClientWrapper, FabricClientWrapper>();
     builder.Services.AddSingleton <IQueryClientWrapper, QueryClientWrapper>();
     builder.Services.AddSingleton <IPropertyManagementClientWrapper, PropertyManagementClientWrapper>();
     builder.Services.AddSingleton <IServiceManagementClientWrapper, ServiceManagementClientWrapper>();
     builder.Services.AddSingleton <IHealthClientWrapper, HealthClientWrapper>();
     builder.Services.AddSingleton <ICachedServiceFabricCaller, CachedServiceFabricCaller>();
     builder.Services.AddSingleton <IServiceExtensionLabelsProvider, ServiceExtensionLabelsProvider>();
     builder.Services.AddSingleton <IDiscoverer, Discoverer>();
     builder.Services.AddSingleton <IProxyConfigProvider, ServiceFabricConfigProvider>();
 }
Ejemplo n.º 24
0
    public static IReverseProxyBuilder AddRuntimeStateManagers(this IReverseProxyBuilder builder)
    {
        builder.Services.TryAddSingleton <ITimerFactory, TimerFactory>();
        builder.Services.TryAddSingleton <IDestinationHealthUpdater, DestinationHealthUpdater>();

        builder.Services.TryAddSingleton <IClusterDestinationsUpdater, ClusterDestinationsUpdater>();
        builder.Services.TryAddEnumerable(new[] {
            ServiceDescriptor.Singleton <IAvailableDestinationsPolicy, HealthyAndUnknownDestinationsPolicy>(),
            ServiceDescriptor.Singleton <IAvailableDestinationsPolicy, HealthyOrPanicDestinationsPolicy>()
        });
        return(builder);
    }
        public static IReverseProxyBuilder AddSessionAffinityProvider(this IReverseProxyBuilder builder)
        {
            builder.Services.TryAddEnumerable(new[] {
                new ServiceDescriptor(typeof(IAffinityFailurePolicy), typeof(RedistributeAffinityFailurePolicy), ServiceLifetime.Singleton),
                new ServiceDescriptor(typeof(IAffinityFailurePolicy), typeof(Return503ErrorAffinityFailurePolicy), ServiceLifetime.Singleton)
            });
            builder.Services.TryAddEnumerable(new[] {
                new ServiceDescriptor(typeof(ISessionAffinityProvider), typeof(CookieSessionAffinityProvider), ServiceLifetime.Singleton),
                new ServiceDescriptor(typeof(ISessionAffinityProvider), typeof(CustomHeaderSessionAffinityProvider), ServiceLifetime.Singleton)
            });

            return(builder);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Uses Service Fabric dynamic service discovery as the configuration source for the Proxy
        /// via a specific implementation of <see cref="IProxyConfigProvider" />.
        /// </summary>
        public static IReverseProxyBuilder LoadFromServiceFabric(this IReverseProxyBuilder builder)
        {
            builder.Services.AddSingleton <IQueryClientWrapper, QueryClientWrapper>();
            builder.Services.AddSingleton <IPropertyManagementClientWrapper, PropertyManagementClientWrapper>();
            builder.Services.AddSingleton <IServiceManagementClientWrapper, ServiceManagementClientWrapper>();
            builder.Services.AddSingleton <IHealthClientWrapper, HealthClientWrapper>();
            builder.Services.AddSingleton <IServiceFabricCaller, CachedServiceFabricCaller>();
            builder.Services.AddSingleton <IServiceExtensionLabelsProvider, ServiceExtensionLabelsProvider>();
            builder.Services.AddSingleton <IDiscoverer, Discoverer>();
            builder.Services.AddSingleton <IProxyConfigProvider, ServiceFabricConfigProvider>();

            return(builder);
        }
 public static IReverseProxyBuilder AddConfigBuilder(this IReverseProxyBuilder builder)
 {
     builder.Services.TryAddSingleton <IConfigValidator, ConfigValidator>();
     builder.Services.TryAddSingleton <IRandomFactory, RandomFactory>();
     builder.AddTransformFactory <ForwardedTransformFactory>();
     builder.AddTransformFactory <HttpMethodTransformFactory>();
     builder.AddTransformFactory <PathTransformFactory>();
     builder.AddTransformFactory <QueryTransformFactory>();
     builder.AddTransformFactory <RequestHeadersTransformFactory>();
     builder.AddTransformFactory <ResponseTransformFactory>();
     builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <MatcherPolicy, HeaderMatcherPolicy>());
     return(builder);
 }
    public static IReverseProxyBuilder LoadFromMessages(this IReverseProxyBuilder builder)
    {
        if (builder is null)
        {
            throw new ArgumentNullException(nameof(builder));
        }

        var provider = new KubernetesConfigProvider();

        builder.Services.AddSingleton <IProxyConfigProvider>(provider);
        builder.Services.AddSingleton <IUpdateConfig>(provider);
        return(builder);
    }
Ejemplo n.º 29
0
        public static IReverseProxyBuilder AddLoadBalancingPolicies(this IReverseProxyBuilder builder)
        {
            builder.Services.TryAddSingleton <IRandomFactory, RandomFactory>();

            builder.Services.TryAddEnumerable(new[] {
                new ServiceDescriptor(typeof(ILoadBalancingPolicy), typeof(FirstLoadBalancingPolicy), ServiceLifetime.Singleton),
                new ServiceDescriptor(typeof(ILoadBalancingPolicy), typeof(LeastRequestsLoadBalancingPolicy), ServiceLifetime.Singleton),
                new ServiceDescriptor(typeof(ILoadBalancingPolicy), typeof(RandomLoadBalancingPolicy), ServiceLifetime.Singleton),
                new ServiceDescriptor(typeof(ILoadBalancingPolicy), typeof(PowerOfTwoChoicesLoadBalancingPolicy), ServiceLifetime.Singleton),
                new ServiceDescriptor(typeof(ILoadBalancingPolicy), typeof(RoundRobinLoadBalancingPolicy), ServiceLifetime.Singleton)
            });

            return(builder);
        }
    /// <summary>
    /// Provides a callback to customize <see cref="SocketsHttpHandler"/> settings used for proxying requests.
    /// This will be called each time a cluster is added or changed. Cluster settings are applied to the handler before
    /// the callback. Custom data can be provided in the cluster metadata.
    /// </summary>
    public static IReverseProxyBuilder ConfigureHttpClient(this IReverseProxyBuilder builder, Action <ForwarderHttpClientContext, SocketsHttpHandler> configure)
    {
        if (configure is null)
        {
            throw new ArgumentNullException(nameof(configure));
        }

        builder.Services.AddSingleton <IForwarderHttpClientFactory>(services =>
        {
            var logger = services.GetRequiredService <ILogger <ForwarderHttpClientFactory> >();
            return(new CallbackHttpClientFactory(logger, configure));
        });
        return(builder);
    }