Skip to content

Commit 2a8f3dc

Browse files
authored
Merge branch 'develop' into feature/add-feature-for-ocelot-pipeline-configuration
2 parents 81d796c + 5dbbbef commit 2a8f3dc

File tree

565 files changed

+4761
-4437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

565 files changed

+4761
-4437
lines changed

Ocelot.sln

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
4-
VisualStudioVersion = 17.0.32112.339
4+
VisualStudioVersion = 17.6.33723.286
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{5CFB79B7-C9DC-45A4-9A75-625D92471702}"
77
EndProject
@@ -86,6 +86,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "open-tracing", "open-tracin
8686
EndProject
8787
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OcelotOpenTracing", "samples\OcelotOpenTracing\OcelotOpenTracing.csproj", "{C9427E78-4281-4F59-A66E-17C0B66550E5}"
8888
EndProject
89+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "service-discovery", "service-discovery", "{25C30AAA-12DD-4BA5-A53F-9271E54EBAB7}"
90+
EndProject
91+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.Samples.ServiceDiscovery.ApiGateway", "samples\OcelotServiceDiscovery\ApiGateway\Ocelot.Samples.ServiceDiscovery.ApiGateway.csproj", "{D37209EA-C13E-42AE-B851-A8604F1FCD0E}"
92+
EndProject
93+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ocelot.Samples.ServiceDiscovery.DownstreamService", "samples\OcelotServiceDiscovery\DownstreamService\Ocelot.Samples.ServiceDiscovery.DownstreamService.csproj", "{E2AC741A-4120-4D59-B5E4-16382ED45E8D}"
94+
EndProject
8995
Global
9096
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9197
Debug|Any CPU = Debug|Any CPU
@@ -188,6 +194,14 @@ Global
188194
{C9427E78-4281-4F59-A66E-17C0B66550E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
189195
{C9427E78-4281-4F59-A66E-17C0B66550E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
190196
{C9427E78-4281-4F59-A66E-17C0B66550E5}.Release|Any CPU.Build.0 = Release|Any CPU
197+
{D37209EA-C13E-42AE-B851-A8604F1FCD0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
198+
{D37209EA-C13E-42AE-B851-A8604F1FCD0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
199+
{D37209EA-C13E-42AE-B851-A8604F1FCD0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
200+
{D37209EA-C13E-42AE-B851-A8604F1FCD0E}.Release|Any CPU.Build.0 = Release|Any CPU
201+
{E2AC741A-4120-4D59-B5E4-16382ED45E8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
202+
{E2AC741A-4120-4D59-B5E4-16382ED45E8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
203+
{E2AC741A-4120-4D59-B5E4-16382ED45E8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
204+
{E2AC741A-4120-4D59-B5E4-16382ED45E8D}.Release|Any CPU.Build.0 = Release|Any CPU
191205
EndGlobalSection
192206
GlobalSection(SolutionProperties) = preSolution
193207
HideSolutionNode = FALSE
@@ -224,6 +238,9 @@ Global
224238
{11C622AD-8C0A-4CF4-811B-3DBB76550797} = {5CFB79B7-C9DC-45A4-9A75-625D92471702}
225239
{731C6A8A-69ED-445C-A132-C638AA93F9C7} = {8FA0CBA0-0338-48EB-B37F-83CA5022237C}
226240
{C9427E78-4281-4F59-A66E-17C0B66550E5} = {731C6A8A-69ED-445C-A132-C638AA93F9C7}
241+
{25C30AAA-12DD-4BA5-A53F-9271E54EBAB7} = {8FA0CBA0-0338-48EB-B37F-83CA5022237C}
242+
{D37209EA-C13E-42AE-B851-A8604F1FCD0E} = {25C30AAA-12DD-4BA5-A53F-9271E54EBAB7}
243+
{E2AC741A-4120-4D59-B5E4-16382ED45E8D} = {25C30AAA-12DD-4BA5-A53F-9271E54EBAB7}
227244
EndGlobalSection
228245
GlobalSection(ExtensibilityGlobals) = postSolution
229246
SolutionGuid = {21476EFF-778A-4F97-8A56-D1AF1CEC0C48}

README.md

+17-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
# Ocelot
88

9-
Ocelot is a .NET API Gateway. This project is aimed at people using .NET running a micro services / service oriented architecture
9+
Ocelot is a .NET API Gateway. This project is aimed at people using .NET running a microservices / service-oriented architecture
1010
that need a unified point of entry into their system. However it will work with anything that speaks HTTP and run on any platform that ASP.NET Core supports.
1111

1212
In particular I want easy integration with IdentityServer reference and bearer tokens.
@@ -15,7 +15,11 @@ We have been unable to find this in my current workplace without having to write
1515

1616
Ocelot is a bunch of middlewares in a specific order.
1717

18-
Ocelot manipulates the HttpRequest object into a state specified by its configuration until it reaches a request builder middleware where it creates a HttpRequestMessage object which is used to make a request to a downstream service. The middleware that makes the request is the last thing in the Ocelot pipeline. It does not call the next middleware. The response from the downstream service is retrieved as the requests goes back up the Ocelot pipeline. There is a piece of middleware that maps the HttpResponseMessage onto the HttpResponse object and that is returned to the client. That is basically it with a bunch of other features!
18+
Ocelot manipulates the `HttpRequest` object into a state specified by its configuration until it reaches a request builder middleware, where it creates a `HttpRequestMessage` object which is used to make a request to a downstream service.
19+
The middleware that makes the request is the last thing in the Ocelot pipeline. It does not call the next middleware.
20+
The response from the downstream service is retrieved as the requests goes back up the Ocelot pipeline.
21+
There is a piece of middleware that maps the `HttpResponseMessage` onto the `HttpResponse` object and that is returned to the client.
22+
That is basically it with a bunch of other features!
1923

2024
## Features
2125

@@ -39,19 +43,21 @@ A quick list of Ocelot's capabilities for more information see the [documentatio
3943
* Configuration / Administration REST API
4044
* Platform / Cloud Agnostic
4145

42-
## How to install
46+
## Install
4347

4448
Ocelot is designed to work with ASP.NET and it targets `net7.0`.
4549

46-
Install Ocelot and it's dependencies using NuGet.
50+
Install Ocelot and its dependencies using NuGet Package Manager:
51+
```powershell
52+
Install-Package Ocelot
53+
```
4754

48-
`Install-Package Ocelot`
55+
Or via the .NET CLI:
56+
```shell
57+
dotnet add package Ocelot
58+
```
4959

50-
Or via the .NET Core CLI:
51-
52-
`dotnet add package ocelot`
53-
54-
All versions can be found [here](https://www.nuget.org/packages/Ocelot/)
60+
All versions can be found [here](https://www.nuget.org/packages/Ocelot/).
5561

5662
## Documentation
5763

@@ -67,16 +73,6 @@ We love to receive contributions from the community so please keep them coming :
6773

6874
Pull requests, issues and commentary welcome!
6975

70-
Please complete the relevant template for issues and PRs. Sometimes it's worth getting in touch with us to discuss changes before doing any work incase this is something we are already doing or it might not make sense. We can also give advice on the easiest way to do things :)
76+
Please complete the relevant template for issues and PRs. Sometimes it's worth getting in touch with us to discuss changes before doing any work in case this is something we are already doing or it might not make sense. We can also give advice on the easiest way to do things :)
7177

7278
Finally we mark all existing issues as help wanted, small, medium and large effort. If you want to contribute for the first time I suggest looking at a help wanted & small effort issue :)
73-
74-
## Donate
75-
76-
If you think this project is worth supporting financially please make a contribution using the button below! We use the money to run the https://threemammals.com website.
77-
78-
[![Support via PayPal](https://cdn.rawgit.com/twolfson/paypal-github-button/1.0.0/dist/button.svg)](https://www.paypal.me/ThreeMammals/)
79-
80-
## Things that are currently annoying me
81-
82-
[![](https://codescene.io/projects/697/status.svg) Get more details at **codescene.io**.](https://codescene.io/projects/697/jobs/latest-successful/results)

docs/building/building.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ Building
33

44
* You can also just run `dotnet tool restore && dotnet cake` locally!. Output will got to the `./artifacts` directory.
55

6-
* 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.
6+
* 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.
7+
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.
78

8-
* 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.
9+
* There is a Makefile to make it easier to call the various targets in `build.cake`. The scripts are called with **.sh** but can be easily changed to **.ps1** if you are using Windows.
910

10-
* Alternatively you can build the project in VS2022 with the latest .NET 7.0 SDK.
11+
* Alternatively you can build the project in VS2022 with the latest .NET 7.0 SDK.

docs/features/administration.rst

+38-25
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@ Administration
33

44
Ocelot supports changing configuration during runtime via an authenticated HTTP API. This can be authenticated in two ways either using Ocelot's internal IdentityServer (for authenticating requests to the administration API only) or hooking the administration API authentication into your own IdentityServer.
55

6-
The first thing you need to do if you want to use the administration API is bring in the relavent NuGet package..
6+
The first thing you need to do if you want to use the administration API is bring in the relavent NuGet package:
77

8-
``Install-Package Ocelot.Administration``
8+
.. code-block:: powershell
99
10-
This will bring down everything needed by the admin API.
10+
Install-Package Ocelot.Administration
11+
12+
This will bring down everything needed by the administration API.
1113

1214
Providing your own IdentityServer
13-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
---------------------------------
1416

15-
All you need to do to hook into your own IdentityServer is add the following to your ConfigureServices method.
17+
All you need to do to hook into your own IdentityServer is add the following configuration options with authentication to your ``ConfigureServices`` method.
18+
After that we must pass these options to ``AddAdministration()`` extension of the ``OcelotBuilder`` being returned by ``AddOcelot()`` [#f1]_ like below:
1619

1720
.. code-block:: csharp
1821
@@ -26,7 +29,7 @@ All you need to do to hook into your own IdentityServer is add the following to
2629
{
2730
ValidateAudience = false,
2831
};
29-
// etc....
32+
// etc...
3033
};
3134
3235
services
@@ -36,18 +39,21 @@ All you need to do to hook into your own IdentityServer is add the following to
3639
3740
You now need to get a token from your IdentityServer and use in subsequent requests to Ocelot's administration API.
3841

39-
This feature was implemented for `issue 228 <https://github.com/ThreeMammals/Ocelot/issues/228>`_. It is useful because the IdentityServer authentication middleware needs the URL of the IdentityServer. If you are using the internal IdentityServer it might not alaways be possible to have the Ocelot URL.
42+
This feature was implemented for `Issue 228 <https://github.com/ThreeMammals/Ocelot/issues/228>`_. It is useful because the IdentityServer authentication middleware needs the URL of the IdentityServer.
43+
If you are using the internal IdentityServer it might not always be possible to have the Ocelot URL.
4044

4145
Internal IdentityServer
42-
^^^^^^^^^^^^^^^^^^^^^^^
46+
-----------------------
4347

44-
The API is authenticated using bearer tokens that you request from Ocelot iteself. This is provided by the amazing `Identity Server <https://github.com/IdentityServer/IdentityServer4>`_ project that I have been using for a few years now. Check them out.
48+
The API is authenticated using Bearer tokens that you request from Ocelot itself. This is provided by the amazing `Identity Server <https://github.com/IdentityServer/IdentityServer4>`_ project that I have been using for a few years now. Check them out.
4549

46-
In order to enable the administration section you need to do a few things. First of all add this to yourinitial Startup.cs.
50+
In order to enable the administration section you need to do a few things. First of all add this to your initial **Startup.cs**.
4751

48-
The path can be anything you want and it is obviously reccomended don't usea url you would like to route through with Ocelot as this will not work. The administration uses theMapWhen functionality of asp.net core and all requests to {root}/administration will be sent there not to the Ocelot middleware.
52+
The path can be anything you want and it is obviously recommended don't use a URL you would like to route through with Ocelot as this will not work.
53+
The administration uses the ``MapWhen`` functionality of ASP.NET Core and all requests to "**{root}/administration**" will be sent there not to the Ocelot middleware.
4954

5055
The secret is the client secret that Ocelot's internal IdentityServer will use to authenticate requests to the administration API. This can be whatever you want it to be!
56+
In order to pass this secret string as parameter we must call the ``AddAdministration()`` extension of the ``OcelotBuilder`` being returned by ``AddOcelot()`` [#f1]_ like below:
5157

5258
.. code-block:: csharp
5359
@@ -58,30 +64,33 @@ The secret is the client secret that Ocelot's internal IdentityServer will use t
5864
.AddAdministration("/administration", "secret");
5965
}
6066
61-
In order for the administration API to work, Ocelot / IdentityServer must be able to call itself for validation. This means that you need to add the base url of Ocelot to global configuration if it is not default (http://localhost:5000). Please note if you are using something like docker to host Ocelot it might not be able to call back to localhost etc and you need to know what you are doing with docker networking in this scenario. Anyway this can be done as follows..
67+
In order for the administration API to work, Ocelot / IdentityServer must be able to call itself for validation.
68+
This means that you need to add the base URL of Ocelot to global configuration if it is not default (http://localhost:5000).
69+
Please note, if you are using something like Docker to host Ocelot it might not be able to call back to **localhost** etc and you need to know what you are doing with Docker networking in this scenario.
70+
Anyway, this can be done as follows.
6271

63-
If you want to run on a different host and port locally..
72+
If you want to run on a different host and port locally:
6473

6574
.. code-block:: json
6675
6776
"GlobalConfiguration": {
6877
"BaseUrl": "http://localhost:55580"
6978
}
7079
71-
or if Ocelot is exposed via dns
80+
or if Ocelot is exposed via DNS:
7281

7382
.. code-block:: json
7483
7584
"GlobalConfiguration": {
7685
"BaseUrl": "http://mydns.com"
7786
}
7887
79-
Now if you went with the configuration options above and want to access the API you can use the postman scriptscalled ocelot.postman_collection.json in the solution to change the Ocelot configuration. Obviously these will need to be changed if you are running Ocelot on a different url to http://localhost:5000.
80-
88+
Now if you went with the configuration options above and want to access the API you can use the Postman scripts called **ocelot.postman_collection.json** in the solution to change the Ocelot configuration.
89+
Obviously these will need to be changed if you are running Ocelot on a different URL to http://localhost:5000.
8190

82-
The scripts show you how to request a bearer token from ocelot and then use it to GET the existing configuration and POST a configuration.
91+
The scripts show you how to request a Bearer token from Ocelot and then use it to GET the existing configuration and POST a configuration.
8392

84-
If you are running multiple Ocelot instances in a cluster then you need to use a certificate to sign the bearer tokens used to access the administration API.
93+
If you are running multiple Ocelot instances in a cluster then you need to use a certificate to sign the Bearer tokens used to access the administration API.
8594

8695
In order to do this you need to add two more environmental variables for each Ocelot in the cluster.
8796

@@ -90,11 +99,11 @@ In order to do this you need to add two more environmental variables for each Oc
9099
``OCELOT_CERTIFICATE_PASSWORD``
91100
The password for the certificate.
92101

93-
Normally Ocelot just uses temporary signing credentials but if you set these environmental variables then it will use the certificate. If all the other Ocelot instances in thecluster have the same certificate then you are good!
94-
102+
Normally Ocelot just uses temporary signing credentials but if you set these environmental variables then it will use the certificate.
103+
If all the other Ocelot instances in the cluster have the same certificate then you are good!
95104

96105
Administration API
97-
^^^^^^^^^^^^^^^^^^
106+
------------------
98107

99108
**POST {adminPath}/connect/token**
100109

@@ -117,15 +126,19 @@ This gets the current Ocelot configuration. It is exactly the same JSON we use t
117126

118127
**POST {adminPath}/configuration**
119128

120-
This overrwrites the existing configuration (should probably be a put!). I reccomend getting your config from the GET endpoint, making any changes and posting it back...simples.
129+
This overwrites the existing configuration (should probably be a put!). I recommend getting your config from the GET endpoint, making any changes and posting it back...simples.
121130

122-
The body of the request is JSON and it is the same format as the FileConfiguration.cs that we use to set up
123-
Ocelot on a file system.
131+
The body of the request is JSON and it is the same format as the FileConfiguration.cs that we use to set up Ocelot on a file system.
124132

125-
Please note that if you want to use this API then the process running Ocelot must have permission to write to the disk where your ocelot.json or ocelot.{environment}.json is located. This is because Ocelot will overwrite them on save.
133+
Please note that if you want to use this API then the process running Ocelot must have permission to write to the disk where your **ocelot.json** or **ocelot.{environment}.json** is located.
134+
This is because Ocelot will overwrite them on save.
126135

127136
**DELETE {adminPath}/outputcache/{region}**
128137

129138
This clears a region of the cache. If you are using a backplane it will clear all instances of the cache! Giving your the ability to run a cluster of Ocelots and cache over all of them in memory and clear them all at the same time / just use a distributed cache.
130139

131140
The region is whatever you set against the Region field in the FileCacheOptions section of the Ocelot configuration.
141+
142+
""""
143+
144+
.. [#f1] The ``AddOcelot`` method adds default ASP.NET services to DI-container. You could call another more extended ``AddOcelotUsingBuilder`` method while configuring services to build and use custom builder via an ``IMvcCoreBuilder`` interface object. See more instructions in :doc:`../features/dependencyinjection`, "**The AddOcelotUsingBuilder method**" section.

docs/features/authentication.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,6 @@ NOTE: In order to get Ocelot to view the scope claim from Okta properly, you hav
172172
Allowed Scopes
173173
^^^^^^^^^^^^^
174174

175-
If you add scopes to AllowedScopes Ocelot will get all the user claims (from the token) of the type scope and make sure that the user has all of the scopes in the list.
175+
If you add scopes to AllowedScopes Ocelot will get all the user claims (from the token) of the type scope and make sure that the user has at least one of the scopes in the list.
176176

177177
This is a way to restrict access to a Route on a per scope basis.

0 commit comments

Comments
 (0)