From e73ecfd379879ff1c9ddf478fc3361feb3e7a9fe Mon Sep 17 00:00:00 2001 From: Gato Date: Sun, 7 Jun 2026 10:07:14 +0200 Subject: [PATCH] feat(version): exposer GET /api/v1/version public sans authentification Co-Authored-By: Claude Sonnet 4.6 --- .gitea/workflows/ci.yml | 28 +++++++++++-------- build.gradle | 4 +++ .../infrastructure/config/SecurityConfig.java | 1 + .../rest/controller/VersionController.java | 26 +++++++++++++++++ .../interfaces/VersionControllerIT.java | 24 ++++++++++++++++ 5 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/olhar/olharapi/interfaces/rest/controller/VersionController.java create mode 100644 src/test/java/com/olhar/olharapi/interfaces/VersionControllerIT.java diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 6061ad1..df01693 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -11,22 +11,28 @@ jobs: test: name: Tests runs-on: ubuntu-latest + container: + image: eclipse-temurin:25-jdk + services: + postgres: + image: postgres:16 + env: + POSTGRES_DB: olhar_test + POSTGRES_USER: olhar + POSTGRES_PASSWORD: olhar + env: + SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/olhar_test + SPRING_DATASOURCE_USERNAME: olhar + SPRING_DATASOURCE_PASSWORD: olhar + SPRING_DATASOURCE_DRIVER_CLASS_NAME: org.postgresql.Driver + SECURITY_JWT_SECRET: test-secret-key-for-ci-testing-only-must-be-long-enough + steps: - name: Checkout uses: actions/checkout@v4 - - name: Build image de test - run: docker build -f Dockerfile.test -t olhar-api-test:ci . - - name: Lancer les tests - run: | - docker run --rm \ - --network host \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -e DOCKER_HOST=unix:///var/run/docker.sock \ - -e TESTCONTAINERS_RYUK_DISABLED=true \ - olhar-api-test:ci \ - ./gradlew test --no-daemon + run: ./gradlew test --no-daemon build-and-push: name: Build & push image Docker diff --git a/build.gradle b/build.gradle index 0a33a40..baaec0c 100644 --- a/build.gradle +++ b/build.gradle @@ -70,6 +70,10 @@ tasks.named('test') { useJUnitPlatform() } +springBoot { + buildInfo() +} + tasks.named('bootJar') { archiveFileName = 'olhar-api.jar' } diff --git a/src/main/java/com/olhar/olharapi/infrastructure/config/SecurityConfig.java b/src/main/java/com/olhar/olharapi/infrastructure/config/SecurityConfig.java index 60dee67..ba8e5f0 100644 --- a/src/main/java/com/olhar/olharapi/infrastructure/config/SecurityConfig.java +++ b/src/main/java/com/olhar/olharapi/infrastructure/config/SecurityConfig.java @@ -30,6 +30,7 @@ public class SecurityConfig { .authorizeHttpRequests(auth -> auth .requestMatchers( "/api/v1/auth/**", + "/api/v1/version", "/swagger-ui/**", "/swagger-ui.html", "/api-docs/**", diff --git a/src/main/java/com/olhar/olharapi/interfaces/rest/controller/VersionController.java b/src/main/java/com/olhar/olharapi/interfaces/rest/controller/VersionController.java new file mode 100644 index 0000000..f45cc82 --- /dev/null +++ b/src/main/java/com/olhar/olharapi/interfaces/rest/controller/VersionController.java @@ -0,0 +1,26 @@ +package com.olhar.olharapi.interfaces.rest.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.boot.info.BuildProperties; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Map; + +@RestController +@RequestMapping("/api/v1/version") +@RequiredArgsConstructor +@Tag(name = "Version", description = "Version de l'API") +public class VersionController { + + private final BuildProperties buildProperties; + + @GetMapping + @Operation(summary = "Retourne la version de l'API") + public Map getVersion() { + return Map.of("version", buildProperties.getVersion()); + } +} diff --git a/src/test/java/com/olhar/olharapi/interfaces/VersionControllerIT.java b/src/test/java/com/olhar/olharapi/interfaces/VersionControllerIT.java new file mode 100644 index 0000000..ec93f18 --- /dev/null +++ b/src/test/java/com/olhar/olharapi/interfaces/VersionControllerIT.java @@ -0,0 +1,24 @@ +package com.olhar.olharapi.interfaces; + +import com.olhar.olharapi.infrastructure.AbstractIntegrationTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.assertj.core.api.Assertions.assertThat; + +class VersionControllerIT extends AbstractIntegrationTest { + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void getVersion_shouldReturnVersionWithoutAuthentication() { + ResponseEntity response = restTemplate.getForEntity("/api/v1/version", String.class); + + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getBody()).contains("version"); + } +}