Added a get authentication test, removed the infrastructure name space as it seemed pointless, started thinking about how to pass claims on with the request

This commit is contained in:
tom.pallister
2016-10-17 18:00:36 +01:00
parent ce84ad4fc2
commit 3d60602c7e
97 changed files with 614 additions and 508 deletions

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Http;
namespace Ocelot.Library.Infrastructure.Authentication
namespace Ocelot.Library.Authentication
{
using Microsoft.AspNetCore.Http;
public class AuthenticationHandler
{
public AuthenticationHandler(string provider, RequestDelegate handler)

View File

@ -1,11 +1,11 @@
using IdentityServer4.AccessTokenValidation;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Responses;
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
namespace Ocelot.Library.Infrastructure.Authentication
namespace Ocelot.Library.Authentication
{
using IdentityServer4.AccessTokenValidation;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Responses;
using AuthenticationOptions = Configuration.AuthenticationOptions;
/// <summary>
/// Cannot unit test things in this class due to use of extension methods
/// </summary>

View File

@ -1,11 +1,11 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
namespace Ocelot.Library.Infrastructure.Authentication
namespace Ocelot.Library.Authentication
{
using System.Collections.Generic;
using Errors;
using Microsoft.AspNetCore.Builder;
using Responses;
using AuthenticationOptions = Configuration.AuthenticationOptions;
public class AuthenticationHandlerFactory : IAuthenticationHandlerFactory
{
private readonly IAuthenticationHandlerCreator _creator;

View File

@ -0,0 +1,12 @@
namespace Ocelot.Library.Authentication
{
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Responses;
using AuthenticationOptions = Configuration.AuthenticationOptions;
public interface IAuthenticationHandlerCreator
{
Response<RequestDelegate> CreateIdentityServerAuthenticationHandler(IApplicationBuilder app, AuthenticationOptions authOptions);
}
}

View File

@ -0,0 +1,11 @@
namespace Ocelot.Library.Authentication
{
using Microsoft.AspNetCore.Builder;
using Responses;
using AuthenticationOptions = Configuration.AuthenticationOptions;
public interface IAuthenticationHandlerFactory
{
Response<AuthenticationHandler> Get(IApplicationBuilder app, AuthenticationOptions authOptions);
}
}

View File

@ -1,4 +1,4 @@
namespace Ocelot.Library.Infrastructure.Authentication
namespace Ocelot.Library.Authentication
{
public enum SupportAuthenticationProviders
{

View File

@ -1,7 +1,7 @@
using Ocelot.Library.Infrastructure.Errors;
namespace Ocelot.Library.Infrastructure.Authentication
namespace Ocelot.Library.Authentication
{
using Errors;
public class UnableToCreateAuthenticationHandlerError : Error
{
public UnableToCreateAuthenticationHandlerError(string message)

View File

@ -1,7 +1,6 @@
using System.Collections.Generic;
namespace Ocelot.Library.Infrastructure.Builder
namespace Ocelot.Library.Builder
{
using System.Collections.Generic;
using Configuration;
public class ReRouteBuilder

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace Ocelot.Library.Infrastructure.Configuration
namespace Ocelot.Library.Configuration
{
using System.Collections.Generic;
public class AuthenticationOptions
{
public AuthenticationOptions(string provider, string providerRootUrl, string scopeName, bool requireHttps, List<string> additionalScopes, string scopeSecret)

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace Ocelot.Library.Infrastructure.Configuration
namespace Ocelot.Library.Configuration
{
using System.Collections.Generic;
public interface IOcelotConfiguration
{
List<ReRoute> ReRoutes { get; }

View File

@ -1,9 +1,9 @@
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Ocelot.Library.Infrastructure.Configuration.Yaml;
namespace Ocelot.Library.Infrastructure.Configuration
namespace Ocelot.Library.Configuration
{
using System.Collections.Generic;
using Microsoft.Extensions.Options;
using Yaml;
public class OcelotConfiguration : IOcelotConfiguration
{
private readonly IOptions<YamlConfiguration> _options;

View File

@ -1,4 +1,4 @@
namespace Ocelot.Library.Infrastructure.Configuration
namespace Ocelot.Library.Configuration
{
public class ReRoute
{

View File

@ -1,9 +1,8 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
namespace Ocelot.Library.Configuration.Yaml
{
using System.Collections.Generic;
using Errors;
public class ConfigurationValidationResult
{
public ConfigurationValidationResult(bool isError)

View File

@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Ocelot.Library.Infrastructure.Authentication;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
namespace Ocelot.Library.Configuration.Yaml
{
using System;
using System.Collections.Generic;
using System.Linq;
using Authentication;
using Errors;
using Responses;
public class ConfigurationValidator : IConfigurationValidator
{
public Response<ConfigurationValidationResult> IsValid(YamlConfiguration configuration)

View File

@ -1,8 +1,7 @@
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
namespace Ocelot.Library.Configuration.Yaml
{
using Errors;
public class DownstreamTemplateAlreadyUsedError : Error
{
public DownstreamTemplateAlreadyUsedError(string message) : base(message, OcelotErrorCode.DownstreamTemplateAlreadyUsedError)

View File

@ -1,7 +1,7 @@
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
namespace Ocelot.Library.Configuration.Yaml
{
using Responses;
public interface IConfigurationValidator
{
Response<ConfigurationValidationResult> IsValid(YamlConfiguration configuration);

View File

@ -1,7 +1,7 @@
using Ocelot.Library.Infrastructure.Errors;
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
namespace Ocelot.Library.Configuration.Yaml
{
using Errors;
public class UnsupportedAuthenticationProviderError : Error
{
public UnsupportedAuthenticationProviderError(string message)

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
namespace Ocelot.Library.Configuration.Yaml
{
using System.Collections.Generic;
public class YamlAuthenticationOptions
{
public string Provider { get; set; }

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
namespace Ocelot.Library.Configuration.Yaml
{
using System.Collections.Generic;
public class YamlConfiguration
{
public YamlConfiguration()

View File

@ -1,4 +1,4 @@
namespace Ocelot.Library.Infrastructure.Configuration.Yaml
namespace Ocelot.Library.Configuration.Yaml
{
public class YamlReRoute
{

View File

@ -0,0 +1,44 @@
namespace Ocelot.Library.DependencyInjection
{
using Authentication;
using Configuration;
using Configuration.Yaml;
using DownstreamRouteFinder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Repository;
using RequestBuilder;
using Requester;
using Responder;
using UrlMatcher;
using UrlTemplateReplacer;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddOcelot(this IServiceCollection services, IConfigurationRoot configurationRoot)
{
services.Configure<YamlConfiguration>(configurationRoot);
// Add framework services.
services.AddSingleton<IConfigurationValidator, ConfigurationValidator>();
services.AddSingleton<IOcelotConfiguration, OcelotConfiguration>();
services.AddSingleton<IUrlPathToUrlTemplateMatcher, RegExUrlMatcher>();
services.AddSingleton<ITemplateVariableNameAndValueFinder, TemplateVariableNameAndValueFinder>();
services.AddSingleton<IDownstreamUrlTemplateVariableReplacer, DownstreamUrlTemplateVariableReplacer>();
services.AddSingleton<IDownstreamRouteFinder, DownstreamRouteFinder>();
services.AddSingleton<IHttpRequester, HttpClientHttpRequester>();
services.AddSingleton<IHttpResponder, HttpContextResponder>();
services.AddSingleton<IRequestBuilder, HttpRequestBuilder>();
services.AddSingleton<IErrorsToHttpStatusCodeMapper, ErrorsToHttpStatusCodeMapper>();
services.AddSingleton<IAuthenticationHandlerFactory, AuthenticationHandlerFactory>();
services.AddSingleton<IAuthenticationHandlerCreator, AuthenticationHandlerCreator>();
// see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped<IScopedRequestDataRepository, ScopedRequestDataRepository>();
return services;
}
}
}

View File

@ -1,9 +1,8 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.UrlMatcher;
namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
namespace Ocelot.Library.DownstreamRouteFinder
{
using System.Collections.Generic;
using Configuration;
using UrlMatcher;
public class DownstreamRoute
{

View File

@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Options;
using Ocelot.Library.Infrastructure.Configuration;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
using Ocelot.Library.Infrastructure.UrlMatcher;
namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
namespace Ocelot.Library.DownstreamRouteFinder
{
using System;
using System.Collections.Generic;
using System.Linq;
using Configuration;
using Errors;
using Responses;
using UrlMatcher;
public class DownstreamRouteFinder : IDownstreamRouteFinder
{
private readonly IOcelotConfiguration _configuration;

View File

@ -1,7 +1,7 @@
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
namespace Ocelot.Library.DownstreamRouteFinder
{
using Responses;
public interface IDownstreamRouteFinder
{
Response<DownstreamRoute> FindDownstreamRoute(string upstreamUrlPath, string upstreamHttpMethod);

View File

@ -0,0 +1,11 @@
namespace Ocelot.Library.DownstreamRouteFinder
{
using Errors;
public class UnableToFindDownstreamRouteError : Error
{
public UnableToFindDownstreamRouteError() : base("UnableToFindDownstreamRouteError", OcelotErrorCode.UnableToFindDownstreamRouteError)
{
}
}
}

View File

@ -1,4 +1,4 @@
namespace Ocelot.Library.Infrastructure.Errors
namespace Ocelot.Library.Errors
{
public abstract class Error
{

View File

@ -1,4 +1,4 @@
namespace Ocelot.Library.Infrastructure.Errors
namespace Ocelot.Library.Errors
{
public enum OcelotErrorCode
{

View File

@ -1,12 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Responses;
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
namespace Ocelot.Library.Infrastructure.Authentication
{
public interface IAuthenticationHandlerCreator
{
Response<RequestDelegate> CreateIdentityServerAuthenticationHandler(IApplicationBuilder app, AuthenticationOptions authOptions);
}
}

View File

@ -1,11 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Ocelot.Library.Infrastructure.Responses;
using AuthenticationOptions = Ocelot.Library.Infrastructure.Configuration.AuthenticationOptions;
namespace Ocelot.Library.Infrastructure.Authentication
{
public interface IAuthenticationHandlerFactory
{
Response<AuthenticationHandler> Get(IApplicationBuilder app, AuthenticationOptions authOptions);
}
}

View File

@ -1,16 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.DownstreamRouteFinder
{
public class UnableToFindDownstreamRouteError : Error
{
public UnableToFindDownstreamRouteError() : base("UnableToFindDownstreamRouteError", OcelotErrorCode.UnableToFindDownstreamRouteError)
{
}
}
}

View File

@ -1,12 +0,0 @@
using System.Net.Http;
using System.Threading.Tasks;
using Ocelot.Library.Infrastructure.RequestBuilder;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Requester
{
public interface IHttpRequester
{
Task<Response<HttpResponseMessage>> GetResponse(Request request);
}
}

View File

@ -1,11 +0,0 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Responder
{
public interface IErrorsToHttpStatusCodeMapper
{
Response<int> Map(List<Error> errors);
}
}

View File

@ -1,9 +0,0 @@
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.UrlMatcher
{
public interface IUrlPathToUrlTemplateMatcher
{
Response<UrlMatch> Match(string upstreamUrlPath, string upstreamUrlPathTemplate);
}
}

View File

@ -1,10 +0,0 @@
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.UrlTemplateReplacer
{
public interface IDownstreamUrlTemplateVariableReplacer
{
Response<string> ReplaceTemplateVariables(DownstreamRoute downstreamRoute);
}
}

View File

@ -1,15 +1,15 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Authentication;
using Ocelot.Library.Infrastructure.Configuration;
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Repository;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using System.Collections.Generic;
using System.Threading.Tasks;
using Authentication;
using Configuration;
using DownstreamRouteFinder;
using Errors;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Repository;
public class AuthenticationMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using Microsoft.AspNetCore.Builder;
public static class AuthenticationMiddlewareMiddlewareExtensions
{
public static IApplicationBuilder UseAuthenticationMiddleware(this IApplicationBuilder builder)

View File

@ -0,0 +1,23 @@
namespace Ocelot.Library.Middleware
{
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Repository;
public class ClaimsParserMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;
public ClaimsParserMiddleware(RequestDelegate next, IScopedRequestDataRepository scopedRequestDataRepository)
: base(scopedRequestDataRepository)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
await _next.Invoke(context);
}
}
}

View File

@ -1,10 +1,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Repository;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using System.Threading.Tasks;
using DownstreamRouteFinder;
using Microsoft.AspNetCore.Http;
using Repository;
public class DownstreamRouteFinderMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using Microsoft.AspNetCore.Builder;
public static class DownstreamRouteFinderMiddlewareExtensions
{
public static IApplicationBuilder UseDownstreamRouteFinderMiddleware(this IApplicationBuilder builder)

View File

@ -1,11 +1,11 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.UrlTemplateReplacer;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using System.Threading.Tasks;
using DownstreamRouteFinder;
using Microsoft.AspNetCore.Http;
using Repository;
using UrlTemplateReplacer;
public class DownstreamUrlCreatorMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using Microsoft.AspNetCore.Builder;
public static class DownstreamUrlCreatorMiddlewareExtensions
{
public static IApplicationBuilder UseDownstreamUrlCreatorMiddleware(this IApplicationBuilder builder)

View File

@ -1,10 +1,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.RequestBuilder;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Repository;
using RequestBuilder;
public class HttpRequestBuilderMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using Microsoft.AspNetCore.Builder;
public static class HttpRequestBuilderMiddlewareExtensions
{
public static IApplicationBuilder UseHttpRequestBuilderMiddleware(this IApplicationBuilder builder)

View File

@ -1,11 +1,11 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.RequestBuilder;
using Ocelot.Library.Infrastructure.Requester;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Repository;
using RequestBuilder;
using Requester;
public class HttpRequesterMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using Microsoft.AspNetCore.Builder;
public static class HttpRequesterMiddlewareExtensions
{
public static IApplicationBuilder UseHttpRequesterMiddleware(this IApplicationBuilder builder)

View File

@ -1,11 +1,11 @@
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.Responder;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Repository;
using Responder;
public class HttpResponderMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;

View File

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Builder;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using Microsoft.AspNetCore.Builder;
public static class HttpResponderMiddlewareExtensions
{
public static IApplicationBuilder UseHttpResponderMiddleware(this IApplicationBuilder builder)

View File

@ -1,10 +1,9 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using System.Collections.Generic;
using Errors;
using Repository;
public abstract class OcelotMiddleware
{
private readonly IScopedRequestDataRepository _scopedRequestDataRepository;

View File

@ -0,0 +1,24 @@
namespace Ocelot.Library.Middleware
{
using Microsoft.AspNetCore.Builder;
public static class OcelotMiddlewareExtensions
{
public static IApplicationBuilder UseOcelot(this IApplicationBuilder builder)
{
builder.UseHttpResponderMiddleware();
builder.UseDownstreamRouteFinderMiddleware();
builder.UseAuthenticationMiddleware();
builder.UseDownstreamUrlCreatorMiddleware();
builder.UseHttpRequestBuilderMiddleware();
builder.UseHttpRequesterMiddleware();
return builder;
}
}
}

View File

@ -1,7 +1,7 @@
using Ocelot.Library.Infrastructure.Errors;
namespace Ocelot.Library.Infrastructure.Middleware
namespace Ocelot.Library.Middleware
{
using Errors;
public class UnauthenticatedError : Error
{
public UnauthenticatedError(string message) : base(message, OcelotErrorCode.UnauthenticatedError)

View File

@ -1,8 +1,7 @@
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Repository
namespace Ocelot.Library.Repository
{
using Errors;
public class CannotAddDataError : Error
{
public CannotAddDataError(string message) : base(message, OcelotErrorCode.CannotAddDataError)

View File

@ -1,8 +1,7 @@
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Repository
namespace Ocelot.Library.Repository
{
using Errors;
public class CannotFindDataError : Error
{
public CannotFindDataError(string message) : base(message, OcelotErrorCode.CannotFindDataError)

View File

@ -1,7 +1,7 @@
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Repository
namespace Ocelot.Library.Repository
{
using Responses;
public interface IScopedRequestDataRepository
{
Response Add<T>(string key, T value);

View File

@ -1,11 +1,11 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Repository
namespace Ocelot.Library.Repository
{
using System;
using System.Collections.Generic;
using Errors;
using Microsoft.AspNetCore.Http;
using Responses;
public class ScopedRequestDataRepository : IScopedRequestDataRepository
{
private readonly IHttpContextAccessor _httpContextAccessor;

View File

@ -1,14 +1,14 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.RequestBuilder
namespace Ocelot.Library.RequestBuilder
{
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Responses;
public class HttpRequestBuilder : IRequestBuilder
{
public async Task<Response<Request>> Build(string httpMethod, string downstreamUrl, Stream content, IHeaderDictionary headers,

View File

@ -1,10 +1,10 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.RequestBuilder
namespace Ocelot.Library.RequestBuilder
{
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Responses;
public interface IRequestBuilder
{
Task<Response<Request>> Build(string httpMethod,

View File

@ -1,8 +1,8 @@
using System.Net;
using System.Net.Http;
namespace Ocelot.Library.Infrastructure.RequestBuilder
namespace Ocelot.Library.RequestBuilder
{
using System.Net;
using System.Net.Http;
public class Request
{
public Request(HttpRequestMessage httpRequestMessage, CookieContainer cookieContainer)

View File

@ -1,13 +1,13 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.RequestBuilder;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Requester
namespace Ocelot.Library.Requester
{
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Errors;
using RequestBuilder;
using Responses;
public class HttpClientHttpRequester : IHttpRequester
{
public async Task<Response<HttpResponseMessage>> GetResponse(Request request)

View File

@ -0,0 +1,12 @@
namespace Ocelot.Library.Requester
{
using System.Net.Http;
using System.Threading.Tasks;
using RequestBuilder;
using Responses;
public interface IHttpRequester
{
Task<Response<HttpResponseMessage>> GetResponse(Request request);
}
}

View File

@ -1,9 +1,8 @@
using System;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Requester
namespace Ocelot.Library.Requester
{
using System;
using Errors;
public class UnableToCompleteRequestError : Error
{
public UnableToCompleteRequestError(Exception exception)

View File

@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using Ocelot.Library.Infrastructure.Errors;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.Responder
namespace Ocelot.Library.Responder
{
using System.Collections.Generic;
using System.Linq;
using Errors;
using Responses;
public class ErrorsToHttpStatusCodeMapper : IErrorsToHttpStatusCodeMapper
{
public Response<int> Map(List<Error> errors)

View File

@ -1,9 +1,9 @@
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace Ocelot.Library.Responder
{
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace Ocelot.Library.Infrastructure.Responder
{
/// <summary>
/// Cannot unit test things in this class due to methods not being implemented
/// on .net concretes used for testing

View File

@ -0,0 +1,11 @@
namespace Ocelot.Library.Responder
{
using System.Collections.Generic;
using Errors;
using Responses;
public interface IErrorsToHttpStatusCodeMapper
{
Response<int> Map(List<Error> errors);
}
}

View File

@ -1,9 +1,9 @@
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace Ocelot.Library.Infrastructure.Responder
namespace Ocelot.Library.Responder
{
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
public interface IHttpResponder
{
Task<HttpContext> CreateResponse(HttpContext context, HttpResponseMessage response);

View File

@ -1,8 +1,8 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Errors;
namespace Ocelot.Library.Infrastructure.Responses
namespace Ocelot.Library.Responses
{
using System.Collections.Generic;
using Errors;
public class ErrorResponse : Response
{
public ErrorResponse(List<Error> errors) : base(errors)

View File

@ -1,8 +1,8 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Errors;
namespace Ocelot.Library.Infrastructure.Responses
namespace Ocelot.Library.Responses
{
using System.Collections.Generic;
using Errors;
public class ErrorResponse<T> : Response<T>
{
public ErrorResponse(List<Error> errors) : base(errors)

View File

@ -1,4 +1,4 @@
namespace Ocelot.Library.Infrastructure.Responses
namespace Ocelot.Library.Responses
{
public class OkResponse : Response
{

View File

@ -1,4 +1,4 @@
namespace Ocelot.Library.Infrastructure.Responses
namespace Ocelot.Library.Responses
{
public class OkResponse<T> : Response<T>
{

View File

@ -1,8 +1,8 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Errors;
namespace Ocelot.Library.Infrastructure.Responses
namespace Ocelot.Library.Responses
{
using System.Collections.Generic;
using Errors;
public abstract class Response
{
protected Response()

View File

@ -1,8 +1,8 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Errors;
namespace Ocelot.Library.Infrastructure.Responses
namespace Ocelot.Library.Responses
{
using System.Collections.Generic;
using Errors;
public abstract class Response<T> : Response
{
protected Response(T data)

View File

@ -1,8 +1,8 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.UrlMatcher
namespace Ocelot.Library.UrlMatcher
{
using System.Collections.Generic;
using Responses;
public interface ITemplateVariableNameAndValueFinder
{
Response<List<TemplateVariableNameAndValue>> Find(string upstreamUrlPath, string upstreamUrlPathTemplate);

View File

@ -0,0 +1,9 @@
namespace Ocelot.Library.UrlMatcher
{
using Responses;
public interface IUrlPathToUrlTemplateMatcher
{
Response<UrlMatch> Match(string upstreamUrlPath, string upstreamUrlPathTemplate);
}
}

View File

@ -1,8 +1,8 @@
using System.Text.RegularExpressions;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.UrlMatcher
namespace Ocelot.Library.UrlMatcher
{
using System.Text.RegularExpressions;
using Responses;
public class RegExUrlMatcher : IUrlPathToUrlTemplateMatcher
{
public Response<UrlMatch> Match(string upstreamUrlPath, string upstreamUrlPathTemplate)

View File

@ -1,4 +1,4 @@
namespace Ocelot.Library.Infrastructure.UrlMatcher
namespace Ocelot.Library.UrlMatcher
{
public class TemplateVariableNameAndValue
{

View File

@ -1,9 +1,9 @@
using System.Collections.Generic;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.UrlMatcher
namespace Ocelot.Library.UrlMatcher
{
public class TemplateVariableNameAndValueFinder : ITemplateVariableNameAndValueFinder
using System.Collections.Generic;
using Responses;
public class TemplateVariableNameAndValueFinder : ITemplateVariableNameAndValueFinder
{
public Response<List<TemplateVariableNameAndValue>> Find(string upstreamUrlPath, string upstreamUrlPathTemplate)
{

View File

@ -1,4 +1,4 @@
namespace Ocelot.Library.Infrastructure.UrlMatcher
namespace Ocelot.Library.UrlMatcher
{
public class UrlMatch
{

View File

@ -1,9 +1,9 @@
using System.Text;
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Responses;
namespace Ocelot.Library.Infrastructure.UrlTemplateReplacer
namespace Ocelot.Library.UrlTemplateReplacer
{
using System.Text;
using DownstreamRouteFinder;
using Responses;
public class DownstreamUrlTemplateVariableReplacer : IDownstreamUrlTemplateVariableReplacer
{
public Response<string> ReplaceTemplateVariables(DownstreamRoute downstreamRoute)

View File

@ -0,0 +1,10 @@
namespace Ocelot.Library.UrlTemplateReplacer
{
using DownstreamRouteFinder;
using Responses;
public interface IDownstreamUrlTemplateVariableReplacer
{
Response<string> ReplaceTemplateVariables(DownstreamRoute downstreamRoute);
}
}

View File

@ -1,26 +1,14 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Memory;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Ocelot.Library.Infrastructure.Authentication;
using Ocelot.Library.Infrastructure.Configuration;
using Ocelot.Library.Infrastructure.Configuration.Yaml;
using Ocelot.Library.Infrastructure.DownstreamRouteFinder;
using Ocelot.Library.Infrastructure.Middleware;
using Ocelot.Library.Infrastructure.Repository;
using Ocelot.Library.Infrastructure.RequestBuilder;
using Ocelot.Library.Infrastructure.Requester;
using Ocelot.Library.Infrastructure.Responder;
using Ocelot.Library.Infrastructure.UrlMatcher;
using Ocelot.Library.Infrastructure.UrlTemplateReplacer;
namespace Ocelot
{
using Library.DependencyInjection;
using Library.Middleware;
public class Startup
{
public Startup(IHostingEnvironment env)
@ -45,26 +33,7 @@ namespace Ocelot
services.AddMvcCore().AddAuthorization().AddJsonFormatters();
services.AddAuthentication();
services.AddLogging();
services.Configure<YamlConfiguration>(Configuration);
// Add framework services.
services.AddSingleton<IConfigurationValidator, ConfigurationValidator>();
services.AddSingleton<IOcelotConfiguration, OcelotConfiguration>();
services.AddSingleton<IUrlPathToUrlTemplateMatcher, RegExUrlMatcher>();
services.AddSingleton<ITemplateVariableNameAndValueFinder, TemplateVariableNameAndValueFinder>();
services.AddSingleton<IDownstreamUrlTemplateVariableReplacer, DownstreamUrlTemplateVariableReplacer>();
services.AddSingleton<IDownstreamRouteFinder, DownstreamRouteFinder>();
services.AddSingleton<IHttpRequester, HttpClientHttpRequester>();
services.AddSingleton<IHttpResponder, HttpContextResponder>();
services.AddSingleton<IRequestBuilder, HttpRequestBuilder>();
services.AddSingleton<IErrorsToHttpStatusCodeMapper, ErrorsToHttpStatusCodeMapper>();
services.AddSingleton<IAuthenticationHandlerFactory, AuthenticationHandlerFactory>();
services.AddSingleton<IAuthenticationHandlerCreator, AuthenticationHandlerCreator>();
// see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped<IScopedRequestDataRepository, ScopedRequestDataRepository>();
services.AddOcelot(Configuration);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -74,17 +43,7 @@ namespace Ocelot
loggerFactory.AddDebug();
app.UseHttpResponderMiddleware();
app.UseDownstreamRouteFinderMiddleware();
app.UseAuthenticationMiddleware();
app.UseDownstreamUrlCreatorMiddleware();
app.UseHttpRequestBuilderMiddleware();
app.UseHttpRequesterMiddleware();
app.UseOcelot();
}
}
}