diff --git a/.circleci/config.yml b/.circleci/config.yml
index 65fe36918a..4a5f1d9366 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -1,32 +1,32 @@
version: 2.1
orbs:
- queue: eddiewebb/queue@1.5.0
+ queue: eddiewebb/queue@2.2.1
jobs:
build:
docker:
- - image: mijitt0m/ocelot-build:0.0.3
+ - image: mijitt0m/ocelot-build:0.0.9
steps:
- checkout
- - run: make build
+ - run: dotnet tool restore && dotnet cake
release:
docker:
- - image: mijitt0m/ocelot-build:0.0.3
+ - image: mijitt0m/ocelot-build:0.0.9
steps:
- checkout
- - run: make release
+ - run: dotnet tool restore && dotnet cake --target=Release
workflows:
version: 2
- master:
+ main:
jobs:
- queue/block_workflow:
time: "20"
- only-on-branch: master
+ only-on-branch: main
- release:
requires:
- queue/block_workflow
filters:
branches:
- only: master
+ only: main
develop:
jobs:
- build:
@@ -39,5 +39,5 @@ workflows:
filters:
branches:
ignore:
- - master
+ - main
- develop
diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json
new file mode 100644
index 0000000000..ce3369c2ea
--- /dev/null
+++ b/.config/dotnet-tools.json
@@ -0,0 +1,18 @@
+{
+ "version": 1,
+ "isRoot": true,
+ "tools": {
+ "cake.tool": {
+ "version": "3.0.0",
+ "commands": [
+ "dotnet-cake"
+ ]
+ },
+ "coveralls.net": {
+ "version": "4.0.1",
+ "commands": [
+ "csmacnz.Coveralls"
+ ]
+ }
+ }
+}
\ No newline at end of file
diff --git a/.dockerignore b/.dockerignore
index 43f01f6dcc..aee45d8a2b 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -1,4 +1,5 @@
*/*/bin
*/*/obj
artifacts/
-TestResults/
\ No newline at end of file
+TestResults/
+tools/
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 4980a426c1..220172830f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -183,7 +183,7 @@ ClientBin/
*.dbmdl
*.dbproj.schemaview
*.pfx
-!idsrv3test.pfx
+!mycert.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
diff --git a/Makefile b/Makefile
deleted file mode 100644
index a83aa708ea..0000000000
--- a/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
-NAME ?= ocelot
-
-build:
- ./build.sh
-
-build_and_run_tests:
- ./build.sh --target=RunTests
-
-release:
- ./build.sh --target=Release
-
-run_acceptance_tests:
- ./build.sh --target=RunAcceptanceTests
-
-run_benchmarks:
- ./build.sh --target=RunBenchmarkTests
-
-run_unit_tests:
- ./build.sh --target=RunUnitTests
-
-release_notes:
- ./build.sh --target=ReleaseNotes
-
-
\ No newline at end of file
diff --git a/Ocelot.sln b/Ocelot.sln
index ade57b25fe..b59c188a26 100644
--- a/Ocelot.sln
+++ b/Ocelot.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.29613.14
+# Visual Studio Version 17
+VisualStudioVersion = 17.0.32112.339
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5CFB79B7-C9DC-45A4-9A75-625D92471702}"
EndProject
@@ -50,7 +50,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.Provider.Kubernetes"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{8FA0CBA0-0338-48EB-B37F-83CA5022237C}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OcelotBasic", "samples\OcelotBasic\OcelotBasic.csproj", "{ED0B3A09-112B-4BA4-82D6-11569BC7A99B}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.Samples.OcelotBasic.ApiGateway", "samples\OcelotBasic\Ocelot.Samples.OcelotBasic.ApiGateway.csproj", "{ED0B3A09-112B-4BA4-82D6-11569BC7A99B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdministrationApi", "samples\AdministrationApi\AdministrationApi.csproj", "{B180F8AE-2F8F-44F9-9E5D-FE65B84B742E}"
EndProject
@@ -64,9 +64,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DownstreamService", "sample
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "k8s", "k8s", "{4B706988-4817-43A8-ABE1-32A67998C2C8}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiGateway", "samples\OcelotKube\ApiGateway\ApiGateway.csproj", "{8500055B-2C51-4CF1-A6EE-F05BB3E9BF16}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.Samples.OcelotKube.ApiGateway", "samples\OcelotKube\ApiGateway\Ocelot.Samples.OcelotKube.ApiGateway.csproj", "{8500055B-2C51-4CF1-A6EE-F05BB3E9BF16}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DownstreamService", "samples\OcelotKube\DownstreamService\DownstreamService.csproj", "{7B319B8C-8155-4779-BD93-5ABD05CA2AB6}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.Samples.OcelotKube.DownstreamService", "samples\OcelotKube\DownstreamService\Ocelot.Samples.OcelotKube.DownstreamService.csproj", "{7B319B8C-8155-4779-BD93-5ABD05CA2AB6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "service-fabric", "service-fabric", "{B412628F-C325-47E1-A8D9-873DE04C8AF5}"
EndProject
diff --git a/README.md b/README.md
index c9ff5a61fc..bfbafbb48a 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,8 @@
-[
](https://threemammals.com/ocelot)
+
-[](https://circleci.com/gh/ThreeMammals/Ocelot/tree/master)
+[](https://circleci.com/gh/ThreeMammals/Ocelot/tree/main)
-[](https://coveralls.io/github/ThreeMammals/Ocelot?branch=master)
-
-[Slack](https://threemammals.slack.com)
+[](https://coveralls.io/github/ThreeMammals/Ocelot)
# Ocelot
@@ -13,7 +11,7 @@ that need a unified point of entry into their system. However it will work with
In particular I want easy integration with IdentityServer reference and bearer tokens.
-We have been unable to find this in my current workplacewithout having to write our own Javascript middlewares to handle the IdentityServer reference tokens. We would rather use the IdentityServer code that already existsto do this.
+We have been unable to find this in my current workplace without having to write our own Javascript middlewares to handle the IdentityServer reference tokens. We would rather use the IdentityServer code that already exists to do this.
Ocelot is a bunch of middlewares in a specific order.
@@ -43,7 +41,7 @@ A quick list of Ocelot's capabilities for more information see the [documentatio
## How to install
-Ocelot is designed to work with ASP.NET Core only and it targets `netcoreapp3.1`.
+Ocelot is designed to work with ASP.NET and it targets `net7.0`.
Install Ocelot and it's dependencies using NuGet.
@@ -81,4 +79,4 @@ If you think this project is worth supporting financially please make a contribu
## Things that are currently annoying me
-[ Get more details at **codescene.io**.](https://codescene.io/projects/697/jobs/latest-successful/results)
+[ Get more details at **codescene.io**.](https://codescene.io/projects/697/jobs/latest-successful/results)
\ No newline at end of file
diff --git a/build.cake b/build.cake
index efd9e76b15..67d1448081 100644
--- a/build.cake
+++ b/build.cake
@@ -1,11 +1,9 @@
-#tool "nuget:?package=GitVersion.CommandLine&version=5.0.1"
-#addin nuget:?package=Cake.Json
+#tool "dotnet:?package=GitVersion.Tool&version=5.8.1"
+#tool "dotnet:?package=coveralls.net&version=4.0.1"
#addin nuget:?package=Newtonsoft.Json
-#addin nuget:?package=System.Net.Http&version=4.3.4
#addin nuget:?package=System.Text.Encodings.Web&version=4.7.1
-#tool "nuget:?package=ReportGenerator"
-#tool "nuget:?package=coveralls.net&version=0.7.0"
-#addin Cake.Coveralls&version=0.10.1
+#tool "nuget:?package=ReportGenerator&version=5.1.19"
+#addin Cake.Coveralls&version=1.1.0
// compile
var compileConfig = Argument("configuration", "Release");
@@ -82,12 +80,12 @@ Task("Compile")
.IsDependentOn("Version")
.Does(() =>
{
- var settings = new DotNetCoreBuildSettings
+ var settings = new DotNetBuildSettings
{
Configuration = compileConfig,
};
- DotNetCoreBuild(slnFile, settings);
+ DotNetBuild(slnFile, settings);
});
Task("Clean")
@@ -95,7 +93,10 @@ Task("Clean")
{
if (DirectoryExists(artifactsDir))
{
- DeleteDirectory(artifactsDir, recursive:true);
+ DeleteDirectory(artifactsDir, new DeleteDirectorySettings {
+ Recursive = true,
+ Force = true
+ });
}
CreateDirectory(artifactsDir);
});
@@ -176,7 +177,7 @@ Task("RunUnitTests")
.IsDependentOn("Compile")
.Does(() =>
{
- var testSettings = new DotNetCoreTestSettings
+ var testSettings = new DotNetTestSettings
{
Configuration = compileConfig,
ResultsDirectory = artifactsForUnitTestsDir,
@@ -186,17 +187,15 @@ Task("RunUnitTests")
};
EnsureDirectoryExists(artifactsForUnitTestsDir);
- DotNetCoreTest(unitTestAssemblies, testSettings);
+ DotNetTest(unitTestAssemblies, testSettings);
var coverageSummaryFile = GetSubDirectories(artifactsForUnitTestsDir).First().CombineWithFilePath(File("coverage.cobertura.xml"));
Information(coverageSummaryFile);
Information(artifactsForUnitTestsDir);
- // todo bring back report generator to get a friendly report
- // ReportGenerator(coverageSummaryFile, artifactsForUnitTestsDir);
- // https://github.com/danielpalme/ReportGenerator
+ GenerateReport(coverageSummaryFile);
- if (IsRunningOnCircleCI() && IsMaster())
+ if (IsRunningOnCircleCI() && IsMainOrDevelop())
{
var repoToken = EnvironmentVariable(coverallsRepoToken);
if (string.IsNullOrEmpty(repoToken))
@@ -231,7 +230,7 @@ Task("RunAcceptanceTests")
.IsDependentOn("Compile")
.Does(() =>
{
- var settings = new DotNetCoreTestSettings
+ var settings = new DotNetTestSettings
{
Configuration = compileConfig,
ArgumentCustomization = args => args
@@ -240,14 +239,14 @@ Task("RunAcceptanceTests")
};
EnsureDirectoryExists(artifactsForAcceptanceTestsDir);
- DotNetCoreTest(acceptanceTestAssemblies, settings);
+ DotNetTest(acceptanceTestAssemblies, settings);
});
Task("RunIntegrationTests")
.IsDependentOn("Compile")
.Does(() =>
{
- var settings = new DotNetCoreTestSettings
+ var settings = new DotNetTestSettings
{
Configuration = compileConfig,
ArgumentCustomization = args => args
@@ -256,7 +255,7 @@ Task("RunIntegrationTests")
};
EnsureDirectoryExists(artifactsForIntegrationTestsDir);
- DotNetCoreTest(integrationTestAssemblies, settings);
+ DotNetTest(integrationTestAssemblies, settings);
});
Task("CreateArtifacts")
@@ -364,6 +363,21 @@ Task("PublishToNuget")
RunTarget(target);
+private void GenerateReport(Cake.Core.IO.FilePath coverageSummaryFile)
+{
+ var dir = System.IO.Directory.GetCurrentDirectory();
+ Information(dir);
+
+ var reportSettings = new ProcessArgumentBuilder();
+ reportSettings.Append($"-targetdir:" + $"{dir}/{artifactsForUnitTestsDir}");
+ reportSettings.Append($"-reports:" + coverageSummaryFile);
+
+ var toolpath = Context.Tools.Resolve("net7.0/ReportGenerator.dll");
+ Information($"Tool Path : {toolpath.ToString()}");
+
+ DotNetExecute(toolpath, reportSettings);
+}
+
/// Gets unique nuget version for this commit
private GitVersion GetNuGetVersionForCommit()
{
@@ -416,9 +430,9 @@ private void PublishPackages(ConvertableDirectoryPath packagesDir, ConvertableFi
Information("Calling NuGetPush");
- NuGetPush(
+ DotNetNuGetPush(
codePackage,
- new NuGetPushSettings {
+ new DotNetNuGetPushSettings {
ApiKey = feedApiKey,
Source = codeFeedUrl
});
@@ -427,7 +441,7 @@ private void PublishPackages(ConvertableDirectoryPath packagesDir, ConvertableFi
private void CreateGitHubRelease()
{
- var json = $"{{ \"tag_name\": \"{versioning.NuGetVersion}\", \"target_commitish\": \"master\", \"name\": \"{versioning.NuGetVersion}\", \"body\": \"{ReleaseNotesAsJson()}\", \"draft\": true, \"prerelease\": true }}";
+ var json = $"{{ \"tag_name\": \"{versioning.NuGetVersion}\", \"target_commitish\": \"main\", \"name\": \"{versioning.NuGetVersion}\", \"body\": \"{ReleaseNotesAsJson()}\", \"draft\": true, \"prerelease\": true }}";
var content = new System.Net.Http.StringContent(json, System.Text.Encoding.UTF8, "application/json");
@@ -483,7 +497,7 @@ private void UploadFileToGitHubRelease(FilePath file)
private void CompleteGitHubRelease()
{
- var json = $"{{ \"tag_name\": \"{versioning.NuGetVersion}\", \"target_commitish\": \"master\", \"name\": \"{versioning.NuGetVersion}\", \"body\": \"{ReleaseNotesAsJson()}\", \"draft\": false, \"prerelease\": false }}";
+ var json = $"{{ \"tag_name\": \"{versioning.NuGetVersion}\", \"target_commitish\": \"main\", \"name\": \"{versioning.NuGetVersion}\", \"body\": \"{ReleaseNotesAsJson()}\", \"draft\": false, \"prerelease\": false }}";
var request = new System.Net.Http.HttpRequestMessage(new System.Net.Http.HttpMethod("Patch"), $"https://api.github.com/repos/ThreeMammals/Ocelot/releases/{releaseId}");
request.Content = new System.Net.Http.StringContent(json, System.Text.Encoding.UTF8, "application/json");
@@ -541,7 +555,19 @@ private bool IsRunningOnCircleCI()
return !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("CIRCLECI"));
}
-private bool IsMaster()
+private bool IsMainOrDevelop()
{
- return Environment.GetEnvironmentVariable("CIRCLE_BRANCH").ToLower() == "master";
+ var env = Environment.GetEnvironmentVariable("CIRCLE_BRANCH").ToLower();
+
+ if(env == "main")
+ {
+ return true;
+ }
+
+ if(env == "develop")
+ {
+ return true;
+ }
+
+ return false;
}
\ No newline at end of file
diff --git a/build.ps1 b/build.ps1
deleted file mode 100644
index a336e2985c..0000000000
--- a/build.ps1
+++ /dev/null
@@ -1,256 +0,0 @@
-##########################################################################
-# This is the Cake bootstrapper script for PowerShell.
-# This file was downloaded from https://github.com/cake-build/resources
-# Feel free to change this file to fit your needs.
-##########################################################################
-
-<#
-
-.SYNOPSIS
-This is a Powershell script to bootstrap a Cake build.
-
-.DESCRIPTION
-This Powershell script will download NuGet if missing, restore NuGet tools (including Cake)
-and execute your Cake build script with the parameters you provide.
-
-.PARAMETER Script
-The build script to execute.
-.PARAMETER Target
-The build script target to run.
-.PARAMETER Configuration
-The build configuration to use.
-.PARAMETER Verbosity
-Specifies the amount of information to be displayed.
-.PARAMETER ShowDescription
-Shows description about tasks.
-.PARAMETER DryRun
-Performs a dry run.
-.PARAMETER SkipToolPackageRestore
-Skips restoring of packages.
-.PARAMETER ScriptArgs
-Remaining arguments are added here.
-
-.LINK
-https://cakebuild.net
-
-#>
-
-[CmdletBinding()]
-Param(
- [string]$Script = "build.cake",
- [string]$Target,
- [string]$Configuration,
- [ValidateSet("Quiet", "Minimal", "Normal", "Verbose", "Diagnostic")]
- [string]$Verbosity,
- [switch]$ShowDescription,
- [Alias("WhatIf", "Noop")]
- [switch]$DryRun,
- [switch]$SkipToolPackageRestore,
- [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
- [string[]]$ScriptArgs
-)
-
-# Attempt to set highest encryption available for SecurityProtocol.
-# PowerShell will not set this by default (until maybe .NET 4.6.x). This
-# will typically produce a message for PowerShell v2 (just an info
-# message though)
-try {
- # Set TLS 1.2 (3072), then TLS 1.1 (768), then TLS 1.0 (192), finally SSL 3.0 (48)
- # Use integers because the enumeration values for TLS 1.2 and TLS 1.1 won't
- # exist in .NET 4.0, even though they are addressable if .NET 4.5+ is
- # installed (.NET 4.5 is an in-place upgrade).
- # PowerShell Core already has support for TLS 1.2 so we can skip this if running in that.
- if (-not $IsCoreCLR) {
- [System.Net.ServicePointManager]::SecurityProtocol = 3072 -bor 768 -bor 192 -bor 48
- }
- } catch {
- Write-Output 'Unable to set PowerShell to use TLS 1.2 and TLS 1.1 due to old .NET Framework installed. If you see underlying connection closed or trust errors, you may need to upgrade to .NET Framework 4.5+ and PowerShell v3'
- }
-
-[Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null
-function MD5HashFile([string] $filePath)
-{
- if ([string]::IsNullOrEmpty($filePath) -or !(Test-Path $filePath -PathType Leaf))
- {
- return $null
- }
-
- [System.IO.Stream] $file = $null;
- [System.Security.Cryptography.MD5] $md5 = $null;
- try
- {
- $md5 = [System.Security.Cryptography.MD5]::Create()
- $file = [System.IO.File]::OpenRead($filePath)
- return [System.BitConverter]::ToString($md5.ComputeHash($file))
- }
- finally
- {
- if ($file -ne $null)
- {
- $file.Dispose()
- }
- }
-}
-
-function GetProxyEnabledWebClient
-{
- $wc = New-Object System.Net.WebClient
- $proxy = [System.Net.WebRequest]::GetSystemWebProxy()
- $proxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
- $wc.Proxy = $proxy
- return $wc
-}
-
-Write-Host "Preparing to run build script..."
-
-if(!$PSScriptRoot){
- $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
-}
-
-$TOOLS_DIR = Join-Path $PSScriptRoot "tools"
-$ADDINS_DIR = Join-Path $TOOLS_DIR "Addins"
-$MODULES_DIR = Join-Path $TOOLS_DIR "Modules"
-$NUGET_EXE = Join-Path $TOOLS_DIR "nuget.exe"
-$CAKE_EXE = Join-Path $TOOLS_DIR "Cake/Cake.exe"
-$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
-$PACKAGES_CONFIG = Join-Path $TOOLS_DIR "packages.config"
-$PACKAGES_CONFIG_MD5 = Join-Path $TOOLS_DIR "packages.config.md5sum"
-$ADDINS_PACKAGES_CONFIG = Join-Path $ADDINS_DIR "packages.config"
-$MODULES_PACKAGES_CONFIG = Join-Path $MODULES_DIR "packages.config"
-
-# Make sure tools folder exists
-if ((Test-Path $PSScriptRoot) -and !(Test-Path $TOOLS_DIR)) {
- Write-Verbose -Message "Creating tools directory..."
- New-Item -Path $TOOLS_DIR -Type Directory | Out-Null
-}
-
-# Make sure that packages.config exist.
-if (!(Test-Path $PACKAGES_CONFIG)) {
- Write-Verbose -Message "Downloading packages.config..."
- try {
- $wc = GetProxyEnabledWebClient
- $wc.DownloadFile("https://cakebuild.net/download/bootstrapper/packages", $PACKAGES_CONFIG)
- } catch {
- Throw "Could not download packages.config."
- }
-}
-
-# Try find NuGet.exe in path if not exists
-if (!(Test-Path $NUGET_EXE)) {
- Write-Verbose -Message "Trying to find nuget.exe in PATH..."
- $existingPaths = $Env:Path -Split ';' | Where-Object { (![string]::IsNullOrEmpty($_)) -and (Test-Path $_ -PathType Container) }
- $NUGET_EXE_IN_PATH = Get-ChildItem -Path $existingPaths -Filter "nuget.exe" | Select -First 1
- if ($NUGET_EXE_IN_PATH -ne $null -and (Test-Path $NUGET_EXE_IN_PATH.FullName)) {
- Write-Verbose -Message "Found in PATH at $($NUGET_EXE_IN_PATH.FullName)."
- $NUGET_EXE = $NUGET_EXE_IN_PATH.FullName
- }
-}
-
-# Try download NuGet.exe if not exists
-if (!(Test-Path $NUGET_EXE)) {
- Write-Verbose -Message "Downloading NuGet.exe..."
- try {
- $wc = GetProxyEnabledWebClient
- $wc.DownloadFile($NUGET_URL, $NUGET_EXE)
- } catch {
- Throw "Could not download NuGet.exe."
- }
-}
-
-# Save nuget.exe path to environment to be available to child processed
-$env:NUGET_EXE = $NUGET_EXE
-$env:NUGET_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) {
- "mono `"$NUGET_EXE`""
-} else {
- "`"$NUGET_EXE`""
-}
-
-# Restore tools from NuGet?
-if(-Not $SkipToolPackageRestore.IsPresent) {
- Push-Location
- Set-Location $TOOLS_DIR
-
- # Check for changes in packages.config and remove installed tools if true.
- [string] $md5Hash = MD5HashFile $PACKAGES_CONFIG
- if((!(Test-Path $PACKAGES_CONFIG_MD5)) -Or
- ($md5Hash -ne (Get-Content $PACKAGES_CONFIG_MD5 ))) {
- Write-Verbose -Message "Missing or changed package.config hash..."
- Get-ChildItem -Exclude packages.config,nuget.exe,Cake.Bakery |
- Remove-Item -Recurse -Force
- }
-
- Write-Verbose -Message "Restoring tools from NuGet..."
-
- $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$TOOLS_DIR`""
-
- if ($LASTEXITCODE -ne 0) {
- Throw "An error occurred while restoring NuGet tools."
- }
- else
- {
- $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
- }
- Write-Verbose -Message ($NuGetOutput | Out-String)
-
- Pop-Location
-}
-
-# Restore addins from NuGet
-if (Test-Path $ADDINS_PACKAGES_CONFIG) {
- Push-Location
- Set-Location $ADDINS_DIR
-
- Write-Verbose -Message "Restoring addins from NuGet..."
- $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$ADDINS_DIR`""
-
- if ($LASTEXITCODE -ne 0) {
- Throw "An error occurred while restoring NuGet addins."
- }
-
- Write-Verbose -Message ($NuGetOutput | Out-String)
-
- Pop-Location
-}
-
-# Restore modules from NuGet
-if (Test-Path $MODULES_PACKAGES_CONFIG) {
- Push-Location
- Set-Location $MODULES_DIR
-
- Write-Verbose -Message "Restoring modules from NuGet..."
- $NuGetOutput = Invoke-Expression "& $env:NUGET_EXE_INVOCATION install -ExcludeVersion -OutputDirectory `"$MODULES_DIR`""
-
- if ($LASTEXITCODE -ne 0) {
- Throw "An error occurred while restoring NuGet modules."
- }
-
- Write-Verbose -Message ($NuGetOutput | Out-String)
-
- Pop-Location
-}
-
-# Make sure that Cake has been installed.
-if (!(Test-Path $CAKE_EXE)) {
- Throw "Could not find Cake.exe at $CAKE_EXE"
-}
-
-$CAKE_EXE_INVOCATION = if ($IsLinux -or $IsMacOS) {
- "mono `"$CAKE_EXE`""
-} else {
- "`"$CAKE_EXE`""
-}
-
- # Build an array (not a string) of Cake arguments to be joined later
-$cakeArguments = @()
-if ($Script) { $cakeArguments += "`"$Script`"" }
-if ($Target) { $cakeArguments += "-target=`"$Target`"" }
-if ($Configuration) { $cakeArguments += "-configuration=$Configuration" }
-if ($Verbosity) { $cakeArguments += "-verbosity=$Verbosity" }
-if ($ShowDescription) { $cakeArguments += "-showdescription" }
-if ($DryRun) { $cakeArguments += "-dryrun" }
-$cakeArguments += $ScriptArgs
-
-# Start Cake
-Write-Host "Running build script..."
-Invoke-Expression "& $CAKE_EXE_INVOCATION $($cakeArguments -join " ")"
-exit $LASTEXITCODE
diff --git a/build.sh b/build.sh
deleted file mode 100755
index b9e12527f1..0000000000
--- a/build.sh
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/usr/bin/env bash
-
-##########################################################################
-# This is the Cake bootstrapper script for Linux and OS X.
-# This file was downloaded from https://github.com/cake-build/resources
-# Feel free to change this file to fit your needs.
-##########################################################################
-
-# Define directories.
-SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
-TOOLS_DIR=$SCRIPT_DIR/tools
-ADDINS_DIR=$TOOLS_DIR/Addins
-MODULES_DIR=$TOOLS_DIR/Modules
-NUGET_EXE=$TOOLS_DIR/nuget.exe
-CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe
-PACKAGES_CONFIG=$TOOLS_DIR/packages.config
-PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum
-ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config
-MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config
-
-# Define md5sum or md5 depending on Linux/OSX
-MD5_EXE=
-if [[ "$(uname -s)" == "Darwin" ]]; then
- MD5_EXE="md5 -r"
-else
- MD5_EXE="md5sum"
-fi
-
-# Define default arguments.
-SCRIPT="build.cake"
-CAKE_ARGUMENTS=()
-
-# Parse arguments.
-for i in "$@"; do
- case $1 in
- -s|--script) SCRIPT="$2"; shift ;;
- --) shift; CAKE_ARGUMENTS+=("$@"); break ;;
- *) CAKE_ARGUMENTS+=("$1") ;;
- esac
- shift
-done
-
-# Make sure the tools folder exist.
-if [ ! -d "$TOOLS_DIR" ]; then
- mkdir "$TOOLS_DIR"
-fi
-
-# Make sure that packages.config exist.
-if [ ! -f "$TOOLS_DIR/packages.config" ]; then
- echo "Downloading packages.config..."
- curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages
- if [ $? -ne 0 ]; then
- echo "An error occurred while downloading packages.config."
- exit 1
- fi
-fi
-
-# Download NuGet if it does not exist.
-if [ ! -f "$NUGET_EXE" ]; then
- echo "Downloading NuGet..."
- curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
- if [ $? -ne 0 ]; then
- echo "An error occurred while downloading nuget.exe."
- exit 1
- fi
-fi
-
-# Restore tools from NuGet.
-pushd "$TOOLS_DIR" >/dev/null
-if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then
- find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf
-fi
-
-mono "$NUGET_EXE" install -ExcludeVersion
-if [ $? -ne 0 ]; then
- echo "Could not restore NuGet tools."
- exit 1
-fi
-
-$MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5"
-
-popd >/dev/null
-
-# Restore addins from NuGet.
-if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then
- pushd "$ADDINS_DIR" >/dev/null
-
- mono "$NUGET_EXE" install -ExcludeVersion
- if [ $? -ne 0 ]; then
- echo "Could not restore NuGet addins."
- exit 1
- fi
-
- popd >/dev/null
-fi
-
-# Restore modules from NuGet.
-if [ -f "$MODULES_PACKAGES_CONFIG" ]; then
- pushd "$MODULES_DIR" >/dev/null
-
- mono "$NUGET_EXE" install -ExcludeVersion
- if [ $? -ne 0 ]; then
- echo "Could not restore NuGet modules."
- exit 1
- fi
-
- popd >/dev/null
-fi
-
-# Make sure that Cake has been installed.
-if [ ! -f "$CAKE_EXE" ]; then
- echo "Could not find Cake.exe at '$CAKE_EXE'."
- exit 1
-fi
-
-# Start Cake
-exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}"
diff --git a/codeanalysis.ruleset b/codeanalysis.ruleset
index 4b278ba80a..0198bd195d 100644
--- a/codeanalysis.ruleset
+++ b/codeanalysis.ruleset
@@ -1,5 +1,5 @@
-
+
@@ -50,12 +50,11 @@
-
+
-
@@ -70,14 +69,14 @@
-
+
-
+
diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base
index cc6798c375..691339490a 100644
--- a/docker/Dockerfile.base
+++ b/docker/Dockerfile.base
@@ -1,16 +1,9 @@
-# this is the dockerfile that create the ocelot build container
-# build with the docker-build.sh file in this folder
-FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS build
+FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine
-RUN apt install gnupg ca-certificates
-RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
-RUN echo "deb https://download.mono-project.com/repo/ubuntu stable-bionic main" | tee /etc/apt/sources.list.d/mono-official-stable.list
-RUN apt update
-RUN apt-get -y install mono-devel
+RUN apk add bash icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib git openssh-client
-RUN wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb \
- && dpkg -i packages-microsoft-prod.deb \
- && apt-get update; \
- apt-get install -y apt-transport-https && \
- apt-get update && \
- apt-get install -y dotnet-sdk-5.0
\ No newline at end of file
+RUN curl -L --output ./dotnet-install.sh https://dot.net/v1/dotnet-install.sh
+
+RUN chmod u+x ./dotnet-install.sh
+
+RUN ./dotnet-install.sh -c 6.0 -i /usr/share/dotnet
diff --git a/docker/Dockerfile.build b/docker/Dockerfile.build
index 4b99c053cf..5498c6106a 100644
--- a/docker/Dockerfile.build
+++ b/docker/Dockerfile.build
@@ -1,15 +1,16 @@
# call from ocelot repo root with
-# docker build --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
-FROM mijitt0m/ocelot-build:0.0.3
+# docker build --platform linux/arm64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
+# docker build --platform linux/amd64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
+FROM mijitt0m/ocelot-build:0.0.9
ARG OCELOT_COVERALLS_TOKEN
ENV OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN
-WORKDIR /src
+WORKDIR /build
COPY ./. .
-RUN chmod u+x build.sh
+RUN dotnet tool restore
-RUN make build
+RUN dotnet cake
\ No newline at end of file
diff --git a/docker/Dockerfile.release b/docker/Dockerfile.release
index 0ce0e95eac..e2659c035e 100644
--- a/docker/Dockerfile.release
+++ b/docker/Dockerfile.release
@@ -1,7 +1,7 @@
# call from ocelot repo root with
-# docker build --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN --build-arg OCELOT_GITHUB_API_KEY=$OCELOT_GITHUB_API_KEY --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.release .
-
-FROM mijitt0m/ocelot-build:0.0.3
+# docker build --platform linux/arm64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN --build-arg OCELOT_GITHUB_API_KEY=$OCELOT_GITHUB_API_KEY --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
+# docker build --platform linux/amd64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN --build-arg OCELOT_GITHUB_API_KEY=$OCELOT_GITHUB_API_KEY --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
+FROM mijitt0m/ocelot-build:0.0.9
ARG OCELOT_COVERALLS_TOKEN
ARG OCELOT_NUTGET_API_KEY
@@ -11,10 +11,10 @@ ENV OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN
ENV OCELOT_NUTGET_API_KEY=$OCELOT_NUTGET_API_KEY
ENV OCELOT_GITHUB_API_KEY=$OCELOT_GITHUB_API_KEY
-WORKDIR /src
+WORKDIR /build
COPY ./. .
-RUN chmod u+x build.sh
+RUN dotnet tool restore
-RUN make release
+RUN dotnet cake
\ No newline at end of file
diff --git a/docker/docker-build.sh b/docker/build.sh
similarity index 60%
rename from docker/docker-build.sh
rename to docker/build.sh
index d2d639347f..bf2cee9b54 100755
--- a/docker/docker-build.sh
+++ b/docker/build.sh
@@ -1,7 +1,7 @@
# this script build the ocelot docker file
-version=0.0.3
-docker build -t mijitt0m/ocelot-build -f Dockerfile.base .
+version=0.0.9
+docker build --platform linux/amd64 -t mijitt0m/ocelot-build -f Dockerfile.base .
echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
docker tag mijitt0m/ocelot-build mijitt0m/ocelot-build:$version
docker push mijitt0m/ocelot-build:latest
-docker push mijitt0m/ocelot-build:$version
+docker push mijitt0m/ocelot-build:$version
\ No newline at end of file
diff --git a/docs/building/building.rst b/docs/building/building.rst
index 0a494f9f00..4544eccd97 100644
--- a/docs/building/building.rst
+++ b/docs/building/building.rst
@@ -1,10 +1,10 @@
Building
========
-* The best way to build Ocelot is using the Dockerfile.build file which can be found in the docker folder in Ocelot root. Use the following command `docker build -f ./docker/Dockerfile.build .`.
+* You can also just run `dotnet tool restore && dotnet cake` locally!. Output will got to the `./artifacts` directory.
-* You'll can run the `./build.ps1` or `./build.sh` script depending on your OS. This will compile, run unit and acceptance tests and build the output packages locally. Output will got to the `./artifacts` directory.
+* The best way to replicate the CI process is to build Ocelot locally is using the Dockerfile.build file which can be found in the docker folder in Ocelot root. Use the following command `docker build --platform linux/amd64 -f ./docker/Dockerfile.build .` for example. You will need to change the platform flag depending on your platform.
* There is a Makefile to make it easier to call the various targers in `build.cake`. The scripts are called with .sh but can be easily changed to ps1 if you are using Windows.
-* Alternatively you can build the project in VS2019 with the latest .NET Core SDK.
\ No newline at end of file
+* Alternatively you can build the project in VS2022 with the latest .NET 7.0 SDK.
\ No newline at end of file
diff --git a/docs/building/releaseprocess.rst b/docs/building/releaseprocess.rst
index 7a89a1f074..40da815673 100644
--- a/docs/building/releaseprocess.rst
+++ b/docs/building/releaseprocess.rst
@@ -2,7 +2,7 @@ Release process
===============
* The release process works best with Git Flow branching.
-* Contributors can do whatever they want on PRs and merges to master will result in packages being released to GitHub and NuGet.
+* Contributors can do whatever they want on PRs and merges to main will result in packages being released to GitHub and NuGet.
Ocelot uses the following process to accept work into the NuGet packages.
@@ -25,7 +25,7 @@ In order for a PR to be merged the following must have occured.
5. After the PR is merged to develop the Ocelot NuGet packages will not be updated until a release is created.
-6. When enough work has been completed to justify a new release. Develop will be merged into master the release process will begin which builds the code, versions it, pushes artifacts to GitHub and NuGet packages to NuGet.
+6. When enough work has been completed to justify a new release. Develop will be merged into main the release process will begin which builds the code, versions it, pushes artifacts to GitHub and NuGet packages to NuGet.
7. The final step is to go back to GitHub and close any issues that are now fixed. You should see something like this in`GitHub `_ and this in `NuGet `_.
@@ -34,4 +34,4 @@ Notes
All NuGet package builds & releases are done with CircleCI `here _` and all releases are done from `here _`.
-Only TomPallister can merge releases into master at the moment. This is to ensure there is a final quality gate in place. Tom is mainly looking for security issues on the final merge.
+Only TomPallister can merge releases into main at the moment. This is to ensure there is a final quality gate in place. Tom is mainly looking for security issues on the final merge.
diff --git a/docs/building/tests.rst b/docs/building/tests.rst
index d1fc8aba78..c21e91cfd8 100644
--- a/docs/building/tests.rst
+++ b/docs/building/tests.rst
@@ -1,24 +1,18 @@
Tests
=====
-The tests should all just run and work apart from the integration tests which need the following
-environmental variables setting. This is a manual step at the moment.
+The tests should all just run and work as part of the build process. You can of course also run them in visual studio.
- ``OCELOT_USERNAME=admin``
- ``OCELOT_HASH=kE/mxd1hO9h9Sl2VhGhwJUd9xZEv4NP6qXoN39nIqM4=``
+Create SSL Cert for Testing
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
- ``OCELOT_SALT=zzWITpnDximUNKYLiUam/w==``
+You can do this via openssl:
-On windows you can use..
-
- ``SETX OCELOT_USERNAME admin``
-
-On mac..
-
- ``export OCELOT_USERNAME=admin``
-
-I need to work out a nicer way of doing this in the future.
+Install openssl package (if you are using Windows, download binaries here).
+Generate private key: `openssl genrsa 2048 > private.pem`
+Generate the self signed certificate: `openssl req -x509 -days 1000 -new -key private.pem -out public.pem`
+If needed, create PFX: `openssl pkcs12 -export -in public.pem -inkey private.pem -out mycert.pfx`
\ No newline at end of file
diff --git a/docs/features/caching.rst b/docs/features/caching.rst
index 9f3368a632..f6c2a7fd2a 100644
--- a/docs/features/caching.rst
+++ b/docs/features/caching.rst
@@ -29,7 +29,7 @@ Finally in order to use caching on a route in your Route configuration add this
In this example ttl seconds is set to 15 which means the cache will expire after 15 seconds.
-If you look at the example `here `_ you can see how the cache manager is setup and then passed into the Ocelot AddCacheManager configuration method. You can use any settings supported by the CacheManager package and just pass them in.
+If you look at the example `here `_ you can see how the cache manager is setup and then passed into the Ocelot AddCacheManager configuration method. You can use any settings supported by the CacheManager package and just pass them in.
Anyway Ocelot currently supports caching on the URL of the downstream service and setting a TTL in seconds to expire the cache. You can also clear the cache for a region by calling Ocelot's administration API.
diff --git a/docs/features/configuration.rst b/docs/features/configuration.rst
index b931032ac5..d41b05a88f 100644
--- a/docs/features/configuration.rst
+++ b/docs/features/configuration.rst
@@ -1,7 +1,7 @@
Configuration
============
-An example configuration can be found `here `_. There are two sections to the configuration. An array of Routes and a GlobalConfiguration. The Routes are the objects that tell Ocelot how to treat an upstream request. The Global configuration is a bit hacky and allows overrides of Route specific settings. It's useful if you don't want to manage lots of Route specific settings.
+An example configuration can be found `here `_. There are two sections to the configuration. An array of Routes and a GlobalConfiguration. The Routes are the objects that tell Ocelot how to treat an upstream request. The Global configuration is a bit hacky and allows overrides of Route specific settings. It's useful if you don't want to manage lots of Route specific settings.
.. code-block:: json
diff --git a/docs/features/graphql.rst b/docs/features/graphql.rst
index df0b2b00a9..5c74c0564a 100644
--- a/docs/features/graphql.rst
+++ b/docs/features/graphql.rst
@@ -4,7 +4,7 @@ GraphQL
OK you got me Ocelot doesn't directly support GraphQL but so many people have asked about it I wanted to show how easy it is to integrate the `graphql-dotnet `_ library.
-Please see the sample project `OcelotGraphQL `_. Using a combination of the graphql-dotnet project and Ocelot's DelegatingHandler features this is pretty easy to do.
+Please see the sample project `OcelotGraphQL `_. Using a combination of the graphql-dotnet project and Ocelot's DelegatingHandler features this is pretty easy to do.
However I do not intend to integrate more closely with GraphQL at the moment. Check out the samples readme and that should give you enough instruction on how to do this!
Good luck and have fun :>
diff --git a/docs/index.rst b/docs/index.rst
index 983d247158..8df5b21c46 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -12,7 +12,8 @@ Thanks for taking a look at the Ocelot documentation. Please use the left hand n
introduction/gettingstarted
introduction/contributing
introduction/notsupported
-
+ introduction/gotchas
+
.. toctree::
:maxdepth: 2
:hidden:
diff --git a/docs/introduction/gettingstarted.rst b/docs/introduction/gettingstarted.rst
index c223620176..e29983b333 100644
--- a/docs/introduction/gettingstarted.rst
+++ b/docs/introduction/gettingstarted.rst
@@ -1,14 +1,14 @@
Getting Started
===============
-Ocelot is designed to work with .NET Core only and is currently on netcoreapp3.1.
+Ocelot is designed to work with ASP.NET and is currently on net6.0.
-.NET Core 3.1
-^^^^^^^^^^^^^
+.NET 7.0
+^^^^^^^^
**Install NuGet package**
-Install Ocelot and it's dependencies using nuget. You will need to create a netcoreapp3.1 project and bring the package into it. Then follow the Startup below and :doc:`../features/configuration` sections
+Install Ocelot and it's dependencies using nuget. You will need to create a net6.0 project and bring the package into it. Then follow the Startup below and :doc:`../features/configuration` sections
to get up and running.
``Install-Package Ocelot``
@@ -103,87 +103,4 @@ Then in your Program.cs you will want to have the following. The main things to
.Run();
}
}
- }
-
-
- **Note:** When using ASP.NET Core 2.2 and you want to use In-Process hosting, replace **.UseIISIntegration()** with **.UseIIS()**, otherwise you'll get startup errors.
-
-.NET Core 1.0
-^^^^^^^^^^^^^
-
-**Install NuGet package**
-
-Install Ocelot and it's dependecies using nuget. You will need to create a netcoreapp1.0+ projct and bring the package into it. Then follow the Startup below and :doc:`../features/configuration` sections to get up and running. Please note you will need to choose one of the Ocelot packages from the NuGet feed.
-
-All versions can be found `here `_.
-
-**Configuration**
-
-The following is a very basic ocelot.json. It won't do anything but should get Ocelot starting.
-
-.. code-block:: json
-
- {
- "Routes": [],
- "GlobalConfiguration": {}
- }
-
-**Program**
-
-Then in your Program.cs you will want to have the following.
-
-.. code-block:: csharp
-
- public class Program
- {
- public static void Main(string[] args)
- {
- IWebHostBuilder builder = new WebHostBuilder();
-
- builder.ConfigureServices(s => {
- });
-
- builder.UseKestrel()
- .UseContentRoot(Directory.GetCurrentDirectory())
- .UseStartup();
-
- var host = builder.Build();
-
- host.Run();
- }
- }
-
-**Startup**
-
-An example startup using a json file for configuration can be seen below.
-
-.. code-block:: csharp
-
- public class Startup
- {
- public Startup(IHostingEnvironment env)
- {
- var builder = new ConfigurationBuilder()
- .SetBasePath(env.ContentRootPath)
- .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
- .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
- .AddJsonFile("ocelot.json")
- .AddEnvironmentVariables();
-
- Configuration = builder.Build();
- }
-
- public IConfigurationRoot Configuration { get; }
-
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddOcelot(Configuration);
- }
-
- public void Configure(IApplicationBuilder app)
- {
- app.UseOcelot().Wait();
- }
- }
-
-This is pretty much all you need to get going.
+ }
\ No newline at end of file
diff --git a/docs/introduction/gotchas.rst b/docs/introduction/gotchas.rst
new file mode 100644
index 0000000000..e980e03706
--- /dev/null
+++ b/docs/introduction/gotchas.rst
@@ -0,0 +1,4 @@
+Gotchas
+=============
+
+**Note:** When using ASP.NET Core 2.2 and you want to use In-Process hosting, replace **.UseIISIntegration()** with **.UseIIS()**, otherwise you'll get startup errors.
\ No newline at end of file
diff --git a/images/ocelot_logo.png b/images/ocelot_logo.png
new file mode 100644
index 0000000000..78cae888be
Binary files /dev/null and b/images/ocelot_logo.png differ
diff --git a/samples/AdministrationApi/AdministrationApi.csproj b/samples/AdministrationApi/AdministrationApi.csproj
index 7c5f80ecd0..59739bdee2 100644
--- a/samples/AdministrationApi/AdministrationApi.csproj
+++ b/samples/AdministrationApi/AdministrationApi.csproj
@@ -1,13 +1,13 @@
-
-
- net5.0
-
-
-
-
-
-
-
-
-
+
+
+ net7.0
+
+
+
+
+
+
+
+
+
diff --git a/samples/AdministrationApi/Issue645.postman_collection.json b/samples/AdministrationApi/Issue645.postman_collection.json
index 2cdd868efa..c9bac89f56 100644
--- a/samples/AdministrationApi/Issue645.postman_collection.json
+++ b/samples/AdministrationApi/Issue645.postman_collection.json
@@ -132,7 +132,7 @@
"id": "0f60e7b3-e4f1-4458-bbc4-fc4809e86b2d",
"type": "text/javascript",
"exec": [
- ""
+ string.Empty
]
}
},
@@ -142,7 +142,7 @@
"id": "1279a2cf-b771-4a86-9dfa-302b240fac62",
"type": "text/javascript",
"exec": [
- ""
+ string.Empty
]
}
}
diff --git a/samples/AdministrationApi/Program.cs b/samples/AdministrationApi/Program.cs
index a69f1dc61b..36695bf9ae 100644
--- a/samples/AdministrationApi/Program.cs
+++ b/samples/AdministrationApi/Program.cs
@@ -1,45 +1,48 @@
-using Microsoft.AspNetCore.Hosting;
+using System.IO;
+
+using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
+
using Ocelot.Administration;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
-using System.IO;
namespace AdministrationApi
{
public class Program
-{
- public static void Main(string[] args)
{
- new WebHostBuilder()
- .UseKestrel()
- .UseUrls("http://localhost:5000")
- .UseContentRoot(Directory.GetCurrentDirectory())
- .ConfigureAppConfiguration((hostingContext, config) =>
- {
- config
- .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
- .AddJsonFile("appsettings.json", true, true)
- .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
- .AddJsonFile("ocelot.json")
- .AddEnvironmentVariables();
- })
- .ConfigureServices(s => {
- s.AddOcelot()
- .AddAdministration("/administration", "secret");
- })
- .ConfigureLogging((hostingContext, logging) =>
- {
- logging.AddConsole();
- })
- .UseIISIntegration()
- .Configure(app =>
- {
- app.UseOcelot().Wait();
- })
- .Build()
- .Run();
+ public static void Main(string[] args)
+ {
+ new WebHostBuilder()
+ .UseKestrel()
+ .UseUrls("http://localhost:5000")
+ .UseContentRoot(Directory.GetCurrentDirectory())
+ .ConfigureAppConfiguration((hostingContext, config) =>
+ {
+ config
+ .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
+ .AddJsonFile("appsettings.json", true, true)
+ .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
+ .AddJsonFile("ocelot.json")
+ .AddEnvironmentVariables();
+ })
+ .ConfigureServices(s =>
+ {
+ s.AddOcelot()
+ .AddAdministration("/administration", "secret");
+ })
+ .ConfigureLogging((hostingContext, logging) =>
+ {
+ logging.AddConsole();
+ })
+ .UseIISIntegration()
+ .Configure(app =>
+ {
+ app.UseOcelot().Wait();
+ })
+ .Build()
+ .Run();
+ }
}
}
-}
diff --git a/samples/OcelotBasic/OcelotBasic.csproj b/samples/OcelotBasic/Ocelot.Samples.OcelotBasic.ApiGateway.csproj
similarity index 51%
rename from samples/OcelotBasic/OcelotBasic.csproj
rename to samples/OcelotBasic/Ocelot.Samples.OcelotBasic.ApiGateway.csproj
index be6fd6dab6..a6e612a78f 100644
--- a/samples/OcelotBasic/OcelotBasic.csproj
+++ b/samples/OcelotBasic/Ocelot.Samples.OcelotBasic.ApiGateway.csproj
@@ -1,16 +1,16 @@
-
-
-
- net5.0
-
-
+
+
+
+ net7.0
+ InProcess
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/samples/OcelotBasic/Program.cs b/samples/OcelotBasic/Program.cs
index c0d8bed6ab..b5856d857a 100644
--- a/samples/OcelotBasic/Program.cs
+++ b/samples/OcelotBasic/Program.cs
@@ -1,42 +1,40 @@
-using System.IO;
+using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Hosting;
-using Ocelot.DependencyInjection;
-using Ocelot.Middleware;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using System.IO;
+
+namespace Ocelot.Samples.OcelotBasic.ApiGateway;
-namespace OcelotBasic
+public class Program
{
- public class Program
+ public static void Main(string[] args)
{
- public static void Main(string[] args)
- {
- new WebHostBuilder()
- .UseKestrel()
- .UseContentRoot(Directory.GetCurrentDirectory())
- .ConfigureAppConfiguration((hostingContext, config) =>
- {
- config
- .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
- .AddJsonFile("appsettings.json", true, true)
- .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
- .AddJsonFile("ocelot.json")
- .AddEnvironmentVariables();
- })
- .ConfigureServices(s => {
- s.AddOcelot();
- })
- .ConfigureLogging((hostingContext, logging) =>
- {
- //add your logging
- })
- .UseIISIntegration()
- .Configure(app =>
- {
- app.UseOcelot().Wait();
- })
- .Build()
- .Run();
- }
+ new WebHostBuilder()
+ .UseKestrel()
+ .UseContentRoot(Directory.GetCurrentDirectory())
+ .ConfigureAppConfiguration((hostingContext, config) =>
+ {
+ config
+ .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
+ .AddJsonFile("appsettings.json", true, true)
+ .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
+ .AddJsonFile("ocelot.json")
+ .AddEnvironmentVariables();
+ })
+ .ConfigureLogging((hostingContext, logging) =>
+ {
+ if (hostingContext.HostingEnvironment.IsDevelopment())
+ {
+ logging.ClearProviders();
+ logging.AddConsole();
+ }
+ //add your logging
+ })
+ .UseIISIntegration()
+ .UseStartup()
+ .Build()
+ .Run();
}
}
diff --git a/samples/OcelotBasic/Properties/launchSettings.json b/samples/OcelotBasic/Properties/launchSettings.json
index b500ae576f..924e292df4 100644
--- a/samples/OcelotBasic/Properties/launchSettings.json
+++ b/samples/OcelotBasic/Properties/launchSettings.json
@@ -11,17 +11,19 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
+ "launchUrl": "posts/1",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
- "OcelotBasic": {
+ "ApiGateway": {
"commandName": "Project",
"launchBrowser": true,
+ "launchUrl": "posts/1",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
-}
\ No newline at end of file
+}
diff --git a/samples/OcelotBasic/Startup.cs b/samples/OcelotBasic/Startup.cs
new file mode 100644
index 0000000000..62b8b422be
--- /dev/null
+++ b/samples/OcelotBasic/Startup.cs
@@ -0,0 +1,30 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Ocelot.DependencyInjection;
+using Ocelot.Middleware;
+
+namespace Ocelot.Samples.OcelotBasic.ApiGateway;
+
+public class Startup
+{
+ // This method gets called by the runtime. Use this method to add services to the container.
+ // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
+ public void ConfigureServices(IServiceCollection services)
+ {
+ services.AddOcelot();
+ services.AddLogging();
+ }
+
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+ if (env.IsDevelopment())
+ {
+ app.UseDeveloperExceptionPage();
+ }
+
+ app.UseOcelot().Wait();
+ }
+}
diff --git a/samples/OcelotBasic/appsettings.Development.json b/samples/OcelotBasic/appsettings.Development.json
index dba68eb124..07053a355f 100644
--- a/samples/OcelotBasic/appsettings.Development.json
+++ b/samples/OcelotBasic/appsettings.Development.json
@@ -1,9 +1,11 @@
{
"Logging": {
"LogLevel": {
- "Default": "Information",
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
+ "Default": "Debug",
+ "Microsoft": "Information",
+ "Microsoft.AspNetCore": "Information",
+ "Microsoft.Hosting.Lifetime": "Information",
+ "System": "Information"
}
}
}
diff --git a/samples/OcelotBasic/appsettings.json b/samples/OcelotBasic/appsettings.json
index 81ff877711..7376aada1c 100644
--- a/samples/OcelotBasic/appsettings.json
+++ b/samples/OcelotBasic/appsettings.json
@@ -1,9 +1,7 @@
{
"Logging": {
"LogLevel": {
- "Default": "Information",
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
+ "Default": "Warning"
}
},
"AllowedHosts": "*"
diff --git a/samples/OcelotBasic/ocelot.json b/samples/OcelotBasic/ocelot.json
index 9051b76f43..2864550cd7 100644
--- a/samples/OcelotBasic/ocelot.json
+++ b/samples/OcelotBasic/ocelot.json
@@ -18,4 +18,4 @@
"GlobalConfiguration": {
"BaseUrl": "https://localhost:5000"
}
-}
\ No newline at end of file
+}
diff --git a/samples/OcelotEureka/ApiGateway/ApiGateway.csproj b/samples/OcelotEureka/ApiGateway/ApiGateway.csproj
index f7f4c81e43..a286c8a164 100644
--- a/samples/OcelotEureka/ApiGateway/ApiGateway.csproj
+++ b/samples/OcelotEureka/ApiGateway/ApiGateway.csproj
@@ -1,7 +1,7 @@
- net5.0
+ net7.0
@@ -15,9 +15,9 @@
-
-
-
+
+
+
diff --git a/samples/OcelotEureka/ApiGateway/Program.cs b/samples/OcelotEureka/ApiGateway/Program.cs
index f2cd87f92f..f80237b4c3 100644
--- a/samples/OcelotEureka/ApiGateway/Program.cs
+++ b/samples/OcelotEureka/ApiGateway/Program.cs
@@ -1,14 +1,14 @@
using Ocelot.Provider.Eureka;
using Ocelot.Provider.Polly;
+using Microsoft.AspNetCore;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+
+using Ocelot.DependencyInjection;
+using Ocelot.Middleware;
namespace ApiGateway
{
- using Microsoft.AspNetCore;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.Extensions.Configuration;
- using Ocelot.DependencyInjection;
- using Ocelot.Middleware;
-
public class Program
{
public static void Main(string[] args)
diff --git a/samples/OcelotEureka/DownstreamService/Controllers/CategoryController.cs b/samples/OcelotEureka/DownstreamService/Controllers/CategoryController.cs
index 53350be745..5ce38f4757 100644
--- a/samples/OcelotEureka/DownstreamService/Controllers/CategoryController.cs
+++ b/samples/OcelotEureka/DownstreamService/Controllers/CategoryController.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+
using Microsoft.AspNetCore.Mvc;
namespace DownstreamService.Controllers
diff --git a/samples/OcelotEureka/DownstreamService/DownstreamService.csproj b/samples/OcelotEureka/DownstreamService/DownstreamService.csproj
index 67a861a8a5..748249c002 100644
--- a/samples/OcelotEureka/DownstreamService/DownstreamService.csproj
+++ b/samples/OcelotEureka/DownstreamService/DownstreamService.csproj
@@ -1,7 +1,7 @@
- net5.0
+ net7.0
diff --git a/samples/OcelotEureka/DownstreamService/Program.cs b/samples/OcelotEureka/DownstreamService/Program.cs
index ddce0c2868..130b46f0e6 100644
--- a/samples/OcelotEureka/DownstreamService/Program.cs
+++ b/samples/OcelotEureka/DownstreamService/Program.cs
@@ -1,4 +1,5 @@
using System;
+
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
diff --git a/samples/OcelotEureka/DownstreamService/Startup.cs b/samples/OcelotEureka/DownstreamService/Startup.cs
index aa488ad840..56a187c2c9 100644
--- a/samples/OcelotEureka/DownstreamService/Startup.cs
+++ b/samples/OcelotEureka/DownstreamService/Startup.cs
@@ -1,19 +1,13 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Options;
+using Microsoft.Extensions.Hosting;
+
+using Steeltoe.Discovery.Client;
namespace DownstreamService
{
- using Microsoft.Extensions.Hosting;
- using Steeltoe.Discovery.Client;
-
public class Startup
{
public Startup(IConfiguration configuration)
@@ -39,7 +33,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
}
app.UseDiscoveryClient();
- app.UseMvc();
}
}
}
diff --git a/samples/OcelotGraphQL/OcelotGraphQL.csproj b/samples/OcelotGraphQL/OcelotGraphQL.csproj
index f205c25e33..06956a7f8a 100644
--- a/samples/OcelotGraphQL/OcelotGraphQL.csproj
+++ b/samples/OcelotGraphQL/OcelotGraphQL.csproj
@@ -1,6 +1,6 @@
- net5.0
+ net7.0
@@ -11,7 +11,7 @@
-
-
+
+
diff --git a/samples/OcelotGraphQL/Program.cs b/samples/OcelotGraphQL/Program.cs
index ef23d98d42..bbf5eff48d 100644
--- a/samples/OcelotGraphQL/Program.cs
+++ b/samples/OcelotGraphQL/Program.cs
@@ -1,22 +1,21 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Net;
+using System.Net.Http;
+using System.Threading;
using System.Threading.Tasks;
-using Microsoft.AspNetCore;
+
+using GraphQL;
+using GraphQL.Types;
+
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
-using Ocelot.Middleware;
+
using Ocelot.DependencyInjection;
-using GraphQL.Types;
-using GraphQL;
-using Ocelot.Requester;
-using Ocelot.Responses;
-using System.Net.Http;
-using System.Net;
-using Microsoft.Extensions.DependencyInjection;
-using System.Threading;
+using Ocelot.Middleware;
namespace OcelotGraphQL
{
@@ -28,7 +27,7 @@ public class Hero
public class Query
{
- private readonly List _heroes = new List
+ private readonly List _heroes = new()
{
new Hero { Id = 1, Name = "R2-D2" },
new Hero { Id = 2, Name = "Batman" },
@@ -45,35 +44,35 @@ public Hero GetHero(int id)
public class GraphQlDelegatingHandler : DelegatingHandler
{
- //private readonly ISchema _schema;
- private readonly IDocumentExecuter _executer;
+ //private readonly ISchema _schema;
+ private readonly IDocumentExecuter _executer;
private readonly IDocumentWriter _writer;
public GraphQlDelegatingHandler(IDocumentExecuter executer, IDocumentWriter writer)
{
- _executer = executer;
+ _executer = executer;
_writer = writer;
}
- protected async override Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
+ protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
//try get query from body, could check http method :)
- var query = await request.Content.ReadAsStringAsync();
+ var query = await request.Content.ReadAsStringAsync(cancellationToken);
//if not body try query string, dont hack like this in real world..
if (query.Length == 0)
{
var decoded = WebUtility.UrlDecode(request.RequestUri.Query);
- query = decoded.Replace("?query=", "");
+ query = decoded.Replace("?query=", string.Empty);
}
-
+
var result = await _executer.ExecuteAsync(_ =>
{
_.Query = query;
- });
-
+ });
+
var responseBody = await _writer.WriteToStringAsync(result);
-
+
//maybe check for errors and headers etc in real world?
var response = new HttpResponseMessage(HttpStatusCode.OK)
{
diff --git a/samples/OcelotKube/ApiGateway/Dockerfile b/samples/OcelotKube/ApiGateway/Dockerfile
index 1e3fcd1163..990742e4a9 100644
--- a/samples/OcelotKube/ApiGateway/Dockerfile
+++ b/samples/OcelotKube/ApiGateway/Dockerfile
@@ -1,19 +1,20 @@
-FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim AS base
+FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
+EXPOSE 443
-FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build
+FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
-COPY ["ApiGateway/ApiGateway.csproj", "ApiGateway/"]
-RUN dotnet restore "ApiGateway/ApiGateway.csproj"
+COPY ["ApiGateway/Ocelot.Samples.OcelotKube.ApiGateway.csproj", "ApiGateway/"]
+RUN dotnet restore "ApiGateway/Ocelot.Samples.OcelotKube.ApiGateway.csproj"
COPY . .
WORKDIR "/src/ApiGateway"
-RUN dotnet build "ApiGateway.csproj" -c Release -o /app
+RUN dotnet build "Ocelot.Samples.OcelotKube.ApiGateway.csproj" -c Release -o /app/build
FROM build AS publish
-RUN dotnet publish "ApiGateway.csproj" -c Release -o /app
+RUN dotnet publish "Ocelot.Samples.OcelotKube.ApiGateway.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
-COPY --from=publish /app .
-ENTRYPOINT ["dotnet", "ApiGateway.dll"]
\ No newline at end of file
+COPY --from=publish /app/publish .
+ENTRYPOINT ["dotnet", "Ocelot.Samples.OcelotKube.ApiGateway.dll"]
diff --git a/samples/OcelotKube/ApiGateway/ApiGateway.csproj b/samples/OcelotKube/ApiGateway/Ocelot.Samples.OcelotKube.ApiGateway.csproj
similarity index 50%
rename from samples/OcelotKube/ApiGateway/ApiGateway.csproj
rename to samples/OcelotKube/ApiGateway/Ocelot.Samples.OcelotKube.ApiGateway.csproj
index a96c220ee1..5d08a3b8ad 100644
--- a/samples/OcelotKube/ApiGateway/ApiGateway.csproj
+++ b/samples/OcelotKube/ApiGateway/Ocelot.Samples.OcelotKube.ApiGateway.csproj
@@ -1,15 +1,18 @@
-
-
-
- net5.0
- InProcess
- Linux
-
-
-
-
-
-
-
-
-
+
+
+
+ net7.0
+ InProcess
+ Linux
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/OcelotKube/ApiGateway/Program.cs b/samples/OcelotKube/ApiGateway/Program.cs
index 978c8ccc9b..36f5fe49cd 100644
--- a/samples/OcelotKube/ApiGateway/Program.cs
+++ b/samples/OcelotKube/ApiGateway/Program.cs
@@ -1,32 +1,27 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
-using Ocelot.DependencyInjection;
-using Ocelot.Middleware;
-using Ocelot.Provider.Kubernetes;
-namespace ApiGateway
+namespace Ocelot.Samples.OcelotKube.ApiGateway;
+
+public class Program
{
- public class Program
+ public static void Main(string[] args)
{
- public static void Main(string[] args)
- {
- BuildWebHost(args).Run();
- }
-
- public static IWebHost BuildWebHost(string[] args) =>
- WebHost.CreateDefaultBuilder(args)
- .ConfigureAppConfiguration((hostingContext, config) =>
- {
- config
- .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
- .AddJsonFile("appsettings.json", true, true)
- .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
- .AddJsonFile("ocelot.json", false, false)
- .AddEnvironmentVariables();
- })
- .UseStartup()
- .Build();
+ BuildWebHost(args).Run();
}
-}
+ public static IWebHost BuildWebHost(string[] args) =>
+ WebHost.CreateDefaultBuilder(args)
+ .ConfigureAppConfiguration((hostingContext, config) =>
+ {
+ config
+ .SetBasePath(hostingContext.HostingEnvironment.ContentRootPath)
+ .AddJsonFile("appsettings.json", true, true)
+ .AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true, true)
+ .AddJsonFile("ocelot.json", false, false)
+ .AddEnvironmentVariables();
+ })
+ .UseStartup()
+ .Build();
+}
diff --git a/samples/OcelotKube/ApiGateway/Properties/launchSettings.json b/samples/OcelotKube/ApiGateway/Properties/launchSettings.json
index 5315ab2c80..5684b76570 100644
--- a/samples/OcelotKube/ApiGateway/Properties/launchSettings.json
+++ b/samples/OcelotKube/ApiGateway/Properties/launchSettings.json
@@ -11,6 +11,7 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
+ "launchUrl": "values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
@@ -18,6 +19,7 @@
"ApiGateway": {
"commandName": "Project",
"launchBrowser": true,
+ "launchUrl": "values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
@@ -26,7 +28,7 @@
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
- "launchUrl": "{Scheme}://localhost:{ServicePort}"
+ "launchUrl": "{Scheme}://localhost:{ServicePort}/values"
}
}
-}
\ No newline at end of file
+}
diff --git a/samples/OcelotKube/ApiGateway/Startup.cs b/samples/OcelotKube/ApiGateway/Startup.cs
index 3e37ffa3ce..2afcde95c6 100644
--- a/samples/OcelotKube/ApiGateway/Startup.cs
+++ b/samples/OcelotKube/ApiGateway/Startup.cs
@@ -2,31 +2,31 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
+
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Provider.Kubernetes;
-namespace ApiGateway
+namespace Ocelot.Samples.OcelotKube.ApiGateway;
+
+public class Startup
{
- public class Startup
+ // This method gets called by the runtime. Use this method to add services to the container.
+ // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
+ public void ConfigureServices(IServiceCollection services)
{
- // This method gets called by the runtime. Use this method to add services to the container.
- // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddOcelot()
- .AddKubernetes();
- }
+ services.AddOcelot()
+ .AddKubernetes();
+ }
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
+ {
+ if (env.IsDevelopment())
{
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
-
- app.UseOcelot().Wait();
+ app.UseDeveloperExceptionPage();
}
+
+ app.UseOcelot().Wait();
}
}
diff --git a/samples/OcelotKube/DownstreamService/Controllers/ValuesController.cs b/samples/OcelotKube/DownstreamService/Controllers/ValuesController.cs
index 425cf18deb..48ebcb7d2f 100644
--- a/samples/OcelotKube/DownstreamService/Controllers/ValuesController.cs
+++ b/samples/OcelotKube/DownstreamService/Controllers/ValuesController.cs
@@ -1,45 +1,41 @@
-using System;
+using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Mvc;
-namespace DownstreamService.Controllers
+namespace Ocelot.Samples.OcelotKube.DownstreamService.Controllers;
+
+[ApiController]
+[Route("api/[controller]")]
+public class ValuesController : ControllerBase
{
- [Route("api/[controller]")]
- [ApiController]
- public class ValuesController : ControllerBase
+ // GET api/values
+ [HttpGet]
+ public ActionResult> Get()
{
- // GET api/values
- [HttpGet]
- public ActionResult> Get()
- {
- return new string[] { "value1", "value2" };
- }
+ return new[] { "value1", "value2" };
+ }
- // GET api/values/5
- [HttpGet("{id}")]
- public ActionResult Get(int id)
- {
- return "value";
- }
+ // GET api/values/5
+ [HttpGet("{id}")]
+ public ActionResult Get(int id)
+ {
+ return "value";
+ }
- // POST api/values
- [HttpPost]
- public void Post([FromBody] string value)
- {
- }
+ // POST api/values
+ [HttpPost]
+ public void Post([FromBody] string value)
+ {
+ }
- // PUT api/values/5
- [HttpPut("{id}")]
- public void Put(int id, [FromBody] string value)
- {
- }
+ // PUT api/values/5
+ [HttpPut("{id}")]
+ public void Put(int id, [FromBody] string value)
+ {
+ }
- // DELETE api/values/5
- [HttpDelete("{id}")]
- public void Delete(int id)
- {
- }
+ // DELETE api/values/5
+ [HttpDelete("{id}")]
+ public void Delete(int id)
+ {
}
}
diff --git a/samples/OcelotKube/DownstreamService/Controllers/WeatherForecastController.cs b/samples/OcelotKube/DownstreamService/Controllers/WeatherForecastController.cs
new file mode 100644
index 0000000000..33222b1f1a
--- /dev/null
+++ b/samples/OcelotKube/DownstreamService/Controllers/WeatherForecastController.cs
@@ -0,0 +1,39 @@
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Ocelot.Samples.OcelotKube.DownstreamService.Controllers;
+
+using Models;
+
+[ApiController]
+[Route("api/[controller]")]
+public class WeatherForecastController : ControllerBase
+{
+ private static readonly string[] Summaries = new[]
+ {
+ "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
+ };
+
+ private readonly ILogger _logger;
+
+ public WeatherForecastController(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ [HttpGet(Name = "GetWeatherForecast")]
+ public IEnumerable Get()
+ {
+ return Enumerable.Range(1, 5)
+ .Select(index => new WeatherForecast
+ {
+ Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
+ TemperatureC = Random.Shared.Next(-20, 55),
+ Summary = Summaries[Random.Shared.Next(Summaries.Length)]
+ })
+ .ToArray();
+ }
+}
diff --git a/samples/OcelotKube/DownstreamService/Dockerfile b/samples/OcelotKube/DownstreamService/Dockerfile
index a96955150d..985096fcc8 100644
--- a/samples/OcelotKube/DownstreamService/Dockerfile
+++ b/samples/OcelotKube/DownstreamService/Dockerfile
@@ -1,19 +1,20 @@
-FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
+FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80
+EXPOSE 443
-FROM microsoft/dotnet:2.1-sdk AS build
+FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
-COPY ["DownstreamService/DownstreamService.csproj", "DownstreamService/"]
-RUN dotnet restore "DownstreamService/DownstreamService.csproj"
+COPY ["DownstreamService/Ocelot.Samples.OcelotKube.DownstreamService.csproj", "DownstreamService/"]
+RUN dotnet restore "DownstreamService/Ocelot.Samples.OcelotKube.DownstreamService.csproj"
COPY . .
WORKDIR "/src/DownstreamService"
-RUN dotnet build "DownstreamService.csproj" -c Release -o /app
+RUN dotnet build "Ocelot.Samples.OcelotKube.DownstreamService.csproj" -c Release -o /app/build
FROM build AS publish
-RUN dotnet publish "DownstreamService.csproj" -c Release -o /app
+RUN dotnet publish "Ocelot.Samples.OcelotKube.DownstreamService.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
-COPY --from=publish /app .
-ENTRYPOINT ["dotnet", "DownstreamService.dll"]
+COPY --from=publish /app/publish .
+ENTRYPOINT ["dotnet", "Ocelot.Samples.OcelotKube.DownstreamService.dll"]
diff --git a/samples/OcelotKube/DownstreamService/Dockerfile.develop b/samples/OcelotKube/DownstreamService/Dockerfile.develop
deleted file mode 100644
index 6f49a29097..0000000000
--- a/samples/OcelotKube/DownstreamService/Dockerfile.develop
+++ /dev/null
@@ -1,15 +0,0 @@
-FROM microsoft/dotnet:2.1-sdk
-ARG BUILD_CONFIGURATION=Debug
-ENV ASPNETCORE_ENVIRONMENT=Development
-ENV DOTNET_USE_POLLING_FILE_WATCHER=true
-EXPOSE 80
-
-WORKDIR /src
-COPY ["DownstreamService/DownstreamService.csproj", "DownstreamService/"]
-
-RUN dotnet restore "DownstreamService/DownstreamService.csproj"
-COPY . .
-WORKDIR "/src/DownstreamService"
-RUN dotnet build --no-restore "DownstreamService.csproj" -c $BUILD_CONFIGURATION
-
-ENTRYPOINT ["dotnet", "run", "--no-build", "--no-launch-profile", "-c", "$BUILD_CONFIGURATION", "--"]
\ No newline at end of file
diff --git a/samples/OcelotKube/DownstreamService/Models/WeatherForecast.cs b/samples/OcelotKube/DownstreamService/Models/WeatherForecast.cs
new file mode 100644
index 0000000000..66e01aee62
--- /dev/null
+++ b/samples/OcelotKube/DownstreamService/Models/WeatherForecast.cs
@@ -0,0 +1,14 @@
+using System;
+
+namespace Ocelot.Samples.OcelotKube.DownstreamService.Models;
+
+public class WeatherForecast
+{
+ public DateOnly Date { get; set; }
+
+ public int TemperatureC { get; set; }
+
+ public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
+
+ public string Summary { get; set; }
+}
diff --git a/samples/OcelotKube/DownstreamService/DownstreamService.csproj b/samples/OcelotKube/DownstreamService/Ocelot.Samples.OcelotKube.DownstreamService.csproj
similarity index 65%
rename from samples/OcelotKube/DownstreamService/DownstreamService.csproj
rename to samples/OcelotKube/DownstreamService/Ocelot.Samples.OcelotKube.DownstreamService.csproj
index 732c6594b6..56b2d53e75 100644
--- a/samples/OcelotKube/DownstreamService/DownstreamService.csproj
+++ b/samples/OcelotKube/DownstreamService/Ocelot.Samples.OcelotKube.DownstreamService.csproj
@@ -1,13 +1,14 @@
-
-
-
- net5.0
- InProcess
- Linux
-
-
-
-
-
-
-
+
+
+
+ net7.0
+ InProcess
+ Linux
+
+
+
+
+
+
+
+
diff --git a/samples/OcelotKube/DownstreamService/Program.cs b/samples/OcelotKube/DownstreamService/Program.cs
index 03e1b8aea9..94f139c014 100644
--- a/samples/OcelotKube/DownstreamService/Program.cs
+++ b/samples/OcelotKube/DownstreamService/Program.cs
@@ -1,24 +1,57 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore;
+using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using System.Text.Json;
+using System.Text.Json.Serialization;
-namespace DownstreamService
+namespace Ocelot.Samples.OcelotKube.DownstreamService;
+
+public class Program
{
- public class Program
+ public static void Main(string[] args)
{
- public static void Main(string[] args)
+ var builder = WebApplication.CreateBuilder(args);
+
+ builder.Services
+ // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
+ .AddEndpointsApiExplorer()
+ .AddSwaggerGen()
+
+ .AddControllers()
+ .AddJsonOptions(options =>
+ {
+ options.AllowInputFormatterExceptionMessages = true;
+
+ var jOptions = options.JsonSerializerOptions;
+ jOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase, true));
+ jOptions.PropertyNameCaseInsensitive = true;
+ jOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
+ });
+
+ AddApplicationServices(builder.Services);
+
+ var app = builder.Build();
+
+ // Configure the HTTP request pipeline.
+ if (app.Environment.IsDevelopment())
{
- CreateWebHostBuilder(args).Build().Run();
+ app.UseSwagger();
+ app.UseSwaggerUI();
}
- public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
- WebHost.CreateDefaultBuilder(args)
- .UseStartup();
+ app.UseHttpsRedirection();
+ app.UseAuthorization();
+
+ app.MapControllers();
+ app.Run();
+ }
+
+ private static void AddApplicationServices(IServiceCollection services)
+ {
+ services.AddHttpClient(); // to keep performance of HTTP Client high
+ //services.AddSingleton
+ //services.AddScoped
+ //services.AddTransient
}
}
diff --git a/samples/OcelotKube/DownstreamService/Properties/launchSettings.json b/samples/OcelotKube/DownstreamService/Properties/launchSettings.json
index 30d6118c69..6f9313866a 100644
--- a/samples/OcelotKube/DownstreamService/Properties/launchSettings.json
+++ b/samples/OcelotKube/DownstreamService/Properties/launchSettings.json
@@ -12,7 +12,7 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
- "launchUrl": "api/values",
+ "launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
@@ -20,7 +20,7 @@
"DownstreamService": {
"commandName": "Project",
"launchBrowser": true,
- "launchUrl": "api/values",
+ "launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
@@ -29,7 +29,7 @@
"Docker": {
"commandName": "Docker",
"launchBrowser": true,
- "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values"
+ "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger"
}
}
-}
\ No newline at end of file
+}
diff --git a/samples/OcelotKube/DownstreamService/Startup.cs b/samples/OcelotKube/DownstreamService/Startup.cs
deleted file mode 100644
index a8abb5d404..0000000000
--- a/samples/OcelotKube/DownstreamService/Startup.cs
+++ /dev/null
@@ -1,42 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Microsoft.AspNetCore.Builder;
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.Extensions.Configuration;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Options;
-
-namespace DownstreamService
-{
- public class Startup
- {
- public Startup(IConfiguration configuration)
- {
- Configuration = configuration;
- }
-
- public IConfiguration Configuration { get; }
-
- // This method gets called by the runtime. Use this method to add services to the container.
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
- }
-
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
-
- app.UseMvc();
- }
- }
-}
diff --git a/samples/OcelotOpenTracing/OcelotOpenTracing.csproj b/samples/OcelotOpenTracing/OcelotOpenTracing.csproj
index fad9470ea4..0384c8c01e 100644
--- a/samples/OcelotOpenTracing/OcelotOpenTracing.csproj
+++ b/samples/OcelotOpenTracing/OcelotOpenTracing.csproj
@@ -2,12 +2,12 @@
Exe
- net5.0
+ net7.0
-
-
+
+
diff --git a/samples/OcelotOpenTracing/Program.cs b/samples/OcelotOpenTracing/Program.cs
index e9527930fa..0c472ac23d 100644
--- a/samples/OcelotOpenTracing/Program.cs
+++ b/samples/OcelotOpenTracing/Program.cs
@@ -1,18 +1,21 @@
-namespace OcelotOpenTracing
-{
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Hosting;
- using System.IO;
- using Ocelot.DependencyInjection;
- using Ocelot.Middleware;
- using Microsoft.Extensions.Logging;
- using Ocelot.Tracing.OpenTracing;
- using Jaeger;
- using Microsoft.Extensions.DependencyInjection;
- using OpenTracing;
- using OpenTracing.Util;
+using System.IO;
+
+using Jaeger;
+
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
+using Ocelot.DependencyInjection;
+using Ocelot.Middleware;
+using Ocelot.Tracing.OpenTracing;
+
+using OpenTracing.Util;
+
+namespace OcelotOpenTracing
+{
internal static class Program
{
private static void Main(string[] args)
@@ -35,10 +38,10 @@ private static void Main(string[] args)
})
.ConfigureServices((context, services) =>
{
- services.AddSingleton(sp =>
+ services.AddSingleton(sp =>
{
var loggerFactory = sp.GetService();
- Configuration config = new Configuration(context.HostingEnvironment.ApplicationName, loggerFactory);
+ var config = new Configuration(context.HostingEnvironment.ApplicationName, loggerFactory);
var tracer = config.GetTracer();
GlobalTracer.Register(tracer);
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.cs
index 28ea7abbba..a017ee028e 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.cs
@@ -3,13 +3,14 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------
+using System.Collections.Generic;
+using System.Fabric;
+
+using Microsoft.ServiceFabric.Services.Communication.Runtime;
+using Microsoft.ServiceFabric.Services.Runtime;
+
namespace OcelotApplicationApiGateway
{
- using System.Fabric;
- using Microsoft.ServiceFabric.Services.Communication.Runtime;
- using Microsoft.ServiceFabric.Services.Runtime;
- using System.Collections.Generic;
-
/// Service that handles front-end web requests and acts as a proxy to the back-end data for the UI web page.
/// It is a stateless service that hosts a Web API application on OWIN.
internal sealed class OcelotServiceWebService : StatelessService
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.csproj b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.csproj
index f0fd14d401..416ea124b9 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.csproj
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/OcelotApplicationApiGateway.csproj
@@ -1,11 +1,10 @@
-
+
Stateless Web Service for Stateful OcelotApplicationApiGateway App
-
- net5.0
+ net7.0
OcelotApplicationApiGateway
- Exe
OcelotApplicationApiGateway
+ x64
@@ -13,8 +12,8 @@
-
-
+
+
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Program.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Program.cs
index 7da30a50ad..9a4dd524ef 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Program.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/Program.cs
@@ -3,16 +3,15 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------
-namespace OcelotApplicationApiGateway
+using System;
+using System.Diagnostics.Tracing;
+using System.Threading;
-{
- using System;
- using System.Fabric;
- using System.Threading;
- using Microsoft.ServiceFabric.Services.Runtime;
- using System.Diagnostics.Tracing;
+using Microsoft.ServiceFabric.Services.Runtime;
+namespace OcelotApplicationApiGateway
+{
///
/// The service host is the executable that hosts the Service instances.
///
@@ -25,7 +24,7 @@ public static void Main(string[] args)
{
//Creating a new event listener to redirect the traces to a file
- ServiceEventListener listener = new ServiceEventListener("OcelotApplicationApiGateway");
+ var listener = new ServiceEventListener("OcelotApplicationApiGateway");
listener.EnableEvents(ServiceEventSource.Current, EventLevel.LogAlways, EventKeywords.All);
// The ServiceManifest.XML file defines one or more service type names.
@@ -33,7 +32,7 @@ public static void Main(string[] args)
// When Service Fabric creates an instance of this service type,
// an instance of the class is created in this host process.
ServiceRuntime
- .RegisterServiceAsync("OcelotApplicationApiGatewayType", context => new OcelotServiceWebService (context))
+ .RegisterServiceAsync("OcelotApplicationApiGatewayType", context => new OcelotServiceWebService(context))
.GetAwaiter()
.GetResult();
@@ -44,8 +43,8 @@ public static void Main(string[] args)
catch (Exception ex)
{
ServiceEventSource.Current.ServiceHostInitializationFailed(ex);
- throw ex;
+ throw;
}
}
}
-}
\ No newline at end of file
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventListener.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventListener.cs
index 555f9fde80..d6d64dac21 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventListener.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventListener.cs
@@ -3,19 +3,15 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------
+using System;
+using System.Diagnostics.Tracing;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Text;
+
namespace OcelotApplicationApiGateway
{
- using System;
- using System.IO;
- using System.Linq;
- using System.Diagnostics.Tracing;
- using System.Fabric;
- using System.Fabric.Common;
- using System.Fabric.Common.Tracing;
- using Microsoft.ServiceFabric.Services.Runtime;
- using System.Globalization;
- using System.Text;
-
///
/// ServiceEventListener is a class which listens to the eventsources registered and redirects the traces to a file
/// Note that this class serves as a template to EventListener class and redirects the logs to /tmp/{appnameyyyyMMddHHmmssffff}.
@@ -24,12 +20,12 @@ namespace OcelotApplicationApiGateway
///
internal class ServiceEventListener : EventListener
{
- private string fileName;
- private string filepath = Path.GetTempPath();
+ private readonly string _fileName;
+ private readonly string _filepath = Path.GetTempPath();
public ServiceEventListener(string appName)
{
- this.fileName = appName + DateTime.Now.ToString("yyyyMMddHHmmssffff");
+ _fileName = appName + DateTime.Now.ToString("yyyyMMddHHmmssffff");
}
///
@@ -38,10 +34,10 @@ public ServiceEventListener(string appName)
/// The event arguments that describe the event.
protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
- using (StreamWriter writer = new StreamWriter( new FileStream(filepath + fileName, FileMode.Append)))
+ using (var writer = new StreamWriter(new FileStream(_filepath + _fileName, FileMode.Append)))
{
// report all event information
- writer.Write(" {0} ", Write(eventData.Task.ToString(),
+ writer.Write(" {0} ", Write(eventData.Task.ToString(),
eventData.EventName,
eventData.EventId.ToString(),
eventData.Level));
@@ -55,9 +51,9 @@ protected override void OnEventWritten(EventWrittenEventArgs eventData)
private static String Write(string taskName, string eventName, string id, EventLevel level)
{
- StringBuilder output = new StringBuilder();
+ var output = new StringBuilder();
- DateTime now = DateTime.UtcNow;
+ var now = DateTime.UtcNow;
output.Append(now.ToString("yyyy/MM/dd-HH:mm:ss.fff", CultureInfo.InvariantCulture));
output.Append(',');
output.Append(ConvertLevelToString(level));
@@ -91,4 +87,4 @@ private static string ConvertLevelToString(EventLevel level)
}
}
}
-}
\ No newline at end of file
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventSource.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventSource.cs
index c057995560..f880f6af0b 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventSource.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/ServiceEventSource.cs
@@ -3,19 +3,17 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------
+using System;
+using System.Diagnostics.Tracing;
+
namespace OcelotApplicationApiGateway
{
- using System;
- using System.Diagnostics.Tracing;
- using System.Fabric;
- using Microsoft.ServiceFabric.Services.Runtime;
-
///
/// Implements methods for logging service related events.
///
public class ServiceEventSource : EventSource
{
- public static ServiceEventSource Current = new ServiceEventSource();
+ public static ServiceEventSource Current = new();
// Define an instance method for each event you want to record and apply an [Event] attribute to it.
// The method name is the name of the event.
@@ -28,10 +26,10 @@ public class ServiceEventSource : EventSource
[NonEvent]
public void Message(string message, params object[] args)
{
- if (this.IsEnabled())
+ if (IsEnabled())
{
var finalMessage = string.Format(message, args);
- this.Message(finalMessage);
+ Message(finalMessage);
}
}
@@ -40,9 +38,9 @@ public void Message(string message, params object[] args)
[Event(MessageEventId, Level = EventLevel.Informational, Message = "{0}")]
public void Message(string message)
{
- if (this.IsEnabled())
+ if (IsEnabled())
{
- this.WriteEvent(MessageEventId, message);
+ WriteEvent(MessageEventId, message);
}
}
@@ -51,13 +49,13 @@ public void Message(string message)
[Event(ServiceTypeRegisteredEventId, Level = EventLevel.Informational, Message = "Service host process {0} registered service type {1}")]
public void ServiceTypeRegistered(int hostProcessId, string serviceType)
{
- this.WriteEvent(ServiceTypeRegisteredEventId, hostProcessId, serviceType);
+ WriteEvent(ServiceTypeRegisteredEventId, hostProcessId, serviceType);
}
[NonEvent]
public void ServiceHostInitializationFailed(Exception e)
{
- this.ServiceHostInitializationFailed(e.ToString());
+ ServiceHostInitializationFailed(e.ToString());
}
private const int ServiceHostInitializationFailedEventId = 4;
@@ -65,13 +63,13 @@ public void ServiceHostInitializationFailed(Exception e)
[Event(ServiceHostInitializationFailedEventId, Level = EventLevel.Error, Message = "Service host initialization failed: {0}")]
private void ServiceHostInitializationFailed(string exception)
{
- this.WriteEvent(ServiceHostInitializationFailedEventId, exception);
+ WriteEvent(ServiceHostInitializationFailedEventId, exception);
}
[NonEvent]
public void ServiceWebHostBuilderFailed(Exception e)
{
- this.ServiceWebHostBuilderFailed(e.ToString());
+ ServiceWebHostBuilderFailed(e.ToString());
}
private const int ServiceWebHostBuilderFailedEventId = 5;
@@ -79,7 +77,7 @@ public void ServiceWebHostBuilderFailed(Exception e)
[Event(ServiceWebHostBuilderFailedEventId, Level = EventLevel.Error, Message = "Service Owin Web Host Builder Failed: {0}")]
private void ServiceWebHostBuilderFailed(string exception)
{
- this.WriteEvent(ServiceWebHostBuilderFailedEventId, exception);
+ WriteEvent(ServiceWebHostBuilderFailedEventId, exception);
}
}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/WebCommunicationListener.cs b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/WebCommunicationListener.cs
index c1f4a1730c..18a80a34f8 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/WebCommunicationListener.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationApiGateway/WebCommunicationListener.cs
@@ -3,63 +3,62 @@
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------
+using System;
+using System.Fabric;
+using System.Globalization;
+using System.Threading;
+using System.Threading.Tasks;
+
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Logging;
+using Microsoft.ServiceFabric.Services.Communication.Runtime;
+
+using Ocelot.DependencyInjection;
+using Ocelot.Middleware;
+
namespace OcelotApplicationApiGateway
{
- using System;
- using System.Fabric;
- using System.Fabric.Description;
- using System.Globalization;
- using System.Threading;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.ServiceFabric.Services.Communication.Runtime;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Configuration;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.Extensions.DependencyInjection;
- using Ocelot.DependencyInjection;
- using Ocelot.Middleware;
-
public class WebCommunicationListener : ICommunicationListener
{
- private readonly string appRoot;
- private readonly ServiceContext serviceInitializationParameters;
- private string listeningAddress;
- private string publishAddress;
+ private readonly string _appRoot;
+ private readonly ServiceContext _serviceInitializationParameters;
+ private string _listeningAddress;
+ private string _publishAddress;
// OWIN server handle.
- private IWebHost webHost;
+ private IWebHost _webHost;
public WebCommunicationListener(string appRoot, ServiceContext serviceInitializationParameters)
{
- this.appRoot = appRoot;
- this.serviceInitializationParameters = serviceInitializationParameters;
+ _appRoot = appRoot;
+ _serviceInitializationParameters = serviceInitializationParameters;
}
public Task OpenAsync(CancellationToken cancellationToken)
{
ServiceEventSource.Current.Message("Initialize");
- EndpointResourceDescription serviceEndpoint = this.serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("WebEndpoint");
- int port = serviceEndpoint.Port;
+ var serviceEndpoint = _serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("WebEndpoint");
+ var port = serviceEndpoint.Port;
- this.listeningAddress = string.Format(
+ _listeningAddress = string.Format(
CultureInfo.InvariantCulture,
"http://+:{0}/{1}",
port,
- string.IsNullOrWhiteSpace(this.appRoot)
+ string.IsNullOrWhiteSpace(_appRoot)
? string.Empty
- : this.appRoot.TrimEnd('/') + '/');
+ : _appRoot.TrimEnd('/') + '/');
- this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN);
+ _publishAddress = _listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN);
- ServiceEventSource.Current.Message("Starting web server on {0}", this.listeningAddress);
+ ServiceEventSource.Current.Message("Starting web server on {0}", _listeningAddress);
try
{
- this.webHost = new WebHostBuilder()
+ _webHost = new WebHostBuilder()
.UseKestrel()
- .UseUrls(this.listeningAddress)
+ .UseUrls(_listeningAddress)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config
@@ -74,33 +73,35 @@ public Task OpenAsync(CancellationToken cancellationToken)
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddConsole();
})
- .ConfigureServices(s => {
+ .ConfigureServices(s =>
+ {
s.AddOcelot();
})
- .Configure(a => {
- a.UseOcelot().Wait();
+ .Configure(a =>
+ {
+ a.UseOcelot().Wait(cancellationToken);
})
.Build();
- this.webHost.Start();
+ _webHost.Start();
}
catch (Exception ex)
{
ServiceEventSource.Current.ServiceWebHostBuilderFailed(ex);
}
- return Task.FromResult(this.publishAddress);
+ return Task.FromResult(_publishAddress);
}
public Task CloseAsync(CancellationToken cancellationToken)
{
- this.StopAll();
+ StopAll();
return Task.FromResult(true);
}
public void Abort()
{
- this.StopAll();
+ StopAll();
}
///
@@ -110,10 +111,10 @@ private void StopAll()
{
try
{
- if (this.webHost != null)
+ if (_webHost != null)
{
ServiceEventSource.Current.Message("Stopping web server.");
- this.webHost.Dispose();
+ _webHost.Dispose();
}
}
catch (ObjectDisposedException)
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/ApiGateway.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/ApiGateway.cs
index 8c09088588..e7b7b5f7f7 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationService/ApiGateway.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/ApiGateway.cs
@@ -2,15 +2,13 @@
using System.Collections.Generic;
using System.Fabric;
using System.IO;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
+
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
using Microsoft.ServiceFabric.Services.Communication.AspNetCore;
using Microsoft.ServiceFabric.Services.Communication.Runtime;
using Microsoft.ServiceFabric.Services.Runtime;
-using Microsoft.Extensions.Logging;
namespace OcelotApplicationService
{
@@ -31,7 +29,7 @@ protected override IEnumerable CreateServiceInstanceLis
{
return new ServiceInstanceListener[]
{
- new ServiceInstanceListener(serviceContext =>
+ new(serviceContext =>
new KestrelCommunicationListener(serviceContext, "ServiceEndpoint", (url, listener) =>
{
Console.WriteLine($"Starting Kestrel on {url}");
@@ -41,7 +39,7 @@ protected override IEnumerable CreateServiceInstanceLis
.UseKestrel()
.ConfigureServices(
services => services
- .AddSingleton(serviceContext))
+ .AddSingleton(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.UseUniqueServiceUrl)
.UseStartup()
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/Controllers/ValuesController.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/Controllers/ValuesController.cs
index 13e5699937..b9d4958f32 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationService/Controllers/ValuesController.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/Controllers/ValuesController.cs
@@ -1,7 +1,5 @@
-using System;
using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
+
using Microsoft.AspNetCore.Mvc;
namespace OcelotApplicationService.Controllers
@@ -13,7 +11,7 @@ public class ValuesController : Controller
[HttpGet]
public IEnumerable Get()
{
- return new string[] { "value1", "value2" };
+ return new[] { "value1", "value2" };
}
// GET api/values/5
@@ -25,13 +23,13 @@ public string Get(int id)
// POST api/values
[HttpPost]
- public void Post([FromBody]string value)
+ public void Post([FromBody] string value)
{
}
// PUT api/values/5
[HttpPut("{id}")]
- public void Put(int id, [FromBody]string value)
+ public void Put(int id, [FromBody] string value)
{
}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/OcelotApplicationService.csproj b/samples/OcelotServiceFabric/src/OcelotApplicationService/OcelotApplicationService.csproj
index b7df220e49..f840126171 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationService/OcelotApplicationService.csproj
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/OcelotApplicationService.csproj
@@ -1,18 +1,18 @@
-
+
Stateless Service Application
-
- Exe
- net5.0
+ net7.0
OcelotApplicationService
OcelotApplicationService
$(PackageTargetFallback)
+ x64
-
-
-
-
-
+
+
+
+
+
+
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/Program.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/Program.cs
index b9d7d72e43..4862426a64 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationService/Program.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/Program.cs
@@ -1,8 +1,8 @@
-using Microsoft.ServiceFabric.Services.Runtime;
using System;
using System.Diagnostics;
using System.Threading;
-using System.Threading.Tasks;
+
+using Microsoft.ServiceFabric.Services.Runtime;
namespace OcelotApplicationService
{
@@ -23,7 +23,7 @@ private static void Main()
ServiceRuntime.RegisterServiceAsync("OcelotApplicationServiceType",
context => new ApiGateway(context)).GetAwaiter().GetResult();
- ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(ApiGateway).Name);
+ ServiceEventSource.Current.ServiceTypeRegistered(Environment.ProcessId, nameof(ApiGateway));
// Prevents this host process from terminating so services keeps running.
Thread.Sleep(Timeout.Infinite);
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/Properties/launchSettings.json b/samples/OcelotServiceFabric/src/OcelotApplicationService/Properties/launchSettings.json
new file mode 100644
index 0000000000..fb64c02b5e
--- /dev/null
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/Properties/launchSettings.json
@@ -0,0 +1,12 @@
+{
+ "profiles": {
+ "OcelotApplicationService": {
+ "commandName": "Project",
+ "launchBrowser": true,
+ "environmentVariables": {
+ "ASPNETCORE_ENVIRONMENT": "Development"
+ },
+ "applicationUrl": "https://localhost:57625;http://localhost:57626"
+ }
+ }
+}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/ServiceEventSource.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/ServiceEventSource.cs
index 13e2df12a0..f58ddcbcc2 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationService/ServiceEventSource.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/ServiceEventSource.cs
@@ -1,9 +1,6 @@
using System;
-using System.Collections.Generic;
using System.Diagnostics.Tracing;
using System.Fabric;
-using System.Linq;
-using System.Text;
using System.Threading.Tasks;
namespace OcelotApplicationService
@@ -11,7 +8,7 @@ namespace OcelotApplicationService
[EventSource(Name = "MyCompany-ServiceOcelotApplication-OcelotService")]
internal sealed class ServiceEventSource : EventSource
{
- public static readonly ServiceEventSource Current = new ServiceEventSource();
+ public static readonly ServiceEventSource Current = new();
static ServiceEventSource()
{
@@ -46,9 +43,9 @@ public static class Keywords
[NonEvent]
public void Message(string message, params object[] args)
{
- if (this.IsEnabled())
+ if (IsEnabled())
{
- string finalMessage = string.Format(message, args);
+ var finalMessage = string.Format(message, args);
Message(finalMessage);
}
}
@@ -57,7 +54,7 @@ public void Message(string message, params object[] args)
[Event(MessageEventId, Level = EventLevel.Informational, Message = "{0}")]
public void Message(string message)
{
- if (this.IsEnabled())
+ if (IsEnabled())
{
WriteEvent(MessageEventId, message);
}
@@ -66,10 +63,10 @@ public void Message(string message)
[NonEvent]
public void ServiceMessage(ServiceContext serviceContext, string message, params object[] args)
{
- if (this.IsEnabled())
+ if (IsEnabled())
{
- string finalMessage = string.Format(message, args);
+ var finalMessage = string.Format(message, args);
ServiceMessage(
serviceContext.ServiceName.ToString(),
serviceContext.ServiceTypeName,
@@ -157,14 +154,12 @@ public void ServiceRequestStop(string requestTypeName, string exception = "")
#region Private methods
private static long GetReplicaOrInstanceId(ServiceContext context)
{
- StatelessServiceContext stateless = context as StatelessServiceContext;
- if (stateless != null)
+ if (context is StatelessServiceContext stateless)
{
return stateless.InstanceId;
}
- StatefulServiceContext stateful = context as StatefulServiceContext;
- if (stateful != null)
+ if (context is StatefulServiceContext stateful)
{
return stateful.ReplicaId;
}
diff --git a/samples/OcelotServiceFabric/src/OcelotApplicationService/Startup.cs b/samples/OcelotServiceFabric/src/OcelotApplicationService/Startup.cs
index 022fcb0ee2..53b408e90c 100644
--- a/samples/OcelotServiceFabric/src/OcelotApplicationService/Startup.cs
+++ b/samples/OcelotServiceFabric/src/OcelotApplicationService/Startup.cs
@@ -1,13 +1,8 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Options;
+using Microsoft.Extensions.Hosting;
namespace OcelotApplicationService
{
@@ -27,14 +22,12 @@ public void ConfigureServices(IServiceCollection services)
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env)
+ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
-
- app.UseMvc();
}
}
}
diff --git a/samples/OcelotServiceFabric/src/global.json b/samples/OcelotServiceFabric/src/global.json
deleted file mode 100644
index 8288598ab8..0000000000
--- a/samples/OcelotServiceFabric/src/global.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "projects": [ "../"],
- "sdk": {
- "version": "2.1.4"
- }
-}
\ No newline at end of file
diff --git a/src/Ocelot.Administration/IIdentityServerConfiguration.cs b/src/Ocelot.Administration/IIdentityServerConfiguration.cs
index cbfa289e17..e2260e59a4 100644
--- a/src/Ocelot.Administration/IIdentityServerConfiguration.cs
+++ b/src/Ocelot.Administration/IIdentityServerConfiguration.cs
@@ -1,7 +1,7 @@
+using System.Collections.Generic;
+
namespace Ocelot.Administration
{
- using System.Collections.Generic;
-
public interface IIdentityServerConfiguration
{
string ApiName { get; }
diff --git a/src/Ocelot.Administration/IdentityServerConfiguration.cs b/src/Ocelot.Administration/IdentityServerConfiguration.cs
index a560f032df..0e44044fde 100644
--- a/src/Ocelot.Administration/IdentityServerConfiguration.cs
+++ b/src/Ocelot.Administration/IdentityServerConfiguration.cs
@@ -1,7 +1,7 @@
+using System.Collections.Generic;
+
namespace Ocelot.Administration
{
- using System.Collections.Generic;
-
public class IdentityServerConfiguration : IIdentityServerConfiguration
{
public IdentityServerConfiguration(
diff --git a/src/Ocelot.Administration/IdentityServerMiddlewareConfigurationProvider.cs b/src/Ocelot.Administration/IdentityServerMiddlewareConfigurationProvider.cs
index 0d26346304..1b57a00649 100644
--- a/src/Ocelot.Administration/IdentityServerMiddlewareConfigurationProvider.cs
+++ b/src/Ocelot.Administration/IdentityServerMiddlewareConfigurationProvider.cs
@@ -1,11 +1,14 @@
-namespace Ocelot.Administration
-{
- using Configuration.Repository;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.Extensions.DependencyInjection;
- using Ocelot.Middleware;
- using System.Threading.Tasks;
+using System.Threading.Tasks;
+
+using Ocelot.Configuration.Repository;
+
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using Ocelot.Middleware;
+
+namespace Ocelot.Administration
+{
public static class IdentityServerMiddlewareConfigurationProvider
{
public static OcelotMiddlewareConfigurationDelegate Get = builder =>
diff --git a/src/Ocelot.Administration/Ocelot.Administration.csproj b/src/Ocelot.Administration/Ocelot.Administration.csproj
index e449ce9f32..05419353e7 100644
--- a/src/Ocelot.Administration/Ocelot.Administration.csproj
+++ b/src/Ocelot.Administration/Ocelot.Administration.csproj
@@ -1,6 +1,6 @@
- net5.0
+ net7.0
true
Provides Ocelot extensions to use the administration API and IdentityService dependencies that come with it
Ocelot.Administration
@@ -9,8 +9,7 @@
Ocelot.Administration
API Gateway;.NET core
https://github.com/ThreeMammals/Ocelot.Administration
- https://github.com/ThreeMammals/Ocelot.Administration
- http://threemammals.com/images/ocelot_logo.png
+ https://raw.githubusercontent.com/ThreeMammals/Ocelot/develop/images/ocelot_logo.png
win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64
false
false
@@ -18,6 +17,8 @@
false
Tom Pallister
..\..\codeanalysis.ruleset
+ True
+ 1591
full
@@ -27,11 +28,11 @@
-
+
all
-
+
diff --git a/src/Ocelot.Administration/OcelotBuilderExtensions.cs b/src/Ocelot.Administration/OcelotBuilderExtensions.cs
index cf14fc1e44..23a93460be 100644
--- a/src/Ocelot.Administration/OcelotBuilderExtensions.cs
+++ b/src/Ocelot.Administration/OcelotBuilderExtensions.cs
@@ -1,17 +1,20 @@
-using Ocelot.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.IdentityModel.Tokens.Jwt;
+using System.Linq;
+using System.Security.Cryptography.X509Certificates;
+
using IdentityServer4.AccessTokenValidation;
using IdentityServer4.Models;
+
+using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
-using Ocelot.Middleware;
-using System;
-using System.Collections.Generic;
-using System.IdentityModel.Tokens.Jwt;
-using System.Security.Cryptography.X509Certificates;
-using System.Linq;
using Microsoft.IdentityModel.Tokens;
-using Microsoft.AspNetCore.Authentication.JwtBearer;
+
+using Ocelot.DependencyInjection;
+using Ocelot.Middleware;
namespace Ocelot.Administration
{
@@ -21,7 +24,7 @@ public static IOcelotAdministrationBuilder AddAdministration(this IOcelotBuilder
{
var administrationPath = new AdministrationPath(path);
- builder.Services.AddSingleton(IdentityServerMiddlewareConfigurationProvider.Get);
+ builder.Services.AddSingleton(IdentityServerMiddlewareConfigurationProvider.Get);
//add identity server for admin area
var identityServerConfiguration = IdentityServerConfigurationCreator.GetIdentityServerConfiguration(secret);
@@ -38,7 +41,7 @@ public static IOcelotAdministrationBuilder AddAdministration(this IOcelotBuilder
public static IOcelotAdministrationBuilder AddAdministration(this IOcelotBuilder builder, string path, Action configureOptions)
{
var administrationPath = new AdministrationPath(path);
- builder.Services.AddSingleton(IdentityServerMiddlewareConfigurationProvider.Get);
+ builder.Services.AddSingleton(IdentityServerMiddlewareConfigurationProvider.Get);
if (configureOptions != null)
{
@@ -58,7 +61,7 @@ private static void AddIdentityServer(Action configOptions, IO
private static void AddIdentityServer(IIdentityServerConfiguration identityServerConfiguration, IAdministrationPath adminPath, IOcelotBuilder builder, IConfiguration configuration)
{
- builder.Services.TryAddSingleton(identityServerConfiguration);
+ builder.Services.TryAddSingleton(identityServerConfiguration);
var identityServerBuilder = builder.Services
.AddIdentityServer(o =>
{
@@ -108,11 +111,11 @@ private static List Resources(IIdentityServerConfiguration identity
{
return new List
{
- new ApiResource(identityServerConfiguration.ApiName, identityServerConfiguration.ApiName)
+ new(identityServerConfiguration.ApiName, identityServerConfiguration.ApiName)
{
ApiSecrets = new List
{
- new Secret
+ new()
{
Value = identityServerConfiguration.ApiSecret.Sha256(),
},
@@ -125,11 +128,11 @@ private static List Client(IIdentityServerConfiguration identityServerCo
{
return new List
{
- new Client
+ new()
{
ClientId = identityServerConfiguration.ApiName,
AllowedGrantTypes = GrantTypes.ClientCredentials,
- ClientSecrets = new List {new Secret(identityServerConfiguration.ApiSecret.Sha256())},
+ ClientSecrets = new List {new(identityServerConfiguration.ApiSecret.Sha256())},
AllowedScopes = identityServerConfiguration.AllowedScopes,
},
};
diff --git a/src/Ocelot.Cache.CacheManager/Ocelot.Cache.CacheManager.csproj b/src/Ocelot.Cache.CacheManager/Ocelot.Cache.CacheManager.csproj
index 43baa33295..898dd02c2c 100644
--- a/src/Ocelot.Cache.CacheManager/Ocelot.Cache.CacheManager.csproj
+++ b/src/Ocelot.Cache.CacheManager/Ocelot.Cache.CacheManager.csproj
@@ -1,6 +1,6 @@
- net5.0
+ net7.0
true
Provides Ocelot extensions to use CacheManager.Net
Ocelot.Cache.CacheManager
@@ -9,7 +9,7 @@
Ocelot.Cache.CacheManager
API Gateway;.NET core
https://github.com/ThreeMammals/Ocelot.Cache.CacheManager
- https://github.com/ThreeMammals/Ocelot.Cache.CacheManager
+ https://raw.githubusercontent.com/ThreeMammals/Ocelot/develop/images/ocelot_logo.png
win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64
false
false
@@ -17,6 +17,8 @@
false
Tom Pallister
..\..\codeanalysis.ruleset
+ True
+ 1591
full
@@ -26,7 +28,7 @@
-
+
all
diff --git a/src/Ocelot.Cache.CacheManager/OcelotBuilderExtensions.cs b/src/Ocelot.Cache.CacheManager/OcelotBuilderExtensions.cs
index 7a2c2d8684..f9799607cb 100644
--- a/src/Ocelot.Cache.CacheManager/OcelotBuilderExtensions.cs
+++ b/src/Ocelot.Cache.CacheManager/OcelotBuilderExtensions.cs
@@ -1,13 +1,17 @@
-namespace Ocelot.Cache.CacheManager
-{
- using Configuration;
- using Configuration.File;
- using DependencyInjection;
- using global::CacheManager.Core;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.DependencyInjection.Extensions;
- using System;
+using System;
+
+using Ocelot.Configuration;
+using Ocelot.Configuration.File;
+
+using Ocelot.DependencyInjection;
+using global::CacheManager.Core;
+
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+
+namespace Ocelot.Cache.CacheManager
+{
public static class OcelotBuilderExtensions
{
public static IOcelotBuilder AddCacheManager(this IOcelotBuilder builder, Action settings)
@@ -17,21 +21,21 @@ public static IOcelotBuilder AddCacheManager(this IOcelotBuilder builder, Action
builder.Services.RemoveAll(typeof(ICacheManager));
builder.Services.RemoveAll(typeof(IOcelotCache));
- builder.Services.AddSingleton>(cacheManagerOutputCache);
+ builder.Services.AddSingleton(cacheManagerOutputCache);
builder.Services.AddSingleton>(ocelotOutputCacheManager);
var ocelotConfigCacheManagerOutputCache = CacheFactory.Build("OcelotConfigurationCache", settings);
var ocelotConfigCacheManager = new OcelotCacheManagerCache(ocelotConfigCacheManagerOutputCache);
builder.Services.RemoveAll(typeof(ICacheManager));
builder.Services.RemoveAll(typeof(IOcelotCache));
- builder.Services.AddSingleton>(ocelotConfigCacheManagerOutputCache);
+ builder.Services.AddSingleton(ocelotConfigCacheManagerOutputCache);
builder.Services.AddSingleton>(ocelotConfigCacheManager);
var fileConfigCacheManagerOutputCache = CacheFactory.Build("FileConfigurationCache", settings);
var fileConfigCacheManager = new OcelotCacheManagerCache(fileConfigCacheManagerOutputCache);
builder.Services.RemoveAll(typeof(ICacheManager));
builder.Services.RemoveAll(typeof(IOcelotCache));
- builder.Services.AddSingleton>(fileConfigCacheManagerOutputCache);
+ builder.Services.AddSingleton(fileConfigCacheManagerOutputCache);
builder.Services.AddSingleton>(fileConfigCacheManager);
builder.Services.RemoveAll(typeof(ICacheKeyGenerator));
diff --git a/src/Ocelot.Cache.CacheManager/OcelotCacheManagerCache.cs b/src/Ocelot.Cache.CacheManager/OcelotCacheManagerCache.cs
index a95df4c4f1..b4b31aa65c 100644
--- a/src/Ocelot.Cache.CacheManager/OcelotCacheManagerCache.cs
+++ b/src/Ocelot.Cache.CacheManager/OcelotCacheManagerCache.cs
@@ -1,8 +1,9 @@
-namespace Ocelot.Cache.CacheManager
-{
- using global::CacheManager.Core;
- using System;
+using System;
+
+using global::CacheManager.Core;
+namespace Ocelot.Cache.CacheManager
+{
public class OcelotCacheManagerCache : IOcelotCache
{
private readonly ICacheManager _cacheManager;
diff --git a/src/Ocelot.Provider.Consul/Consul.cs b/src/Ocelot.Provider.Consul/Consul.cs
index 72f15d0954..2e73f52711 100644
--- a/src/Ocelot.Provider.Consul/Consul.cs
+++ b/src/Ocelot.Provider.Consul/Consul.cs
@@ -1,15 +1,20 @@
-namespace Ocelot.Provider.Consul
-{
- using global::Consul;
- using Infrastructure.Extensions;
- using Logging;
- using ServiceDiscovery.Providers;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Values;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+using global::Consul;
+
+using Ocelot.Infrastructure.Extensions;
+
+using Ocelot.Logging;
+using Ocelot.ServiceDiscovery.Providers;
+
+using Ocelot.Values;
+
+namespace Ocelot.Provider.Consul
+{
public class Consul : IServiceDiscoveryProvider
{
private readonly ConsulRegistryConfiguration _config;
@@ -54,7 +59,7 @@ public async Task> Get()
return services.ToList();
}
- private Service BuildService(ServiceEntry serviceEntry, Node serviceNode)
+ private static Service BuildService(ServiceEntry serviceEntry, Node serviceNode)
{
return new Service(
serviceEntry.Service.Service,
@@ -64,7 +69,7 @@ private Service BuildService(ServiceEntry serviceEntry, Node serviceNode)
serviceEntry.Service.Tags ?? Enumerable.Empty());
}
- private bool IsValid(ServiceEntry serviceEntry)
+ private static bool IsValid(ServiceEntry serviceEntry)
{
if (string.IsNullOrEmpty(serviceEntry.Service.Address) || serviceEntry.Service.Address.Contains("http://") || serviceEntry.Service.Address.Contains("https://") || serviceEntry.Service.Port <= 0)
{
@@ -74,7 +79,7 @@ private bool IsValid(ServiceEntry serviceEntry)
return true;
}
- private string GetVersionFromStrings(IEnumerable strings)
+ private static string GetVersionFromStrings(IEnumerable strings)
{
return strings
?.FirstOrDefault(x => x.StartsWith(VersionPrefix, StringComparison.Ordinal))
diff --git a/src/Ocelot.Provider.Consul/ConsulClientFactory.cs b/src/Ocelot.Provider.Consul/ConsulClientFactory.cs
index 94055df790..c8142026fd 100644
--- a/src/Ocelot.Provider.Consul/ConsulClientFactory.cs
+++ b/src/Ocelot.Provider.Consul/ConsulClientFactory.cs
@@ -1,8 +1,9 @@
-namespace Ocelot.Provider.Consul
-{
- using global::Consul;
- using System;
+using System;
+
+using global::Consul;
+namespace Ocelot.Provider.Consul
+{
public class ConsulClientFactory : IConsulClientFactory
{
public IConsulClient Get(ConsulRegistryConfiguration config)
diff --git a/src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs b/src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs
index 56e55dfe7a..e67fd83eb7 100644
--- a/src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs
+++ b/src/Ocelot.Provider.Consul/ConsulFileConfigurationRepository.cs
@@ -1,16 +1,22 @@
-namespace Ocelot.Provider.Consul
-{
- using Configuration.File;
- using Configuration.Repository;
- using global::Consul;
- using Logging;
- using Microsoft.Extensions.Options;
- using Newtonsoft.Json;
- using Responses;
- using System;
- using System.Text;
- using System.Threading.Tasks;
+using System;
+using System.Text;
+using System.Threading.Tasks;
+
+using Ocelot.Configuration.File;
+using Ocelot.Configuration.Repository;
+
+using global::Consul;
+
+using Ocelot.Logging;
+using Microsoft.Extensions.Options;
+
+using Newtonsoft.Json;
+
+using Ocelot.Responses;
+
+namespace Ocelot.Provider.Consul
+{
public class ConsulFileConfigurationRepository : IFileConfigurationRepository
{
private readonly IConsulClient _consul;
@@ -70,7 +76,7 @@ public async Task Set(FileConfiguration ocelotConfiguration)
var kvPair = new KVPair(_configurationKey)
{
- Value = bytes
+ Value = bytes,
};
var result = await _consul.KV.Put(kvPair);
diff --git a/src/Ocelot.Provider.Consul/ConsulMiddlewareConfigurationProvider.cs b/src/Ocelot.Provider.Consul/ConsulMiddlewareConfigurationProvider.cs
index 1b89b4f333..4be20d55d1 100644
--- a/src/Ocelot.Provider.Consul/ConsulMiddlewareConfigurationProvider.cs
+++ b/src/Ocelot.Provider.Consul/ConsulMiddlewareConfigurationProvider.cs
@@ -1,17 +1,21 @@
-namespace Ocelot.Provider.Consul
-{
- using Configuration.Creator;
- using Configuration.File;
- using Configuration.Repository;
- using Microsoft.AspNetCore.Builder;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Options;
- using Middleware;
- using Responses;
- using System;
- using System.Linq;
- using System.Threading.Tasks;
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+
+using Ocelot.Configuration.Creator;
+using Ocelot.Configuration.File;
+using Ocelot.Configuration.Repository;
+
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
+using Ocelot.Middleware;
+
+using Ocelot.Responses;
+
+namespace Ocelot.Provider.Consul
+{
public static class ConsulMiddlewareConfigurationProvider
{
public static OcelotMiddlewareConfigurationDelegate Get = async builder =>
@@ -77,7 +81,7 @@ private static async Task SetFileConfigInConsul(IApplicationBuilder builder,
private static void ThrowToStopOcelotStarting(Response config)
{
- throw new Exception($"Unable to start Ocelot, errors are: {string.Join(",", config.Errors.Select(x => x.ToString()))}");
+ throw new Exception($"Unable to start Ocelot, errors are: {string.Join(',', config.Errors.Select(x => x.ToString()))}");
}
private static bool IsError(Response response)
diff --git a/src/Ocelot.Provider.Consul/ConsulProviderFactory.cs b/src/Ocelot.Provider.Consul/ConsulProviderFactory.cs
index ac1f2dfb0a..9392f461bc 100644
--- a/src/Ocelot.Provider.Consul/ConsulProviderFactory.cs
+++ b/src/Ocelot.Provider.Consul/ConsulProviderFactory.cs
@@ -1,9 +1,11 @@
-namespace Ocelot.Provider.Consul
-{
- using Logging;
- using Microsoft.Extensions.DependencyInjection;
- using ServiceDiscovery;
+using Ocelot.Logging;
+
+using Microsoft.Extensions.DependencyInjection;
+
+using Ocelot.ServiceDiscovery;
+namespace Ocelot.Provider.Consul
+{
public static class ConsulProviderFactory
{
public static ServiceDiscoveryFinderDelegate Get = (provider, config, route) =>
diff --git a/src/Ocelot.Provider.Consul/IConsulClientFactory.cs b/src/Ocelot.Provider.Consul/IConsulClientFactory.cs
index 3710a81816..f9430dec70 100644
--- a/src/Ocelot.Provider.Consul/IConsulClientFactory.cs
+++ b/src/Ocelot.Provider.Consul/IConsulClientFactory.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Provider.Consul
-{
- using global::Consul;
+using global::Consul;
+namespace Ocelot.Provider.Consul
+{
public interface IConsulClientFactory
{
IConsulClient Get(ConsulRegistryConfiguration config);
diff --git a/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj b/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj
index 13472b0269..fc725e207f 100644
--- a/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj
+++ b/src/Ocelot.Provider.Consul/Ocelot.Provider.Consul.csproj
@@ -1,6 +1,6 @@
- net5.0
+ net7.0
true
Provides Ocelot extensions to use Consul
Ocelot.Provider.Consul
@@ -9,8 +9,7 @@
Ocelot.Provider.Consul
API Gateway;.NET core
https://github.com/ThreeMammals/Ocelot.Provider.Consul
- https://github.com/ThreeMammals/Ocelot.Provider.Consul
- http://threemammals.com/images/ocelot_logo.png
+ https://raw.githubusercontent.com/ThreeMammals/Ocelot/develop/images/ocelot_logo.png
win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64
false
false
@@ -18,6 +17,8 @@
false
Tom Pallister
..\..\codeanalysis.ruleset
+ True
+ 1591
full
@@ -27,8 +28,8 @@
-
-
+
+
all
diff --git a/src/Ocelot.Provider.Consul/OcelotBuilderExtensions.cs b/src/Ocelot.Provider.Consul/OcelotBuilderExtensions.cs
index ce2ed95bb7..40548178ca 100644
--- a/src/Ocelot.Provider.Consul/OcelotBuilderExtensions.cs
+++ b/src/Ocelot.Provider.Consul/OcelotBuilderExtensions.cs
@@ -1,17 +1,17 @@
-namespace Ocelot.Provider.Consul
-{
- using Configuration.Repository;
- using DependencyInjection;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.DependencyInjection.Extensions;
- using Middleware;
- using ServiceDiscovery;
+using Ocelot.Configuration.Repository;
+
+using Ocelot.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+
+namespace Ocelot.Provider.Consul
+{
public static class OcelotBuilderExtensions
{
public static IOcelotBuilder AddConsul(this IOcelotBuilder builder)
{
- builder.Services.AddSingleton(ConsulProviderFactory.Get);
+ builder.Services.AddSingleton(ConsulProviderFactory.Get);
builder.Services.AddSingleton();
builder.Services.RemoveAll(typeof(IFileConfigurationPollerOptions));
builder.Services.AddSingleton();
@@ -20,7 +20,7 @@ public static IOcelotBuilder AddConsul(this IOcelotBuilder builder)
public static IOcelotBuilder AddConfigStoredInConsul(this IOcelotBuilder builder)
{
- builder.Services.AddSingleton(ConsulMiddlewareConfigurationProvider.Get);
+ builder.Services.AddSingleton(ConsulMiddlewareConfigurationProvider.Get);
builder.Services.AddHostedService();
builder.Services.AddSingleton();
return builder;
diff --git a/src/Ocelot.Provider.Consul/PollConsul.cs b/src/Ocelot.Provider.Consul/PollConsul.cs
new file mode 100644
index 0000000000..b5ac65d862
--- /dev/null
+++ b/src/Ocelot.Provider.Consul/PollConsul.cs
@@ -0,0 +1,53 @@
+using Ocelot.Logging;
+using Ocelot.ServiceDiscovery.Providers;
+using Ocelot.Values;
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Ocelot.Provider.Consul;
+
+public sealed class PollConsul : IServiceDiscoveryProvider, IDisposable
+{
+ private readonly IOcelotLogger _logger;
+ private readonly IServiceDiscoveryProvider _consulServiceDiscoveryProvider;
+ private Timer _timer;
+ private bool _polling;
+ private List _services;
+
+ public PollConsul(int pollingInterval, IOcelotLoggerFactory factory, IServiceDiscoveryProvider consulServiceDiscoveryProvider)
+ {
+ _logger = factory.CreateLogger();
+ _consulServiceDiscoveryProvider = consulServiceDiscoveryProvider;
+ _services = new List();
+
+ _timer = new Timer(async x =>
+ {
+ if (_polling)
+ {
+ return;
+ }
+
+ _polling = true;
+ await Poll();
+ _polling = false;
+ }, null, pollingInterval, pollingInterval);
+ }
+
+ public void Dispose()
+ {
+ _timer?.Dispose();
+ _timer = null;
+ }
+
+ public Task> Get()
+ {
+ return Task.FromResult(_services);
+ }
+
+ private async Task Poll()
+ {
+ _services = await _consulServiceDiscoveryProvider.Get();
+ }
+}
diff --git a/src/Ocelot.Provider.Consul/PollingConsulServiceDiscoveryProvider.cs b/src/Ocelot.Provider.Consul/PollingConsulServiceDiscoveryProvider.cs
deleted file mode 100644
index 5bace80218..0000000000
--- a/src/Ocelot.Provider.Consul/PollingConsulServiceDiscoveryProvider.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-namespace Ocelot.Provider.Consul
-{
- using Logging;
- using ServiceDiscovery.Providers;
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Threading.Tasks;
- using Values;
-
- public sealed class PollConsul : IServiceDiscoveryProvider, IDisposable
- {
- private readonly IOcelotLogger _logger;
- private readonly IServiceDiscoveryProvider _consulServiceDiscoveryProvider;
- private Timer _timer;
- private bool _polling;
- private List _services;
-
- public PollConsul(int pollingInterval, IOcelotLoggerFactory factory, IServiceDiscoveryProvider consulServiceDiscoveryProvider)
- {
- _logger = factory.CreateLogger();
- _consulServiceDiscoveryProvider = consulServiceDiscoveryProvider;
- _services = new List();
-
- _timer = new Timer(async x =>
- {
- if (_polling)
- {
- return;
- }
-
- _polling = true;
- await Poll();
- _polling = false;
- }, null, pollingInterval, pollingInterval);
- }
-
- public void Dispose()
- {
- _timer?.Dispose();
- _timer = null;
- }
-
- public Task> Get()
- {
- return Task.FromResult(_services);
- }
-
- private async Task Poll()
- {
- _services = await _consulServiceDiscoveryProvider.Get();
- }
- }
-}
diff --git a/src/Ocelot.Provider.Consul/UnableToSetConfigInConsulError.cs b/src/Ocelot.Provider.Consul/UnableToSetConfigInConsulError.cs
index a0f0579cd1..abf7637351 100644
--- a/src/Ocelot.Provider.Consul/UnableToSetConfigInConsulError.cs
+++ b/src/Ocelot.Provider.Consul/UnableToSetConfigInConsulError.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Provider.Consul
-{
- using Ocelot.Errors;
+using Ocelot.Errors;
+namespace Ocelot.Provider.Consul
+{
public class UnableToSetConfigInConsulError : Error
{
public UnableToSetConfigInConsulError(string s)
diff --git a/src/Ocelot.Provider.Eureka/Eureka.cs b/src/Ocelot.Provider.Eureka/Eureka.cs
index 9da8decd1e..b98fc9d043 100644
--- a/src/Ocelot.Provider.Eureka/Eureka.cs
+++ b/src/Ocelot.Provider.Eureka/Eureka.cs
@@ -1,12 +1,15 @@
-namespace Ocelot.Provider.Eureka
-{
- using Ocelot.ServiceDiscovery.Providers;
- using Steeltoe.Discovery;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Ocelot.Values;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+using Ocelot.ServiceDiscovery.Providers;
+
+using Steeltoe.Discovery;
+
+using Ocelot.Values;
+namespace Ocelot.Provider.Eureka
+{
public class Eureka : IServiceDiscoveryProvider
{
private readonly IDiscoveryClient _client;
@@ -26,7 +29,7 @@ public Task> Get()
if (instances != null && instances.Any())
{
- services.AddRange(instances.Select(i => new Service(i.ServiceId, new ServiceHostAndPort(i.Host, i.Port, i.Uri.Scheme), "", "", new List())));
+ services.AddRange(instances.Select(i => new Service(i.ServiceId, new ServiceHostAndPort(i.Host, i.Port, i.Uri.Scheme), string.Empty, string.Empty, new List())));
}
return Task.FromResult(services);
diff --git a/src/Ocelot.Provider.Eureka/EurekaMiddlewareConfigurationProvider.cs b/src/Ocelot.Provider.Eureka/EurekaMiddlewareConfigurationProvider.cs
index f893ed7228..5aec5708b5 100644
--- a/src/Ocelot.Provider.Eureka/EurekaMiddlewareConfigurationProvider.cs
+++ b/src/Ocelot.Provider.Eureka/EurekaMiddlewareConfigurationProvider.cs
@@ -1,15 +1,19 @@
-namespace Ocelot.Provider.Eureka
-{
- using Configuration;
- using Configuration.Repository;
- using Microsoft.Extensions.DependencyInjection;
- using Middleware;
- using Steeltoe.Discovery.Client;
- using System.Threading.Tasks;
+using System.Threading.Tasks;
+
+using Ocelot.Configuration;
+using Ocelot.Configuration.Repository;
+
+using Microsoft.Extensions.DependencyInjection;
+using Ocelot.Middleware;
+
+using Steeltoe.Discovery.Client;
+
+namespace Ocelot.Provider.Eureka
+{
public class EurekaMiddlewareConfigurationProvider
{
- public static OcelotMiddlewareConfigurationDelegate Get = builder =>
+ public static OcelotMiddlewareConfigurationDelegate Get { get; } = builder =>
{
var internalConfigRepo = builder.ApplicationServices.GetService();
@@ -17,7 +21,7 @@ public class EurekaMiddlewareConfigurationProvider
if (UsingEurekaServiceDiscoveryProvider(config.Data))
{
- builder.UseDiscoveryClient();
+ //builder.UseDiscoveryClient();
}
return Task.CompletedTask;
diff --git a/src/Ocelot.Provider.Eureka/EurekaProviderFactory.cs b/src/Ocelot.Provider.Eureka/EurekaProviderFactory.cs
index 13e6fc8f8c..a1d4f522a8 100644
--- a/src/Ocelot.Provider.Eureka/EurekaProviderFactory.cs
+++ b/src/Ocelot.Provider.Eureka/EurekaProviderFactory.cs
@@ -1,9 +1,11 @@
-namespace Ocelot.Provider.Eureka
-{
- using Microsoft.Extensions.DependencyInjection;
- using Ocelot.ServiceDiscovery;
- using Steeltoe.Discovery;
+using Microsoft.Extensions.DependencyInjection;
+
+using Ocelot.ServiceDiscovery;
+using Steeltoe.Discovery;
+
+namespace Ocelot.Provider.Eureka
+{
public static class EurekaProviderFactory
{
public static ServiceDiscoveryFinderDelegate Get = (provider, config, route) =>
diff --git a/src/Ocelot.Provider.Eureka/Ocelot.Provider.Eureka.csproj b/src/Ocelot.Provider.Eureka/Ocelot.Provider.Eureka.csproj
index 3581464d9f..f9543b810a 100644
--- a/src/Ocelot.Provider.Eureka/Ocelot.Provider.Eureka.csproj
+++ b/src/Ocelot.Provider.Eureka/Ocelot.Provider.Eureka.csproj
@@ -1,6 +1,6 @@
- net5.0
+ net7.0
true
Provides Ocelot extensions to use Eureka
Ocelot.Provider.Eureka
@@ -10,7 +10,7 @@
API Gateway;.NET core
https://github.com/ThreeMammals/Ocelot.Provider.Eureka
https://github.com/ThreeMammals/Ocelot.Provider.Eureka
- http://threemammals.com/images/ocelot_logo.png
+ https://raw.githubusercontent.com/ThreeMammals/Ocelot/develop/images/ocelot_logo.png
win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64
false
false
@@ -18,6 +18,8 @@
false
Tom Pallister
..\..\codeanalysis.ruleset
+ True
+ 1591
full
@@ -27,9 +29,9 @@
-
-
-
+
+
+
all
diff --git a/src/Ocelot.Provider.Eureka/OcelotBuilderExtensions.cs b/src/Ocelot.Provider.Eureka/OcelotBuilderExtensions.cs
index e141d19476..0f3d42f614 100644
--- a/src/Ocelot.Provider.Eureka/OcelotBuilderExtensions.cs
+++ b/src/Ocelot.Provider.Eureka/OcelotBuilderExtensions.cs
@@ -1,20 +1,18 @@
-namespace Ocelot.Provider.Eureka
-{
- using DependencyInjection;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.DependencyInjection;
- using Middleware;
- using ServiceDiscovery;
- using Steeltoe.Discovery.Client;
- using System.Linq;
+using Ocelot.DependencyInjection;
+
+using Microsoft.Extensions.DependencyInjection;
+using Steeltoe.Discovery.Client;
+
+namespace Ocelot.Provider.Eureka
+{
public static class OcelotBuilderExtensions
{
public static IOcelotBuilder AddEureka(this IOcelotBuilder builder)
{
builder.Services.AddDiscoveryClient(builder.Configuration);
- builder.Services.AddSingleton(EurekaProviderFactory.Get);
- builder.Services.AddSingleton(EurekaMiddlewareConfigurationProvider.Get);
+ builder.Services.AddSingleton(EurekaProviderFactory.Get);
+ builder.Services.AddSingleton(EurekaMiddlewareConfigurationProvider.Get);
return builder;
}
}
diff --git a/src/Ocelot.Provider.Kubernetes/KubeApiClientExtensions/EndPointClientV1.cs b/src/Ocelot.Provider.Kubernetes/KubeApiClientExtensions/EndPointClientV1.cs
index 3e384d32d5..cb6bd2aab7 100644
--- a/src/Ocelot.Provider.Kubernetes/KubeApiClientExtensions/EndPointClientV1.cs
+++ b/src/Ocelot.Provider.Kubernetes/KubeApiClientExtensions/EndPointClientV1.cs
@@ -1,10 +1,12 @@
-using HTTPlease;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+using HTTPlease;
+
using KubeClient;
using KubeClient.Models;
using KubeClient.ResourceClients;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
namespace Ocelot.Provider.Kubernetes.KubeApiClientExtensions
{
@@ -18,19 +20,24 @@ public EndPointClientV1(IKubeApiClient client) : base(client)
public async Task Get(string serviceName, string kubeNamespace = null, CancellationToken cancellationToken = default)
{
- if (string.IsNullOrEmpty(serviceName)) throw new ArgumentNullException(nameof(serviceName));
+ if (string.IsNullOrEmpty(serviceName))
+ {
+ throw new ArgumentNullException(nameof(serviceName));
+ }
var response = await Http.GetAsync(
_collection.WithTemplateParameters(new
{
Namespace = kubeNamespace ?? KubeClient.DefaultNamespace,
- ServiceName = serviceName
+ ServiceName = serviceName,
}),
cancellationToken
);
if (response.IsSuccessStatusCode)
+ {
return await response.ReadContentAsAsync();
+ }
return null;
}
diff --git a/src/Ocelot.Provider.Kubernetes/KubeProvider.cs b/src/Ocelot.Provider.Kubernetes/KubeProvider.cs
deleted file mode 100644
index 927e4eeadc..0000000000
--- a/src/Ocelot.Provider.Kubernetes/KubeProvider.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using KubeClient;
-using KubeClient.Models;
-using Ocelot.Logging;
-using Ocelot.ServiceDiscovery.Providers;
-using Ocelot.Values;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-using Ocelot.Provider.Kubernetes.KubeApiClientExtensions;
-
-namespace Ocelot.Provider.Kubernetes
-{
- public class KubernetesServiceDiscoveryProvider : IServiceDiscoveryProvider
- {
- private readonly KubeRegistryConfiguration _kubeRegistryConfiguration;
- private readonly IOcelotLogger _logger;
- private readonly IKubeApiClient _kubeApi;
-
- public KubernetesServiceDiscoveryProvider(KubeRegistryConfiguration kubeRegistryConfiguration, IOcelotLoggerFactory factory, IKubeApiClient kubeApi)
- {
- _kubeRegistryConfiguration = kubeRegistryConfiguration;
- _logger = factory.CreateLogger();
- _kubeApi = kubeApi;
- }
-
- public async Task> Get()
- {
- var endpoint = await _kubeApi
- .ResourceClient(client => new EndPointClientV1(client))
- .Get(_kubeRegistryConfiguration.KeyOfServiceInK8s, _kubeRegistryConfiguration.KubeNamespace);
-
- var services = new List();
- if (endpoint != null && endpoint.Subsets.Any())
- {
- services.AddRange(BuildServices(endpoint));
- }
- else
- {
- _logger.LogWarning($"namespace:{_kubeRegistryConfiguration.KubeNamespace }service:{_kubeRegistryConfiguration.KeyOfServiceInK8s} Unable to use ,it is invalid. Address must contain host only e.g. localhost and port must be greater than 0");
- }
- return services;
- }
-
- private List BuildServices(EndpointsV1 endpoint)
- {
- var services = new List();
-
- foreach (var subset in endpoint.Subsets)
- {
- services.AddRange(subset.Addresses.Select(address => new Service(endpoint.Metadata.Name,
- new ServiceHostAndPort(address.Ip, subset.Ports.First().Port),
- endpoint.Metadata.Uid, string.Empty, Enumerable.Empty())));
- }
- return services;
- }
- }
-}
diff --git a/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs b/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs
index 0927ed6dc5..0cfc2a23e5 100644
--- a/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs
+++ b/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs
@@ -1,9 +1,12 @@
-using KubeClient;
+using System;
+
+using KubeClient;
+
using Microsoft.Extensions.DependencyInjection;
+
+using Ocelot.Configuration;
using Ocelot.Logging;
using Ocelot.ServiceDiscovery;
-using System;
-using Ocelot.Configuration;
namespace Ocelot.Provider.Kubernetes
{
@@ -19,10 +22,10 @@ private static ServiceDiscovery.Providers.IServiceDiscoveryProvider GetKubeProvi
{
var kubeClient = provider.GetService();
- var k8sRegistryConfiguration = new KubeRegistryConfiguration()
+ var k8sRegistryConfiguration = new KubeRegistryConfiguration
{
KeyOfServiceInK8s = route.ServiceName,
- KubeNamespace = string.IsNullOrEmpty(route.ServiceNamespace) ? config.Namespace : route.ServiceNamespace
+ KubeNamespace = string.IsNullOrEmpty(route.ServiceNamespace) ? config.Namespace : route.ServiceNamespace,
};
var k8sServiceDiscoveryProvider = new KubernetesServiceDiscoveryProvider(k8sRegistryConfiguration, factory, kubeClient);
@@ -31,6 +34,7 @@ private static ServiceDiscovery.Providers.IServiceDiscoveryProvider GetKubeProvi
{
return new PollKubernetes(config.PollingInterval, factory, k8sServiceDiscoveryProvider);
}
+
return k8sServiceDiscoveryProvider;
}
}
diff --git a/src/Ocelot.Provider.Kubernetes/KubernetesServiceDiscoveryProvider.cs b/src/Ocelot.Provider.Kubernetes/KubernetesServiceDiscoveryProvider.cs
new file mode 100644
index 0000000000..dabf6dae49
--- /dev/null
+++ b/src/Ocelot.Provider.Kubernetes/KubernetesServiceDiscoveryProvider.cs
@@ -0,0 +1,58 @@
+using KubeClient;
+using KubeClient.Models;
+using Ocelot.Logging;
+using Ocelot.Provider.Kubernetes.KubeApiClientExtensions;
+using Ocelot.ServiceDiscovery.Providers;
+using Ocelot.Values;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Ocelot.Provider.Kubernetes;
+
+public class KubernetesServiceDiscoveryProvider : IServiceDiscoveryProvider
+{
+ private readonly KubeRegistryConfiguration _kubeRegistryConfiguration;
+ private readonly IOcelotLogger _logger;
+ private readonly IKubeApiClient _kubeApi;
+
+ public KubernetesServiceDiscoveryProvider(KubeRegistryConfiguration kubeRegistryConfiguration, IOcelotLoggerFactory factory, IKubeApiClient kubeApi)
+ {
+ _kubeRegistryConfiguration = kubeRegistryConfiguration;
+ _logger = factory.CreateLogger();
+ _kubeApi = kubeApi;
+ }
+
+ public async Task> Get()
+ {
+ var endpoint = await _kubeApi
+ .ResourceClient(client => new EndPointClientV1(client))
+ .Get(_kubeRegistryConfiguration.KeyOfServiceInK8s, _kubeRegistryConfiguration.KubeNamespace);
+
+ var services = new List();
+ if (endpoint != null && endpoint.Subsets.Any())
+ {
+ services.AddRange(BuildServices(endpoint));
+ }
+ else
+ {
+ _logger.LogWarning($"namespace:{_kubeRegistryConfiguration.KubeNamespace}service:{_kubeRegistryConfiguration.KeyOfServiceInK8s} Unable to use ,it is invalid. Address must contain host only e.g. localhost and port must be greater than 0");
+ }
+
+ return services;
+ }
+
+ private static List BuildServices(EndpointsV1 endpoint)
+ {
+ var services = new List();
+
+ foreach (var subset in endpoint.Subsets)
+ {
+ services.AddRange(subset.Addresses.Select(address => new Service(endpoint.Metadata.Name,
+ new ServiceHostAndPort(address.Ip, subset.Ports.First().Port),
+ endpoint.Metadata.Uid, string.Empty, Enumerable.Empty())));
+ }
+
+ return services;
+ }
+}
diff --git a/src/Ocelot.Provider.Kubernetes/Ocelot.Provider.Kubernetes.csproj b/src/Ocelot.Provider.Kubernetes/Ocelot.Provider.Kubernetes.csproj
index c8d1ebde18..a9ac561a64 100644
--- a/src/Ocelot.Provider.Kubernetes/Ocelot.Provider.Kubernetes.csproj
+++ b/src/Ocelot.Provider.Kubernetes/Ocelot.Provider.Kubernetes.csproj
@@ -1,12 +1,12 @@
- net5.0
+ net7.0
true
Ocelot
Provides Ocelot extensions to use kubernetes
https://github.com/ThreeMammals/Ocelot
- http://threemammals.com/images/ocelot_logo.png
+ https://raw.githubusercontent.com/ThreeMammals/Ocelot/develop/images/ocelot_logo.png
Ocelot.Provider.Kubernetes
Ocelot.Provider.Kubernetes
@@ -20,6 +20,8 @@
geffzhang
..\..\codeanalysis.ruleset
+ True
+ 1591
@@ -28,8 +30,11 @@
-
-
+
+
+
+ all
+
diff --git a/src/Ocelot.Provider.Kubernetes/OcelotBuilderExtensions.cs b/src/Ocelot.Provider.Kubernetes/OcelotBuilderExtensions.cs
index f979586a56..958b4929e3 100644
--- a/src/Ocelot.Provider.Kubernetes/OcelotBuilderExtensions.cs
+++ b/src/Ocelot.Provider.Kubernetes/OcelotBuilderExtensions.cs
@@ -1,5 +1,7 @@
using KubeClient;
+
using Microsoft.Extensions.DependencyInjection;
+
using Ocelot.DependencyInjection;
namespace Ocelot.Provider.Kubernetes
diff --git a/src/Ocelot.Provider.Kubernetes/PollKubernetes.cs b/src/Ocelot.Provider.Kubernetes/PollKubernetes.cs
index b1a90596e3..cd0e854f40 100644
--- a/src/Ocelot.Provider.Kubernetes/PollKubernetes.cs
+++ b/src/Ocelot.Provider.Kubernetes/PollKubernetes.cs
@@ -1,10 +1,11 @@
-using Ocelot.Logging;
-using Ocelot.ServiceDiscovery.Providers;
-using Ocelot.Values;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
+using Ocelot.Logging;
+using Ocelot.ServiceDiscovery.Providers;
+using Ocelot.Values;
+
namespace Ocelot.Provider.Kubernetes
{
public class PollKubernetes : IServiceDiscoveryProvider
diff --git a/src/Ocelot.Provider.Polly/CircuitBreaker.cs b/src/Ocelot.Provider.Polly/CircuitBreaker.cs
index 8d4c6d4c14..4c9a1ea673 100644
--- a/src/Ocelot.Provider.Polly/CircuitBreaker.cs
+++ b/src/Ocelot.Provider.Polly/CircuitBreaker.cs
@@ -1,21 +1,22 @@
-using Polly;
using System.Collections.Generic;
using System.Linq;
+using Polly;
+
namespace Ocelot.Provider.Polly
{
public class CircuitBreaker
{
- private readonly List _policies = new List();
+ private readonly List _policies = new();
public CircuitBreaker(params IAsyncPolicy[] policies)
{
foreach (var policy in policies.Where(p => p != null))
{
- this._policies.Add(policy);
+ _policies.Add(policy);
}
}
- public IAsyncPolicy[] Policies => this._policies.ToArray();
+ public IAsyncPolicy[] Policies => _policies.ToArray();
}
}
diff --git a/src/Ocelot.Provider.Polly/Ocelot.Provider.Polly.csproj b/src/Ocelot.Provider.Polly/Ocelot.Provider.Polly.csproj
index 8764b0122a..c9ef62be32 100644
--- a/src/Ocelot.Provider.Polly/Ocelot.Provider.Polly.csproj
+++ b/src/Ocelot.Provider.Polly/Ocelot.Provider.Polly.csproj
@@ -1,6 +1,6 @@
- net5.0
+ net7.0
true
Provides Ocelot extensions to use Polly.NET
Ocelot.Provider.Polly
@@ -10,7 +10,7 @@
API Gateway;.NET core
https://github.com/ThreeMammals/Ocelot.Provider.Polly
https://github.com/ThreeMammals/Ocelot.Provider.Polly
- http://threemammals.com/images/ocelot_logo.png
+ https://raw.githubusercontent.com/ThreeMammals/Ocelot/develop/images/ocelot_logo.png
win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64
false
false
@@ -18,6 +18,8 @@
false
Tom Pallister
..\..\codeanalysis.ruleset
+ True
+ 1591
full
@@ -27,10 +29,10 @@
-
+
all
-
+
diff --git a/src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs b/src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs
index 08c892d3d4..3bcf201f1a 100644
--- a/src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs
+++ b/src/Ocelot.Provider.Polly/OcelotBuilderExtensions.cs
@@ -1,18 +1,25 @@
-namespace Ocelot.Provider.Polly
-{
- using Configuration;
- using DependencyInjection;
- using Errors;
- using global::Polly.CircuitBreaker;
- using global::Polly.Timeout;
- using Logging;
- using Microsoft.Extensions.DependencyInjection;
- using Requester;
- using System;
- using System.Collections.Generic;
- using System.Net.Http;
- using System.Threading.Tasks;
+using System;
+using System.Collections.Generic;
+using System.Net.Http;
+using System.Threading.Tasks;
+
+using Ocelot.Configuration;
+
+using Ocelot.DependencyInjection;
+
+using Ocelot.Errors;
+
+using global::Polly.CircuitBreaker;
+using global::Polly.Timeout;
+
+using Ocelot.Logging;
+
+using Microsoft.Extensions.DependencyInjection;
+
+using Ocelot.Requester;
+namespace Ocelot.Provider.Polly
+{
public static class OcelotBuilderExtensions
{
public static IOcelotBuilder AddPolly(this IOcelotBuilder builder)
@@ -21,7 +28,7 @@ public static IOcelotBuilder AddPolly(this IOcelotBuilder builder)
{
{typeof(TaskCanceledException), e => new RequestTimedOutError(e)},
{typeof(TimeoutRejectedException), e => new RequestTimedOutError(e)},
- {typeof(BrokenCircuitException), e => new RequestTimedOutError(e)}
+ {typeof(BrokenCircuitException), e => new RequestTimedOutError(e)},
};
builder.Services.AddSingleton(errorMapping);
diff --git a/src/Ocelot.Provider.Polly/PollyCircuitBreakingDelegatingHandler.cs b/src/Ocelot.Provider.Polly/PollyCircuitBreakingDelegatingHandler.cs
index 8bdcaa4a76..43841c0a60 100644
--- a/src/Ocelot.Provider.Polly/PollyCircuitBreakingDelegatingHandler.cs
+++ b/src/Ocelot.Provider.Polly/PollyCircuitBreakingDelegatingHandler.cs
@@ -1,10 +1,12 @@
-using Ocelot.Logging;
-using Polly;
-using Polly.CircuitBreaker;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
+using Ocelot.Logging;
+
+using Polly;
+using Polly.CircuitBreaker;
+
namespace Ocelot.Provider.Polly
{
public class PollyCircuitBreakingDelegatingHandler : DelegatingHandler
@@ -30,12 +32,12 @@ protected override async Task SendAsync(HttpRequestMessage
}
catch (BrokenCircuitException ex)
{
- _logger.LogError($"Reached to allowed number of exceptions. Circuit is open", ex);
+ _logger.LogError("Reached to allowed number of exceptions. Circuit is open", ex);
throw;
}
catch (HttpRequestException ex)
{
- _logger.LogError($"Error in CircuitBreakingDelegatingHandler.SendAync", ex);
+ _logger.LogError("Error in CircuitBreakingDelegatingHandler.SendAync", ex);
throw;
}
}
diff --git a/src/Ocelot.Provider.Polly/PollyQoSProvider.cs b/src/Ocelot.Provider.Polly/PollyQoSProvider.cs
index def8c7d85e..3dcb697ed1 100644
--- a/src/Ocelot.Provider.Polly/PollyQoSProvider.cs
+++ b/src/Ocelot.Provider.Polly/PollyQoSProvider.cs
@@ -1,13 +1,16 @@
+using System;
+using System.Net.Http;
+
+using Ocelot.Configuration;
+
+using global::Polly;
+using global::Polly.CircuitBreaker;
+using global::Polly.Timeout;
+
+using Ocelot.Logging;
+
namespace Ocelot.Provider.Polly
{
- using global::Polly;
- using global::Polly.CircuitBreaker;
- using global::Polly.Timeout;
- using Ocelot.Configuration;
- using Ocelot.Logging;
- using System;
- using System.Net.Http;
-
public class PollyQoSProvider
{
private readonly AsyncCircuitBreakerPolicy _circuitBreakerPolicy;
diff --git a/src/Ocelot.Provider.Polly/RequestTimedOutError.cs b/src/Ocelot.Provider.Polly/RequestTimedOutError.cs
index 3c52a8dd04..d116ddaaf9 100644
--- a/src/Ocelot.Provider.Polly/RequestTimedOutError.cs
+++ b/src/Ocelot.Provider.Polly/RequestTimedOutError.cs
@@ -1,8 +1,9 @@
-namespace Ocelot.Provider.Polly
-{
- using Ocelot.Errors;
- using System;
+using System;
+
+using Ocelot.Errors;
+namespace Ocelot.Provider.Polly
+{
public class RequestTimedOutError : Error
{
public RequestTimedOutError(Exception exception)
diff --git a/src/Ocelot.Tracing.Butterfly/ButterflyTracer.cs b/src/Ocelot.Tracing.Butterfly/ButterflyTracer.cs
index 3cd63eb0ac..1298e8e235 100644
--- a/src/Ocelot.Tracing.Butterfly/ButterflyTracer.cs
+++ b/src/Ocelot.Tracing.Butterfly/ButterflyTracer.cs
@@ -1,18 +1,21 @@
-namespace Ocelot.Tracing.Butterfly
-{
- using global::Butterfly.Client.AspNetCore;
- using global::Butterfly.Client.Tracing;
- using global::Butterfly.OpenTracing;
- using Infrastructure.Extensions;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.DependencyInjection;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Threading;
- using System.Threading.Tasks;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Threading;
+using System.Threading.Tasks;
+
+using global::Butterfly.Client.AspNetCore;
+using global::Butterfly.Client.Tracing;
+using global::Butterfly.OpenTracing;
+
+using Ocelot.Infrastructure.Extensions;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Ocelot.Tracing.Butterfly
+{
public class ButterflyTracer : DelegatingHandler, Logging.ITracer
{
private readonly IServiceTracer _tracer;
diff --git a/src/Ocelot.Tracing.Butterfly/Ocelot.Tracing.Butterfly.csproj b/src/Ocelot.Tracing.Butterfly/Ocelot.Tracing.Butterfly.csproj
index 1182a364cd..0d6d4a9bef 100644
--- a/src/Ocelot.Tracing.Butterfly/Ocelot.Tracing.Butterfly.csproj
+++ b/src/Ocelot.Tracing.Butterfly/Ocelot.Tracing.Butterfly.csproj
@@ -1,7 +1,7 @@
- net5.0
+ net7.0
true
This package provides methods to integrate Butterfly tracing with Ocelot.
Ocelot.Tracing.Butterfly
@@ -10,7 +10,7 @@
Ocelot.Tracing.Butterfly
API Gateway;.NET core; Butterfly; ButterflyAPM
https://github.com/ThreeMammals/Ocelot
- https://github.com/ThreeMammals/Ocelot
+ https://raw.githubusercontent.com/ThreeMammals/Ocelot/develop/images/ocelot_logo.png
win10-x64;osx.10.11-x64;osx.10.12-x64;win7-x64
false
false
@@ -19,6 +19,8 @@
Tom Pallister
..\..\codeanalysis.ruleset
Ocelot.Tracing.Butterfly
+ True
+ 1591
full
@@ -30,6 +32,9 @@
+
+ all
+
diff --git a/src/Ocelot.Tracing.Butterfly/OcelotBuilderExtensions.cs b/src/Ocelot.Tracing.Butterfly/OcelotBuilderExtensions.cs
index 8c67f0dfa7..7cb920d184 100644
--- a/src/Ocelot.Tracing.Butterfly/OcelotBuilderExtensions.cs
+++ b/src/Ocelot.Tracing.Butterfly/OcelotBuilderExtensions.cs
@@ -1,11 +1,15 @@
-namespace Ocelot.Tracing.Butterfly
-{
- using DependencyInjection;
- using global::Butterfly.Client.AspNetCore;
- using Logging;
- using Microsoft.Extensions.DependencyInjection;
- using System;
+using System;
+
+using Ocelot.DependencyInjection;
+
+using global::Butterfly.Client.AspNetCore;
+using Ocelot.Logging;
+
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Ocelot.Tracing.Butterfly
+{
public static class OcelotBuilderExtensions
{
public static IOcelotBuilder AddButterfly(this IOcelotBuilder builder, Action settings)
diff --git a/src/Ocelot.Tracing.OpenTracing/Ocelot.Tracing.OpenTracing.csproj b/src/Ocelot.Tracing.OpenTracing/Ocelot.Tracing.OpenTracing.csproj
index e341adba24..1cdcb6d06e 100644
--- a/src/Ocelot.Tracing.OpenTracing/Ocelot.Tracing.OpenTracing.csproj
+++ b/src/Ocelot.Tracing.OpenTracing/Ocelot.Tracing.OpenTracing.csproj
@@ -1,17 +1,28 @@
- net5.0
+ net7.0
0.0.0-dev
Kjell-Åke Gafvelin
This package provides OpenTracing support to Ocelot.
https://github.com/ThreeMammals/Ocelot
+ ocelot_logo.png
API Gateway;.NET core; OpenTracing
true
+ True
+ 1591
-
-
+
+
+
+
+
+
+
+
+ all
+
diff --git a/src/Ocelot.Tracing.OpenTracing/OcelotBuilderExtensions.cs b/src/Ocelot.Tracing.OpenTracing/OcelotBuilderExtensions.cs
index 59d7897580..3c01810ae0 100644
--- a/src/Ocelot.Tracing.OpenTracing/OcelotBuilderExtensions.cs
+++ b/src/Ocelot.Tracing.OpenTracing/OcelotBuilderExtensions.cs
@@ -1,15 +1,26 @@
-namespace Ocelot.Tracing.OpenTracing
-{
- using Microsoft.Extensions.DependencyInjection.Extensions;
- using Ocelot.DependencyInjection;
- using Ocelot.Logging;
+//
+// Copyright (c) ThreeMammals. All rights reserved.
+//
+
+namespace Ocelot.Tracing.OpenTracing;
- public static class OcelotBuilderExtensions
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Ocelot.DependencyInjection;
+using Ocelot.Logging;
+
+///
+/// Extension methods for the interface.
+///
+public static class OcelotBuilderExtensions
+{
+ ///
+ /// Adds OpenTracing services using builder.
+ ///
+ /// The Ocelot builder with services.
+ /// An object.
+ public static IOcelotBuilder AddOpenTracing(this IOcelotBuilder builder)
{
- public static IOcelotBuilder AddOpenTracing(this IOcelotBuilder builder)
- {
- builder.Services.TryAddSingleton();
- return builder;
- }
+ builder.Services.TryAddSingleton();
+ return builder;
}
}
diff --git a/src/Ocelot.Tracing.OpenTracing/OpenTracingTracer.cs b/src/Ocelot.Tracing.OpenTracing/OpenTracingTracer.cs
index 744e6ddd3d..a268ae0488 100644
--- a/src/Ocelot.Tracing.OpenTracing/OpenTracingTracer.cs
+++ b/src/Ocelot.Tracing.OpenTracing/OpenTracingTracer.cs
@@ -1,74 +1,87 @@
-namespace Ocelot.Tracing.OpenTracing
+//
+// Copyright (c) ThreeMammals. All rights reserved.
+//
+
+namespace Ocelot.Tracing.OpenTracing;
+
+using System;
+using System.Collections.Generic;
+using System.Net.Http;
+using System.Threading;
+using System.Threading.Tasks;
+using global::OpenTracing;
+using global::OpenTracing.Propagation;
+using global::OpenTracing.Tag;
+using Microsoft.AspNetCore.Http;
+
+///
+/// Default tracer implementation for the interface.
+///
+internal class OpenTracingTracer : Logging.ITracer
{
- using global::OpenTracing;
- using global::OpenTracing.Propagation;
- using global::OpenTracing.Tag;
- using Microsoft.AspNetCore.Http;
- using System;
- using System.Collections.Generic;
- using System.Net.Http;
- using System.Threading;
- using System.Threading.Tasks;
+ private readonly ITracer tracer;
- class OpenTracingTracer : Logging.ITracer
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The tracer.
+ public OpenTracingTracer(ITracer tracer)
{
- private readonly ITracer _tracer;
-
- public OpenTracingTracer(ITracer tracer)
- {
- _tracer = tracer ?? throw new ArgumentNullException(nameof(tracer));
- }
+ this.tracer = tracer ?? throw new ArgumentNullException(nameof(tracer));
+ }
- public void Event(HttpContext httpContext, string @event)
- {
- }
+ ///
+ public void Event(HttpContext httpContext, string @event)
+ {
+ }
- public async Task SendAsync(HttpRequestMessage request,
- CancellationToken cancellationToken,
- Action addTraceIdToRepo,
- Func> baseSendAsync)
+ ///
+ public async Task SendAsync(
+ HttpRequestMessage request,
+ CancellationToken cancellationToken,
+ Action addTraceIdToRepo,
+ Func> baseSendAsync)
+ {
+ using (var scope = this.tracer.BuildSpan(request.RequestUri.AbsoluteUri).StartActive(finishSpanOnDispose: true))
{
- using (IScope scope = _tracer.BuildSpan(request.RequestUri.AbsoluteUri).StartActive(finishSpanOnDispose: true))
- {
- var span = scope.Span;
+ var span = scope.Span;
- span.SetTag(Tags.SpanKind, Tags.SpanKindClient)
- .SetTag(Tags.HttpMethod, request.Method.Method)
- .SetTag(Tags.HttpUrl, request.RequestUri.OriginalString);
+ span.SetTag(Tags.SpanKind, Tags.SpanKindClient)
+ .SetTag(Tags.HttpMethod, request.Method.Method)
+ .SetTag(Tags.HttpUrl, request.RequestUri.OriginalString);
- addTraceIdToRepo(span.Context.SpanId);
+ addTraceIdToRepo(span.Context.SpanId);
- var headers = new Dictionary();
+ var headers = new Dictionary();
- _tracer.Inject(span.Context, BuiltinFormats.HttpHeaders, new TextMapInjectAdapter(headers));
+ this.tracer.Inject(span.Context, BuiltinFormats.HttpHeaders, new TextMapInjectAdapter(headers));
- foreach (var item in headers)
- {
- request.Headers.Add(item.Key, item.Value);
- }
+ foreach (var item in headers)
+ {
+ request.Headers.Add(item.Key, item.Value);
+ }
- try
- {
- var response = await baseSendAsync(request, cancellationToken);
+ try
+ {
+ var response = await baseSendAsync(request, cancellationToken);
- span.SetTag(Tags.HttpStatus, (int)response.StatusCode);
+ span.SetTag(Tags.HttpStatus, (int)response.StatusCode);
- return response;
- }
- catch (HttpRequestException ex)
- {
- Tags.Error.Set(scope.Span, true);
+ return response;
+ }
+ catch (HttpRequestException ex)
+ {
+ Tags.Error.Set(scope.Span, true);
- span.Log(new Dictionary(3)
- {
- { LogFields.Event, Tags.Error.Key },
- { LogFields.ErrorKind, ex.GetType().Name },
- { LogFields.ErrorObject, ex }
- });
- throw;
- }
+ span.Log(new Dictionary(3)
+ {
+ { LogFields.Event, Tags.Error.Key },
+ { LogFields.ErrorKind, ex.GetType().Name },
+ { LogFields.ErrorObject, ex },
+ });
+ throw;
}
}
}
diff --git a/src/Ocelot.Tracing.OpenTracing/stylecop.json b/src/Ocelot.Tracing.OpenTracing/stylecop.json
new file mode 100644
index 0000000000..ebdde954c7
--- /dev/null
+++ b/src/Ocelot.Tracing.OpenTracing/stylecop.json
@@ -0,0 +1,14 @@
+{
+ // ACTION REQUIRED: This file was automatically added to your project, but it
+ // will not take effect until additional steps are taken to enable it. See the
+ // following page for additional information:
+ //
+ // https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
+
+ "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
+ "settings": {
+ "documentationRules": {
+ "companyName": "ThreeMammals"
+ }
+ }
+}
diff --git a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs
index 1c8e9d2fb2..29c3535c75 100644
--- a/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs
+++ b/src/Ocelot/Authentication/Middleware/AuthenticationMiddleware.cs
@@ -1,13 +1,16 @@
-namespace Ocelot.Authentication.Middleware
-{
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Authentication;
- using Ocelot.Configuration;
- using Ocelot.Logging;
- using Ocelot.Middleware;
- using System.Threading.Tasks;
- using Ocelot.DownstreamRouteFinder.Middleware;
+using System.Threading.Tasks;
+
+using Ocelot.Configuration;
+
+using Ocelot.Logging;
+using Microsoft.AspNetCore.Authentication;
+using Microsoft.AspNetCore.Http;
+
+using Ocelot.Middleware;
+
+namespace Ocelot.Authentication.Middleware
+{
public class AuthenticationMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;
diff --git a/src/Ocelot/Authentication/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs b/src/Ocelot/Authentication/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs
index 3d3029f83c..3adddff2d3 100644
--- a/src/Ocelot/Authentication/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs
+++ b/src/Ocelot/Authentication/Middleware/AuthenticationMiddlewareMiddlewareExtensions.cs
@@ -1,7 +1,7 @@
+using Microsoft.AspNetCore.Builder;
+
namespace Ocelot.Authentication.Middleware
{
- using Microsoft.AspNetCore.Builder;
-
public static class AuthenticationMiddlewareMiddlewareExtensions
{
public static IApplicationBuilder UseAuthenticationMiddleware(this IApplicationBuilder builder)
diff --git a/src/Ocelot/Authorization/ClaimValueNotAuthorizedError.cs b/src/Ocelot/Authorization/ClaimValueNotAuthorizedError.cs
index c4d4e81448..2f6b72c4b3 100644
--- a/src/Ocelot/Authorization/ClaimValueNotAuthorizedError.cs
+++ b/src/Ocelot/Authorization/ClaimValueNotAuthorizedError.cs
@@ -1,8 +1,7 @@
-namespace Ocelot.Authorization
-{
- using Ocelot.Errors;
- using System.Net;
+using Ocelot.Errors;
+namespace Ocelot.Authorization
+{
public class ClaimValueNotAuthorizedError : Error
{
public ClaimValueNotAuthorizedError(string message)
diff --git a/src/Ocelot/Authorization/ClaimsAuthorizer.cs b/src/Ocelot/Authorization/ClaimsAuthorizer.cs
index 15da73d74c..850f197deb 100644
--- a/src/Ocelot/Authorization/ClaimsAuthorizer.cs
+++ b/src/Ocelot/Authorization/ClaimsAuthorizer.cs
@@ -1,13 +1,16 @@
-namespace Ocelot.Authorization
-{
- using Ocelot.Infrastructure.Claims.Parser;
- using Ocelot.DownstreamRouteFinder.UrlMatcher;
- using Ocelot.Responses;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Claims;
- using System.Text.RegularExpressions;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Claims;
+using System.Text.RegularExpressions;
+
+using Ocelot.DownstreamRouteFinder.UrlMatcher;
+
+using Ocelot.Infrastructure.Claims.Parser;
+using Ocelot.Responses;
+
+namespace Ocelot.Authorization
+{
public class ClaimsAuthorizer : IClaimsAuthorizer
{
private readonly IClaimsParser _claimsParser;
diff --git a/src/Ocelot/Authorization/IClaimsAuthorizer.cs b/src/Ocelot/Authorization/IClaimsAuthorizer.cs
index dc89f01093..b0853f982f 100644
--- a/src/Ocelot/Authorization/IClaimsAuthorizer.cs
+++ b/src/Ocelot/Authorization/IClaimsAuthorizer.cs
@@ -1,11 +1,11 @@
-using Ocelot.DownstreamRouteFinder.UrlMatcher;
-using Ocelot.Responses;
-using System.Security.Claims;
+using System.Security.Claims;
+
+using Ocelot.DownstreamRouteFinder.UrlMatcher;
+using Ocelot.Responses;
+using System.Collections.Generic;
namespace Ocelot.Authorization
{
- using System.Collections.Generic;
-
public interface IClaimsAuthorizer
{
Response Authorize(
diff --git a/src/Ocelot/Authorization/IScopesAuthorizer.cs b/src/Ocelot/Authorization/IScopesAuthorizer.cs
index e0041cd280..e82f5e8623 100644
--- a/src/Ocelot/Authorization/IScopesAuthorizer.cs
+++ b/src/Ocelot/Authorization/IScopesAuthorizer.cs
@@ -1,10 +1,10 @@
-using Ocelot.Responses;
-using System.Security.Claims;
+using System.Security.Claims;
+
+using Ocelot.Responses;
+using System.Collections.Generic;
namespace Ocelot.Authorization
{
- using System.Collections.Generic;
-
public interface IScopesAuthorizer
{
Response Authorize(ClaimsPrincipal claimsPrincipal, List routeAllowedScopes);
diff --git a/src/Ocelot/Authorization/Middleware/AuthorizationMiddleware.cs b/src/Ocelot/Authorization/Middleware/AuthorizationMiddleware.cs
index 3a9c5d8022..b1bbcb7c7e 100644
--- a/src/Ocelot/Authorization/Middleware/AuthorizationMiddleware.cs
+++ b/src/Ocelot/Authorization/Middleware/AuthorizationMiddleware.cs
@@ -1,13 +1,17 @@
-namespace Ocelot.Authorization.Middleware
-{
- using Ocelot.Configuration;
- using Ocelot.Logging;
- using Ocelot.Middleware;
- using Ocelot.Responses;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Http;
- using Ocelot.DownstreamRouteFinder.Middleware;
+using System.Threading.Tasks;
+
+using Ocelot.Configuration;
+
+using Ocelot.Logging;
+
+using Microsoft.AspNetCore.Http;
+using Ocelot.Middleware;
+
+using Ocelot.Responses;
+
+namespace Ocelot.Authorization.Middleware
+{
public class AuthorizationMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;
diff --git a/src/Ocelot/Authorization/Middleware/AuthorizationMiddlewareMiddlewareExtensions.cs b/src/Ocelot/Authorization/Middleware/AuthorizationMiddlewareMiddlewareExtensions.cs
index 260cc86e08..c537010980 100644
--- a/src/Ocelot/Authorization/Middleware/AuthorizationMiddlewareMiddlewareExtensions.cs
+++ b/src/Ocelot/Authorization/Middleware/AuthorizationMiddlewareMiddlewareExtensions.cs
@@ -1,7 +1,7 @@
+using Microsoft.AspNetCore.Builder;
+
namespace Ocelot.Authorization.Middleware
{
- using Microsoft.AspNetCore.Builder;
-
public static class AuthorizationMiddlewareMiddlewareExtensions
{
public static IApplicationBuilder UseAuthorizationMiddleware(this IApplicationBuilder builder)
diff --git a/src/Ocelot/Authorization/ScopeNotAuthorizedError.cs b/src/Ocelot/Authorization/ScopeNotAuthorizedError.cs
index dc5823a326..e1dcade7bc 100644
--- a/src/Ocelot/Authorization/ScopeNotAuthorizedError.cs
+++ b/src/Ocelot/Authorization/ScopeNotAuthorizedError.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Authorization
-{
- using Ocelot.Errors;
+using Ocelot.Errors;
+namespace Ocelot.Authorization
+{
public class ScopeNotAuthorizedError : Error
{
public ScopeNotAuthorizedError(string message)
diff --git a/src/Ocelot/Authorization/ScopesAuthorizer.cs b/src/Ocelot/Authorization/ScopesAuthorizer.cs
index 7fd7e2aaf0..a451021c89 100644
--- a/src/Ocelot/Authorization/ScopesAuthorizer.cs
+++ b/src/Ocelot/Authorization/ScopesAuthorizer.cs
@@ -1,16 +1,16 @@
-using Ocelot.Responses;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
+
+using Ocelot.Responses;
+using Ocelot.Infrastructure.Claims.Parser;
namespace Ocelot.Authorization
{
- using Infrastructure.Claims.Parser;
-
public class ScopesAuthorizer : IScopesAuthorizer
{
private readonly IClaimsParser _claimsParser;
- private readonly string _scope = "scope";
+ private const string Scope = "scope";
public ScopesAuthorizer(IClaimsParser claimsParser)
{
@@ -24,7 +24,7 @@ public Response Authorize(ClaimsPrincipal claimsPrincipal, List ro
return new OkResponse(true);
}
- var values = _claimsParser.GetValuesByClaimType(claimsPrincipal.Claims, _scope);
+ var values = _claimsParser.GetValuesByClaimType(claimsPrincipal.Claims, Scope);
if (values.IsError)
{
@@ -33,12 +33,12 @@ public Response Authorize(ClaimsPrincipal claimsPrincipal, List ro
var userScopes = values.Data;
- var matchesScopes = routeAllowedScopes.Intersect(userScopes).ToList();
+ var matchesScopes = routeAllowedScopes.Intersect(userScopes);
- if (matchesScopes.Count == 0)
+ if (!matchesScopes.Any())
{
return new ErrorResponse(
- new ScopeNotAuthorizedError($"no one user scope: '{string.Join(",", userScopes)}' match with some allowed scope: '{string.Join(",", routeAllowedScopes)}'"));
+ new ScopeNotAuthorizedError($"no one user scope: '{string.Join(',', userScopes)}' match with some allowed scope: '{string.Join(',', routeAllowedScopes)}'"));
}
return new OkResponse(true);
diff --git a/src/Ocelot/Authorization/UnauthorizedError.cs b/src/Ocelot/Authorization/UnauthorizedError.cs
index 689f9e2f2f..efe1d9ff7f 100644
--- a/src/Ocelot/Authorization/UnauthorizedError.cs
+++ b/src/Ocelot/Authorization/UnauthorizedError.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Authorization
-{
- using Ocelot.Errors;
+using Ocelot.Errors;
+namespace Ocelot.Authorization
+{
public class UnauthorizedError : Error
{
public UnauthorizedError(string message)
diff --git a/src/Ocelot/Authorization/UserDoesNotHaveClaimError.cs b/src/Ocelot/Authorization/UserDoesNotHaveClaimError.cs
index 08c19d9f8b..9994aaee32 100644
--- a/src/Ocelot/Authorization/UserDoesNotHaveClaimError.cs
+++ b/src/Ocelot/Authorization/UserDoesNotHaveClaimError.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Authorization
-{
- using Ocelot.Errors;
+using Ocelot.Errors;
+namespace Ocelot.Authorization
+{
public class UserDoesNotHaveClaimError : Error
{
public UserDoesNotHaveClaimError(string message)
diff --git a/src/Ocelot/Cache/AspMemoryCache.cs b/src/Ocelot/Cache/AspMemoryCache.cs
index 6a28dbbfc7..878b48a88c 100644
--- a/src/Ocelot/Cache/AspMemoryCache.cs
+++ b/src/Ocelot/Cache/AspMemoryCache.cs
@@ -1,9 +1,10 @@
-namespace Ocelot.Cache
-{
- using System;
- using System.Collections.Generic;
- using Microsoft.Extensions.Caching.Memory;
+using System;
+using System.Collections.Generic;
+
+using Microsoft.Extensions.Caching.Memory;
+namespace Ocelot.Cache
+{
public class AspMemoryCache : IOcelotCache
{
private readonly IMemoryCache _memoryCache;
@@ -28,7 +29,7 @@ public void Add(string key, T value, TimeSpan ttl, string region)
}
public T Get(string key, string region)
- {
+ {
if (_memoryCache.TryGetValue(key, out T value))
{
return value;
@@ -51,7 +52,7 @@ public void ClearRegion(string region)
public void AddAndDelete(string key, T value, TimeSpan ttl, string region)
{
- if (_memoryCache.TryGetValue(key, out T oldValue))
+ if (_memoryCache.TryGetValue(key, out T _))
{
_memoryCache.Remove(key);
}
diff --git a/src/Ocelot/Cache/CacheKeyGenerator.cs b/src/Ocelot/Cache/CacheKeyGenerator.cs
index 2c1f44d0d7..46b4315665 100644
--- a/src/Ocelot/Cache/CacheKeyGenerator.cs
+++ b/src/Ocelot/Cache/CacheKeyGenerator.cs
@@ -1,22 +1,22 @@
-namespace Ocelot.Cache
-{
- using Ocelot.Request.Middleware;
- using System.Text;
- using System.Threading.Tasks;
+using System.Text;
+using System.Threading.Tasks;
+
+using Ocelot.Request.Middleware;
+namespace Ocelot.Cache
+{
public class CacheKeyGenerator : ICacheKeyGenerator
{
public string GenerateRequestCacheKey(DownstreamRequest downstreamRequest)
{
- string hashedContent = null;
- StringBuilder downStreamUrlKeyBuilder = new StringBuilder($"{downstreamRequest.Method}-{downstreamRequest.OriginalString}");
+ var downStreamUrlKeyBuilder = new StringBuilder($"{downstreamRequest.Method}-{downstreamRequest.OriginalString}");
if (downstreamRequest.Content != null)
{
- string requestContentString = Task.Run(async () => await downstreamRequest.Content.ReadAsStringAsync()).Result;
+ var requestContentString = Task.Run(async () => await downstreamRequest.Content.ReadAsStringAsync()).Result;
downStreamUrlKeyBuilder.Append(requestContentString);
}
- hashedContent = MD5Helper.GenerateMd5(downStreamUrlKeyBuilder.ToString());
+ var hashedContent = MD5Helper.GenerateMd5(downStreamUrlKeyBuilder.ToString());
return hashedContent;
}
}
diff --git a/src/Ocelot/Cache/CacheObject.cs b/src/Ocelot/Cache/CacheObject.cs
index ef310a0694..baa4e3f6b6 100644
--- a/src/Ocelot/Cache/CacheObject.cs
+++ b/src/Ocelot/Cache/CacheObject.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Cache
-{
- using System;
+using System;
+namespace Ocelot.Cache
+{
internal class CacheObject
{
public CacheObject(T value, DateTime expires)
diff --git a/src/Ocelot/Cache/CachedResponse.cs b/src/Ocelot/Cache/CachedResponse.cs
index aa2fafcc6f..b0806252c1 100644
--- a/src/Ocelot/Cache/CachedResponse.cs
+++ b/src/Ocelot/Cache/CachedResponse.cs
@@ -16,18 +16,18 @@ string reasonPhrase
StatusCode = statusCode;
Headers = headers ?? new Dictionary>();
ContentHeaders = contentHeaders ?? new Dictionary>();
- Body = body ?? "";
+ Body = body ?? string.Empty;
ReasonPhrase = reasonPhrase;
}
- public HttpStatusCode StatusCode { get; private set; }
+ public HttpStatusCode StatusCode { get; }
- public Dictionary> Headers { get; private set; }
+ public Dictionary> Headers { get; }
- public Dictionary> ContentHeaders { get; private set; }
+ public Dictionary> ContentHeaders { get; }
- public string Body { get; private set; }
+ public string Body { get; }
- public string ReasonPhrase { get; private set; }
+ public string ReasonPhrase { get; }
}
}
diff --git a/src/Ocelot/Cache/ICacheKeyGenerator.cs b/src/Ocelot/Cache/ICacheKeyGenerator.cs
index 838b9ecd2f..32a1f989ed 100644
--- a/src/Ocelot/Cache/ICacheKeyGenerator.cs
+++ b/src/Ocelot/Cache/ICacheKeyGenerator.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Cache
-{
- using Ocelot.Request.Middleware;
+using Ocelot.Request.Middleware;
+namespace Ocelot.Cache
+{
public interface ICacheKeyGenerator
{
string GenerateRequestCacheKey(DownstreamRequest downstreamRequest);
diff --git a/src/Ocelot/Cache/IRegionCreator.cs b/src/Ocelot/Cache/IRegionCreator.cs
index 4277ed6875..da1b042dab 100644
--- a/src/Ocelot/Cache/IRegionCreator.cs
+++ b/src/Ocelot/Cache/IRegionCreator.cs
@@ -6,4 +6,4 @@ public interface IRegionCreator
{
string Create(FileRoute route);
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Cache/MD5Helper.cs b/src/Ocelot/Cache/MD5Helper.cs
index ff8eaa30be..c268fb021c 100644
--- a/src/Ocelot/Cache/MD5Helper.cs
+++ b/src/Ocelot/Cache/MD5Helper.cs
@@ -7,10 +7,10 @@ public static class MD5Helper
{
public static string GenerateMd5(byte[] contentBytes)
{
- MD5 md5 = MD5.Create();
- byte[] hash = md5.ComputeHash(contentBytes);
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < hash.Length; i++)
+ var md5 = MD5.Create();
+ var hash = md5.ComputeHash(contentBytes);
+ var sb = new StringBuilder();
+ for (var i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}
@@ -20,7 +20,7 @@ public static string GenerateMd5(byte[] contentBytes)
public static string GenerateMd5(string contentString)
{
- byte[] contentBytes = Encoding.Unicode.GetBytes(contentString);
+ var contentBytes = Encoding.Unicode.GetBytes(contentString);
return GenerateMd5(contentBytes);
}
}
diff --git a/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs b/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs
index ea544d2b51..7679ac617b 100644
--- a/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs
+++ b/src/Ocelot/Cache/Middleware/OutputCacheMiddleware.cs
@@ -1,15 +1,17 @@
-namespace Ocelot.Cache.Middleware
-{
- using Ocelot.Logging;
- using Ocelot.Middleware;
- using System;
- using System.IO;
- using System.Linq;
- using System.Net.Http;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.Http;
- using Ocelot.DownstreamRouteFinder.Middleware;
+using System;
+using System.IO;
+using System.Linq;
+using System.Net.Http;
+using System.Threading.Tasks;
+
+using Ocelot.Logging;
+
+using Microsoft.AspNetCore.Http;
+using Ocelot.Middleware;
+
+namespace Ocelot.Cache.Middleware
+{
public class OutputCacheMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;
@@ -40,7 +42,7 @@ public async Task Invoke(HttpContext httpContext)
var downstreamRequest = httpContext.Items.DownstreamRequest();
var downstreamUrlKey = $"{downstreamRequest.Method}-{downstreamRequest.OriginalString}";
- string downStreamRequestCacheKey = _cacheGenerator.GenerateRequestCacheKey(downstreamRequest);
+ var downStreamRequestCacheKey = _cacheGenerator.GenerateRequestCacheKey(downstreamRequest);
Logger.LogDebug($"Started checking cache for {downstreamUrlKey}");
@@ -78,7 +80,7 @@ public async Task Invoke(HttpContext httpContext)
Logger.LogDebug($"finished response added to cache for {downstreamUrlKey}");
}
- private void SetHttpResponseMessageThisRequest(HttpContext context,
+ private static void SetHttpResponseMessageThisRequest(HttpContext context,
DownstreamResponse response)
{
context.Items.UpsertDownstreamResponse(response);
diff --git a/src/Ocelot/Cache/Middleware/OutputCacheMiddlewareExtensions.cs b/src/Ocelot/Cache/Middleware/OutputCacheMiddlewareExtensions.cs
index 48e032901f..76e406eeb9 100644
--- a/src/Ocelot/Cache/Middleware/OutputCacheMiddlewareExtensions.cs
+++ b/src/Ocelot/Cache/Middleware/OutputCacheMiddlewareExtensions.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Cache.Middleware
-{
- using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Builder;
+namespace Ocelot.Cache.Middleware
+{
public static class OutputCacheMiddlewareExtensions
{
public static IApplicationBuilder UseOutputCacheMiddleware(this IApplicationBuilder builder)
diff --git a/src/Ocelot/Cache/RegionCreator.cs b/src/Ocelot/Cache/RegionCreator.cs
index 050d6f2f25..737d886e5b 100644
--- a/src/Ocelot/Cache/RegionCreator.cs
+++ b/src/Ocelot/Cache/RegionCreator.cs
@@ -1,5 +1,6 @@
-using Ocelot.Configuration.File;
using System.Linq;
+
+using Ocelot.Configuration.File;
namespace Ocelot.Cache
{
@@ -12,9 +13,9 @@ public string Create(FileRoute route)
return route?.FileCacheOptions?.Region;
}
- var methods = string.Join("", route.UpstreamHttpMethod.Select(m => m));
+ var methods = string.Join(string.Empty, route.UpstreamHttpMethod.Select(m => m));
- var region = $"{methods}{route.UpstreamPathTemplate.Replace("/", "")}";
+ var region = $"{methods}{route.UpstreamPathTemplate.Replace("/", string.Empty)}";
return region;
}
diff --git a/src/Ocelot/Cache/Regions.cs b/src/Ocelot/Cache/Regions.cs
index 05f254cb81..cfb1142a1d 100644
--- a/src/Ocelot/Cache/Regions.cs
+++ b/src/Ocelot/Cache/Regions.cs
@@ -1,7 +1,7 @@
+using System.Collections.Generic;
+
namespace Ocelot.Cache
{
- using System.Collections.Generic;
-
public class Regions
{
public Regions(List value)
diff --git a/src/Ocelot/Claims/AddClaimsToRequest.cs b/src/Ocelot/Claims/AddClaimsToRequest.cs
index ab197c2b0f..56e9f28241 100644
--- a/src/Ocelot/Claims/AddClaimsToRequest.cs
+++ b/src/Ocelot/Claims/AddClaimsToRequest.cs
@@ -1,10 +1,12 @@
-using Microsoft.AspNetCore.Http;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Claims;
+
+using Microsoft.AspNetCore.Http;
+
using Ocelot.Configuration;
using Ocelot.Infrastructure.Claims.Parser;
using Ocelot.Responses;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Claims;
namespace Ocelot.Claims
{
@@ -37,7 +39,7 @@ public Response SetClaimsOnContext(List claimsToThings, HttpContex
identity?.RemoveClaim(exists);
}
- identity?.AddClaim(new System.Security.Claims.Claim(config.ExistingKey, value.Data));
+ identity?.AddClaim(new Claim(config.ExistingKey, value.Data));
}
return new OkResponse();
diff --git a/src/Ocelot/Claims/IAddClaimsToRequest.cs b/src/Ocelot/Claims/IAddClaimsToRequest.cs
index b9db39f5bc..902df93af8 100644
--- a/src/Ocelot/Claims/IAddClaimsToRequest.cs
+++ b/src/Ocelot/Claims/IAddClaimsToRequest.cs
@@ -1,7 +1,9 @@
-using Microsoft.AspNetCore.Http;
+using System.Collections.Generic;
+
+using Microsoft.AspNetCore.Http;
+
using Ocelot.Configuration;
-using Ocelot.Responses;
-using System.Collections.Generic;
+using Ocelot.Responses;
namespace Ocelot.Claims
{
diff --git a/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddlewareExtensions.cs b/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddlewareExtensions.cs
index d2d03dd73c..eee0bb3430 100644
--- a/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddlewareExtensions.cs
+++ b/src/Ocelot/Claims/Middleware/ClaimsBuilderMiddlewareExtensions.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Claims.Middleware
-{
- using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Builder;
+namespace Ocelot.Claims.Middleware
+{
public static class ClaimsBuilderMiddlewareExtensions
{
public static IApplicationBuilder UseClaimsToClaimsMiddleware(this IApplicationBuilder builder)
diff --git a/src/Ocelot/Claims/Middleware/ClaimsToClaimsMiddleware.cs b/src/Ocelot/Claims/Middleware/ClaimsToClaimsMiddleware.cs
index 780736b215..e163a88497 100644
--- a/src/Ocelot/Claims/Middleware/ClaimsToClaimsMiddleware.cs
+++ b/src/Ocelot/Claims/Middleware/ClaimsToClaimsMiddleware.cs
@@ -1,12 +1,14 @@
-namespace Ocelot.Claims.Middleware
+using System.Linq;
+using System.Threading.Tasks;
+
+using Ocelot.Logging;
+
+using Microsoft.AspNetCore.Http;
+
+using Ocelot.Middleware;
+
+namespace Ocelot.Claims.Middleware
{
- using Microsoft.AspNetCore.Http;
- using Ocelot.DownstreamRouteFinder.Middleware;
- using Ocelot.Logging;
- using Ocelot.Middleware;
- using System.Linq;
- using System.Threading.Tasks;
-
public class ClaimsToClaimsMiddleware : OcelotMiddleware
{
private readonly RequestDelegate _next;
diff --git a/src/Ocelot/Configuration/AuthenticationOptions.cs b/src/Ocelot/Configuration/AuthenticationOptions.cs
index 9cede79549..d9a912b53e 100644
--- a/src/Ocelot/Configuration/AuthenticationOptions.cs
+++ b/src/Ocelot/Configuration/AuthenticationOptions.cs
@@ -10,7 +10,7 @@ public AuthenticationOptions(List allowedScopes, string authenticationPr
AuthenticationProviderKey = authenticationProviderKey;
}
- public List AllowedScopes { get; private set; }
- public string AuthenticationProviderKey { get; private set; }
+ public List AllowedScopes { get; }
+ public string AuthenticationProviderKey { get; }
}
}
diff --git a/src/Ocelot/Configuration/Builder/AuthenticationOptionsBuilder.cs b/src/Ocelot/Configuration/Builder/AuthenticationOptionsBuilder.cs
index 352bc8a6b5..65408e3a4b 100644
--- a/src/Ocelot/Configuration/Builder/AuthenticationOptionsBuilder.cs
+++ b/src/Ocelot/Configuration/Builder/AuthenticationOptionsBuilder.cs
@@ -4,7 +4,7 @@ namespace Ocelot.Configuration.Builder
{
public class AuthenticationOptionsBuilder
{
- private List _allowedScopes = new List();
+ private List _allowedScopes = new();
private string _authenticationProviderKey;
public AuthenticationOptionsBuilder WithAllowedScopes(List allowedScopes)
@@ -24,4 +24,4 @@ public AuthenticationOptions Build()
return new AuthenticationOptions(_allowedScopes, _authenticationProviderKey);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs b/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs
deleted file mode 100644
index 5ee5ddf739..0000000000
--- a/src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs
+++ /dev/null
@@ -1,305 +0,0 @@
-using Ocelot.Configuration.Creator;
-using Ocelot.Values;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Http;
-
-namespace Ocelot.Configuration.Builder
-{
- public class DownstreamRouteBuilder
- {
- private AuthenticationOptions _authenticationOptions;
- private string _loadBalancerKey;
- private string _downstreamPathTemplate;
- private UpstreamPathTemplate _upstreamTemplatePattern;
- private List _upstreamHttpMethod;
- private bool _isAuthenticated;
- private List _claimsToHeaders;
- private List _claimToClaims;
- private Dictionary _routeClaimRequirement;
- private bool _isAuthorized;
- private List _claimToQueries;
- private List _claimToDownstreamPath;
- private string _requestIdHeaderKey;
- private bool _isCached;
- private CacheOptions _fileCacheOptions;
- private string _downstreamScheme;
- private LoadBalancerOptions _loadBalancerOptions;
- private QoSOptions _qosOptions;
- private HttpHandlerOptions _httpHandlerOptions;
- private bool _enableRateLimiting;
- private RateLimitOptions _rateLimitOptions;
- private bool _useServiceDiscovery;
- private string _serviceName;
- private string _serviceNamespace;
- private List _upstreamHeaderFindAndReplace;
- private List _downstreamHeaderFindAndReplace;
- private readonly List _downstreamAddresses;
- private string _key;
- private List _delegatingHandlers;
- private List _addHeadersToDownstream;
- private List _addHeadersToUpstream;
- private bool _dangerousAcceptAnyServerCertificateValidator;
- private SecurityOptions _securityOptions;
- private string _downstreamHttpMethod;
- private Version _downstreamHttpVersion;
-
- public DownstreamRouteBuilder()
- {
- _downstreamAddresses = new List();
- _delegatingHandlers = new List();
- _addHeadersToDownstream = new List();
- _addHeadersToUpstream = new List();
- }
-
- public DownstreamRouteBuilder WithDownstreamAddresses(List downstreamAddresses)
- {
- _downstreamAddresses.AddRange(downstreamAddresses);
- return this;
- }
-
- public DownstreamRouteBuilder WithDownStreamHttpMethod(string method)
- {
- _downstreamHttpMethod = method;
- return this;
- }
-
- public DownstreamRouteBuilder WithLoadBalancerOptions(LoadBalancerOptions loadBalancerOptions)
- {
- _loadBalancerOptions = loadBalancerOptions;
- return this;
- }
-
- public DownstreamRouteBuilder WithDownstreamScheme(string downstreamScheme)
- {
- _downstreamScheme = downstreamScheme;
- return this;
- }
-
- public DownstreamRouteBuilder WithDownstreamPathTemplate(string input)
- {
- _downstreamPathTemplate = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithUpstreamPathTemplate(UpstreamPathTemplate input)
- {
- _upstreamTemplatePattern = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithUpstreamHttpMethod(List input)
- {
- _upstreamHttpMethod = (input.Count == 0) ? new List() : input.Select(x => new HttpMethod(x.Trim())).ToList();
- return this;
- }
-
- public DownstreamRouteBuilder WithIsAuthenticated(bool input)
- {
- _isAuthenticated = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithIsAuthorized(bool input)
- {
- _isAuthorized = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithRequestIdKey(string input)
- {
- _requestIdHeaderKey = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithClaimsToHeaders(List input)
- {
- _claimsToHeaders = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithClaimsToClaims(List input)
- {
- _claimToClaims = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithRouteClaimsRequirement(Dictionary input)
- {
- _routeClaimRequirement = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithClaimsToQueries(List input)
- {
- _claimToQueries = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithClaimsToDownstreamPath(List input)
- {
- _claimToDownstreamPath = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithIsCached(bool input)
- {
- _isCached = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithCacheOptions(CacheOptions input)
- {
- _fileCacheOptions = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithQosOptions(QoSOptions input)
- {
- _qosOptions = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithLoadBalancerKey(string loadBalancerKey)
- {
- _loadBalancerKey = loadBalancerKey;
- return this;
- }
-
- public DownstreamRouteBuilder WithAuthenticationOptions(AuthenticationOptions authenticationOptions)
- {
- _authenticationOptions = authenticationOptions;
- return this;
- }
-
- public DownstreamRouteBuilder WithEnableRateLimiting(bool input)
- {
- _enableRateLimiting = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithRateLimitOptions(RateLimitOptions input)
- {
- _rateLimitOptions = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithHttpHandlerOptions(HttpHandlerOptions input)
- {
- _httpHandlerOptions = input;
- return this;
- }
-
- public DownstreamRouteBuilder WithUseServiceDiscovery(bool useServiceDiscovery)
- {
- _useServiceDiscovery = useServiceDiscovery;
- return this;
- }
-
- public DownstreamRouteBuilder WithServiceName(string serviceName)
- {
- _serviceName = serviceName;
- return this;
- }
-
- public DownstreamRouteBuilder WithServiceNamespace(string serviceNamespace)
- {
- _serviceNamespace = serviceNamespace;
- return this;
- }
-
- public DownstreamRouteBuilder WithUpstreamHeaderFindAndReplace(List upstreamHeaderFindAndReplace)
- {
- _upstreamHeaderFindAndReplace = upstreamHeaderFindAndReplace;
- return this;
- }
-
- public DownstreamRouteBuilder WithDownstreamHeaderFindAndReplace(List downstreamHeaderFindAndReplace)
- {
- _downstreamHeaderFindAndReplace = downstreamHeaderFindAndReplace;
- return this;
- }
-
- public DownstreamRouteBuilder WithKey(string key)
- {
- _key = key;
- return this;
- }
-
- public DownstreamRouteBuilder WithDelegatingHandlers(List delegatingHandlers)
- {
- _delegatingHandlers = delegatingHandlers;
- return this;
- }
-
- public DownstreamRouteBuilder WithAddHeadersToDownstream(List addHeadersToDownstream)
- {
- _addHeadersToDownstream = addHeadersToDownstream;
- return this;
- }
-
- public DownstreamRouteBuilder WithAddHeadersToUpstream(List addHeadersToUpstream)
- {
- _addHeadersToUpstream = addHeadersToUpstream;
- return this;
- }
-
- public DownstreamRouteBuilder WithDangerousAcceptAnyServerCertificateValidator(bool dangerousAcceptAnyServerCertificateValidator)
- {
- _dangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
- return this;
- }
-
- public DownstreamRouteBuilder WithSecurityOptions(SecurityOptions securityOptions)
- {
- _securityOptions = securityOptions;
- return this;
- }
-
- public DownstreamRouteBuilder WithDownstreamHttpVersion(Version downstreamHttpVersion)
- {
- _downstreamHttpVersion = downstreamHttpVersion;
- return this;
- }
-
- public DownstreamRoute Build()
- {
- return new DownstreamRoute(
- _key,
- _upstreamTemplatePattern,
- _upstreamHeaderFindAndReplace,
- _downstreamHeaderFindAndReplace,
- _downstreamAddresses,
- _serviceName,
- _serviceNamespace,
- _httpHandlerOptions,
- _useServiceDiscovery,
- _enableRateLimiting,
- _qosOptions,
- _downstreamScheme,
- _requestIdHeaderKey,
- _isCached,
- _fileCacheOptions,
- _loadBalancerOptions,
- _rateLimitOptions,
- _routeClaimRequirement,
- _claimToQueries,
- _claimsToHeaders,
- _claimToClaims,
- _claimToDownstreamPath,
- _isAuthenticated,
- _isAuthorized,
- _authenticationOptions,
- new DownstreamPathTemplate(_downstreamPathTemplate),
- _loadBalancerKey,
- _delegatingHandlers,
- _addHeadersToDownstream,
- _addHeadersToUpstream,
- _dangerousAcceptAnyServerCertificateValidator,
- _securityOptions,
- _downstreamHttpMethod,
- _downstreamHttpVersion);
- }
- }
-}
diff --git a/src/Ocelot/Configuration/Builder/DownstreamRouteBuilder.cs b/src/Ocelot/Configuration/Builder/DownstreamRouteBuilder.cs
new file mode 100644
index 0000000000..e185bf5846
--- /dev/null
+++ b/src/Ocelot/Configuration/Builder/DownstreamRouteBuilder.cs
@@ -0,0 +1,304 @@
+using Ocelot.Configuration.Creator;
+using Ocelot.Values;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+
+namespace Ocelot.Configuration.Builder;
+
+public class DownstreamRouteBuilder
+{
+ private AuthenticationOptions _authenticationOptions;
+ private string _loadBalancerKey;
+ private string _downstreamPathTemplate;
+ private UpstreamPathTemplate _upstreamTemplatePattern;
+ private List _upstreamHttpMethod;
+ private bool _isAuthenticated;
+ private List _claimsToHeaders;
+ private List _claimToClaims;
+ private Dictionary _routeClaimRequirement;
+ private bool _isAuthorized;
+ private List _claimToQueries;
+ private List _claimToDownstreamPath;
+ private string _requestIdHeaderKey;
+ private bool _isCached;
+ private CacheOptions _fileCacheOptions;
+ private string _downstreamScheme;
+ private LoadBalancerOptions _loadBalancerOptions;
+ private QoSOptions _qosOptions;
+ private HttpHandlerOptions _httpHandlerOptions;
+ private bool _enableRateLimiting;
+ private RateLimitOptions _rateLimitOptions;
+ private bool _useServiceDiscovery;
+ private string _serviceName;
+ private string _serviceNamespace;
+ private List _upstreamHeaderFindAndReplace;
+ private List _downstreamHeaderFindAndReplace;
+ private readonly List _downstreamAddresses;
+ private string _key;
+ private List _delegatingHandlers;
+ private List _addHeadersToDownstream;
+ private List _addHeadersToUpstream;
+ private bool _dangerousAcceptAnyServerCertificateValidator;
+ private SecurityOptions _securityOptions;
+ private string _downstreamHttpMethod;
+ private Version _downstreamHttpVersion;
+
+ public DownstreamRouteBuilder()
+ {
+ _downstreamAddresses = new List();
+ _delegatingHandlers = new List();
+ _addHeadersToDownstream = new List();
+ _addHeadersToUpstream = new List();
+ }
+
+ public DownstreamRouteBuilder WithDownstreamAddresses(List downstreamAddresses)
+ {
+ _downstreamAddresses.AddRange(downstreamAddresses);
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithDownStreamHttpMethod(string method)
+ {
+ _downstreamHttpMethod = method;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithLoadBalancerOptions(LoadBalancerOptions loadBalancerOptions)
+ {
+ _loadBalancerOptions = loadBalancerOptions;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithDownstreamScheme(string downstreamScheme)
+ {
+ _downstreamScheme = downstreamScheme;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithDownstreamPathTemplate(string input)
+ {
+ _downstreamPathTemplate = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithUpstreamPathTemplate(UpstreamPathTemplate input)
+ {
+ _upstreamTemplatePattern = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithUpstreamHttpMethod(List input)
+ {
+ _upstreamHttpMethod = (input.Count == 0) ? new List() : input.Select(x => new HttpMethod(x.Trim())).ToList();
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithIsAuthenticated(bool input)
+ {
+ _isAuthenticated = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithIsAuthorized(bool input)
+ {
+ _isAuthorized = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithRequestIdKey(string input)
+ {
+ _requestIdHeaderKey = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithClaimsToHeaders(List input)
+ {
+ _claimsToHeaders = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithClaimsToClaims(List input)
+ {
+ _claimToClaims = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithRouteClaimsRequirement(Dictionary input)
+ {
+ _routeClaimRequirement = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithClaimsToQueries(List input)
+ {
+ _claimToQueries = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithClaimsToDownstreamPath(List input)
+ {
+ _claimToDownstreamPath = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithIsCached(bool input)
+ {
+ _isCached = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithCacheOptions(CacheOptions input)
+ {
+ _fileCacheOptions = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithQosOptions(QoSOptions input)
+ {
+ _qosOptions = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithLoadBalancerKey(string loadBalancerKey)
+ {
+ _loadBalancerKey = loadBalancerKey;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithAuthenticationOptions(AuthenticationOptions authenticationOptions)
+ {
+ _authenticationOptions = authenticationOptions;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithEnableRateLimiting(bool input)
+ {
+ _enableRateLimiting = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithRateLimitOptions(RateLimitOptions input)
+ {
+ _rateLimitOptions = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithHttpHandlerOptions(HttpHandlerOptions input)
+ {
+ _httpHandlerOptions = input;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithUseServiceDiscovery(bool useServiceDiscovery)
+ {
+ _useServiceDiscovery = useServiceDiscovery;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithServiceName(string serviceName)
+ {
+ _serviceName = serviceName;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithServiceNamespace(string serviceNamespace)
+ {
+ _serviceNamespace = serviceNamespace;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithUpstreamHeaderFindAndReplace(List upstreamHeaderFindAndReplace)
+ {
+ _upstreamHeaderFindAndReplace = upstreamHeaderFindAndReplace;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithDownstreamHeaderFindAndReplace(List downstreamHeaderFindAndReplace)
+ {
+ _downstreamHeaderFindAndReplace = downstreamHeaderFindAndReplace;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithKey(string key)
+ {
+ _key = key;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithDelegatingHandlers(List delegatingHandlers)
+ {
+ _delegatingHandlers = delegatingHandlers;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithAddHeadersToDownstream(List addHeadersToDownstream)
+ {
+ _addHeadersToDownstream = addHeadersToDownstream;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithAddHeadersToUpstream(List addHeadersToUpstream)
+ {
+ _addHeadersToUpstream = addHeadersToUpstream;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithDangerousAcceptAnyServerCertificateValidator(bool dangerousAcceptAnyServerCertificateValidator)
+ {
+ _dangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithSecurityOptions(SecurityOptions securityOptions)
+ {
+ _securityOptions = securityOptions;
+ return this;
+ }
+
+ public DownstreamRouteBuilder WithDownstreamHttpVersion(Version downstreamHttpVersion)
+ {
+ _downstreamHttpVersion = downstreamHttpVersion;
+ return this;
+ }
+
+ public DownstreamRoute Build()
+ {
+ return new DownstreamRoute(
+ _key,
+ _upstreamTemplatePattern,
+ _upstreamHeaderFindAndReplace,
+ _downstreamHeaderFindAndReplace,
+ _downstreamAddresses,
+ _serviceName,
+ _serviceNamespace,
+ _httpHandlerOptions,
+ _useServiceDiscovery,
+ _enableRateLimiting,
+ _qosOptions,
+ _downstreamScheme,
+ _requestIdHeaderKey,
+ _isCached,
+ _fileCacheOptions,
+ _loadBalancerOptions,
+ _rateLimitOptions,
+ _routeClaimRequirement,
+ _claimToQueries,
+ _claimsToHeaders,
+ _claimToClaims,
+ _claimToDownstreamPath,
+ _isAuthenticated,
+ _isAuthorized,
+ _authenticationOptions,
+ new DownstreamPathTemplate(_downstreamPathTemplate),
+ _loadBalancerKey,
+ _delegatingHandlers,
+ _addHeadersToDownstream,
+ _addHeadersToUpstream,
+ _dangerousAcceptAnyServerCertificateValidator,
+ _securityOptions,
+ _downstreamHttpMethod,
+ _downstreamHttpVersion);
+ }
+}
diff --git a/src/Ocelot/Configuration/Builder/RouteBuilder.cs b/src/Ocelot/Configuration/Builder/RouteBuilder.cs
index 1194b5ea77..8129606cf9 100644
--- a/src/Ocelot/Configuration/Builder/RouteBuilder.cs
+++ b/src/Ocelot/Configuration/Builder/RouteBuilder.cs
@@ -1,11 +1,13 @@
-namespace Ocelot.Configuration.Builder
-{
- using Ocelot.Configuration.File;
- using Ocelot.Values;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+
+using Ocelot.Configuration.File;
+
+using Ocelot.Values;
+namespace Ocelot.Configuration.Builder
+{
public class RouteBuilder
{
private UpstreamPathTemplate _upstreamTemplatePattern;
diff --git a/src/Ocelot/Configuration/Builder/UpstreamPathTemplateBuilder.cs b/src/Ocelot/Configuration/Builder/UpstreamPathTemplateBuilder.cs
index 21b2130253..cf3a1f0123 100644
--- a/src/Ocelot/Configuration/Builder/UpstreamPathTemplateBuilder.cs
+++ b/src/Ocelot/Configuration/Builder/UpstreamPathTemplateBuilder.cs
@@ -1,7 +1,7 @@
-namespace Ocelot.Configuration.Builder
-{
- using Values;
+using Ocelot.Values;
+namespace Ocelot.Configuration.Builder
+{
public class UpstreamPathTemplateBuilder
{
private string _template;
diff --git a/src/Ocelot/Configuration/CacheOptions.cs b/src/Ocelot/Configuration/CacheOptions.cs
index e5738a46e6..d509b38e91 100644
--- a/src/Ocelot/Configuration/CacheOptions.cs
+++ b/src/Ocelot/Configuration/CacheOptions.cs
@@ -8,8 +8,8 @@ public CacheOptions(int ttlSeconds, string region)
Region = region;
}
- public int TtlSeconds { get; private set; }
+ public int TtlSeconds { get; }
- public string Region { get; private set; }
+ public string Region { get; }
}
}
diff --git a/src/Ocelot/Configuration/ChangeTracking/IOcelotConfigurationChangeTokenSource.cs b/src/Ocelot/Configuration/ChangeTracking/IOcelotConfigurationChangeTokenSource.cs
index f69d91aff0..a79c2e06b2 100644
--- a/src/Ocelot/Configuration/ChangeTracking/IOcelotConfigurationChangeTokenSource.cs
+++ b/src/Ocelot/Configuration/ChangeTracking/IOcelotConfigurationChangeTokenSource.cs
@@ -1,7 +1,7 @@
+using Microsoft.Extensions.Primitives;
+
namespace Ocelot.Configuration.ChangeTracking
{
- using Microsoft.Extensions.Primitives;
-
///
/// source which is activated when Ocelot's configuration is changed.
///
diff --git a/src/Ocelot/Configuration/ChangeTracking/OcelotConfigurationChangeToken.cs b/src/Ocelot/Configuration/ChangeTracking/OcelotConfigurationChangeToken.cs
index ecefcf9b14..7b584a8ee1 100644
--- a/src/Ocelot/Configuration/ChangeTracking/OcelotConfigurationChangeToken.cs
+++ b/src/Ocelot/Configuration/ChangeTracking/OcelotConfigurationChangeToken.cs
@@ -1,15 +1,16 @@
+using System;
+using System.Collections.Generic;
+
+using Microsoft.Extensions.Primitives;
+
namespace Ocelot.Configuration.ChangeTracking
{
- using System;
- using System.Collections.Generic;
- using Microsoft.Extensions.Primitives;
-
public class OcelotConfigurationChangeToken : IChangeToken
{
public const double PollingIntervalSeconds = 1;
private readonly ICollection _callbacks = new List();
- private readonly object _lock = new object();
+ private readonly object _lock = new();
private DateTime? _timeChanged;
public IDisposable RegisterChangeCallback(Action