Reducing Warnings from Ocelot (#743)

This commit is contained in:
Thiago Loureiro 2019-01-11 21:56:23 +01:00 committed by Marcelo Castagna
parent 6495891a07
commit 02e5cea7b1
9 changed files with 28 additions and 27 deletions

View File

@ -1,9 +1,8 @@
using Microsoft.AspNetCore.Builder;
using Ocelot.Middleware.Pipeline;
using Ocelot.Middleware.Pipeline;
namespace Ocelot.Claims.Middleware
{
public static class ClaimsToClaimsMiddlewareExtensions
public static class ClaimsBuilderMiddlewareExtensions
{
public static IOcelotPipelineBuilder UseClaimsToClaimsMiddleware(this IOcelotPipelineBuilder builder)
{

View File

@ -2,7 +2,6 @@ using Ocelot.Configuration.File;
namespace Ocelot.Configuration.Creator
{
public class LoadBalancerOptionsCreator : ILoadBalancerOptionsCreator
{
public LoadBalancerOptions Create(FileLoadBalancerOptions options)

View File

@ -26,7 +26,6 @@ namespace Ocelot.Infrastructure
{ "{BaseUrl}", GetBaseUrl() },
{ "{TraceId}", GetTraceId() },
{ "{RemoteIpAddress}", GetRemoteIpAddress() }
};
_requestPlaceholders = new Dictionary<string, Func<DownstreamRequest, string>>
@ -37,10 +36,10 @@ namespace Ocelot.Infrastructure
public Response<string> Get(string key)
{
if(_placeholders.ContainsKey(key))
if (_placeholders.ContainsKey(key))
{
var response = _placeholders[key].Invoke();
if(!response.IsError)
if (!response.IsError)
{
return new OkResponse<string>(response.Data);
}
@ -51,7 +50,7 @@ namespace Ocelot.Infrastructure
public Response<string> Get(string key, DownstreamRequest request)
{
if(_requestPlaceholders.ContainsKey(key))
if (_requestPlaceholders.ContainsKey(key))
{
return new OkResponse<string>(_requestPlaceholders[key].Invoke(request));
}
@ -61,7 +60,7 @@ namespace Ocelot.Infrastructure
public Response Add(string key, Func<Response<string>> func)
{
if(_placeholders.ContainsKey(key))
if (_placeholders.ContainsKey(key))
{
return new ErrorResponse(new CannotAddPlaceholderError($"Unable to add placeholder: {key}, placeholder already exists"));
}
@ -72,7 +71,7 @@ namespace Ocelot.Infrastructure
public Response Remove(string key)
{
if(!_placeholders.ContainsKey(key))
if (!_placeholders.ContainsKey(key))
{
return new ErrorResponse(new CannotRemovePlaceholderError($"Unable to remove placeholder: {key}, placeholder does not exists"));
}
@ -91,7 +90,7 @@ namespace Ocelot.Infrastructure
var remoteIdAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
return new OkResponse<string>(remoteIdAddress);
}
catch (Exception e)
catch
{
return new ErrorResponse<string>(new CouldNotFindPlaceholderError("{RemoteIpAddress}"));
}

View File

@ -1,9 +1,9 @@
using System;
using Ocelot.Configuration;
using Ocelot.Responses;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using Ocelot.Configuration;
using Ocelot.Responses;
namespace Ocelot.LoadBalancer.LoadBalancers
{
@ -35,6 +35,7 @@ namespace Ocelot.LoadBalancer.LoadBalancers
{
return new ErrorResponse<ILoadBalancer>(result.Errors);
}
loadBalancer = result.Data;
AddLoadBalancer(reRoute.LoadBalancerKey, loadBalancer);
}
@ -43,10 +44,12 @@ namespace Ocelot.LoadBalancer.LoadBalancers
}
result = await _factory.Get(reRoute, config);
if (result.IsError)
{
return new ErrorResponse<ILoadBalancer>(result.Errors);
}
loadBalancer = result.Data;
AddLoadBalancer(reRoute.LoadBalancerKey, loadBalancer);
return new OkResponse<ILoadBalancer>(loadBalancer);

View File

@ -15,7 +15,6 @@ namespace Ocelot.Logging
{
_logger = factory.CreateLogger<OcelotDiagnosticListener>();
_tracer = serviceProvider.GetService<ITracer>();
}
[DiagnosticName("Ocelot.MiddlewareException")]

View File

@ -76,6 +76,7 @@
// now create the config
var internalConfigCreator = builder.ApplicationServices.GetService<IInternalConfigurationCreator>();
var internalConfig = await internalConfigCreator.Create(fileConfig.CurrentValue);
//Configuration error, throw error message
if (internalConfig.IsError)
{
@ -102,7 +103,7 @@
await configuration(builder);
}
if(AdministrationApiInUse(adminPath))
if (AdministrationApiInUse(adminPath))
{
//We have to make sure the file config is set for the ocelot.env.json and ocelot.json so that if we pull it from the
//admin api it works...boy this is getting a spit spags boll.

View File

@ -40,6 +40,7 @@
/// This allows the user to implement there own query string manipulation logic
/// </summary>
public Func<DownstreamContext, Func<Task>, Task> PreQueryStringBuilderMiddleware { get; set; }
/// <summary>
/// This is an extension that will branch to different pipes
/// </summary>

View File

@ -2,14 +2,13 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Removed code and changed RequestDelete to OcelotRequestDelete, HttpContext to DownstreamContext, removed some exception handling messages
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace Ocelot.Middleware.Pipeline
{
@ -167,10 +166,12 @@ namespace Ocelot.Middleware.Pipeline
{
throw new ArgumentNullException(nameof(app));
}
if (pipelineBuilderFunc == null)
{
throw new ArgumentNullException(nameof(pipelineBuilderFunc));
}
var branchBuilder = app.New();
var predicate = pipelineBuilderFunc.Invoke(branchBuilder);
var branch = branchBuilder.Build();

View File

@ -26,8 +26,7 @@
HttpRequestMessage request,
CancellationToken cancellationToken)
{
return _tracer.SendAsync(request, cancellationToken, x => _repo.Add("TraceId", x), (r,c) => base.SendAsync(r, c));
return _tracer.SendAsync(request, cancellationToken, x => _repo.Add("TraceId", x), (r, c) => base.SendAsync(r, c));
}
}
}