public static async Task <IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, Action <OcelotPipelineConfiguration> pipelineConfiguration)
        {
            var config = new OcelotPipelineConfiguration();

            pipelineConfiguration?.Invoke(config);
            return(await builder.UseOcelot(config));
        }
        private static IApplicationBuilder CreateOcelotPipeline(IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
        {
            var pipelineBuilder = new OcelotPipelineBuilder(builder.ApplicationServices);

            pipelineBuilder.BuildOcelotPipeline(pipelineConfiguration);

            var firstDelegate = pipelineBuilder.Build();

            /*
             * inject first delegate into first piece of asp.net middleware..maybe not like this
             * then because we are updating the http context in ocelot it comes out correct for
             * rest of asp.net..
             */

            builder.Properties["analysis.NextMiddlewareName"] = "TransitionToOcelotMiddleware";

            builder.Use(async(context, task) =>
            {
                var downstreamContext = new DownstreamContext(context);
                await firstDelegate.Invoke(downstreamContext);
            });

            return(builder);
        }
        public static async Task <IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
        {
            var configuration = await CreateConfiguration(builder);

            ConfigureDiagnosticListener(builder);

            return(CreateOcelotPipeline(builder, pipelineConfiguration));
        }
Beispiel #4
0
        public static async Task <IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
        {
            var configuration = await CreateConfiguration(builder);

            CreateAdministrationArea(builder, configuration);

            if (UsingRafty(builder))
            {
                SetUpRafty(builder);
            }

            if (UsingEurekaServiceDiscoveryProvider(configuration))
            {
                builder.UseDiscoveryClient();
            }

            ConfigureDiagnosticListener(builder);

            var pipelineBuilder = new OcelotPipelineBuilder(builder.ApplicationServices);

            pipelineBuilder.BuildOcelotPipeline(pipelineConfiguration);

            var firstDelegate = pipelineBuilder.Build();

            /*
             * inject first delegate into first piece of asp.net middleware..maybe not like this
             * then because we are updating the http context in ocelot it comes out correct for
             * rest of asp.net..
             */

            builder.Properties["analysis.NextMiddlewareName"] = "TransitionToOcelotMiddleware";

            builder.Use(async(context, task) =>
            {
                var downstreamContext = new DownstreamContext(context);
                await firstDelegate.Invoke(downstreamContext);
            });

            return(builder);
        }
        public static async Task <IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
        {
            var configuration = await CreateConfiguration(builder);

            CreateAdministrationArea(builder, configuration);

            if (UsingRafty(builder))
            {
                SetUpRafty(builder);
            }

            if (UsingEurekaServiceDiscoveryProvider(configuration))
            {
                builder.UseDiscoveryClient();
            }

            ConfigureDiagnosticListener(builder);

            return(CreateOcelotPipeline(builder, pipelineConfiguration));
        }
Beispiel #6
0
        public static async Task <IApplicationBuilder> UseOcelot(this IApplicationBuilder app, Action <IOcelotPipelineBuilder, OcelotPipelineConfiguration> builderAction, OcelotPipelineConfiguration configuration)
        {
            await CreateConfiguration(app);  // initConfiguration

            ConfigureDiagnosticListener(app);

            var ocelotPipelineBuilder = new OcelotPipelineBuilder(app.ApplicationServices);

            builderAction?.Invoke(ocelotPipelineBuilder, configuration ?? new OcelotPipelineConfiguration());

            var ocelotDelegate = ocelotPipelineBuilder.Build();

            app.Properties["analysis.NextMiddlewareName"] = "TransitionToOcelotMiddleware";

            app.Use(async(context, task) =>
            {
                var downstreamContext = new DownstreamContext(context);
                await ocelotDelegate.Invoke(downstreamContext);
            });

            return(app);
        }
Beispiel #7
0
        /// <summary>
        /// Registers Ocelot with a combination of default middlewares and optional middlewares in the configuration
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="pipelineConfiguration"></param>
        /// <returns></returns>
        public static async Task <IApplicationBuilder> UseOcelot(this IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
        {
            var configuration = await CreateConfiguration(builder);

            CreateAdministrationArea(builder, configuration);

            if (UsingRafty(builder))
            {
                SetUpRafty(builder);
            }

            ConfigureDiagnosticListener(builder);

            var pipelineBuilder = new OcelotPipelineBuilder(builder.ApplicationServices);

            pipelineBuilder.BuildOcelotPipeline(pipelineConfiguration);

            var firstDelegate = pipelineBuilder.Build();

            //inject first delegate into first piece of asp.net middleware..maybe not like this
            //then because we are updating the http context in ocelot it comes out correct for
            //rest of asp.net..

            builder.Use(async(context, task) =>
            {
                var downstreamContext = new DownstreamContext(context);
                await firstDelegate.Invoke(downstreamContext);
            });

            return(builder);
        }
Beispiel #8
0
        private static IApplicationBuilder CreateOcelotPipeline(IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
        {
            builder.BuildOcelotPipeline(pipelineConfiguration);

            /*
             * inject first delegate into first piece of asp.net middleware..maybe not like this
             * then because we are updating the http context in ocelot it comes out correct for
             * rest of asp.net..
             */

            builder.Properties["analysis.NextMiddlewareName"] = "TransitionToOcelotMiddleware";

            return(builder);
        }
Beispiel #9
0
        public static async Task <IApplicationBuilder> UseOcelot(this IApplicationBuilder app, Action <IApplicationBuilder, OcelotPipelineConfiguration> builderAction, OcelotPipelineConfiguration configuration)
        {
            await CreateConfiguration(app);

            ConfigureDiagnosticListener(app);

            builderAction?.Invoke(app, configuration ?? new OcelotPipelineConfiguration());

            app.Properties["analysis.NextMiddlewareName"] = "TransitionToOcelotMiddleware";

            return(app);
        }
Beispiel #10
0
        public static RequestDelegate BuildOcelotPipeline(this IApplicationBuilder app,
                                                          OcelotPipelineConfiguration pipelineConfiguration)
        {
            // this sets up the downstream context and gets the config
            app.UseDownstreamContextMiddleware();

            // This is registered to catch any global exceptions that are not handled
            // It also sets the Request Id if anything is set globally
            app.UseExceptionHandlerMiddleware();

            // If the request is for websockets upgrade we fork into a different pipeline
            app.MapWhen(httpContext => httpContext.WebSockets.IsWebSocketRequest,
                        wenSocketsApp =>
            {
                wenSocketsApp.UseDownstreamRouteFinderMiddleware();
                wenSocketsApp.UseMultiplexingMiddleware();
                wenSocketsApp.UseDownstreamRequestInitialiser();
                wenSocketsApp.UseLoadBalancingMiddleware();
                wenSocketsApp.UseDownstreamUrlCreatorMiddleware();
                wenSocketsApp.UseWebSocketsProxyMiddleware();
            });

            // Allow the user to respond with absolutely anything they want.
            app.UseIfNotNull(pipelineConfiguration.PreErrorResponderMiddleware);

            // This is registered first so it can catch any errors and issue an appropriate response
            app.UseResponderMiddleware();

            // Then we get the downstream route information
            app.UseDownstreamRouteFinderMiddleware();

            // Multiplex the request if required
            app.UseMultiplexingMiddleware();

            // This security module, IP whitelist blacklist, extended security mechanism
            app.UseSecurityMiddleware();

            //Expand other branch pipes
            if (pipelineConfiguration.MapWhenOcelotPipeline != null)
            {
                foreach (var pipeline in pipelineConfiguration.MapWhenOcelotPipeline)
                {
                    // todo why is this asking for an app app?
                    app.MapWhen(pipeline.Key, pipeline.Value);
                }
            }

            // Now we have the ds route we can transform headers and stuff?
            app.UseHttpHeadersTransformationMiddleware();

            // Initialises downstream request
            app.UseDownstreamRequestInitialiser();

            // We check whether the request is ratelimit, and if there is no continue processing
            app.UseRateLimiting();

            // This adds or updates the request id (initally we try and set this based on global config in the error handling middleware)
            // If anything was set at global level and we have a different setting at re route level the global stuff will be overwritten
            // This means you can get a scenario where you have a different request id from the first piece of middleware to the request id middleware.
            app.UseRequestIdMiddleware();

            // Allow pre authentication logic. The idea being people might want to run something custom before what is built in.
            app.UseIfNotNull(pipelineConfiguration.PreAuthenticationMiddleware);

            // Now we know where the client is going to go we can authenticate them.
            // We allow the ocelot middleware to be overriden by whatever the
            // user wants
            if (pipelineConfiguration.AuthenticationMiddleware == null)
            {
                app.UseAuthenticationMiddleware();
            }
            else
            {
                app.Use(pipelineConfiguration.AuthenticationMiddleware);
            }

            // The next thing we do is look at any claims transforms in case this is important for authorisation
            app.UseClaimsToClaimsMiddleware();

            // Allow pre authorisation logic. The idea being people might want to run something custom before what is built in.
            app.UseIfNotNull(pipelineConfiguration.PreAuthorisationMiddleware);

            // Now we have authenticated and done any claims transformation we
            // can authorise the request
            // We allow the ocelot middleware to be overriden by whatever the
            // user wants
            if (pipelineConfiguration.AuthorisationMiddleware == null)
            {
                app.UseAuthorisationMiddleware();
            }
            else
            {
                app.Use(pipelineConfiguration.AuthorisationMiddleware);
            }

            // Now we can run the claims to headers transformation middleware
            app.UseClaimsToHeadersMiddleware();

            // Allow the user to implement their own query string manipulation logic
            app.UseIfNotNull(pipelineConfiguration.PreQueryStringBuilderMiddleware);

            // Now we can run any claims to query string transformation middleware
            app.UseClaimsToQueryStringMiddleware();

            app.UseClaimsToDownstreamPathMiddleware();

            // Get the load balancer for this request
            app.UseLoadBalancingMiddleware();

            // This takes the downstream route we retrieved earlier and replaces any placeholders with the variables that should be used
            app.UseDownstreamUrlCreatorMiddleware();

            // Not sure if this is the best place for this but we use the downstream url
            // as the basis for our cache key.
            app.UseOutputCacheMiddleware();

            //We fire off the request and set the response on the scoped data repo
            app.UseHttpRequesterMiddleware();

            return(app.Build());
        }