Skip to content

Commit f5f80a8

Browse files
committed
Config server added with authorization
1 parent 38ecda9 commit f5f80a8

File tree

60 files changed

+1048
-178
lines changed

Some content is hidden

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

60 files changed

+1048
-178
lines changed

.idea/compiler.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

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

api/src/main/java/io/javatab/microservices/api/composite/course/CourseCompositeService.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,37 @@
33
import io.swagger.v3.oas.annotations.Operation;
44
import io.swagger.v3.oas.annotations.responses.ApiResponse;
55
import io.swagger.v3.oas.annotations.responses.ApiResponses;
6-
import org.springframework.web.bind.annotation.GetMapping;
7-
import org.springframework.web.bind.annotation.PathVariable;
6+
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
7+
import io.swagger.v3.oas.annotations.tags.Tag;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.web.bind.annotation.*;
810
import reactor.core.publisher.Mono;
911

12+
@SecurityRequirement(name = "security_auth")
13+
@Tag(name = "CourseComposite", description = "REST API for composite course information.")
1014
public interface CourseCompositeService {
1115

16+
// TODO:: Update API definitions
17+
/**
18+
* Sample usage: "curl $HOST:$PORT/course-composite/1".
19+
*
20+
* @param courseId of the course
21+
* @return the composite course info, if found, else null
22+
*/
23+
@Operation(
24+
summary = "${open-api.course-composite.get-composite-course.description}",
25+
description = "${open-api.course-composite.get-composite-course.notes}")
26+
@ApiResponses(value = {
27+
@ApiResponse(responseCode = "200", description = "${open-api.responseCodes.ok.description}"),
28+
@ApiResponse(responseCode = "400", description = "${open-api.responseCodes.badRequest.description}"),
29+
@ApiResponse(responseCode = "404", description = "${open-api.responseCodes.notFound.description}"),
30+
@ApiResponse(responseCode = "422", description = "${open-api.responseCodes.unprocessableEntity.description}")
31+
})
32+
@ResponseStatus(HttpStatus.ACCEPTED)
33+
@PostMapping("/course-composite")
34+
Mono<String> createProduct(@RequestBody CourseAggregate body);
35+
36+
1237
/**
1338
* Sample usage: "curl $HOST:$PORT/course-composite/1".
1439
*
@@ -26,4 +51,24 @@ public interface CourseCompositeService {
2651
})
2752
@GetMapping("/course-composite/{courseId}")
2853
Mono<CourseAggregate> getCourse(@PathVariable("courseId") int courseId);
54+
55+
/**
56+
* Sample usage: "curl $HOST:$PORT/course-composite/1".
57+
*
58+
* @param courseId of the course
59+
* @return the composite course info, if found, else null
60+
*/
61+
@Operation(
62+
summary = "${open-api.course-composite.get-composite-course.description}",
63+
description = "${open-api.course-composite.get-composite-course.notes}")
64+
@ApiResponses(value = {
65+
@ApiResponse(responseCode = "200", description = "${open-api.responseCodes.ok.description}"),
66+
@ApiResponse(responseCode = "400", description = "${open-api.responseCodes.badRequest.description}"),
67+
@ApiResponse(responseCode = "404", description = "${open-api.responseCodes.notFound.description}"),
68+
@ApiResponse(responseCode = "422", description = "${open-api.responseCodes.unprocessableEntity.description}")
69+
})
70+
@ResponseStatus(HttpStatus.ACCEPTED)
71+
@DeleteMapping("/course-composite/{courseId}")
72+
Mono<String> deleteCourse(@PathVariable("courseId") int courseId);
73+
2974
}

config-repo/application.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
app:
2+
eureka-username: user
3+
eureka-password: password
4+
eureka-server: localhost
5+
auth-server: localhost
6+
7+
eureka:
8+
client:
9+
serviceUrl:
10+
defaultZone: "http://${app.eureka-username}:${app.eureka-password}@${app.eureka-server}:8761/eureka/"
11+
initialInstanceInfoReplicationIntervalSeconds: 5
12+
registryFetchIntervalSeconds: 5
13+
instance:
14+
leaseRenewalIntervalInSeconds: 5
15+
leaseExpirationDurationInSeconds: 5
16+
17+
# WARNING: Exposing all management endpoints over http should only be used during development, must be locked down in production!
18+
management.endpoint.health.show-details: "ALWAYS"
19+
management.endpoints.web.exposure.include: "*"
20+
21+
---
22+
spring.config.activate.on-profile: docker
23+
app:
24+
eureka-server: eureka
25+
auth-server: auth-server

