Skip to content

Commit

Permalink
#645 added a sample project using the administration api, tested loca…
Browse files Browse the repository at this point in the history
…lly and works as expected (#660)
  • Loading branch information
TomPallister authored Oct 13, 2018
1 parent 89639ce commit 41d4f9c
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 0 deletions.
13 changes: 13 additions & 0 deletions samples/AdministrationApi/AdministrationApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Ocelot" Version="12.0.1"/>
<PackageReference Include="Ocelot.Administration" Version="0.1.0"/>
</ItemGroup>
</Project>
150 changes: 150 additions & 0 deletions samples/AdministrationApi/Issue645.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"info": {
"_postman_id": "6234b40a-e363-4c73-8577-1c9074abb951",
"name": "Issue645",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "1. GET http://localhost: 55580/administration/.well-known/openid-configuration",
"request": {
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer {{AccessToken}}"
}
],
"body": {},
"url": {
"raw": "http://localhost:5000/administration/.well-known/openid-configuration",
"protocol": "http",
"host": [
"localhost"
],
"port": "5000",
"path": [
"administration",
".well-known",
"openid-configuration"
]
}
},
"response": []
},
{
"name": "3. GET http://localhost: 55580/administration/configuration",
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "Bearer {{AccessToken}}"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"reRoutes\": [\r\n {\r\n \"downstreamPathTemplate\": \"/{everything}\",\r\n \"upstreamPathTemplate\": \"/templates/{everything}\",\r\n \"upstreamHttpMethod\": [\r\n \"GET\"\r\n ],\r\n \"addHeadersToRequest\": {},\r\n \"upstreamHeaderTransform\": {},\r\n \"downstreamHeaderTransform\": {},\r\n \"addClaimsToRequest\": {},\r\n \"routeClaimsRequirement\": {},\r\n \"addQueriesToRequest\": {},\r\n \"requestIdKey\": null,\r\n \"fileCacheOptions\": {\r\n \"ttlSeconds\": 0,\r\n \"region\": null\r\n },\r\n \"reRouteIsCaseSensitive\": false,\r\n \"downstreamScheme\": \"http\",\r\n \"qoSOptions\": {\r\n \"exceptionsAllowedBeforeBreaking\": 0,\r\n \"durationOfBreak\": 0,\r\n \"timeoutValue\": 0\r\n },\r\n \"loadBalancerOptions\": {\r\n \"type\": null,\r\n \"key\": null,\r\n \"expiry\": 0\r\n },\r\n \"rateLimitOptions\": {\r\n \"clientWhitelist\": [],\r\n \"enableRateLimiting\": false,\r\n \"period\": null,\r\n \"periodTimespan\": 0,\r\n \"limit\": 0\r\n },\r\n \"authenticationOptions\": {\r\n \"authenticationProviderKey\": null,\r\n \"allowedScopes\": []\r\n },\r\n \"httpHandlerOptions\": {\r\n \"allowAutoRedirect\": false,\r\n \"useCookieContainer\": false,\r\n \"useTracing\": false,\r\n \"useProxy\": true\r\n },\r\n \"downstreamHostAndPorts\": [\r\n {\r\n \"host\": \"localhost\",\r\n \"port\": 50689\r\n }\r\n ],\r\n \"upstreamHost\": null,\r\n \"key\": null,\r\n \"delegatingHandlers\": [],\r\n \"priority\": 1,\r\n \"timeout\": 0,\r\n \"dangerousAcceptAnyServerCertificateValidator\": false\r\n }\r\n ],\r\n \"aggregates\": [],\r\n \"globalConfiguration\": {\r\n \"requestIdKey\": \"Request-Id\",\r\n \"rateLimitOptions\": {\r\n \"clientIdHeader\": \"ClientId\",\r\n \"quotaExceededMessage\": null,\r\n \"rateLimitCounterPrefix\": \"ocelot\",\r\n \"disableRateLimitHeaders\": false,\r\n \"httpStatusCode\": 429\r\n },\r\n \"qoSOptions\": {\r\n \"exceptionsAllowedBeforeBreaking\": 0,\r\n \"durationOfBreak\": 0,\r\n \"timeoutValue\": 0\r\n },\r\n \"baseUrl\": \"http://localhost:55580\",\r\n \"loadBalancerOptions\": {\r\n \"type\": null,\r\n \"key\": null,\r\n \"expiry\": 0\r\n },\r\n \"downstreamScheme\": null,\r\n \"httpHandlerOptions\": {\r\n \"allowAutoRedirect\": false,\r\n \"useCookieContainer\": false,\r\n \"useTracing\": false,\r\n \"useProxy\": true\r\n }\r\n }\r\n}"
},
"url": {
"raw": "http://localhost:5000/administration/configuration",
"protocol": "http",
"host": [
"localhost"
],
"port": "5000",
"path": [
"administration",
"configuration"
]
}
},
"response": []
},
{
"name": "2. POST http://localhost: 55580/administration/connect/token",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var jsonData = JSON.parse(responseBody);",
"postman.setGlobalVariable(\"AccessToken\", jsonData.access_token);",
"postman.setGlobalVariable(\"RefreshToken\", jsonData.refresh_token);"
]
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "client_id",
"value": "admin",
"type": "text"
},
{
"key": "client_secret",
"value": "secret",
"type": "text"
},
{
"key": "scope",
"value": "admin",
"type": "text"
},
{
"key": "grant_type",
"value": "client_credentials",
"type": "text"
}
]
},
"url": {
"raw": "http://localhost:5000/administration/connect/token",
"protocol": "http",
"host": [
"localhost"
],
"port": "5000",
"path": [
"administration",
"connect",
"token"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"id": "0f60e7b3-e4f1-4458-bbc4-fc4809e86b2d",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "1279a2cf-b771-4a86-9dfa-302b240fac62",
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
50 changes: 50 additions & 0 deletions samples/AdministrationApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Ocelot.DependencyInjection;
using Ocelot.Middleware;
using Ocelot.Administration;

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();
}
}
}
27 changes: 27 additions & 0 deletions samples/AdministrationApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:9943",
"sslPort": 44396
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"AdministrationApi": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
92 changes: 92 additions & 0 deletions samples/AdministrationApi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"reRoutes": [
{
"downstreamPathTemplate": "/{everything}",
"upstreamPathTemplate": "/templates/{everything}",
"upstreamHttpMethod": [
"GET"
],
"addHeadersToRequest": {},
"upstreamHeaderTransform": {},
"downstreamHeaderTransform": {},
"addClaimsToRequest": {},
"routeClaimsRequirement": {},
"addQueriesToRequest": {},
"requestIdKey": null,
"fileCacheOptions": {
"ttlSeconds": 0,
"region": null
},
"reRouteIsCaseSensitive": false,
"downstreamScheme": "http",
"qoSOptions": {
"exceptionsAllowedBeforeBreaking": 0,
"durationOfBreak": 0,
"timeoutValue": 0
},
"loadBalancerOptions": {
"type": null,
"key": null,
"expiry": 0
},
"rateLimitOptions": {
"clientWhitelist": [],
"enableRateLimiting": false,
"period": null,
"periodTimespan": 0,
"limit": 0
},
"authenticationOptions": {
"authenticationProviderKey": null,
"allowedScopes": []
},
"httpHandlerOptions": {
"allowAutoRedirect": false,
"useCookieContainer": false,
"useTracing": false,
"useProxy": true
},
"downstreamHostAndPorts": [
{
"host": "localhost",
"port": 50689
}
],
"upstreamHost": null,
"key": null,
"delegatingHandlers": [],
"priority": 1,
"timeout": 0,
"dangerousAcceptAnyServerCertificateValidator": false
}
],
"aggregates": [],
"globalConfiguration": {
"requestIdKey": "Request-Id",
"rateLimitOptions": {
"clientIdHeader": "ClientId",
"quotaExceededMessage": null,
"rateLimitCounterPrefix": "ocelot",
"disableRateLimitHeaders": false,
"httpStatusCode": 429
},
"qoSOptions": {
"exceptionsAllowedBeforeBreaking": 0,
"durationOfBreak": 0,
"timeoutValue": 0
},
"baseUrl": "http://localhost:55580",
"loadBalancerOptions": {
"type": null,
"key": null,
"expiry": 0
},
"downstreamScheme": null,
"httpHandlerOptions": {
"allowAutoRedirect": false,
"useCookieContainer": false,
"useTracing": false,
"useProxy": true
}
}
}
10 changes: 10 additions & 0 deletions samples/AdministrationApi/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": true,
"LogLevel": {
"Default": "Trace",
"System": "Trace",
"Microsoft": "Trace"
}
}
}
18 changes: 18 additions & 0 deletions samples/AdministrationApi/ocelot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"ReRoutes": [
{
"DownstreamPathTemplate": "/service/stats/collected",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5100
}
],
"UpstreamPathTemplate": "/api/stats/collected"
}
],
"GlobalConfiguration": {
"BaseUrl": "http://localhost:5000"
}
}
1 change: 1 addition & 0 deletions samples/AdministrationApi/tempkey.rsa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"KeyId":"44cc0f50fec6905aa63902a5a5aa9f6b","Parameters":{"D":"Utr6ZW4f9G5IOmkibdGWtujp3J38XuxyDeBxxmR4WhYzknu6QLGPJOuYpzF9bGXcpBoZoPVw1bXtDQXr3eoQt14/ndY3nZOka3+vXeEBc4C9BLHOv7QYzS+lvxduyS1xpRsUX/z5iL/UrvpllO0Ii4JiurBuO1Vi642M1930oT7Iw9sI7o8nNe7bCgMEeTAGgOG/c1SRFV1oA1eg5QaLlBVL4633p5XIhY9ZX7x0RVCfbxcgHYor6YAfK0f792j5qkHJa69WoTLf3kF7QSHDeg5vCG6tzUvSmVt+TgpU7w8wIch+9zkQhoFv5i7wGBDwWu7YFdc2fd7ESbfu7r3EOQ==","DP":"rah2ooiX6Ldf0g+Wwh7E7t7uvIlJVcYX/oGFrHjX2Zv7uNimMYxwQqJGxWSyDbqNaqVNH73KHuvJXbVz0Bch8VM16pJEhcw/cMehiW0/QvjVKwe0B8r7C5iCff3w56N303NdynObv4XwPCXKDLqbWjHBeNtVx3ffCUAm1FOyYjc=","DQ":"Gjkt8WCO68zHnLYJ3MYPUrrVwTxEThrN7D7zHCF24bldIu4aDd2SF9Ne/nOn3pXipQT98h+3i545W/9GDdj8LA+mLJU0RSByBQsq+KFjJbHVlG7XuNPIClB4o3JGKQ3BT29sN/we4vW4KOdTB3UlBLdw5oa0XmrhO4EockLjJGs=","Exponent":"AQAB","InverseQ":"pNDcSxe3RS1gQ4ORDCPy0EfLifTGjli/4OsaTC/F3THTrq8tqpq7qDlAn95h2bLDFDjK29X3u1NyJgzSgEP2LdhNloRgTVCDoFOmE40DvGmVg1PPaeaLXFnV+zQpam3gL34/GNdt1dFXzVE5yb7VSwqsRTJHXoylEddU/LKG8hs=","Modulus":"u8aKNe9Ma7P6w/Atz9eH0j8SqDvaOZ68cI59GEszYrGiNCdG16XqEUTnrhRCn7HkyWdTS3gcSROEldAG1TAp8E3SvwUzU14M2K13QjQDFdCE6H6oiCSecBP/WfiCdSPOqQ5WLksefGi4sMLMRuo3xrtXWXUFpViHRryQc6zlYcmbGoxCz3bDL0/ATTWf+kxCf4BFGV6TDFOQDzF2tTOz823dqpb3+/bjuiY6FkcUFtYIY+jrPwIvjzDU1DDufsFJHPfvvsFfUFX2BziyZMFifzAnd+Nggq2LS2rem/S9BZe/0NnMHp603IPNiumi2DuWXasTqDUPSAbipXwRqhUuYQ==","P":"1Ley2G5UXKYmMu+Yz2Et2c6oUP8w1W/JIYs0VMKR3IF2nSS6aAYr5CBe93nLPElMeKWXK6V2NhsXwQbTWd4RBsQzdFe/ncghGLCWqwzNdZ12g3YPVmw3cG91ASyhxXb9drOi1ukFCMJp+UNdp6qj0zhDOqQtqQLUiSC7qUryh8s=","Q":"4fuhKLbcxJOOAMvPN6QJ2xyYbJg0UsdZARKpJ5J/atFoMajZL8D7tGCAyPwBSYsZcgBNQiJ1dU316Kjq/7tlunK6baZrmFhM7yzfPXIBhH5GkI8i5X3By7TUvdFDiYG2UfVIqA1tRQ+wx8z3Ts8JqAXYJJxskHPJJM5Hi8av5QM="}}

0 comments on commit 41d4f9c

Please sign in to comment.