diff --git a/.github/workflows/pull-request_backend.yml b/.github/workflows/pull-request_backend.yml index f340361a75..314c714f96 100644 --- a/.github/workflows/pull-request_backend.yml +++ b/.github/workflows/pull-request_backend.yml @@ -25,6 +25,7 @@ env: GHCR_REGISTRY: ghcr.io JAVA_VERSION: 17 DOCKER_HUB_REGISTRY_NAMESPACE: tractusx + BACKEND_IMAGE_DOCKER_HUB: traceability-foss jobs: Check-Changelog-update: @@ -114,16 +115,16 @@ jobs: key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - - name: Verify Sonar Scan - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} - SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} - SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} - run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/home/runner/work/tx-traceability-foss/tx-traceability-foss/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} + # - name: Verify Sonar Scan + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any + # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN_BACKEND }} + # SONAR_ORGANIZATION: ${{ vars.SONAR_ORGANIZATION }} + # SONAR_PROJECT_KEY: ${{ vars.SONAR_PROJECT_KEY_BACKEND }} + # run: mvn -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn --batch-mode sonar:sonar -Dsonar.coverage.jacoco.xmlReportPaths=/home/runner/work/traceability-foss/tx-traceability-foss/tx-coverage/target/site/jacoco-aggregate/jacoco.xml -Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY_BACKEND }} -Dsonar.organization=${{ vars.SONAR_ORGANIZATION }} Publish-docker-image: - needs: [ "Test-and-Sonar" ] + # needs: [ "Test-and-Sonar" ] runs-on: ubuntu-latest defaults: run: @@ -142,8 +143,10 @@ jobs: distribution: 'temurin' cache: 'maven' - - name: Login to GHCR Registry + env: + DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} + if: env.DOCKER_HUB_USER == '' uses: docker/login-action@v3 with: registry: ${{ env.GHCR_REGISTRY }} @@ -151,9 +154,30 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build & Push docker image for GHCR ${{ env.GHCR_REGISTRY }}/${{ github.repository }}:${{ github.event.pull_request.head.sha }} + env: + DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} + if: env.DOCKER_HUB_USER == '' uses: docker/build-push-action@v5 with: context: . push: true tags: ${{ env.GHCR_REGISTRY }}/${{ github.repository }}:${{ github.event.pull_request.head.sha }} + - name: Login to Docker Hub + env: + DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} + if: env.DOCKER_HUB_USER != '' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Build & push docker image for Docker Hub ${{ env.DOCKER_HUB_REGISTRY_NAMESPACE }}/${{ env.BACKEND_IMAGE_DOCKER_HUB }}:${{ github.event.pull_request.head.sha }} + env: + DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }} + if: env.DOCKER_HUB_USER != '' + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ env.DOCKER_HUB_REGISTRY_NAMESPACE }}/${{ env.BACKEND_IMAGE_DOCKER_HUB }}:${{ github.event.pull_request.head.sha }} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/PolicyStartUpConfig.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/PolicyStartUpConfig.java index fb92971ea1..67aff58f74 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/PolicyStartUpConfig.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/PolicyStartUpConfig.java @@ -74,8 +74,8 @@ public class PolicyStartUpConfig { @ConditionalOnProperty(name = "applicationConfig.registerDecentralRegistryPermissions.enabled", havingValue = "true") public void registerDecentralRegistryPermissions() throws JsonProcessingException { ObjectMapper mapper = new ObjectMapper(); - mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); mapper.registerModule(new JavaTimeModule()); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); List acceptedPolicy = buildAcceptedPolicies(); defaultAcceptedPoliciesProvider.addAcceptedPolicies(acceptedPolicy); log.info("Successfully added permission to irs client lib provider: {}", mapper.writeValueAsString(acceptedPolicy)); diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RequestResponseLoggingInterceptor.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RequestResponseLoggingInterceptor.java deleted file mode 100644 index f6e51b1123..0000000000 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RequestResponseLoggingInterceptor.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2023, 2024 Contributors to the Eclipse Foundation - * - * See the NOTICE file(s) distributed with this work for additional - * information regarding copyright ownership. - * - * This program and the accompanying materials are made available under the - * terms of the Apache License, Version 2.0 which is available at - * https://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * SPDX-License-Identifier: Apache-2.0 - ********************************************************************************/ - - -package org.eclipse.tractusx.traceability.common.config; - - -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.jetbrains.annotations.NotNull; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.stream.Collectors; - - -@RequiredArgsConstructor -@Slf4j -public class RequestResponseLoggingInterceptor implements ClientHttpRequestInterceptor { - - - @Override - @NotNull - public ClientHttpResponse intercept(final HttpRequest request, final byte[] body, - final ClientHttpRequestExecution execution) throws IOException { - ClientHttpResponse response = execution.execute(request, body); - InputStreamReader isr = null; - BufferedReader br = null; - try { - String requestBody = new String(body, StandardCharsets.UTF_8); - log.info("Request body: {}", requestBody.replaceAll("[\r\n]+", " ")); - isr = new InputStreamReader( - response.getBody(), StandardCharsets.UTF_8); - br = new BufferedReader(isr); - String bodys = br.lines() - .collect(Collectors.joining("\n")); - log.info("Response body: {}", bodys.replaceAll("[\r\n]+", " ")); - return response; - } finally { - if (isr != null) - isr.close(); - - if (br != null) - br.close(); - } - } - -} diff --git a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java index ff9cfb7701..32b316b61e 100644 --- a/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java +++ b/tx-backend/src/main/java/org/eclipse/tractusx/traceability/common/config/RestTemplateConfiguration.java @@ -103,7 +103,6 @@ public RestTemplate edcRestTemplate(@Autowired EdcProperties edcProperties) { .rootUri(edcProperties.getProviderEdcUrl()) .defaultHeader(EDC_API_KEY_HEADER_NAME, edcProperties.getApiAuthKey()) .setConnectTimeout(Duration.ofSeconds(10L)) - .additionalInterceptors(new RequestResponseLoggingInterceptor()) .setReadTimeout(Duration.ofSeconds(25L)) .build(); } @@ -116,7 +115,6 @@ public RestTemplate edcDtrAssetRestTemplate(@Autowired EdcProperties edcProperti .defaultHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) .defaultHeader(EDC_API_KEY_HEADER_NAME, edcProperties.getApiAuthKey()) .setConnectTimeout(Duration.ofSeconds(10L)) - .additionalInterceptors(new RequestResponseLoggingInterceptor()) .setReadTimeout(Duration.ofSeconds(25L)) .build(); } @@ -132,7 +130,6 @@ public RestTemplate digitalTwinRegistryCreateShellRestTemplate() { public RestTemplate edcNotificationTemplate(@Autowired EdcProperties edcProperties) { return new RestTemplateBuilder() .defaultHeader(EDC_API_KEY_HEADER_NAME, edcProperties.getApiAuthKey()) - .additionalInterceptors(new RequestResponseLoggingInterceptor()) .build(); } @@ -143,7 +140,6 @@ public RestTemplate irsAdminTemplate(@Autowired TraceabilityProperties traceabil .rootUri(traceabilityProperties.getIrsBase()) .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) // Set Content-Type header .defaultHeader(IRS_API_KEY_HEADER_NAME, traceabilityProperties.getAdminApiKey()) - .messageConverters(customMessageConverters()) .build(); } @@ -184,17 +180,8 @@ public RestTemplate digitalTwinRegistryRestTemplate( /* RestTemplate used by the edc client library*/ @Bean(EDC_CLIENT_REST_TEMPLATE) public RestTemplate edcClientRestTemplate() { - ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory()); - RestTemplate restTemplate = new RestTemplate(factory); - - List interceptors = restTemplate.getInterceptors(); - if (CollectionUtils.isEmpty(interceptors)) { - interceptors = new ArrayList<>(); - } - interceptors.add(new RequestResponseLoggingInterceptor()); - restTemplate.setErrorHandler(new DefaultResponseErrorHandler()); - restTemplate.setInterceptors(interceptors); - return restTemplate; + return new RestTemplateBuilder() + .build(); } private RestTemplateBuilder oAuthRestTemplate(final RestTemplateBuilder restTemplateBuilder, @@ -225,7 +212,6 @@ private List> customMessageConverters() { .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_ENUMS, true) .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) - .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) .build() .registerModules(javaTimeModule));