config-repo/course-composite.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
server.port: 8016
2+
spring.application.name: course-composite
3+
4+
springdoc:
5+
swagger-ui.path: /openapi/swagger-ui.html
6+
api-docs.path: /openapi/v3/api-docs
7+
packagesToScan: io.javatab.microservices.composite.course
8+
pathsToMatch: /**
9+
cache:
10+
disabled: true
11+
swagger-ui:
12+
oauth2-redirect-url: https://localhost:8443/webjars/swagger-ui/oauth2-redirect.html
13+
oauth:
14+
clientId: writer
15+
clientSecret: secret
16+
useBasicAuthenticationWithAccessCodeGrant: true
17+
oAuthFlow:
18+
authorizationUrl: https://localhost:8443/oauth2/authorize
19+
tokenUrl: https://localhost:8443/oauth2/token
20+
21+
server.forward-headers-strategy: framework
22+
23+
open-api:
24+
version: 1.0.0
25+
title: Course Composite API
26+
description: Composite API to fetch data from multiple microservices
27+
termsOfService:
28+
license:
29+
licenseUrl:
30+
externalDocDesc:
31+
externalDocUrl:
32+
contact:
33+
name: Nasruddin
34+
url:
35+
email: webo.geeky@mail.com
36+
37+
responseCodes:
38+
ok.description: OK
39+
badRequest.description: Bad Request, invalid format of the request. See response message for more information
40+
notFound.description: Not found, the specified id does not exist
41+
unprocessableEntity.description: Unprocessable entity, input parameters caused the processing to fail. See response message for more information
42+
43+
course-composite:
44+
get-composite-course:
45+
description: Returns a composite view of the specified course id
46+
notes: |
47+
# Normal response
48+
If the requested course id is found the method will return information regarding:
49+
1. Base course information
50+
1. Student subscribed
51+
1. Vote
52+
1. Service Addresses\n(technical information regarding the addresses of the microservices that created the response)
53+
54+
# Expected partial and error responses
55+
In the following cases, only a partial response be created (used to simplify testing of error conditions)
56+
57+
## Course id 113
58+
200 - Ok, but no students will be returned
59+
60+
## Non numerical course id
61+
400 - A **Bad Request** error will be returned
62+
63+
## course id 13
64+
404 - A **Not Found** error will be returned
65+
66+
## Negative course ids
67+
422 - An **Unprocessable Entity** error will be returned
68+
69+
app:
70+
eureka-username: user
71+
eureka-password: password
72+
eureka-server: localhost
73+
auth-server: localhost
74+
75+
eureka:
76+
client:
77+
serviceUrl:
78+
defaultZone: "http://${app.eureka-username}:${app.eureka-password}@${app.eureka-server}:8761/eureka/"
79+
80+
initialInstanceInfoReplicationIntervalSeconds: 5
81+
registryFetchIntervalSeconds: 5
82+
instance:
83+
leaseRenewalIntervalInSeconds: 5
84+
leaseExpirationDurationInSeconds: 5
85+
86+
spring.security.oauth2.resourceserver.jwt.issuer-uri: http://${app.auth-server}:9999
87+
88+
logging:
89+
level:
90+
root: INFO
91+
se.magnus: DEBUG
92+
org.springframework.web.server.adapter.HttpWebHandlerAdapter: TRACE
93+
94+
management.endpoint.health.show-details: "ALWAYS"
95+
management.endpoints.web.exposure.include: "*"
96+
97+
---
98+
spring.config.activate.on-profile: docker
99+
server.port: 8080
100+
app:
101+
eureka-server: eureka
102+
auth-server: auth-server

config-repo/course.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
server.port: 8012
2+
spring.application.name: course
3+
logging:
4+
level:
5+
root: INFO
6+
io.javatab.microservices: DEBUG
7+
8+
app:
9+
eureka-username: user
10+
eureka-password: password
11+
eureka-server: localhost
12+
13+
eureka:
14+
client:
15+
serviceUrl:
16+
defaultZone: "http://${app.eureka-username}:${app.eureka-password}@${app.eureka-server}:8761/eureka/"
17+
initialInstanceInfoReplicationIntervalSeconds: 5
18+
registryFetchIntervalSeconds: 5
19+
instance:
20+
leaseRenewalIntervalInSeconds: 5
21+
leaseExpirationDurationInSeconds: 5
22+
23+
---
24+
spring.config.activate.on-profile: docker
25+
server.port: 8080
26+
app.eureka-server: eureka
27+
spring.data.mongodb.host: mongodb

config-repo/search.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
server.port: 8015
2+
3+
---
4+
spring.config.activate.on-profile: docker
5+
server.port: 8080
6+
spring.elasticsearch:
7+
uris: http://elasticsearch:9200

config-repo/student.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
server.port: 8013
2+
spring:
3+
application:
4+
name: student
5+
datasource:
6+
driver-class-name: org.postgresql.Driver
7+
username: user
8+
password: pwd
9+
url: jdbc:postgresql://localhost:5432/test
10+
jpa:
11+
database-platform: org.hibernate.dialect.PostgreSQLDialect
12+
hibernate:
13+
ddl-auto: update
14+
15+
16+
---
17+
spring.config.activate.on-profile: docker
18+
server.port: 8080
19+
app.eureka-server: eureka
20+
spring.datasource.url: jdbc:postgresql://postgres:5432/test

config-repo/vote.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
server.port: 8014
2+
spring.redis:
3+
host: localhost
4+
port: 6379
5+
client-type: lettuce
6+
7+
---
8+
spring.config.activate.on-profile: docker
9+
server.port: 8080
10+
spring.redis:
11+
host: redis
12+
port: 6379
13+
client-type: lettuce
14+

docker/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CONFIG_SERVER_ENCRYPT_KEY=my-very-secure-encrypt-key
2+
CONFIG_SERVER_USR=dev-user
3+
CONFIG_SERVER_PWD=dev-password

0 commit comments

Comments
 (0)