forked from ThreeMammals/Ocelot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/more dynamic routes (ThreeMammals#508)
* Made the file config poller use IHostedService, bit more generic, not just need to provide the correct implementations of the repo services and it will poll anything..this means we can open up redis for ThreeMammals#458 * removed comments * ThreeMammals#458 allow users to set rate limits per service for dynamic re routes * ThreeMammals#458 added docs for rate limting on dynamic reroutes
- Loading branch information
1 parent
0f2cf2d
commit b0a20d1
Showing
19 changed files
with
652 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions
18
src/Ocelot/Configuration/Creator/IRateLimitOptionsCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
using Ocelot.Configuration.File; | ||
|
||
namespace Ocelot.Configuration.Creator | ||
{ | ||
public interface IRateLimitOptionsCreator | ||
{ | ||
RateLimitOptions Create(FileReRoute fileReRoute, FileGlobalConfiguration globalConfiguration, bool enableRateLimiting); | ||
} | ||
} | ||
using Ocelot.Configuration.File; | ||
|
||
namespace Ocelot.Configuration.Creator | ||
{ | ||
public interface IRateLimitOptionsCreator | ||
{ | ||
RateLimitOptions Create(FileRateLimitRule fileRateLimitRule, FileGlobalConfiguration globalConfiguration); | ||
} | ||
} |
64 changes: 32 additions & 32 deletions
64
src/Ocelot/Configuration/Creator/RateLimitOptionsCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
using System; | ||
using Ocelot.Configuration.Builder; | ||
using Ocelot.Configuration.File; | ||
|
||
namespace Ocelot.Configuration.Creator | ||
{ | ||
public class RateLimitOptionsCreator : IRateLimitOptionsCreator | ||
{ | ||
public RateLimitOptions Create(FileReRoute fileReRoute, FileGlobalConfiguration globalConfiguration, bool enableRateLimiting) | ||
{ | ||
RateLimitOptions rateLimitOption = null; | ||
|
||
if (enableRateLimiting) | ||
{ | ||
rateLimitOption = new RateLimitOptionsBuilder() | ||
.WithClientIdHeader(globalConfiguration.RateLimitOptions.ClientIdHeader) | ||
.WithClientWhiteList(fileReRoute.RateLimitOptions.ClientWhitelist) | ||
.WithDisableRateLimitHeaders(globalConfiguration.RateLimitOptions.DisableRateLimitHeaders) | ||
.WithEnableRateLimiting(fileReRoute.RateLimitOptions.EnableRateLimiting) | ||
.WithHttpStatusCode(globalConfiguration.RateLimitOptions.HttpStatusCode) | ||
.WithQuotaExceededMessage(globalConfiguration.RateLimitOptions.QuotaExceededMessage) | ||
.WithRateLimitCounterPrefix(globalConfiguration.RateLimitOptions.RateLimitCounterPrefix) | ||
.WithRateLimitRule(new RateLimitRule(fileReRoute.RateLimitOptions.Period, | ||
fileReRoute.RateLimitOptions.PeriodTimespan, | ||
fileReRoute.RateLimitOptions.Limit)) | ||
.Build(); | ||
} | ||
|
||
return rateLimitOption; | ||
} | ||
} | ||
} | ||
using System; | ||
using Ocelot.Configuration.Builder; | ||
using Ocelot.Configuration.File; | ||
|
||
namespace Ocelot.Configuration.Creator | ||
{ | ||
public class RateLimitOptionsCreator : IRateLimitOptionsCreator | ||
{ | ||
public RateLimitOptions Create(FileRateLimitRule fileRateLimitRule, FileGlobalConfiguration globalConfiguration) | ||
{ | ||
RateLimitOptions rateLimitOption = null; | ||
|
||
if (fileRateLimitRule != null && fileRateLimitRule.EnableRateLimiting) | ||
{ | ||
rateLimitOption = new RateLimitOptionsBuilder() | ||
.WithClientIdHeader(globalConfiguration.RateLimitOptions.ClientIdHeader) | ||
.WithClientWhiteList(fileRateLimitRule.ClientWhitelist) | ||
.WithDisableRateLimitHeaders(globalConfiguration.RateLimitOptions.DisableRateLimitHeaders) | ||
.WithEnableRateLimiting(fileRateLimitRule.EnableRateLimiting) | ||
.WithHttpStatusCode(globalConfiguration.RateLimitOptions.HttpStatusCode) | ||
.WithQuotaExceededMessage(globalConfiguration.RateLimitOptions.QuotaExceededMessage) | ||
.WithRateLimitCounterPrefix(globalConfiguration.RateLimitOptions.RateLimitCounterPrefix) | ||
.WithRateLimitRule(new RateLimitRule(fileRateLimitRule.Period, | ||
fileRateLimitRule.PeriodTimespan, | ||
fileRateLimitRule.Limit)) | ||
.Build(); | ||
} | ||
|
||
return rateLimitOption; | ||
} | ||
} | ||
} |
88 changes: 44 additions & 44 deletions
88
src/Ocelot/Configuration/Creator/ReRouteOptionsCreator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
using Ocelot.Configuration.Builder; | ||
using Ocelot.Configuration.File; | ||
|
||
namespace Ocelot.Configuration.Creator | ||
{ | ||
public class ReRouteOptionsCreator : IReRouteOptionsCreator | ||
{ | ||
public ReRouteOptions Create(FileReRoute fileReRoute) | ||
{ | ||
var isAuthenticated = IsAuthenticated(fileReRoute); | ||
var isAuthorised = IsAuthorised(fileReRoute); | ||
var isCached = IsCached(fileReRoute); | ||
var enableRateLimiting = IsEnableRateLimiting(fileReRoute); | ||
|
||
var options = new ReRouteOptionsBuilder() | ||
.WithIsAuthenticated(isAuthenticated) | ||
.WithIsAuthorised(isAuthorised) | ||
.WithIsCached(isCached) | ||
.WithRateLimiting(enableRateLimiting) | ||
.Build(); | ||
|
||
return options; | ||
} | ||
|
||
private static bool IsEnableRateLimiting(FileReRoute fileReRoute) | ||
{ | ||
return (fileReRoute.RateLimitOptions != null && fileReRoute.RateLimitOptions.EnableRateLimiting) ? true : false; | ||
} | ||
|
||
private bool IsAuthenticated(FileReRoute fileReRoute) | ||
{ | ||
return !string.IsNullOrEmpty(fileReRoute.AuthenticationOptions?.AuthenticationProviderKey); | ||
} | ||
|
||
private bool IsAuthorised(FileReRoute fileReRoute) | ||
{ | ||
return fileReRoute.RouteClaimsRequirement?.Count > 0; | ||
} | ||
|
||
private bool IsCached(FileReRoute fileReRoute) | ||
{ | ||
return fileReRoute.FileCacheOptions.TtlSeconds > 0; | ||
} | ||
using Ocelot.Configuration.Builder; | ||
using Ocelot.Configuration.File; | ||
|
||
namespace Ocelot.Configuration.Creator | ||
{ | ||
public class ReRouteOptionsCreator : IReRouteOptionsCreator | ||
{ | ||
public ReRouteOptions Create(FileReRoute fileReRoute) | ||
{ | ||
var isAuthenticated = IsAuthenticated(fileReRoute); | ||
var isAuthorised = IsAuthorised(fileReRoute); | ||
var isCached = IsCached(fileReRoute); | ||
var enableRateLimiting = IsEnableRateLimiting(fileReRoute); | ||
|
||
var options = new ReRouteOptionsBuilder() | ||
.WithIsAuthenticated(isAuthenticated) | ||
.WithIsAuthorised(isAuthorised) | ||
.WithIsCached(isCached) | ||
.WithRateLimiting(enableRateLimiting) | ||
.Build(); | ||
|
||
return options; | ||
} | ||
|
||
private static bool IsEnableRateLimiting(FileReRoute fileReRoute) | ||
{ | ||
return (fileReRoute.RateLimitOptions != null && fileReRoute.RateLimitOptions.EnableRateLimiting) ? true : false; | ||
} | ||
|
||
private bool IsAuthenticated(FileReRoute fileReRoute) | ||
{ | ||
return !string.IsNullOrEmpty(fileReRoute.AuthenticationOptions?.AuthenticationProviderKey); | ||
} | ||
|
||
private bool IsAuthorised(FileReRoute fileReRoute) | ||
{ | ||
return fileReRoute.RouteClaimsRequirement?.Count > 0; | ||
} | ||
|
||
private bool IsCached(FileReRoute fileReRoute) | ||
{ | ||
return fileReRoute.FileCacheOptions.TtlSeconds > 0; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Ocelot.Configuration.File | ||
{ | ||
public class FileConfiguration | ||
{ | ||
public FileConfiguration() | ||
{ | ||
ReRoutes = new List<FileReRoute>(); | ||
GlobalConfiguration = new FileGlobalConfiguration(); | ||
Aggregates = new List<FileAggregateReRoute>(); | ||
} | ||
|
||
public List<FileReRoute> ReRoutes { get; set; } | ||
|
||
// Seperate field for aggregates because this let's you re-use ReRoutes in multiple Aggregates | ||
public List<FileAggregateReRoute> Aggregates { get;set; } | ||
public FileGlobalConfiguration GlobalConfiguration { get; set; } | ||
} | ||
} | ||
using System.Collections.Generic; | ||
|
||
namespace Ocelot.Configuration.File | ||
{ | ||
public class FileConfiguration | ||
{ | ||
public FileConfiguration() | ||
{ | ||
ReRoutes = new List<FileReRoute>(); | ||
GlobalConfiguration = new FileGlobalConfiguration(); | ||
Aggregates = new List<FileAggregateReRoute>(); | ||
DynamicReRoutes = new List<FileDynamicReRoute>(); | ||
} | ||
|
||
public List<FileReRoute> ReRoutes { get; set; } | ||
public List<FileDynamicReRoute> DynamicReRoutes { get; set; } | ||
|
||
// Seperate field for aggregates because this let's you re-use ReRoutes in multiple Aggregates | ||
public List<FileAggregateReRoute> Aggregates { get;set; } | ||
public FileGlobalConfiguration GlobalConfiguration { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Ocelot.Configuration.File | ||
{ | ||
public class FileDynamicReRoute | ||
{ | ||
public string ServiceName { get; set; } | ||
public FileRateLimitRule RateLimitRule { get; set; } | ||
} | ||
} |
Oops, something went wrong.