Skip to content

Commit 848ef1c

Browse files
Added rust service, fixed claims for nodejs service, adde 'kid' for security service - build nodejs-service, build rust-service, build authentication-service
1 parent 27a9885 commit 848ef1c

29 files changed

Lines changed: 5997 additions & 80 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: CI - Build and push Docker images - Rust Service
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
push:
9+
branches: [ master ]
10+
11+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
12+
jobs:
13+
# This workflow contains a single job called "build"
14+
build:
15+
if: contains(toJson(github), 'build rust-service')
16+
name: Build Jar/Docker Image and Publish to DockerHub
17+
18+
# The type of runner that the job will run on
19+
runs-on: ubuntu-latest
20+
21+
# Steps represent a sequence of tasks that will be executed as part of the job
22+
steps:
23+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
24+
- name: Checkout
25+
uses: actions/checkout@v2
26+
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v1
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v1
32+
33+
# Login to Dockerhub
34+
- name: Login to DockerHub
35+
uses: docker/login-action@v1
36+
with:
37+
username: ${{ secrets.DOCKERHUB_USERNAME }}
38+
password: ${{ secrets.DOCKERHUB_TOKEN }}
39+
40+
- name: Build and push
41+
id: docker_build
42+
uses: docker/build-push-action@v2
43+
with:
44+
context: ./rust-service
45+
file: ./rust-service/Dockerfile
46+
platforms: linux/amd64,linux/arm64
47+
push: true
48+
tags: fielcapao/microservices-design-patterns-rust-service-service:latest
49+
build-args: |
50+
GITHUB_SHA=$GITHUB_SHA
51+
GITHUB_REF=$GITHUB_REF
52+
PORT=8089
53+
54+
- name: Image digest
55+
run: echo ${{ steps.docker_build.outputs.digest }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ Access it [Swagger UI](http://localhost:{SERVICE_PORT}/swagger-ui.html) - `http:
386386
* [X] Java - Quarkus/JDK 25
387387
* [X] Java - Add TestContainers
388388
* [] Add Open Telemetry
389+
* [X] Rust – Add Service using Rust/Actix-web
389390

390391
### References
391392
[Pattern Microservice Architecture](https://microservices.io/patterns/microservices.html)

authentication-service/src/main/java/com/microservice/authentication/AuthenticationServiceApplication.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ JwtEncoder jwtEncoder(AuthenticationProperties properties) {
148148
JSONObject jsonObject = new JSONObject();
149149
jsonObject.put("alg", JWSAlgorithm.HS256.getName());
150150
jsonObject.put("typ", "JWT");
151+
jsonObject.put("kid", "test");
151152

152153
JWSHeader header = JWSHeader.parse(jsonObject);
153154
SignedJWT signedJWT = new SignedJWT(header, claimsSet);
@@ -156,6 +157,7 @@ JwtEncoder jwtEncoder(AuthenticationProperties properties) {
156157
return Jwt.withTokenValue(signedJWT.serialize())
157158
.header("alg", header.getAlgorithm().getName())
158159
.header("typ", "JWT")
160+
.header("kid", header.getKeyID())
159161
.subject(claimsSet.getSubject())
160162
.issuer(claimsSet.getIssuer())
161163
.claims(claims -> claims.putAll(claimsSet.getClaims()))

authentication-service/src/main/java/com/microservice/authentication/controller/JwksSymmetricController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public class JwksSymmetricController {
2424
@ResponseBody
2525
public Map<String, Object> index() {
2626
OctetSequenceKey key = new OctetSequenceKey.Builder(authenticationProperties.getJwt().getKeyValue().getBytes(StandardCharsets.UTF_8))
27-
// .algorithm(Algorithm.parse("HS256"))
28-
// .keyID("test")
27+
.algorithm(Algorithm.parse("HS256"))
28+
.keyID("test")
2929
.build();
3030

3131
// return new JWKSet(key).toJSONObject();

docker/docker-compose.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,32 @@ services:
192192
aliases:
193193
- receipt-api
194194

195+
warehouse-api:
196+
build:
197+
args:
198+
- PORT=8089
199+
context: ../rust-service
200+
dockerfile: Dockerfile
201+
container_name: warehouse-api
202+
environment:
203+
- HOST_NAME=warehouse-api
204+
- CONSUL_SERVER=service-discovery
205+
- MONGODB_URI=mongodb://mongodb-datasource/docker
206+
- SERVER_PORT=8089
207+
- RUST_LOG=TRACE
208+
- APP_NAME=rust-service
209+
- CONSUL_ENABLED=true
210+
- SPRING_PROFILES_ACTIVE=dev
211+
depends_on:
212+
- service-discovery
213+
- mongodb-datasource
214+
ports:
215+
- 8089:8089
216+
networks:
217+
net:
218+
aliases:
219+
- warehouse-api
220+
195221
post-api:
196222
build:
197223
args:

docker/service-discovery-load-configuration.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ if ! curl -k --retry 5 --retry-connrefused --retry-delay 5 -H "Content-Type: app
1010
curl --request PUT --data-binary @spring-cloud-config/edge-server.yml http://service-discovery:8500/v1/kv/config/edge-server/data
1111
curl --request PUT --data-binary @spring-cloud-config/authentication-service.yml http://service-discovery:8500/v1/kv/config/authentication-service/data
1212
curl --request PUT --data-binary @spring-cloud-config/quarkus-service.yml http://service-discovery:8500/v1/kv/config/quarkus-service/data
13+
curl --request PUT --data-binary @spring-cloud-config/applicationDev.yml http://service-discovery:8500/v1/kv/config/rust-service/dev
1314
fi

docker/spring-cloud-config/edge-server.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ spring:
5959
uri: lb://week-menu-api
6060
predicates:
6161
- Path=/api/week-menu/**
62+
filters:
63+
- StripPrefix=2
6264
- id: kotlin-service
6365
uri: lb://kotlin-service
6466
predicates:
@@ -73,7 +75,7 @@ spring:
7375
uri: lb://python-service
7476
predicates:
7577
- Path=/api/products/**,/api/receipts/**
76-
- id: kotlin-service-swagger
78+
- id: python-service-swagger
7779
uri: lb://kotlin-service
7880
predicates:
7981
- Path=/swagger/python-service/**
@@ -83,6 +85,16 @@ spring:
8385
uri: lb://go-service
8486
predicates:
8587
- Path=/api/posts/**
88+
- id: rust-service
89+
uri: lb://rust-service
90+
predicates:
91+
- Path=/api/warehouses/**
92+
- id: rust-service-swagger
93+
uri: lb://rust-service
94+
predicates:
95+
- Path=/swagger/rust-service/**
96+
filters:
97+
- RewritePath=/rust-service/(?<segment>.*), /$\{segment}
8698

8799
com:
88100
microservice:

edge-server/src/main/java/com/springboot/edgeserver/EdgeServerApplication.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@
2727
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
2828
import org.springframework.context.annotation.Bean;
2929
import org.springframework.context.annotation.Primary;
30+
import org.springframework.core.Ordered;
31+
import org.springframework.core.annotation.Order;
3032
import org.springframework.core.task.AsyncTaskExecutor;
3133
import org.springframework.core.task.support.TaskExecutorAdapter;
34+
import org.springframework.http.HttpHeaders;
3235
import org.springframework.http.HttpStatus;
36+
import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
3337
import org.springframework.security.authentication.ReactiveAuthenticationManager;
3438
import org.springframework.security.core.userdetails.ReactiveUserDetailsService;
3539
import org.springframework.session.ReactiveSessionRepository;
@@ -41,6 +45,8 @@
4145
import org.springframework.web.reactive.function.server.RouterFunction;
4246
import org.springframework.web.reactive.function.server.ServerResponse;
4347
import org.springframework.web.server.ResponseStatusException;
48+
import org.springframework.web.server.ServerWebExchange;
49+
import org.springframework.web.server.WebFilter;
4450

4551
import static org.springframework.web.reactive.function.server.RequestPredicates.GET;
4652
import static org.springframework.web.reactive.function.server.RequestPredicates.POST;
@@ -57,6 +63,26 @@ public static void main(String[] args) {
5763
SpringApplication.run(EdgeServerApplication.class, args);
5864
}
5965

66+
@Bean
67+
@Order(Ordered.HIGHEST_PRECEDENCE)
68+
WebFilter writeableHeaders() {
69+
return (exchange, chain) -> {
70+
HttpHeaders writeableHeaders = HttpHeaders.copyOf(
71+
exchange.getRequest().getHeaders());
72+
ServerHttpRequestDecorator writeableRequest = new ServerHttpRequestDecorator(
73+
exchange.getRequest()) {
74+
@Override
75+
public HttpHeaders getHeaders() {
76+
return writeableHeaders;
77+
}
78+
};
79+
ServerWebExchange writeableExchange = exchange.mutate()
80+
.request(writeableRequest)
81+
.build();
82+
return chain.filter(writeableExchange);
83+
};
84+
}
85+
6086
@Bean
6187
@ConditionalOnMissingBean
6288
public SpringSessionWebSessionStore<Session> springSessionWebSessionStore(ReactiveSessionRepository reactiveSessionRepository) {

nodejs-service/package-lock.json

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs-service/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
"await-sleep": "0.0.1",
1818
"body-parser": "^1.18.3",
1919
"cookie-parser": "1.4.3",
20-
"cors": "2.8.5",
2120
"dotenv": "6.2.0",
2221
"express": "^4.16.3",
2322
"express-actuator": "1.1.0",
@@ -41,7 +40,8 @@
4140
"zipkin-transport-http": "0.16.2",
4241
"consul": "2.0.1",
4342
"yaml": "2.8.2",
44-
"request": "2.88.2"
43+
"request": "2.88.2",
44+
"jwks-rsa": "3.2.1"
4545
},
4646
"devDependencies": {
4747
"@babel/core": "^7.7.4",

0 commit comments

Comments
 (0)