From b18c8e5f2b0951a10608e476f614117fcae497e7 Mon Sep 17 00:00:00 2001 From: Philip Wood Date: Sat, 3 Mar 2018 13:34:19 +0000 Subject: [PATCH] Fix single-line comment spacing SA1512, SA1515 --- src/Ocelot/Configuration/File/FileConfiguration.cs | 1 + src/Ocelot/Configuration/File/FileRateLimitRule.cs | 1 + src/Ocelot/Configuration/RateLimitRule.cs | 3 ++- .../Middleware/DownstreamRouteFinderMiddleware.cs | 4 ++-- src/Ocelot/Middleware/DownstreamContext.cs | 2 -- src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs | 8 +++++--- src/Ocelot/Raft/FilePeersProvider.cs | 2 ++ src/Ocelot/Raft/SqlLiteLog.cs | 6 ++++++ .../RateLimit/Middleware/ClientRateLimitMiddleware.cs | 2 ++ src/Ocelot/RateLimit/RateLimitCore.cs | 2 ++ .../Infrastructure/HttpDataRepositoryTests.cs | 6 ++++-- 11 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Ocelot/Configuration/File/FileConfiguration.cs b/src/Ocelot/Configuration/File/FileConfiguration.cs index 6d73ce3f..e38ae6cb 100644 --- a/src/Ocelot/Configuration/File/FileConfiguration.cs +++ b/src/Ocelot/Configuration/File/FileConfiguration.cs @@ -12,6 +12,7 @@ namespace Ocelot.Configuration.File } public List ReRoutes { get; set; } + // Seperate field for aggregates because this let's you re-use ReRoutes in multiple Aggregates public List Aggregates { get;set; } public FileGlobalConfiguration GlobalConfiguration { get; set; } diff --git a/src/Ocelot/Configuration/File/FileRateLimitRule.cs b/src/Ocelot/Configuration/File/FileRateLimitRule.cs index 2dda3084..5e1616e6 100644 --- a/src/Ocelot/Configuration/File/FileRateLimitRule.cs +++ b/src/Ocelot/Configuration/File/FileRateLimitRule.cs @@ -26,6 +26,7 @@ namespace Ocelot.Configuration.File public string Period { get; set; } public double PeriodTimespan { get; set; } + /// /// Maximum number of requests that a client can make in a defined period /// diff --git a/src/Ocelot/Configuration/RateLimitRule.cs b/src/Ocelot/Configuration/RateLimitRule.cs index d77919ae..9240087c 100644 --- a/src/Ocelot/Configuration/RateLimitRule.cs +++ b/src/Ocelot/Configuration/RateLimitRule.cs @@ -17,9 +17,10 @@ namespace Ocelot.Configuration public string Period { get; private set; } public double PeriodTimespan { get; private set; } + /// /// Maximum number of requests that a client can make in a defined period /// public long Limit { get; private set; } } -} \ No newline at end of file +} diff --git a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs index e5348410..c9da50a4 100644 --- a/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs +++ b/src/Ocelot/DownstreamRouteFinder/Middleware/DownstreamRouteFinderMiddleware.cs @@ -59,8 +59,8 @@ namespace Ocelot.DownstreamRouteFinder.Middleware return; } - //todo - put this back in - // _logger.LogDebug("downstream template is {downstreamRoute.Data.ReRoute.DownstreamPath}", downstreamRoute.Data.ReRoute.DownstreamReRoute.DownstreamPathTemplate); + // todo - put this back in + //// _logger.LogDebug("downstream template is {downstreamRoute.Data.ReRoute.DownstreamPath}", downstreamRoute.Data.ReRoute.DownstreamReRoute.DownstreamPathTemplate); context.TemplatePlaceholderNameAndValues = downstreamRoute.Data.TemplatePlaceholderNameAndValues; diff --git a/src/Ocelot/Middleware/DownstreamContext.cs b/src/Ocelot/Middleware/DownstreamContext.cs index 84ebc77a..1c805deb 100644 --- a/src/Ocelot/Middleware/DownstreamContext.cs +++ b/src/Ocelot/Middleware/DownstreamContext.cs @@ -22,8 +22,6 @@ namespace Ocelot.Middleware public HttpRequestMessage DownstreamRequest { get; set; } public HttpResponseMessage DownstreamResponse { get; set; } public List Errors { get;set; } - //public string RequestId {get;set;} - //public string PreviousRequestId {get;set;} public bool IsError => Errors.Count > 0; } } diff --git a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs index 541a8e93..cda82bef 100644 --- a/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs +++ b/src/Ocelot/Middleware/OcelotMiddlewareExtensions.cs @@ -59,9 +59,11 @@ 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.. + /* + 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) => { diff --git a/src/Ocelot/Raft/FilePeersProvider.cs b/src/Ocelot/Raft/FilePeersProvider.cs index 1eddf5e3..d31dc2ca 100644 --- a/src/Ocelot/Raft/FilePeersProvider.cs +++ b/src/Ocelot/Raft/FilePeersProvider.cs @@ -27,11 +27,13 @@ namespace Ocelot.Raft _finder = finder; _options = options; _peers = new List(); + //todo - sort out async nonsense.. var config = _provider.Get().GetAwaiter().GetResult(); foreach (var item in _options.Value.Peers) { var httpClient = new HttpClient(); + //todo what if this errors? var httpPeer = new HttpPeer(item.HostAndPort, httpClient, _finder, config.Data, _identityServerConfig); _peers.Add(httpPeer); diff --git a/src/Ocelot/Raft/SqlLiteLog.cs b/src/Ocelot/Raft/SqlLiteLog.cs index 9ca32af4..aff04bf5 100644 --- a/src/Ocelot/Raft/SqlLiteLog.cs +++ b/src/Ocelot/Raft/SqlLiteLog.cs @@ -133,6 +133,7 @@ namespace Ocelot.Raft TypeNameHandling = TypeNameHandling.All }; var data = JsonConvert.SerializeObject(log, jsonSerializerSettings); + //todo - sql injection dont copy this.. var sql = $"insert into logs (data) values ('{data}')"; using(var command = new SqliteCommand(sql, connection)) @@ -157,6 +158,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var sql = $"select data from logs where id = {index};"; using(var command = new SqliteCommand(sql, connection)) @@ -187,6 +189,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var sql = $"select data from logs where id = {index}"; using(var command = new SqliteCommand(sql, connection)) @@ -211,6 +214,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var sql = $"select id, data from logs where id >= {index}"; using(var command = new SqliteCommand(sql, connection)) @@ -243,6 +247,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var sql = $"select data from logs where id = {index}"; using(var command = new SqliteCommand(sql, connection)) @@ -270,6 +275,7 @@ namespace Ocelot.Raft using(var connection = new SqliteConnection($"Data Source={_path};")) { connection.Open(); + //todo - sql injection dont copy this.. var deleteSql = $"delete from logs where id >= {indexOfCommand};"; using(var deleteCommand = new SqliteCommand(deleteSql, connection)) diff --git a/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs b/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs index 2061decc..4ceb91f8 100644 --- a/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs +++ b/src/Ocelot/RateLimit/Middleware/ClientRateLimitMiddleware.cs @@ -31,6 +31,7 @@ namespace Ocelot.RateLimit.Middleware public async Task Invoke(DownstreamContext context) { var options = context.DownstreamReRoute.RateLimitOptions; + // check if rate limiting is enabled if (!context.DownstreamReRoute.EnableEndpointEndpointRateLimiting) { @@ -66,6 +67,7 @@ namespace Ocelot.RateLimit.Middleware LogBlockedRequest(context.HttpContext, identity, counter, rule, context.DownstreamReRoute); var retrystring = retryAfter.ToString(System.Globalization.CultureInfo.InvariantCulture); + // break execution await ReturnQuotaExceededResponse(context.HttpContext, options, retrystring); diff --git a/src/Ocelot/RateLimit/RateLimitCore.cs b/src/Ocelot/RateLimit/RateLimitCore.cs index cc027dfb..82124c85 100644 --- a/src/Ocelot/RateLimit/RateLimitCore.cs +++ b/src/Ocelot/RateLimit/RateLimitCore.cs @@ -38,6 +38,7 @@ namespace Ocelot.RateLimit { // increment request count var totalRequests = entry.Value.TotalRequests + 1; + // deep copy counter = new RateLimitCounter(entry.Value.Timestamp, totalRequests); } @@ -70,6 +71,7 @@ namespace Ocelot.RateLimit { var counterId = ComputeCounterKey(requestIdentity, option); var rule = option.RateLimitRule; + // stores: id (string) - timestamp (datetime) - total_requests (long) _counterHandler.Set(counterId, counter, expirationTime); } diff --git a/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs b/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs index 407e9f47..c9f66009 100644 --- a/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs +++ b/test/Ocelot.UnitTests/Infrastructure/HttpDataRepositoryTests.cs @@ -21,8 +21,10 @@ namespace Ocelot.UnitTests.Infrastructure _httpDataRepository = new HttpDataRepository(_httpContextAccessor); } - //TODO - Additional tests -> Type mistmatch aka Add string, request int - //TODO - Additional tests -> HttpContent null. This should never happen + /* + TODO - Additional tests -> Type mistmatch aka Add string, request int + TODO - Additional tests -> HttpContent null. This should never happen + */ [Fact] public void get_returns_correct_key_from_http_context()