Skip to content

Commit

Permalink
Update SonarQube workflow and add comments to Gateway service
Browse files Browse the repository at this point in the history
The SonarQube Github workflow has been adjusted to streamline the build and analysis steps, and specifying Zulu as the Java distribution to set up. Several areas of the Gateway service, such as the AuthenticationFilter and RoutesConfiguration, have been enriched with documentation comments to improve clarity.
  • Loading branch information
MichiBaum committed Jul 19, 2024
1 parent 600c723 commit 670f38d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
name: Sonarqube

name: SonarQube Analysis
on: [push, pull_request]

jobs:
build:
name: Build
name: SonarQube Analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis

- name: Set up JDK 21
- name: Set up Zulu JDK 21
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'

- name: Maven clean compile
run: mvn clean compile -DdockerHub.username=${{secrets.DOCKER_USERNAME}} -DdockerHub.password=${{secrets.DOCKER_PASSWORD}} -DdockerHub.publish=false

- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn sonar:sonar -Dsonar.projectKey=MichiBaum_Microservices
run: |
mvn clean compile -DdockerHub.username=${{secrets.DOCKERHUB_USERNAME}} -DdockerHub.password=${{secrets.DOCKERHUB_PASSWORD}} -DdockerHub.publish=false
mvn sonar:sonar -Dsonar.projectKey=MichiBaum_Microservices
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ class AuthenticationFilter(
private val authenticationValidator: AuthenticationValidator
) : GatewayFilter {

/**
* Filters the incoming request based on the presence and validity of the Authorization header.
*
* @param exchange The ServerWebExchange object representing the current HTTP exchange.
* @param chain The GatewayFilterChain object representing the chain of filters to be executed.
* @return A Mono<Void> that represents the completion of the filter chain.
* @throws Exception if the ServerWebExchange or GatewayFilterChain is null.
*/
override fun filter(
exchange: ServerWebExchange?,
chain: GatewayFilterChain?
Expand All @@ -36,6 +44,12 @@ class AuthenticationFilter(
return Mono.error(Exception("ServerWebExchange or GatewayFilterChain is null"))
}

/**
* Handles authentication failure by setting the response status code to 403 (FORBIDDEN).
*
* @param exchange The ServerWebExchange object representing the current HTTP exchange.
* @return A Mono<Void> that represents the completion of the method.
*/
private fun handleAuthenticationFailure(exchange: ServerWebExchange): Mono<Void> {
val response: ServerHttpResponse = exchange.response
response.setStatusCode(HttpStatus.FORBIDDEN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class RoutesConfiguration(private val authenticationFilter: AuthenticationFilter
const val WEBSITE_SERVICE_URI = "lb://website-service"
}

/**
* Creates and returns a RouteLocator bean that defines the routes for the application.
*
* @param builder The RouteLocatorBuilder used to build the routes.
* @return A RouteLocator object that represents the defined routes.
*/
@Bean
fun routes(builder: RouteLocatorBuilder): RouteLocator {
return builder.routes {
Expand Down
1 change: 1 addition & 0 deletions gateway-service/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ spring:
admin:
client:
enabled: true
# ?
username: admin
password: admin

Expand Down

0 comments on commit 670f38d

Please sign in to comment.