Skip to content

Commit

Permalink
update occelot apigw
Browse files Browse the repository at this point in the history
  • Loading branch information
meofiscoding committed Nov 19, 2023
1 parent 0ba2090 commit d18f739
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 95 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Microsoft.IdentityModel.Tokens;
using Ocelot.DependencyInjection;
Expand All @@ -16,9 +15,9 @@
options.Authority = builder.Configuration["IdentityUrl"];
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = false
ValidateAudience = true,
ValidAudiences = new[] { "payment", "movies" }
};
// options.Configuration = new OpenIdConnectConfiguration();
});

builder.Services.AddOcelot();
Expand Down Expand Up @@ -47,8 +46,8 @@
builder.AllowAnyMethod();
});
app.UseHttpsRedirection();
app.UseAuthorization();
app.UseAuthentication();
app.UseAuthorization();
app.UseOcelot().Wait();
app.MapControllers();
app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"IdentityUrl":"http://localhost:5002"
"IdentityUrl":"https://localhost:7096"
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
}
},
"AllowedHosts": "*",
"IdentityUrl": "http://localhost:5002"
"IdentityUrl": "https://localhost:7096"
}

Original file line number Diff line number Diff line change
@@ -1,24 +1,122 @@
{
"Routes": [
{
"DownstreamPathTemplate": "/api/pricingPlans",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5031
}
],
"UpstreamHttpMethod": [
"GET"
],
"UpstreamPathTemplate": "/payment/planform/{everything}",
"AuthenticationOptions": {
"AuthenticationProviderKey": "IdentityApiKey",
"AllowedScopes": [
"payment"
]
}
},
{
"DownstreamPathTemplate": "/api/pricingPlans",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5031
}
],
"UpstreamHttpMethod": [
"GET"
],
"UpstreamPathTemplate": "/payment/planform",
"AuthenticationOptions": {
"AuthenticationProviderKey": "IdentityApiKey",
"AllowedScopes": [
"payment"
]
}
},
{
"DownstreamPathTemplate": "/api/subscription",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5031
}
],
"UpstreamHttpMethod": [
"POST"
],
"UpstreamPathTemplate": "/payment/subscriptions",
"AuthenticationOptions": {
"AuthenticationProviderKey": "IdentityApiKey",
"AllowedScopes": [
"payment"
]
}
},
{
"DownstreamPathTemplate": "/api/create-payment-intent",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5031
}
],
"UpstreamHttpMethod": [
"POST"
],
"UpstreamPathTemplate": "/payment/checkout",
"AuthenticationOptions": {
"AuthenticationProviderKey": "IdentityApiKey",
"AllowedScopes": [
"payment"
]
}
},
{
"DownstreamPathTemplate": "/subscription/success",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "localhost",
"Port": 5031
}
],
"UpstreamHttpMethod": [
"POST"
],
"UpstreamPathTemplate": "/payment/success",
"AuthenticationOptions": {
"AuthenticationProviderKey": "IdentityApiKey",
"AllowedScopes": [
"payment"
]
}
},
{
"DownstreamPathTemplate": "/api/movie",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
// Uncomment this to use the local api
// "Host": "localhost",
// "Port": 8000

"Host": "localhost",
"Port": 8000
// Uncomment this to use the docker container
"Host": "movie.api",
"Port": 80
// "Host": "movie.api",
// "Port": 80
}
],
"UpstreamPathTemplate": "/movies",
"UpstreamHttpMethod": [
"GET",
"POST",
"PUT"
"POST"
],
"AuthenticationOptions": {
"AuthenticationProviderKey": "IdentityApiKey",
Expand All @@ -27,8 +125,5 @@
]
}
}
],
"GlobalConfiguration": {
"BaseUrl": "http:localhost:5001"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"DatabaseName": "sampleDB",
"CollectionName": "movies"
},
"IdentityUrl":"http://localhost:5002",
"IdentityUrl":"https://localhost:7096",
"EventBusSettings": {
"HostAddress": "amqp://guest:guest@localhost:5672"
}
Expand Down
2 changes: 1 addition & 1 deletion SimpleServer/src/Services/Movie/Movie.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}
},
"AllowedHosts": "*",
"IdentityUrl":"http://localhost:5002",
"IdentityUrl":"https://localhost:7096",
"EventBusSettings": {
"HostAddress": "amqp://guest:guest@localhost:5672"
}
Expand Down
1 change: 1 addition & 0 deletions SimpleServer/src/Services/Payment/Payment.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Tokens;
using Payment.API;
using Payment.API.Data;
using Payment.API.GrpcService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
"ConnectionStrings": {
"PaymentDB": "User ID=meofadmin;Password=123456;Server=localhost;Port=5432;Database=PaymentDB"
},
//"Kestrel": {
// "EndpointDefaults": {
// "Protocols": "Http2"
// }
//},
"GrpcUrl": "http://localhost:50050",
"IdentityUrl": "http://localhost:5286"
"GrpcUrl": "https://aks.20.44.235.37.nip.io/",
"IdentityUrl": "https://localhost:7096"
}
26 changes: 14 additions & 12 deletions deploy/k8s/apigw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,28 @@ spec:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: movie-service-ingress
name: apigw-service-ingress
namespace: ingress-nginx
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/use-regex: "true"
cert-manager.io/cluster-issuer: letsencrypt
# nginx.ingress.kubernetes.io/rewrite-target: /identity/$2
spec:
tls:
- hosts:
- frontend.20.211.61.204.nip.io # update IP address here
- aks.20.44.235.37.nip.io # update IP address here
secretName: app-web-cert
rules:
- host: frontend.20.211.61.204.nip.io
http:
paths:
- path: /movies(/|$)(.*)
pathType: Prefix
backend:
service:
name: apigw-service
port:
number: 80
- host: aks.20.44.235.37.nip.io
http:
paths:
- path: /(.*)
pathType: Prefix
backend:
service:
name: apigw-service
port:
number: 80

32 changes: 2 additions & 30 deletions deploy/k8s/identity-grpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: identity-grpc
image: 281901/identity:dev
image: 281901/identity.grpc:dev
imagePullPolicy: Always
ports:
- containerPort: 80
Expand Down Expand Up @@ -61,32 +61,4 @@ spec:
app: identity-grpc
ports:
- protocol: TCP
port: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: identity-service-ingress
namespace: ingress-nginx
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/use-regex: "true"
cert-manager.io/cluster-issuer: letsencrypt
# nginx.ingress.kubernetes.io/rewrite-target: /identity/$2
spec:
tls:
- hosts:
- aks.20.44.235.37.nip.io # update IP address here
secretName: app-web-cert
rules:
- host: aks.20.44.235.37.nip.io
http:
paths:
- path: /(.*)
pathType: Prefix
backend:
service:
name: identity-grpc-service
port:
number: 80
port: 80
11 changes: 11 additions & 0 deletions deploy/k8s/ocelot-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ data:
"movies"
]
}
},
{
"DownstreamPathTemplate": "/",
"DownstreamScheme": "http",
"DownstreamHostAndPorts": [
{
"Host": "identity-grpc-service",
"Port": 80
}
],
"UpstreamPathTemplate": "/identity-grpc",
}
]
}
26 changes: 0 additions & 26 deletions deploy/k8s/ocelot.Development.json

This file was deleted.

0 comments on commit d18f739

Please sign in to comment.