mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 00:58:15 +08:00
removed another pointless abstraction
This commit is contained in:
@ -1,9 +1,5 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Ocelot.Cache;
|
||||
using Ocelot.Configuration.Provider;
|
||||
|
||||
namespace Ocelot.Cache
|
||||
{
|
||||
@ -11,7 +7,7 @@ namespace Ocelot.Cache
|
||||
[Route("outputcache")]
|
||||
public class OutputCacheController : Controller
|
||||
{
|
||||
private IOcelotCache<CachedResponse> _cache;
|
||||
private readonly IOcelotCache<CachedResponse> _cache;
|
||||
|
||||
public OutputCacheController(IOcelotCache<CachedResponse> cache)
|
||||
{
|
||||
@ -26,4 +22,4 @@ namespace Ocelot.Cache
|
||||
return new NoContentResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
|
||||
|
||||
namespace Ocelot.Configuration.Authentication
|
||||
{
|
||||
public class HashMatcher : IHashMatcher
|
||||
{
|
||||
public bool Match(string password, string salt, string hash)
|
||||
{
|
||||
byte[] s = Convert.FromBase64String(salt);
|
||||
|
||||
string hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
|
||||
password: password,
|
||||
salt: s,
|
||||
prf: KeyDerivationPrf.HMACSHA256,
|
||||
iterationCount: 10000,
|
||||
numBytesRequested: 256 / 8));
|
||||
|
||||
return hashed == hash;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace Ocelot.Configuration.Authentication
|
||||
{
|
||||
public interface IHashMatcher
|
||||
{
|
||||
bool Match(string password, string salt, string hash);
|
||||
}
|
||||
}
|
@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using IdentityServer4.AccessTokenValidation;
|
||||
using IdentityServer4.Models;
|
||||
using Ocelot.Configuration.Provider;
|
||||
|
||||
namespace Ocelot.Configuration.Creator
|
||||
{
|
||||
|
@ -2,34 +2,34 @@ using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Configuration.Provider;
|
||||
using Ocelot.Configuration.Setter;
|
||||
using Ocelot.Raft;
|
||||
using Rafty.Concensus;
|
||||
|
||||
namespace Ocelot.Configuration
|
||||
{
|
||||
using Repository;
|
||||
|
||||
[Authorize]
|
||||
[Route("configuration")]
|
||||
public class FileConfigurationController : Controller
|
||||
{
|
||||
private readonly IFileConfigurationProvider _configGetter;
|
||||
private readonly IFileConfigurationSetter _configSetter;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IFileConfigurationRepository _repo;
|
||||
private readonly IFileConfigurationSetter _setter;
|
||||
private readonly IServiceProvider _provider;
|
||||
|
||||
public FileConfigurationController(IFileConfigurationProvider getFileConfig, IFileConfigurationSetter configSetter, IServiceProvider serviceProvider)
|
||||
public FileConfigurationController(IFileConfigurationRepository repo, IFileConfigurationSetter setter, IServiceProvider provider)
|
||||
{
|
||||
_configGetter = getFileConfig;
|
||||
_configSetter = configSetter;
|
||||
_serviceProvider = serviceProvider;
|
||||
_repo = repo;
|
||||
_setter = setter;
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Get()
|
||||
{
|
||||
var response = await _configGetter.Get();
|
||||
var response = await _repo.Get();
|
||||
|
||||
if(response.IsError)
|
||||
{
|
||||
@ -43,7 +43,7 @@ namespace Ocelot.Configuration
|
||||
public async Task<IActionResult> Post([FromBody]FileConfiguration fileConfiguration)
|
||||
{
|
||||
//todo - this code is a bit shit sort it out..
|
||||
var test = _serviceProvider.GetService(typeof(INode));
|
||||
var test = _provider.GetService(typeof(INode));
|
||||
if (test != null)
|
||||
{
|
||||
var node = (INode)test;
|
||||
@ -56,7 +56,7 @@ namespace Ocelot.Configuration
|
||||
return new OkObjectResult(result.Command.Configuration);
|
||||
}
|
||||
|
||||
var response = await _configSetter.Set(fileConfiguration);
|
||||
var response = await _setter.Set(fileConfiguration);
|
||||
|
||||
if (response.IsError)
|
||||
{
|
||||
|
@ -1,23 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Provider
|
||||
{
|
||||
public class FileConfigurationProvider : IFileConfigurationProvider
|
||||
{
|
||||
private readonly IFileConfigurationRepository _repo;
|
||||
|
||||
public FileConfigurationProvider(IFileConfigurationRepository repo)
|
||||
{
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
public async Task<Response<FileConfiguration>> Get()
|
||||
{
|
||||
var fileConfig = await _repo.Get();
|
||||
return new OkResponse<FileConfiguration>(fileConfig.Data);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Provider
|
||||
{
|
||||
public interface IFileConfigurationProvider
|
||||
{
|
||||
Task<Response<FileConfiguration>> Get();
|
||||
}
|
||||
}
|
@ -1,54 +1,54 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Newtonsoft.Json;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Repository
|
||||
{
|
||||
public class FileConfigurationRepository : IFileConfigurationRepository
|
||||
{
|
||||
private readonly string _configFilePath;
|
||||
|
||||
private static readonly object _lock = new object();
|
||||
|
||||
private const string ConfigurationFileName = "ocelot";
|
||||
|
||||
public FileConfigurationRepository(IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_configFilePath = $"{AppContext.BaseDirectory}/{ConfigurationFileName}{(string.IsNullOrEmpty(hostingEnvironment.EnvironmentName) ? string.Empty : ".")}{hostingEnvironment.EnvironmentName}.json";
|
||||
}
|
||||
|
||||
public Task<Response<FileConfiguration>> Get()
|
||||
{
|
||||
string jsonConfiguration;
|
||||
|
||||
lock(_lock)
|
||||
{
|
||||
jsonConfiguration = System.IO.File.ReadAllText(_configFilePath);
|
||||
}
|
||||
|
||||
var fileConfiguration = JsonConvert.DeserializeObject<FileConfiguration>(jsonConfiguration);
|
||||
|
||||
return Task.FromResult<Response<FileConfiguration>>(new OkResponse<FileConfiguration>(fileConfiguration));
|
||||
}
|
||||
|
||||
public Task<Response> Set(FileConfiguration fileConfiguration)
|
||||
{
|
||||
string jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration);
|
||||
|
||||
lock(_lock)
|
||||
{
|
||||
if (System.IO.File.Exists(_configFilePath))
|
||||
{
|
||||
System.IO.File.Delete(_configFilePath);
|
||||
}
|
||||
|
||||
System.IO.File.WriteAllText(_configFilePath, jsonConfiguration);
|
||||
}
|
||||
|
||||
return Task.FromResult<Response>(new OkResponse());
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Newtonsoft.Json;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Repository
|
||||
{
|
||||
public class DiskFileConfigurationRepository : IFileConfigurationRepository
|
||||
{
|
||||
private readonly string _configFilePath;
|
||||
|
||||
private static readonly object _lock = new object();
|
||||
|
||||
private const string ConfigurationFileName = "ocelot";
|
||||
|
||||
public DiskFileConfigurationRepository(IHostingEnvironment hostingEnvironment)
|
||||
{
|
||||
_configFilePath = $"{AppContext.BaseDirectory}/{ConfigurationFileName}{(string.IsNullOrEmpty(hostingEnvironment.EnvironmentName) ? string.Empty : ".")}{hostingEnvironment.EnvironmentName}.json";
|
||||
}
|
||||
|
||||
public Task<Response<FileConfiguration>> Get()
|
||||
{
|
||||
string jsonConfiguration;
|
||||
|
||||
lock(_lock)
|
||||
{
|
||||
jsonConfiguration = System.IO.File.ReadAllText(_configFilePath);
|
||||
}
|
||||
|
||||
var fileConfiguration = JsonConvert.DeserializeObject<FileConfiguration>(jsonConfiguration);
|
||||
|
||||
return Task.FromResult<Response<FileConfiguration>>(new OkResponse<FileConfiguration>(fileConfiguration));
|
||||
}
|
||||
|
||||
public Task<Response> Set(FileConfiguration fileConfiguration)
|
||||
{
|
||||
string jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration);
|
||||
|
||||
lock(_lock)
|
||||
{
|
||||
if (System.IO.File.Exists(_configFilePath))
|
||||
{
|
||||
System.IO.File.Delete(_configFilePath);
|
||||
}
|
||||
|
||||
System.IO.File.WriteAllText(_configFilePath, jsonConfiguration);
|
||||
}
|
||||
|
||||
return Task.FromResult<Response>(new OkResponse());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Responses;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Repository
|
||||
{
|
||||
|
@ -1,44 +1,44 @@
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Setter
|
||||
{
|
||||
public class FileConfigurationSetter : IFileConfigurationSetter
|
||||
{
|
||||
private readonly IInternalConfigurationRepository _configRepo;
|
||||
private readonly IInternalConfigurationCreator _configCreator;
|
||||
private readonly IFileConfigurationRepository _repo;
|
||||
|
||||
public FileConfigurationSetter(
|
||||
IInternalConfigurationRepository configRepo,
|
||||
IInternalConfigurationCreator configCreator,
|
||||
IFileConfigurationRepository repo)
|
||||
{
|
||||
_configRepo = configRepo;
|
||||
_configCreator = configCreator;
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
public async Task<Response> Set(FileConfiguration fileConfig)
|
||||
{
|
||||
var response = await _repo.Set(fileConfig);
|
||||
|
||||
if(response.IsError)
|
||||
{
|
||||
return new ErrorResponse(response.Errors);
|
||||
}
|
||||
|
||||
var config = await _configCreator.Create(fileConfig);
|
||||
|
||||
if(!config.IsError)
|
||||
{
|
||||
_configRepo.AddOrReplace(config.Data);
|
||||
}
|
||||
|
||||
return new ErrorResponse(config.Errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System.Threading.Tasks;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Configuration.Setter
|
||||
{
|
||||
public class FileAndInternalConfigurationSetter : IFileConfigurationSetter
|
||||
{
|
||||
private readonly IInternalConfigurationRepository _configRepo;
|
||||
private readonly IInternalConfigurationCreator _configCreator;
|
||||
private readonly IFileConfigurationRepository _repo;
|
||||
|
||||
public FileAndInternalConfigurationSetter(
|
||||
IInternalConfigurationRepository configRepo,
|
||||
IInternalConfigurationCreator configCreator,
|
||||
IFileConfigurationRepository repo)
|
||||
{
|
||||
_configRepo = configRepo;
|
||||
_configCreator = configCreator;
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
public async Task<Response> Set(FileConfiguration fileConfig)
|
||||
{
|
||||
var response = await _repo.Set(fileConfig);
|
||||
|
||||
if(response.IsError)
|
||||
{
|
||||
return new ErrorResponse(response.Errors);
|
||||
}
|
||||
|
||||
var config = await _configCreator.Create(fileConfig);
|
||||
|
||||
if(!config.IsError)
|
||||
{
|
||||
_configRepo.AddOrReplace(config.Data);
|
||||
}
|
||||
|
||||
return new ErrorResponse(config.Errors);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,11 +8,9 @@ namespace Ocelot.DependencyInjection
|
||||
using Ocelot.Authorisation;
|
||||
using Ocelot.Cache;
|
||||
using Ocelot.Claims;
|
||||
using Ocelot.Configuration.Authentication;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Configuration.Parser;
|
||||
using Ocelot.Configuration.Provider;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.Configuration.Setter;
|
||||
using Ocelot.Configuration.Validator;
|
||||
@ -40,8 +38,6 @@ namespace Ocelot.DependencyInjection
|
||||
using IdentityServer4.AccessTokenValidation;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using FileConfigurationProvider = Ocelot.Configuration.Provider.FileConfigurationProvider;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using System.Net.Http;
|
||||
using Butterfly.Client.AspNetCore;
|
||||
@ -86,9 +82,8 @@ namespace Ocelot.DependencyInjection
|
||||
_services.TryAddSingleton<IRateLimitOptionsCreator, RateLimitOptionsCreator>();
|
||||
_services.TryAddSingleton<IBaseUrlFinder, BaseUrlFinder>();
|
||||
_services.TryAddSingleton<IRegionCreator, RegionCreator>();
|
||||
_services.TryAddSingleton<IFileConfigurationRepository, FileConfigurationRepository>();
|
||||
_services.TryAddSingleton<IFileConfigurationSetter, FileConfigurationSetter>();
|
||||
_services.TryAddSingleton<IFileConfigurationProvider, FileConfigurationProvider>();
|
||||
_services.TryAddSingleton<IFileConfigurationRepository, DiskFileConfigurationRepository>();
|
||||
_services.TryAddSingleton<IFileConfigurationSetter, FileAndInternalConfigurationSetter>();
|
||||
_services.TryAddSingleton<IQosProviderHouse, QosProviderHouse>();
|
||||
_services.TryAddSingleton<IQoSProviderFactory, QoSProviderFactory>();
|
||||
_services.TryAddSingleton<IServiceDiscoveryProviderFactory, ServiceDiscoveryProviderFactory>();
|
||||
@ -287,7 +282,6 @@ namespace Ocelot.DependencyInjection
|
||||
private void AddIdentityServer(IIdentityServerConfiguration identityServerConfiguration, IAdministrationPath adminPath)
|
||||
{
|
||||
_services.TryAddSingleton<IIdentityServerConfiguration>(identityServerConfiguration);
|
||||
_services.TryAddSingleton<IHashMatcher, HashMatcher>();
|
||||
var identityServerBuilder = _services
|
||||
.AddIdentityServer(o => {
|
||||
o.IssuerUri = "Ocelot";
|
||||
|
@ -1,7 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Provider;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.DownstreamRouteFinder.Finder;
|
||||
using Ocelot.Infrastructure.Extensions;
|
||||
|
@ -1,10 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Provider;
|
||||
using Ocelot.Configuration.Repository;
|
||||
using Ocelot.Middleware;
|
||||
using Rafty.Concensus;
|
||||
|
@ -1,12 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Newtonsoft.Json;
|
||||
using Ocelot.Authentication;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Provider;
|
||||
using Ocelot.Middleware;
|
||||
using Rafty.Concensus;
|
||||
using Rafty.FiniteStateMachine;
|
||||
@ -16,13 +12,13 @@ namespace Ocelot.Raft
|
||||
[ExcludeFromCoverage]
|
||||
public class HttpPeer : IPeer
|
||||
{
|
||||
private string _hostAndPort;
|
||||
private HttpClient _httpClient;
|
||||
private JsonSerializerSettings _jsonSerializerSettings;
|
||||
private string _baseSchemeUrlAndPort;
|
||||
private readonly string _hostAndPort;
|
||||
private readonly HttpClient _httpClient;
|
||||
private readonly JsonSerializerSettings _jsonSerializerSettings;
|
||||
private readonly string _baseSchemeUrlAndPort;
|
||||
private BearerToken _token;
|
||||
private IInternalConfiguration _config;
|
||||
private IIdentityServerConfiguration _identityServerConfiguration;
|
||||
private readonly IInternalConfiguration _config;
|
||||
private readonly IIdentityServerConfiguration _identityServerConfiguration;
|
||||
|
||||
public HttpPeer(string hostAndPort, HttpClient httpClient, IBaseUrlFinder finder, IInternalConfiguration config, IIdentityServerConfiguration identityServerConfiguration)
|
||||
{
|
||||
|
Reference in New Issue
Block a user