From c8208f55996b858fa638ff2d33a9dae8fd2690bc Mon Sep 17 00:00:00 2001 From: --show-origin Date: Fri, 17 Nov 2023 07:56:55 -0800 Subject: [PATCH 01/13] ci: added codeql scan for java and javascript --- .github/workflows/codeql.yml | 100 +++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..282ecfd8 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,100 @@ +# +# Copyright (c) 2023 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 +# +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: ["main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["main"] + schedule: + - cron: "36 1 * * 0" + workflow_dispatch: + +jobs: + analyze: + name: Analyze + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners + # Consider using larger runners for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["java", "javascript"] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] + # Use only 'java' to analyze code written in Java, Kotlin or both + # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + queries: +security-extended,security-and-quality + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + # Command-line programs to run using the OS shell. + # See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{matrix.language}}" From f03725901f16d71ab05fe082f744daf773bc16f2 Mon Sep 17 00:00:00 2001 From: --show-origin Date: Fri, 17 Nov 2023 08:10:18 -0800 Subject: [PATCH 02/13] ci: set latest tag on main branch --- .github/workflows/build-image-backend.yml | 2 ++ .github/workflows/build-image-frontend.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/build-image-backend.yml b/.github/workflows/build-image-backend.yml index bd92290a..ec957ea8 100644 --- a/.github/workflows/build-image-backend.yml +++ b/.github/workflows/build-image-backend.yml @@ -58,6 +58,8 @@ jobs: images: | ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} tags: | + # set latest tag for main branch + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }},event=pr type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} diff --git a/.github/workflows/build-image-frontend.yml b/.github/workflows/build-image-frontend.yml index ea1db342..6c078d49 100644 --- a/.github/workflows/build-image-frontend.yml +++ b/.github/workflows/build-image-frontend.yml @@ -58,6 +58,8 @@ jobs: images: | ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} tags: | + # set latest tag for main branch + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }},event=pr type=ref,event=branch type=ref,event=pr type=semver,pattern={{version}} From 8f1cf516ab6da6268c3d2ad5c90646aad4d25dda Mon Sep 17 00:00:00 2001 From: --show-origin Date: Fri, 17 Nov 2023 08:41:07 -0800 Subject: [PATCH 03/13] chore: replaced version by commits for all non master/main versions --- .github/workflows/build-image-backend.yml | 10 +++++----- .github/workflows/build-image-frontend.yml | 10 +++++----- .github/workflows/codeql.yml | 8 ++++---- .github/workflows/dash-dependency-check.yml | 10 +++++----- .github/workflows/kics.yml | 4 ++-- .github/workflows/render-puml-to-svg.yml | 4 ++-- .github/workflows/trivy.yml | 4 ++-- .github/workflows/veracode-backend.yml | 6 +++--- .github/workflows/veracode-frontend.yml | 4 ++-- 9 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/build-image-backend.yml b/.github/workflows/build-image-backend.yml index ec957ea8..11d88e0a 100644 --- a/.github/workflows/build-image-backend.yml +++ b/.github/workflows/build-image-backend.yml @@ -48,12 +48,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 # Create SemVer or ref tags dependent of trigger event - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0 with: images: | ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} @@ -68,13 +68,13 @@ jobs: - name: DockerHub login if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3 with: username: ${{ secrets.DOCKER_HUB_USER }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 #v5.1 with: context: ./backend file: ./backend/Dockerfile @@ -85,7 +85,7 @@ jobs: # https://github.com/peter-evans/dockerhub-description - name: Update Docker Hub description if: github.event_name != 'pull_request' - uses: peter-evans/dockerhub-description@v3 + uses: peter-evans/dockerhub-description@dc67fad7001ef9e8e3c124cb7a64e16d0a63d864 #v3.4.2 with: username: ${{ secrets.DOCKER_HUB_USER }} password: ${{ secrets.DOCKER_HUB_TOKEN }} diff --git a/.github/workflows/build-image-frontend.yml b/.github/workflows/build-image-frontend.yml index 6c078d49..f0a01de4 100644 --- a/.github/workflows/build-image-frontend.yml +++ b/.github/workflows/build-image-frontend.yml @@ -48,12 +48,12 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 # Create SemVer or ref tags dependent of trigger event - name: Docker meta id: meta - uses: docker/metadata-action@v4 + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0 with: images: | ${{ env.IMAGE_NAMESPACE }}/${{ env.IMAGE_NAME }} @@ -68,13 +68,13 @@ jobs: - name: DockerHub login if: github.event_name != 'pull_request' - uses: docker/login-action@v2 + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3 with: username: ${{ secrets.DOCKER_HUB_USER }} password: ${{ secrets.DOCKER_HUB_TOKEN }} - name: Build and push - uses: docker/build-push-action@v3 + uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 #v5.1 with: context: ./frontend file: ./frontend/Dockerfile @@ -85,7 +85,7 @@ jobs: # https://github.com/peter-evans/dockerhub-description - name: Update Docker Hub description if: github.event_name != 'pull_request' - uses: peter-evans/dockerhub-description@v3 + uses: peter-evans/dockerhub-description@dc67fad7001ef9e8e3c124cb7a64e16d0a63d864 #v3.4.2 with: username: ${{ secrets.DOCKER_HUB_USER }} password: ${{ secrets.DOCKER_HUB_TOKEN }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 282ecfd8..139cf3e9 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -65,11 +65,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@66b90a5db151a8042fa97405c6cf843bbe433f7b # v2.227 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -82,7 +82,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@66b90a5db151a8042fa97405c6cf843bbe433f7b # v2.227 # Command-line programs to run using the OS shell. # See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun @@ -95,6 +95,6 @@ jobs: # ./location_of_script_within_repo/buildscript.sh - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@66b90a5db151a8042fa97405c6cf843bbe433f7b # v2.227 with: category: "/language:${{matrix.language}}" diff --git a/.github/workflows/dash-dependency-check.yml b/.github/workflows/dash-dependency-check.yml index 6e9bbac5..522ae508 100644 --- a/.github/workflows/dash-dependency-check.yml +++ b/.github/workflows/dash-dependency-check.yml @@ -35,11 +35,11 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Run dash id: run-dash - uses: eclipse-tractusx/sig-infra/.github/actions/run-dash@main + uses: eclipse-tractusx/sig-infra/.github/actions/run-dash@8ee6e411b82105c5f553a6115dd64fb9c6d4df2a #2023-11-17 with: dash_version: "1.0.2" dash_input: "./frontend/package-lock.json" @@ -51,10 +51,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: java-version: '17' distribution: 'temurin' @@ -64,7 +64,7 @@ jobs: - name: Run dash id: run-dash - uses: eclipse-tractusx/sig-infra/.github/actions/run-dash@main + uses: eclipse-tractusx/sig-infra/.github/actions/run-dash@8ee6e411b82105c5f553a6115dd64fb9c6d4df2a #2023-11-17 with: dash_version: "1.0.2" dash_input: "./backend/maven.dependencies" diff --git a/.github/workflows/kics.yml b/.github/workflows/kics.yml index 086374ad..c4f7c7b7 100644 --- a/.github/workflows/kics.yml +++ b/.github/workflows/kics.yml @@ -47,7 +47,7 @@ jobs: security-events: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: KICS scan uses: checkmarx/kics-github-action@master @@ -62,6 +62,6 @@ jobs: # Upload findings to GitHub Advanced Security Dashboard - name: Upload SARIF file for GitHub Advanced Security Dashboard if: always() - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@66b90a5db151a8042fa97405c6cf843bbe433f7b # v2.227 with: sarif_file: kicsResults/results.sarif diff --git a/.github/workflows/render-puml-to-svg.yml b/.github/workflows/render-puml-to-svg.yml index 00180373..e4cd3802 100644 --- a/.github/workflows/render-puml-to-svg.yml +++ b/.github/workflows/render-puml-to-svg.yml @@ -42,9 +42,9 @@ jobs: needs: render-images steps: - name: checkout source repo - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: download generated svg file from job before - uses: actions/download-artifact@v3 + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3 id: download with: name: artifacts diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index ce40fe06..d608a8d0 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -47,7 +47,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Run Trivy vulnerability scanner in repo mode uses: aquasecurity/trivy-action@master @@ -60,7 +60,7 @@ jobs: severity: "CRITICAL,HIGH" - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@66b90a5db151a8042fa97405c6cf843bbe433f7b # v2.227 if: always() with: sarif_file: "trivy-results1.sarif" diff --git a/.github/workflows/veracode-backend.yml b/.github/workflows/veracode-backend.yml index 2251dbba..e7261a0e 100644 --- a/.github/workflows/veracode-backend.yml +++ b/.github/workflows/veracode-backend.yml @@ -42,10 +42,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: java-version: '17' distribution: 'temurin' @@ -54,7 +54,7 @@ jobs: run: cd backend && mvn --batch-mode -DskipTests package - name: Run Veracode Upload And Scan - uses: veracode/veracode-uploadandscan-action@0.2.6 + uses: veracode/veracode-uploadandscan-action@98e2a2941b985e55bfe469ebcb970b2e686625e4 # v0.2.6 with: appname: "PURIS-Backend" createprofile: false diff --git a/.github/workflows/veracode-frontend.yml b/.github/workflows/veracode-frontend.yml index 96b32e26..23325fb5 100644 --- a/.github/workflows/veracode-frontend.yml +++ b/.github/workflows/veracode-frontend.yml @@ -42,13 +42,13 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Zip Project run: zip -r ./frontend/veracode-scan-target.zip ./frontend/ - name: Run Veracode Upload And Scan - uses: veracode/veracode-uploadandscan-action@0.2.4 + uses: veracode/veracode-uploadandscan-action@98e2a2941b985e55bfe469ebcb970b2e686625e4 # v0.2.6 with: appname: "PURIS-Frontend" createprofile: false From 9b1be198deb212a335a6a496d5357dd51d489c2f Mon Sep 17 00:00:00 2001 From: --show-origin Date: Fri, 17 Nov 2023 08:49:00 -0800 Subject: [PATCH 04/13] chore: replaced trivy versions by commits --- .github/workflows/kics.yml | 2 +- .github/workflows/trivy.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/kics.yml b/.github/workflows/kics.yml index c4f7c7b7..ec4b0a96 100644 --- a/.github/workflows/kics.yml +++ b/.github/workflows/kics.yml @@ -50,7 +50,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: KICS scan - uses: checkmarx/kics-github-action@master + uses: checkmarx/kics-github-action@8a44970e3d2eca668be41abe9d4e06709c3b3609 # v1.7.0 with: path: "." fail_on: high diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index baf37141..174e11b9 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -64,7 +64,7 @@ jobs: steps: # Pull image from Docker Hub and run Trivy vulnerability scanner - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@0.14.0 + uses: aquasecurity/trivy-action@2b6a709cf9c4025c5438138008beaddbb02086f0 # v0.14.0 with: image-ref: "tractusx/app-puris-backend:main" format: "sarif" @@ -72,6 +72,6 @@ jobs: vuln-type: "os,library" - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@66b90a5db151a8042fa97405c6cf843bbe433f7b # v2.227 with: sarif_file: "trivy-results-2.sarif" From adbd0fdd1cd038c19eea458e4047cfcdb06505ed Mon Sep 17 00:00:00 2001 From: --show-origin Date: Fri, 17 Nov 2023 08:56:08 -0800 Subject: [PATCH 05/13] chore: replaced trivy versions by commits --- .github/workflows/trivy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index 174e11b9..0b1ed7a7 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -40,7 +40,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Run Trivy vulnerability scanner in repo mode - uses: aquasecurity/trivy-action@master + uses: aquasecurity/trivy-action@2b6a709cf9c4025c5438138008beaddbb02086f0 # v0.14.0 with: image-ref: "tractusx/app-puris-frontend:main" format: "sarif" From 7bc83bd7c7729cd74efcfc93dd89991001197e8a Mon Sep 17 00:00:00 2001 From: --show-origin Date: Tue, 28 Nov 2023 06:45:44 -0800 Subject: [PATCH 06/13] chore: bump java version --- backend/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/pom.xml b/backend/pom.xml index ad0667da..d5775a1f 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -37,7 +37,7 @@ puris-backend PURIS Backend - 11 + 17 2.2.0 2.7.5 8.0.0.Final From a23d2c2b576b644c8ca0310a941c3d130924e417 Mon Sep 17 00:00:00 2001 From: --show-origin Date: Tue, 28 Nov 2023 06:54:49 -0800 Subject: [PATCH 07/13] ci(codeql): added step to setup java --- .github/workflows/codeql.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 139cf3e9..ece55c7a 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -79,6 +79,11 @@ jobs: # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs queries: +security-extended,security-and-quality + - name: Setup java for backend + uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 + with: + java-version: 17 + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild From 4111b6e1d66e454dc2abd850fb6d32da79b70f3e Mon Sep 17 00:00:00 2001 From: --show-origin Date: Tue, 28 Nov 2023 06:59:36 -0800 Subject: [PATCH 08/13] fix(codeql): added missing parameters --- .github/workflows/codeql.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index ece55c7a..4c2a8121 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -83,6 +83,10 @@ jobs: uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: java-version: 17 + distribution: temurin + java-package: jdk + cache: maven + cache-dependency-path: ./backend/pom.xml # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). # If this step fails, then you should remove it and run the build manually (see below) From f431cf961c161ddd44eb74c949ee641467bedf55 Mon Sep 17 00:00:00 2001 From: --show-origin Date: Tue, 28 Nov 2023 07:05:28 -0800 Subject: [PATCH 09/13] fix(codeql): remove unused cache-dependency path --- .github/workflows/codeql.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 4c2a8121..d8bb5c47 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -86,7 +86,6 @@ jobs: distribution: temurin java-package: jdk cache: maven - cache-dependency-path: ./backend/pom.xml # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). # If this step fails, then you should remove it and run the build manually (see below) From 52970ba4a405a1e1ee4b5f2a14d3126e6aff60f3 Mon Sep 17 00:00:00 2001 From: --show-origin Date: Thu, 30 Nov 2023 23:11:31 -0800 Subject: [PATCH 10/13] fix: look for latest instead of main tag in trivy --- .github/workflows/trivy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml index 0b1ed7a7..d5dfd236 100644 --- a/.github/workflows/trivy.yml +++ b/.github/workflows/trivy.yml @@ -42,7 +42,7 @@ jobs: - name: Run Trivy vulnerability scanner in repo mode uses: aquasecurity/trivy-action@2b6a709cf9c4025c5438138008beaddbb02086f0 # v0.14.0 with: - image-ref: "tractusx/app-puris-frontend:main" + image-ref: "tractusx/app-puris-frontend:latest" format: "sarif" output: "trivy-results-1.sarif" vuln-type: "os,library" @@ -66,7 +66,7 @@ jobs: - name: Run Trivy vulnerability scanner uses: aquasecurity/trivy-action@2b6a709cf9c4025c5438138008beaddbb02086f0 # v0.14.0 with: - image-ref: "tractusx/app-puris-backend:main" + image-ref: "tractusx/app-puris-backend:latest" format: "sarif" output: "trivy-results-2.sarif" vuln-type: "os,library" From 8c85b573fb074e937759f5a3c776f05017ade837 Mon Sep 17 00:00:00 2001 From: --show-origin Date: Sun, 3 Dec 2023 00:50:50 -0800 Subject: [PATCH 11/13] chore: updated licenses --- DEPENDENCIES_BACKEND | 2 +- backend/DEPENDENCIES | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DEPENDENCIES_BACKEND b/DEPENDENCIES_BACKEND index 133ea933..67c90818 100644 --- a/DEPENDENCIES_BACKEND +++ b/DEPENDENCIES_BACKEND @@ -39,7 +39,7 @@ maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-core/10.1.13, Apache-2.0 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-el/10.1.13, Apache-2.0, approved, #6997 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-websocket/10.1.13, Apache-2.0, approved, #7920 maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.aspectj/aspectjweaver/1.9.20, EPL-1.0, approved, tools.aspectj +maven/mavencentral/org.aspectj/aspectjweaver/1.9.20, Apache-2.0 AND BSD-3-Clause AND EPL-1.0 AND BSD-3-Clause AND Apache-1.1, approved, #7695 maven/mavencentral/org.assertj/assertj-core/3.24.2, Apache-2.0, approved, #6161 maven/mavencentral/org.eclipse.angus/angus-activation/2.0.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.angus maven/mavencentral/org.glassfish.jaxb/jaxb-core/4.0.3, BSD-3-Clause, approved, ee4j.jaxb diff --git a/backend/DEPENDENCIES b/backend/DEPENDENCIES index 133ea933..67c90818 100644 --- a/backend/DEPENDENCIES +++ b/backend/DEPENDENCIES @@ -39,7 +39,7 @@ maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-core/10.1.13, Apache-2.0 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-el/10.1.13, Apache-2.0, approved, #6997 maven/mavencentral/org.apache.tomcat.embed/tomcat-embed-websocket/10.1.13, Apache-2.0, approved, #7920 maven/mavencentral/org.apiguardian/apiguardian-api/1.1.2, Apache-2.0, approved, clearlydefined -maven/mavencentral/org.aspectj/aspectjweaver/1.9.20, EPL-1.0, approved, tools.aspectj +maven/mavencentral/org.aspectj/aspectjweaver/1.9.20, Apache-2.0 AND BSD-3-Clause AND EPL-1.0 AND BSD-3-Clause AND Apache-1.1, approved, #7695 maven/mavencentral/org.assertj/assertj-core/3.24.2, Apache-2.0, approved, #6161 maven/mavencentral/org.eclipse.angus/angus-activation/2.0.1, EPL-2.0 OR GPL-2.0-only with Classpath-exception-2.0, approved, ee4j.angus maven/mavencentral/org.glassfish.jaxb/jaxb-core/4.0.3, BSD-3-Clause, approved, ee4j.jaxb From 1bad5f98d1b0a54c6e5d83bc59495a137f4f501c Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Mon, 4 Dec 2023 08:45:30 +0100 Subject: [PATCH 12/13] refactor: initial commit --- .../common/edc/controller/EdcController.java | 5 +- .../edc/logic/service/EdcAdapterService.java | 173 +++++++++--------- .../service/ExternalConnectorService.java | 2 +- ...uilder.java => EdcRequestBodyBuilder.java} | 28 +-- .../ProductStockRequestApiServiceImpl.java | 4 +- 5 files changed, 105 insertions(+), 107 deletions(-) rename backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/{EDCRequestBodyBuilder.java => EdcRequestBodyBuilder.java} (90%) diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/controller/EdcController.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/controller/EdcController.java index a96c13d8..96c57e9d 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/controller/EdcController.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/controller/EdcController.java @@ -27,7 +27,6 @@ import org.springframework.web.bind.annotation.*; import java.io.IOException; -import java.net.URL; import java.util.List; /** @@ -51,7 +50,7 @@ public class EdcController { @CrossOrigin public ResponseEntity getEDCCatalog(@RequestParam String dspUrl) { try { - var catalog = edcAdapter.getDSPCatalog(dspUrl); + var catalog = edcAdapter.getCatalog(dspUrl); return ResponseEntity.ok(catalog.toPrettyString()); } catch (IOException e) { log.warn(e.getMessage()); @@ -69,7 +68,7 @@ public ResponseEntity getEDCCatalog(@RequestParam String dspUrl) { @CrossOrigin public ResponseEntity getAssets(@RequestParam String assetId) { try { - var result = edcAdapter.sendDspGetRequest(List.of("v3", "assets", assetId)); + var result = edcAdapter.sendGetRequest(List.of("v3", "assets", assetId)); var stringData = result.body().string(); result.body().close(); return ResponseEntity.ok(stringData); diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java index e9455d4c..db5c9fc2 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java @@ -27,7 +27,7 @@ import org.eclipse.tractusx.puris.backend.common.api.logic.service.VariablesService; import org.eclipse.tractusx.puris.backend.common.edc.logic.dto.EDR_Dto; import org.eclipse.tractusx.puris.backend.common.edc.logic.dto.datatype.DT_ApiMethodEnum; -import org.eclipse.tractusx.puris.backend.common.edc.logic.util.EDCRequestBodyBuilder; +import org.eclipse.tractusx.puris.backend.common.edc.logic.util.EdcRequestBodyBuilder; import org.eclipse.tractusx.puris.backend.masterdata.domain.model.Partner; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -49,7 +49,7 @@ public class EdcAdapterService { private VariablesService variablesService; private ObjectMapper objectMapper; @Autowired - private EDCRequestBodyBuilder edcRequestBodyBuilder; + private EdcRequestBodyBuilder edcRequestBodyBuilder; @Autowired private EndpointDataReferenceService edrService; @@ -57,6 +57,51 @@ public EdcAdapterService(ObjectMapper objectMapper) { this.objectMapper = objectMapper; } + /** + * Util method for issuing a GET request to the management api of your control plane. + * Any caller of this method has the responsibility to close + * the returned Response object after using it. + * @param pathSegments The path segments + * @return The response + * @throws IOException If the connection to your control plane fails + */ + public Response sendGetRequest(List pathSegments) throws IOException { + HttpUrl.Builder urlBuilder = HttpUrl.parse(variablesService.getEdcManagementUrl()).newBuilder(); + for (var pathSegment : pathSegments) { + urlBuilder.addPathSegment(pathSegment); + } + var request = new Request.Builder() + .get() + .url(urlBuilder.build()) + .header("X-Api-Key", variablesService.getEdcApiKey()) + .build(); + return CLIENT.newCall(request).execute(); + } + + /** + * Util method for issuing a POST request to the management api of your control plane. + * Any caller of this method has the responsibility to close + * the returned Response object after using it. + * @param requestBody The request body + * @param pathSegments The path segments + * @return The response from your control plane + * @throws IOException If the connection to your control plane fails + */ + private Response sendPostRequest(JsonNode requestBody, List pathSegments) throws IOException { + HttpUrl.Builder urlBuilder = HttpUrl.parse(variablesService.getEdcManagementUrl()).newBuilder(); + for (var pathSegment : pathSegments) { + urlBuilder.addPathSegment(pathSegment); + } + RequestBody body = RequestBody.create(MediaType.parse("application/json"), requestBody.toString()); + + var request = new Request.Builder() + .post(body) + .url(urlBuilder.build()) + .header("X-Api-Key", variablesService.getEdcApiKey()) + .header("Content-Type", "application/json") + .build(); + return CLIENT.newCall(request).execute(); + } /** * Call this method at startup to register the necessary request and @@ -67,27 +112,27 @@ public EdcAdapterService(ObjectMapper objectMapper) { */ public boolean doInitialAssetRegistration() { boolean result; - log.info("Registration of product-stock request api successful " + (result = registerDSPApiAsset(DT_ApiMethodEnum.REQUEST))); + log.info("Registration of product-stock request api successful " + (result = registerApiAsset(DT_ApiMethodEnum.REQUEST))); if (!result) return false; - log.info("Registration of product-stock response api successful " + (result = registerDSPApiAsset(DT_ApiMethodEnum.RESPONSE))); + log.info("Registration of product-stock response api successful " + (result = registerApiAsset(DT_ApiMethodEnum.RESPONSE))); if (!result) return false; - log.info("Registration of policy successful " + (result = registerDSPSimplePolicy())); + log.info("Registration of policy successful " + (result = registerPublicPolicy())); if (!result) return false; - log.info("Registration of contract definition successful " + (result = registerDSPSimpleContractDefinition())); + log.info("Registration of contract definition successful " + (result = registerPublicContractDefinition())); return result; } /** - * Util method to register a simple contract definition without restrictions + * Util method to register a public contract definition without restrictions * regarding the asset selector. Will therefore be applicable to all assets - * that were registered previously. Must be called after registerDSPSimplePolicy() + * that were registered previously. Must be called after registerPublicPolicy() * * @return true if successful */ - private boolean registerDSPSimpleContractDefinition() { - var body = edcRequestBodyBuilder.buildDSPContractDefinitionWithPublicPolicy(); + private boolean registerPublicContractDefinition() { + var body = edcRequestBodyBuilder.buildContractDefinitionWithPublicPolicyBody(); try { - var response = sendDspPostRequest(body, List.of("v2", "contractdefinitions")); + var response = sendPostRequest(body, List.of("v2", "contractdefinitions")); boolean result = response.isSuccessful(); if (!result) { log.warn("Contract definition registration failed \n" + response.body().string()); @@ -106,10 +151,10 @@ private boolean registerDSPSimpleContractDefinition() { * * @return true if successful */ - private boolean registerDSPSimplePolicy() { - var body = edcRequestBodyBuilder.buildPublicDSPPolicy(); + private boolean registerPublicPolicy() { + var body = edcRequestBodyBuilder.buildPublicPolicyBody(); try { - var response = sendDspPostRequest(body, List.of("v2", "policydefinitions")); + var response = sendPostRequest(body, List.of("v2", "policydefinitions")); boolean result = response.isSuccessful(); if (!result) { log.warn("Policy registration failed \n" + response.body().string()); @@ -128,10 +173,10 @@ private boolean registerDSPSimplePolicy() { * @param apiMethod the api method to register. * @return true if successful. */ - private boolean registerDSPApiAsset(DT_ApiMethodEnum apiMethod) { - var body = edcRequestBodyBuilder.buildDSPCreateAssetBody(apiMethod); + private boolean registerApiAsset(DT_ApiMethodEnum apiMethod) { + var body = edcRequestBodyBuilder.buildCreateAssetBody(apiMethod); try { - var response = sendDspPostRequest(body, List.of("v3", "assets")); + var response = sendPostRequest(body, List.of("v3", "assets")); boolean result = response.isSuccessful(); if (!result) { log.warn("Asset registration failed \n" + response.body().string()); @@ -144,7 +189,6 @@ private boolean registerDSPApiAsset(DT_ApiMethodEnum apiMethod) { } } - /** * Retrieve an (unfiltered) catalog from the partner with the * given dspUrl @@ -153,8 +197,8 @@ private boolean registerDSPApiAsset(DT_ApiMethodEnum apiMethod) { * @return The full catalog * @throws IOException If the connection to the partners control plane fails */ - public JsonNode getDSPCatalog(String dspUrl) throws IOException { - var response = sendDspPostRequest(edcRequestBodyBuilder.buildBasicDSPCatalogRequestBody(dspUrl, null), List.of("v2", "catalog", "request")); + public JsonNode getCatalog(String dspUrl) throws IOException { + var response = sendPostRequest(edcRequestBodyBuilder.buildBasicCatalogRequestBody(dspUrl, null), List.of("v2", "catalog", "request")); String stringData = response.body().string(); response.body().close(); return objectMapper.readTree(stringData); @@ -171,9 +215,9 @@ public JsonNode getDSPCatalog(String dspUrl) throws IOException { * @return An array of Catalog items. * @throws IOException If the connection to the partners control plane fails */ - private JsonNode getDSPCatalogItems(String dspUrl, Map filter) throws IOException { - var response = sendDspPostRequest(edcRequestBodyBuilder. - buildBasicDSPCatalogRequestBody(dspUrl, filter), List.of("v2", "catalog", "request")); + private JsonNode getCatalogItems(String dspUrl, Map filter) throws IOException { + var response = sendPostRequest(edcRequestBodyBuilder. + buildBasicCatalogRequestBody(dspUrl, filter), List.of("v2", "catalog", "request")); String stringData = response.body().string(); if (!response.isSuccessful()) { throw new IOException("Http Catalog Request unsuccessful"); @@ -214,59 +258,14 @@ private JsonNode getDSPCatalogItems(String dspUrl, Map filter) t * @return The JSON response to your contract offer. * @throws IOException If the connection to the partners control plane fails */ - private JsonNode startDspNegotiation(Partner partner, JsonNode catalogItem) throws IOException { - var requestBody = edcRequestBodyBuilder.buildDSPAssetNegotiation(partner, catalogItem); - var response = sendDspPostRequest(requestBody, List.of("v2", "contractnegotiations")); + private JsonNode initiateNegotiation(Partner partner, JsonNode catalogItem) throws IOException { + var requestBody = edcRequestBodyBuilder.buildAssetNegotiationBody(partner, catalogItem); + var response = sendPostRequest(requestBody, List.of("v2", "contractnegotiations")); String responseString = response.body().string(); response.body().close(); return objectMapper.readTree(responseString); } - - /** - * Util method for issuing a GET request to the management api of your control plane. - * - * @param pathSegments The path segments - * @return The response - * @throws IOException If the connection to your control plane fails - */ - public Response sendDspGetRequest(List pathSegments) throws IOException { - HttpUrl.Builder urlBuilder = HttpUrl.parse(variablesService.getEdcManagementUrl()).newBuilder(); - for (var pathSegment : pathSegments) { - urlBuilder.addPathSegment(pathSegment); - } - var request = new Request.Builder() - .get() - .url(urlBuilder.build()) - .header("X-Api-Key", variablesService.getEdcApiKey()) - .build(); - return CLIENT.newCall(request).execute(); - } - - /** - * Util method for issuing a POST request to the management api of your control plane. - * - * @param requestBody The request body - * @param pathSegments The path segments - * @return The response from your control plane - * @throws IOException If the connection to your control plane fails - */ - private Response sendDspPostRequest(JsonNode requestBody, List pathSegments) throws IOException { - HttpUrl.Builder urlBuilder = HttpUrl.parse(variablesService.getEdcManagementUrl()).newBuilder(); - for (var pathSegment : pathSegments) { - urlBuilder.addPathSegment(pathSegment); - } - RequestBody body = RequestBody.create(MediaType.parse("application/json"), requestBody.toString()); - - var request = new Request.Builder() - .post(body) - .url(urlBuilder.build()) - .header("X-Api-Key", variablesService.getEdcApiKey()) - .header("Content-Type", "application/json") - .build(); - return CLIENT.newCall(request).execute(); - } - /** * Sends a request to the own control plane in order to receive * the current status of the previously initiated contractNegotiations as @@ -276,8 +275,8 @@ private Response sendDspPostRequest(JsonNode requestBody, List pathSegme * @return The response body as String * @throws IOException If the connection to your control plane fails */ - public JsonNode getDspNegotiationState(String negotiationId) throws IOException { - var response = sendDspGetRequest(List.of("v2", "contractnegotiations", negotiationId)); + public JsonNode getNegotiationState(String negotiationId) throws IOException { + var response = sendGetRequest(List.of("v2", "contractnegotiations", negotiationId)); String stringData = response.body().string(); response.body().close(); return objectMapper.readTree(stringData); @@ -293,9 +292,9 @@ public JsonNode getDspNegotiationState(String negotiationId) throws IOException * @return The response object * @throws IOException If the connection to your control plane fails */ - public JsonNode startDspPullTransfer(Partner partner, String contractId, String assetId) throws IOException { - var body = edcRequestBodyBuilder.buildDSPDataPullRequestBody(partner, contractId, assetId); - var response = sendDspPostRequest(body, List.of("v2", "transferprocesses")); + public JsonNode initiateProxyPullTransfer(Partner partner, String contractId, String assetId) throws IOException { + var body = edcRequestBodyBuilder.buildProxyPullRequestBody(partner, contractId, assetId); + var response = sendPostRequest(body, List.of("v2", "transferprocesses")); String data = response.body().string(); response.body().close(); return objectMapper.readTree(data); @@ -310,8 +309,8 @@ public JsonNode startDspPullTransfer(Partner partner, String contractId, String * @return The response from your Controlplane * @throws IOException If the connection to your control plane fails */ - public JsonNode getDspTransferState(String transferId) throws IOException { - var response = sendDspGetRequest(List.of("v2", "transferprocesses", transferId)); + public JsonNode getTransferState(String transferId) throws IOException { + var response = sendGetRequest(List.of("v2", "transferprocesses", transferId)); String data = response.body().string(); response.body().close(); return objectMapper.readTree(data); @@ -320,7 +319,7 @@ public JsonNode getDspTransferState(String transferId) throws IOException { /** * Util method for sending a post request the given endpoint - * in order to initiate a consumer pull request. + * in order to initiate a proxy pull request. * Any caller of this method has the responsibility to close * the returned Response object after using it. * @@ -330,7 +329,7 @@ public JsonNode getDspTransferState(String transferId) throws IOException { * @param requestBodyString The request body in JSON format as String * @return The response from the endpoint defined in the url (which is usually the other party's data plane), carrying the asset payload */ - public Response sendDataPullRequest(String url, String authKey, String authCode, String requestBodyString) { + public Response postProxyPullRequest(String url, String authKey, String authCode, String requestBodyString) { try { RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), requestBodyString); Request request = new Request.Builder() @@ -340,7 +339,7 @@ public Response sendDataPullRequest(String url, String authKey, String authCode, .build(); return CLIENT.newCall(request).execute(); } catch (Exception e) { - log.error("Failed to send Data Pull request to " + url, e); + log.error("Failed to send Proxy Pull request to " + url, e); throw new RuntimeException(e); } } @@ -394,33 +393,33 @@ public String[] getContractForResponseApi(Partner partner) { */ public String[] getContractForRequestOrResponseApiApi(Partner partner, Map filter) { try { - JsonNode catalogItem = getDSPCatalogItems(partner.getEdcUrl(), filter).get(0); - JsonNode negotiationResponse = startDspNegotiation(partner, catalogItem); + JsonNode catalogItem = getCatalogItems(partner.getEdcUrl(), filter).get(0); + JsonNode negotiationResponse = initiateNegotiation(partner, catalogItem); String assetApi = catalogItem.get("@id").asText(); String negotiationId = negotiationResponse.get("@id").asText(); // Await confirmation of contract and contractId String contractId = null; for (int i = 0; i < 100; i++) { Thread.sleep(100); - var responseObject = getDspNegotiationState(negotiationId); + var responseObject = getNegotiationState(negotiationId); if ("FINALIZED".equals(responseObject.get("edc:state").asText())) { contractId = responseObject.get("edc:contractAgreementId").asText(); break; } } if (contractId == null) { - var negotiationState = getDspNegotiationState(negotiationId); + var negotiationState = getNegotiationState(negotiationId); log.warn("no contract id, last negotiation state: \n" + negotiationState.toPrettyString()); log.error("Failed to obtain " + assetApi + " from " + partner.getEdcUrl()); return null; } // Initiate transfer of edr - var transferResp = startDspPullTransfer(partner, contractId, assetApi); + var transferResp = initiateProxyPullTransfer(partner, contractId, assetApi); String transferId = transferResp.get("@id").asText(); for (int i = 0; i < 100; i++) { Thread.sleep(100); - transferResp = getDspTransferState(transferId); + transferResp = getTransferState(transferId); if ("STARTED".equals(transferResp.get("edc:state").asText())) { break; } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/ExternalConnectorService.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/ExternalConnectorService.java index eaa217d8..b4e2d9e5 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/ExternalConnectorService.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/ExternalConnectorService.java @@ -76,7 +76,7 @@ public List getAll() { */ private boolean checkUrl(String url) { try { - edcAdapter.getDSPCatalog(url); + edcAdapter.getCatalog(url); } catch (IOException e) { return false; } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EDCRequestBodyBuilder.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java similarity index 90% rename from backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EDCRequestBodyBuilder.java rename to backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java index 53557a74..fb0bae9c 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EDCRequestBodyBuilder.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/util/EdcRequestBodyBuilder.java @@ -17,7 +17,7 @@ */ @Component @Slf4j -public class EDCRequestBodyBuilder { +public class EdcRequestBodyBuilder { @Autowired @@ -49,8 +49,8 @@ public class EDCRequestBodyBuilder { * @param filter Key-value-pairs, may be empty or null * @return The request body */ - public ObjectNode buildBasicDSPCatalogRequestBody(String counterPartyDspUrl, Map filter) { - var objectNode = getEDCContextObject(); + public ObjectNode buildBasicCatalogRequestBody(String counterPartyDspUrl, Map filter) { + var objectNode = getEdcContextObject(); objectNode.put("protocol", "dataspace-protocol-http"); objectNode.put("@type", "CatalogRequest"); objectNode.put("counterPartyAddress", counterPartyDspUrl); @@ -70,7 +70,7 @@ public ObjectNode buildBasicDSPCatalogRequestBody(String counterPartyDspUrl, Map * @param apiMethod The API method you want to register * @return The request body */ - public JsonNode buildDSPCreateAssetBody(DT_ApiMethodEnum apiMethod) { + public JsonNode buildCreateAssetBody(DT_ApiMethodEnum apiMethod) { var body = MAPPER.createObjectNode(); var context = MAPPER.createObjectNode(); context.put(VOCAB_KEY, EDC_NAMESPACE); @@ -114,7 +114,7 @@ public JsonNode buildDSPCreateAssetBody(DT_ApiMethodEnum apiMethod) { * * @return The request body */ - public JsonNode buildPublicDSPPolicy() { + public JsonNode buildPublicPolicyBody() { var body = MAPPER.createObjectNode(); var context = MAPPER.createObjectNode(); context.put("odrl", ODRL_NAMESPACE); @@ -132,13 +132,13 @@ public JsonNode buildPublicDSPPolicy() { } /** - * Creates the request body for registering a simple contract definition. - * Relies on the policy that is created via the buildPublicDSPPolicy() method. + * Creates the request body for registering a public contract definition. + * Relies on the policy that is created via the buildPublicPolicy() method. * * @return The request body */ - public JsonNode buildDSPContractDefinitionWithPublicPolicy() { - var body = getEDCContextObject(); + public JsonNode buildContractDefinitionWithPublicPolicyBody() { + var body = getEdcContextObject(); body.put("@id", publicContractDefinitionId); body.put("accessPolicyId", publicPolicyId); body.put("contractPolicyId", publicPolicyId); @@ -154,7 +154,7 @@ public JsonNode buildDSPContractDefinitionWithPublicPolicy() { * @param dcatCatalogItem The catalog entry that describes the target asset. * @return The request body */ - public ObjectNode buildDSPAssetNegotiation(Partner partner, JsonNode dcatCatalogItem) { + public ObjectNode buildAssetNegotiationBody(Partner partner, JsonNode dcatCatalogItem) { var objectNode = MAPPER.createObjectNode(); var contextNode = MAPPER.createObjectNode(); contextNode.put(VOCAB_KEY, EDC_NAMESPACE); @@ -178,7 +178,7 @@ public ObjectNode buildDSPAssetNegotiation(Partner partner, JsonNode dcatCatalog } /** - * Creates the request body for requesting a data pull transfer using the + * Creates the request body for requesting a proxy pull transfer using the * DSP protocol and the Tractus-X-EDC. * * @param partner The Partner who controls the target asset @@ -186,8 +186,8 @@ public ObjectNode buildDSPAssetNegotiation(Partner partner, JsonNode dcatCatalog * @param assetId The assetId * @return The request body */ - public JsonNode buildDSPDataPullRequestBody(Partner partner, String contractID, String assetId) { - var body = getEDCContextObject(); + public JsonNode buildProxyPullRequestBody(Partner partner, String contractID, String assetId) { + var body = getEdcContextObject(); body.put("@type", "TransferRequestDto"); body.put("connectorId", partner.getBpnl()); body.put("connectorAddress", partner.getEdcUrl()); @@ -213,7 +213,7 @@ public JsonNode buildDSPDataPullRequestBody(Partner partner, String contractID, * * @return A request body stub */ - private ObjectNode getEDCContextObject() { + private ObjectNode getEdcContextObject() { ObjectNode node = MAPPER.createObjectNode(); var context = MAPPER.createObjectNode(); context.put(VOCAB_KEY, EDC_NAMESPACE); diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ProductStockRequestApiServiceImpl.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ProductStockRequestApiServiceImpl.java index fb503558..7443a254 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ProductStockRequestApiServiceImpl.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/stock/logic/service/ProductStockRequestApiServiceImpl.java @@ -230,7 +230,7 @@ public void handleRequest(ProductStockRequest productStockRequest) { try { String requestBody = objectMapper.writeValueAsString(response); - var httpResponse = edcAdapterService.sendDataPullRequest( + var httpResponse = edcAdapterService.postProxyPullRequest( endpoint, authKey, authCode, requestBody); log.info(httpResponse.body().string()); httpResponse.body().close(); @@ -298,7 +298,7 @@ public void doRequest(Material material, Partner supplierPartner){ Response response = null; try { String requestBody = objectMapper.writeValueAsString(productStockRequest); - response = edcAdapterService.sendDataPullRequest(endpoint, authKey, authCode, requestBody); + response = edcAdapterService.postProxyPullRequest(endpoint, authKey, authCode, requestBody); log.debug(response.body().string()); if(response.code() < 400) { productStockRequest = productStockRequestService.updateState(productStockRequest, DT_RequestStateEnum.Requested); From 77bddb9012c417bc7d387fb374aafb9b9d08e762 Mon Sep 17 00:00:00 2001 From: Ernst-Christoph Schrewe Date: Tue, 5 Dec 2023 08:20:59 +0100 Subject: [PATCH 13/13] fix: fixed review issues --- .../puris/backend/AssetCreatorCommandLineRunner.java | 4 ++-- .../backend/common/edc/controller/EdcController.java | 2 +- .../common/edc/logic/service/EdcAdapterService.java | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/AssetCreatorCommandLineRunner.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/AssetCreatorCommandLineRunner.java index 3a87b80b..293462b8 100755 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/AssetCreatorCommandLineRunner.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/AssetCreatorCommandLineRunner.java @@ -36,12 +36,12 @@ public class AssetCreatorCommandLineRunner implements CommandLineRunner { @Override public void run(String... args) throws Exception { - if (!edcAdapterService.doInitialAssetRegistration()) { + if (!edcAdapterService.registerAssetsInitially()) { // retry int retryDelaySeconds = 3; log.warn("retrying initial asset registration in " + retryDelaySeconds + " seconds"); Thread.sleep(retryDelaySeconds * 1000); - log.warn("retry successful: " + edcAdapterService.doInitialAssetRegistration()); + log.warn("retry successful: " + edcAdapterService.registerAssetsInitially()); } } } diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/controller/EdcController.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/controller/EdcController.java index 96c57e9d..c9db0d38 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/controller/EdcController.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/controller/EdcController.java @@ -48,7 +48,7 @@ public class EdcController { */ @GetMapping("/catalog") @CrossOrigin - public ResponseEntity getEDCCatalog(@RequestParam String dspUrl) { + public ResponseEntity getCatalog(@RequestParam String dspUrl) { try { var catalog = edcAdapter.getCatalog(dspUrl); return ResponseEntity.ok(catalog.toPrettyString()); diff --git a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java index db5c9fc2..da601c3d 100644 --- a/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java +++ b/backend/src/main/java/org/eclipse/tractusx/puris/backend/common/edc/logic/service/EdcAdapterService.java @@ -110,7 +110,7 @@ private Response sendPostRequest(JsonNode requestBody, List pathSegments * * @return true if all registrations were successful, otherwise false */ - public boolean doInitialAssetRegistration() { + public boolean registerAssetsInitially() { boolean result; log.info("Registration of product-stock request api successful " + (result = registerApiAsset(DT_ApiMethodEnum.REQUEST))); if (!result) return false; @@ -359,7 +359,7 @@ public String[] getContractForRequestApi(Partner partner) { filter.put("asset:prop:apibusinessobject", "product-stock"); filter.put("asset:prop:apipurpose", "request"); filter.put("asset:prop:version", variablesService.getPurisApiVersion()); - return getContractForRequestOrResponseApiApi(partner, filter); + return getContractForRequestOrResponseApi(partner, filter); } /** @@ -377,7 +377,7 @@ public String[] getContractForResponseApi(Partner partner) { filter.put("asset:prop:apibusinessobject", "product-stock"); filter.put("asset:prop:apipurpose", "response"); filter.put("asset:prop:version", variablesService.getPurisApiVersion()); - return getContractForRequestOrResponseApiApi(partner, filter); + return getContractForRequestOrResponseApi(partner, filter); } /** @@ -391,7 +391,7 @@ public String[] getContractForResponseApi(Partner partner) { * @param filter The filter to be applied on the level of the asset's properties object. * @return A String array or null, if negotiation or transfer have failed or the authCode did not arrive */ - public String[] getContractForRequestOrResponseApiApi(Partner partner, Map filter) { + private String[] getContractForRequestOrResponseApi(Partner partner, Map filter) { try { JsonNode catalogItem = getCatalogItems(partner.getEdcUrl(), filter).get(0); JsonNode negotiationResponse = initiateNegotiation(partner, catalogItem);