diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 5e2f3397..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,109 +0,0 @@ -# This is a basic workflow to help you get started with Actions - -name: Build npm - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - push: - branches: [ master, 1.0.* ] - pull_request: - branches: [ master, 1.0.* ] - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # This workflow contains a single job called "build" - build-admin-ui: - runs-on: ubuntu-latest - env: - NAMESPACE: ${{ secrets. dev_namespace_docker_hub }} - SERVICE_NAME: admin-ui - SERVICE_LOCATION: admin-ui - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - - name: npm install - run: cd ${{ env.SERVICE_LOCATION }} && npm install --ignore-scripts - - - name: npm build - run: cd ${{ env.SERVICE_LOCATION }} && npm run-script build -- --prod --base-href . --output-path=dist - - - name: setup environment - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - VERSION=$BRANCH_NAME - echo "push version $VERSION" - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - - -# This workflow contains a single job called "build" - build-pre-registration-ui: - runs-on: ubuntu-latest - env: - NAMESPACE: ${{ secrets. dev_namespace_docker_hub }} - SERVICE_NAME: pre-registration-ui - SERVICE_LOCATION: pre-registration-ui - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - - name: npm install - run: cd ${{ env.SERVICE_LOCATION }} && npm install --ignore-scripts - - - name: npm build - run: cd ${{ env.SERVICE_LOCATION }} && npm run-script build -- --prod --base-href . --output-path=dist - - - name: setup environment - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - VERSION=$BRANCH_NAME - echo "push version $VERSION" - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - diff --git a/.github/workflows/push-trigger.yml b/.github/workflows/push-trigger.yml new file mode 100644 index 00000000..39818168 --- /dev/null +++ b/.github/workflows/push-trigger.yml @@ -0,0 +1,85 @@ +name: Maven Package upon a push + +on: + release: + types: [published] + pull_request: + types: [opened, reopened, synchronize] + workflow_dispatch: + inputs: + message: + description: 'Message for manually triggering' + required: false + default: 'Triggered for Updates' + type: string + push: + branches: + - '!release-branch' + - release* + - master + - 1.* + - develop + - MOSIP* + +jobs: + build-biosdk-services: + uses: mosip/kattu/.github/workflows/maven-build.yml@master + with: + SERVICE_LOCATION: ./biosdk-services + BUILD_ARTIFACT: biosdk-services + secrets: + OSSRH_USER: ${{ secrets.OSSRH_USER }} + OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + GPG_SECRET: ${{ secrets.GPG_SECRET }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + publish_to_nexus: + if: "${{ !contains(github.ref, 'master') && github.event_name != 'pull_request' && github.event_name != 'release' && github.event_name != 'prerelease' && github.event_name != 'publish' }}" + needs: build-biosdk-services + uses: mosip/kattu/.github/workflows/maven-publish-to-nexus.yml@master + with: + SERVICE_LOCATION: ./biosdk-services + secrets: + OSSRH_URL: ${{ secrets.OSSRH_SNAPSHOT_URL }} + OSSRH_USER: ${{ secrets.OSSRH_USER }} + OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + GPG_SECRET: ${{ secrets.GPG_SECRET }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + sonar_analysis: + needs: build-biosdk-services + if: "${{ github.event_name != 'pull_request' }}" + uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master + with: + SERVICE_LOCATION: ./biosdk-services + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + ORG_KEY: ${{ secrets.ORG_KEY }} + OSSRH_USER: ${{ secrets.OSSRH_USER }} + OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }} + OSSRH_TOKEN: ${{ secrets.OSSRH_TOKEN }} + GPG_SECRET: ${{ secrets.GPG_SECRET }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} + + build-dockers: + needs: build-biosdk-services + strategy: + matrix: + include: + - SERVICE_LOCATION: 'biosdk-services' + SERVICE_NAME: 'biosdk-server' + BUILD_ARTIFACT: 'biosdk-services' + fail-fast: false + uses: mosip/kattu/.github/workflows/docker-build.yml@master + name: ${{ matrix.SERVICE_NAME }} + with: + SERVICE_LOCATION: ${{ matrix.SERVICE_LOCATION }} + SERVICE_NAME: ${{ matrix.SERVICE_NAME }} + BUILD_ARTIFACT: ${{ matrix.BUILD_ARTIFACT }} + secrets: + DEV_NAMESPACE_DOCKER_HUB: ${{ secrets.DEV_NAMESPACE_DOCKER_HUB }} + ACTOR_DOCKER_HUB: ${{ secrets.ACTOR_DOCKER_HUB }} + RELEASE_DOCKER_HUB: ${{ secrets.RELEASE_DOCKER_HUB }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} diff --git a/.github/workflows/push_trigger.yml b/.github/workflows/push_trigger.yml deleted file mode 100644 index d2bb9ac9..00000000 --- a/.github/workflows/push_trigger.yml +++ /dev/null @@ -1,258 +0,0 @@ - -name: Maven Package upon a push - -on: - push: - branches: - - '!release-branch' - - release-1* - - master - - 1.* - - develop - - MOSIP-11719 - -jobs: - build: - runs-on: ubuntu-latest - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: setup environment - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo ${{ env.BRANCH_NAME }} - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven - run: | - cd biosdk-services - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Ready the springboot artifacts - run: find -name '*.jar' -executable -type f -exec zip release.zip {} + - - - name: Upload the springboot jars - uses: actions/upload-artifact@v1 - with: - name: release - path: ./release.zip - - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,author,action,eventName,ref,workflow,job,took # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required - if: failure() # Pick up events even if the job fails or is canceled. - - - docker-biosdk-server: - needs: build - runs-on: ubuntu-latest - env: - NAMESPACE: ${{ secrets. dev_namespace_docker_hub }} - SERVICE_NAME: biosdk-server - SERVICE_LOCATION: biosdk-services - - steps: - - uses: actions/checkout@v2 - - uses: actions/download-artifact@v1 - with: - name: release - path: ./ - - - name: Setup branch name - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo ${{ env.BRANCH_NAME }} - - - name: Get version info from pom - id: getPomVersion - uses: mavrosxristoforos/get-xml-info@1.0 - with: - xml-file: ./${{ env.SERVICE_LOCATION }}/pom.xml - xpath: /*[local-name()="project"]/*[local-name()="version"] - - - name: Unzip and extract the biosdk-server - run: unzip -uj "release.zip" "${{ env.SERVICE_LOCATION }}/target/*" -d "./${{ env.SERVICE_LOCATION }}/target" - - - name: Get current date - id: date - run: echo "::set-output name=date::$(date +'%Y-%m-%d')" - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --build-arg SOURCE=mosip --build-arg COMMIT_HASH=$(git rev-parse HEAD) --build-arg COMMIT_ID=$(git rev-parse --short HEAD) --build-arg BUILD_TIME=${{steps.date.outputs.date}} --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - echo "push version ${{steps.getPomVersion.outputs.info}}" - if [[ $BRANCH_NAME == master ]]; then - VERSION=latest - else - VERSION=$BRANCH_NAME - fi - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,author,action,eventName,ref,workflow,job,took # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required - if: failure() # Pick up events even if the job fails or is canceled. - - - sonar_analysis: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven - run: | - cd biosdk-services - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Analyze with SonarCloud - run: | - cd biosdk-services - mvn -B -Dgpg.skip verify sonar:sonar -Dsonar.projectKey=mosip_${{ github.event.repository.name }} -Dsonar.organization=${{ secrets.ORG_KEY }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - uses: 8398a7/action-slack@v3 - with: - status: ${{ job.status }} - fields: repo,message,commit,workflow,job # selectable (default: repo,message) - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_DEVOPS_WEBHOOK }} # required - if: failure() # Pick up events even if the job fails or is canceled. - - publish_to_nexus: - if: "!contains(github.ref, 'master')" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - uses: actions/checkout@v2 - - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo ${{ env.BRANCH_NAME }} - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.RELEASE_USER}} ${{secrets.RELEASE_TOKEN}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven - run: | - cd biosdk-services - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Publish the maven package - run: | - cd biosdk-services - mvn deploy -DaltDeploymentRepository=ossrh::default::${{ secrets.OSSRH_SNAPSHOT_URL }} -s $GITHUB_WORKSPACE/settings.xml -f pom.xml - env: - GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} - GPG_TTY: $(tty) diff --git a/.github/workflows/release_changes.yml b/.github/workflows/release_changes.yml deleted file mode 100644 index 5d8e1a32..00000000 --- a/.github/workflows/release_changes.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Release/pre-release Preparation. - -on: - workflow_dispatch: - inputs: - message: - description: 'Triggered for release or pe-release' - required: false - default: 'Release Preparation' - releaseTags: - description: 'tag to update' - required: true - snapshotTags: - description: 'tag to be replaced' - required: true - base: - description: 'base branch for PR' - required: true -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: update Branch name in badges - run: | - sed -i 's/branch=.*)]/branch=${{ env.BRANCH_NAME }}\)]/g' README.md - sed -i 's/branch=.*\&/branch=${{ env.BRANCH_NAME }}\&/g' README.md - - - name: Mannualy changing the pom versions - run: find . -type f -name "*pom.xml" -print0 | xargs -0 sed -i "s/${{ github.event.inputs.snapshotTags }}/${{ github.event.inputs.releaseTags }}/g" - - - name: Updating the Release URL in POM - run: | - cd .github/workflows - sed -i 's/OSSRH_SNAPSHOT_URL/RELEASE_URL/g' push_trigger.yml - - - name: Updating libs-snapshot-local to libs-release local for artifactory URL's. - run: find . -type f -name "*Dockerfile" -print0 | xargs -0 sed -i "s/libs-snapshot-local/libs-release-local/g" - - - name: removing -DskipTests - run: find . -type f -name "*push_trigger.yml" -print0 | xargs -0 sed -i "s/"-DskipTests"//g" - -# - name: removing --Dgpg.skip -# run: find . -type f -name "*push_trigger.yml" -print0 | xargs -0 sed -i "s/"-Dgpg.skip"//g" - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 - with: - token: ${{ secrets.ACTION_PAT }} - commit-message: Release Bot Pre-release changes - title: Release changes - body: Automated PR for ${{ github.event.inputs.releaseTags }} release. - branch: release-branch - delete-branch: true - base: ${{ github.event.inputs.base }} diff --git a/.github/workflows/release_trigger.yml b/.github/workflows/release_trigger.yml deleted file mode 100644 index 9b2e24a0..00000000 --- a/.github/workflows/release_trigger.yml +++ /dev/null @@ -1,407 +0,0 @@ -name: Release maven packages and docker upon a release - -on: - release: - types: [published] - -jobs: - build-kernel-ref-idobjectvalidator: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 1.8 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - echo "::set-env name=GPG_TTY::$(tty)" - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - - name: Build with Maven - run: | - cd kernel - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Ready the springboot artifacts - run: find -name '*.jar' -executable -type f -exec zip release.zip {} + - - - name: Upload the springboot jars - uses: actions/upload-artifact@v1 - with: - name: release - path: ./release.zip - - publish_to_nexus: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 1.8 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - echo "::set-env name=GPG_TTY::$(tty)" - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - name: Build with Maven - run: | - cd kernel - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Publish the maven package - run: | - chmod +x ./deploy.sh - ./deploy.sh kernel $GITHUB_WORKSPACE/settings.xml .* - env: - GPG_TTY: $(tty) - - name: Analyze with SonarCloud - run: | - cd kernel - mvn -B verify sonar:sonar -Dsonar.projectKey=${{ secrets.PROJECT_KEY }} -Dsonar.organization=${{ secrets.ORG_KEY }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - # This workflow contains a single job called "build" - - docker-registration-processor-external-integration-service: - - runs-on: ubuntu-latest - env: - NAMESPACE: mosipdev - SERVICE_NAME: registration-processor-external-integration-service - SERVICE_LOCATION: registration-processor/registration-processor-external-integration-service - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 11 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - name: Setup branch and env - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo "GPG_TTY=$(tty)" >> $GITHUB_ENV - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - - name: Build with Maven - run: | - cd registration-processor/registration-processor-external-integration-service - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Ready the springboot artifacts - run: find -name '*.jar' -executable -type f -exec zip release.zip {} + - - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - - echo "BRANCH_NAME=$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" >> $GITHUB_ENV - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install libxml2-utils - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.RELEASE_USER}} ${{secrets.RELEASE_TOKEN}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - -# - name: Analyze with SonarCloud -# run: | -# cd pre-registration-booking-service -# mvn -B verify sonar:sonar -Dsonar.projectKey=${{ secrets.PROJECT_KEY }} -Dsonar.organization=${{ secrets.ORG_KEY }} -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=${{ secrets.SONAR_TOKEN }} -# env: -# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - VERSION=$BRANCH_NAME - echo "push version $VERSION" - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - - build-admin-ui: - runs-on: ubuntu-latest - env: - NAMESPACE: ${{ secrets. dev_namespace_docker_hub }} - SERVICE_NAME: admin-ui - SERVICE_LOCATION: admin-ui - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - - name: npm install - run: cd ${{ env.SERVICE_LOCATION }} && npm install --ignore-scripts - - - name: npm build - run: cd ${{ env.SERVICE_LOCATION }} && npm run-script build -- --prod --base-href . --output-path=dist - - - name: setup environment - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - VERSION=$BRANCH_NAME - echo "push version $VERSION" - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - -# This workflow contains a single job called "build" - build-pre-registration-ui: - - runs-on: ubuntu-latest - env: - NAMESPACE: ${{ secrets. dev_namespace_docker_hub }} - SERVICE_NAME: pre-registration-ui - SERVICE_LOCATION: pre-registration-ui - - # Steps represent a sequence of tasks that will be executed as part of the job - steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 - - uses: actions/setup-node@v1 - - - name: npm install - run: cd ${{ env.SERVICE_LOCATION }} && npm install --ignore-scripts - - - name: npm build - run: cd ${{ env.SERVICE_LOCATION }} && npm run-script build -- --prod --base-href . --output-path=dist - - - name: setup environment - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - - - name: Build image - run: | - cd "./${{env.SERVICE_LOCATION}}" - docker build . --file Dockerfile --tag ${{ env.SERVICE_NAME }} - - - name: Log into registry - run: echo "${{ secrets.release_docker_hub }}" | docker login -u ${{ secrets.actor_docker_hub }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=$NAMESPACE/$SERVICE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - VERSION=$BRANCH_NAME - echo "push version $VERSION" - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $SERVICE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION - - build-demosdk: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 1.8 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - echo "::set-env name=GPG_TTY::$(tty)" - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - - name: Build with Maven - run: | - cd demosdk - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Ready the springboot artifacts - run: find -name '*.jar' -executable -type f -exec zip release.zip {} + - - - name: Upload the springboot jars - uses: actions/upload-artifact@v1 - with: - name: release - path: ./release.zip - - build-authentication-ref-impl: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - ref: ${{ github.ref }} - java-version: 1.8 - server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml - settings-path: ${{ github.workspace }} # location for the settings.xml file - - - name: Setup branch and GPG public key - run: | - # Strip git ref prefix from version - echo "::set-env name=BRANCH_NAME::$(echo ${{ github.ref }} | sed -e 's,.*/\(.*\),\1,')" - echo ${{ env.BRANCH_NAME }} - echo "::set-env name=GPG_TTY::$(tty)" - echo ${{ env.GPG_TTY }} - sudo apt-get --yes install gnupg2 - gpg2 --import ./.github/keys/mosipgpgkey_pub.gpg - gpg2 --quiet --batch --passphrase=${{secrets.gpg_secret}} --allow-secret-key-import --import ./.github/keys/mosipgpgkey_sec.gpg - - - uses: actions/cache@v1 - with: - path: ~/.m2/repository - key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} - restore-keys: | - ${{ runner.os }}-maven-${{ env.BRANCH_NAME }} - - - name: Setup the settings file for ossrh server - run: echo " ossrh ${{secrets.ossrh_user}} ${{secrets.ossrh_secret}} ossrh true gpg2 ${{secrets.gpg_secret}} allow-snapshots true snapshots-repo https://oss.sonatype.org/content/repositories/snapshots false true releases-repo https://oss.sonatype.org/service/local/staging/deploy/maven2 true false sonar . https://sonarcloud.io false " > $GITHUB_WORKSPACE/settings.xml - - - - name: Build with Maven - run: | - cd authentication - mvn -B package -s $GITHUB_WORKSPACE/settings.xml --file pom.xml - - - name: Ready the springboot artifacts - run: find -name '*.jar' -executable -type f -exec zip release.zip {} + - - - name: Upload the springboot jars - uses: actions/upload-artifact@v1 - with: - name: release - path: ./release.zip - diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..41f8135e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea +*/target* +*/logs \ No newline at end of file diff --git a/README.md b/README.md index d7110537..0b1ef516 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,11 @@ [![Maven Package upon a push](https://github.com/mosip/biosdk-services/actions/workflows/push_trigger.yml/badge.svg?branch=release-1.2.0.1)](https://github.com/mosip/biosdk-services/actions/workflows/push_trigger.yml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?branch=release-1.2.0.1&project=mosip_biosdk-services&metric=alert_status)](https://sonarcloud.io/dashboard?branch=release-1.2.0.1&id=mosip_biosdk-services) + # Bio-SDK Service ## Overview -This service provides a mock implementation of Bio-SDK REST Service. It by default loads [Mock BIO SDK](https://github.com/mosip/mosip-mock-services/tree/master/mock-sdk) internally on the startup and exposes the endpoints to perform 1:N match, segmentation, extraction as per the [IBioAPI](https://github.com/mosip/commons/blob/master/kernel/kernel-biometrics-api/src/main/java/io/mosip/kernel/biometrics/spi/IBioApi.java). +This is reference service and provides a mock implementation of Bio-SDK REST Service. By default loads [Mock BIO SDK](https://github.com/mosip/mosip-mock-services/tree/master/mock-sdk) internally on the startup and exposes the endpoints to perform 1:1 match, extraction as per the [IBioAPI](https://github.com/mosip/commons/blob/master/kernel/kernel-biometrics-api/src/main/java/io/mosip/kernel/biometrics/spi/IBioApi.java). To know more about Biometric SDK, refer [biometric-sdk](https://docs.mosip.io/1.2.0/biometrics/biometric-sdk). diff --git a/biosdk-services/Dockerfile b/biosdk-services/Dockerfile index 82d81ec3..e802cfd0 100644 --- a/biosdk-services/Dockerfile +++ b/biosdk-services/Dockerfile @@ -1,72 +1,108 @@ -FROM openjdk:11 - -ARG biosdk_zip_url - -ENV biosdk_zip_file_path=${biosdk_zip_url} - -ARG biosdk_local_dir=biosdk-client - -ENV biosdk_local_dir_name=${biosdk_local_dir} - -ARG sdk_impl - -ARG service_context=/biosdk-service - -ENV service_context_env=${service_context} - -#ENV biosdk_zip_url=$biosdk_zip_url -ENV biosdk_bioapi_impl=${sdk_impl} - -# can be passed during Docker build as build time environment for github branch to pickup configuration from. -ARG container_user=mosip - -# can be passed during Docker build as build time environment for github branch to pickup configuration from. -ARG container_user_group=mosip - -# can be passed during Docker build as build time environment for github branch to pickup configuration from. -ARG container_user_uid=1001 - -# can be passed during Docker build as build time environment for github branch to pickup configuration from. -ARG container_user_gid=1001 - -# install packages and create user -RUN apt-get -y update \ -&& apt-get install -y unzip sudo\ -&& groupadd -g ${container_user_gid} ${container_user_group} \ -&& useradd -u ${container_user_uid} -g ${container_user_group} -s /bin/sh -m ${container_user} - -# set working directory for the user -WORKDIR /home/${container_user} - -ENV work_dir=/home/${container_user} - -ARG loader_path=${work_dir}/additional_jars/ - -RUN mkdir -p ${loader_path} - -ENV loader_path_env=${loader_path} - -ARG logging_level_root=INFO - -ENV logging_level_root_env=${logging_level_root} - -ADD ./target/biosdk-services-*.jar biosdk-services.jar - -ADD ./configure_biosdk.sh configure_biosdk.sh - -RUN chmod 775 biosdk-services.jar - -RUN chmod +x configure_biosdk.sh - -# change permissions of file inside working dir -RUN chown -R ${container_user}:${container_user} /home/${container_user} - -# select container user for all tasks -USER ${container_user_uid}:${container_user_gid} - -EXPOSE 9099 - -ENTRYPOINT [ "./configure_biosdk.sh" ] - -CMD echo $biosdk_bioapi_impl ; \ -java -Dloader.path="${loader_path_env}" -Dbiosdk_bioapi_impl="${biosdk_bioapi_impl}" -Dserver.servlet.context-path="${service_context_env}" -Dlogging.level.root=${logging_level_root_env} -jar biosdk-services.jar +FROM openjdk:11 + +# can be passed during Docker build as build time environment for github branch to pickup configuration from. +ARG spring_config_label + +# can be passed during Docker build as build time environment for spring profiles active +ARG active_profile + +# can be passed during Docker build as build time environment for config server URL +ARG spring_config_url + +# can be passed during Docker build as build time environment for application name +ARG spring_application_name + +# can be passed during Docker build as build time environment for config name +ARG spring_cloud_config_name + +# can be passed during Docker build as build time environment for context path +ARG server_servlet_context + +# environment variable to pass github branch to pickup configuration from, at docker runtime +ENV spring_config_label_env=${spring_config_label} + +# environment variable to pass active profile such as DEV, QA etc at docker runtime +ENV active_profile_env=${active_profile} + +# environment variable to pass spring configuration url, at docker runtime +ENV spring_config_url_env=${spring_config_url} + +# environment variable to pass spring application name, at docker runtime +ENV spring_application_name_env=${spring_application_name} + +# environment variable to pass spring config name, at docker runtime +ENV spring_cloud_config_name_env=${spring_cloud_config_name} + +# environment variable to pass spring context path , at docker runtime +ENV server_servlet_context_env=${server_servlet_context} + +ARG biosdk_zip_url + +ENV biosdk_zip_file_path=${biosdk_zip_url} + +ARG biosdk_local_dir=biosdk-client + +ENV biosdk_local_dir_name=${biosdk_local_dir} + +ARG sdk_impl + +ARG service_context=/biosdk-service + +ENV service_context_env=${service_context} + +#ENV biosdk_zip_url=$biosdk_zip_url +ENV biosdk_bioapi_impl=${sdk_impl} + +# can be passed during Docker build as build time environment for github branch to pickup configuration from. +ARG container_user=mosip + +# can be passed during Docker build as build time environment for github branch to pickup configuration from. +ARG container_user_group=mosip + +# can be passed during Docker build as build time environment for github branch to pickup configuration from. +ARG container_user_uid=1001 + +# can be passed during Docker build as build time environment for github branch to pickup configuration from. +ARG container_user_gid=1001 + +# install packages and create user +RUN apt-get -y update \ +&& apt-get install -y unzip sudo\ +&& groupadd -g ${container_user_gid} ${container_user_group} \ +&& useradd -u ${container_user_uid} -g ${container_user_group} -s /bin/sh -m ${container_user} + +# set working directory for the user +WORKDIR /home/${container_user} + +ENV work_dir=/home/${container_user} + +ARG loader_path=${work_dir}/additional_jars/ + +RUN mkdir -p ${loader_path} + +ENV loader_path_env=${loader_path} + +ARG logging_level_root=INFO + +ENV logging_level_root_env=${logging_level_root} + +ADD ./target/biosdk-services-*.jar biosdk-services.jar + +ADD ./configure_biosdk.sh configure_biosdk.sh + +RUN chmod 775 biosdk-services.jar + +RUN chmod +x configure_biosdk.sh + +# change permissions of file inside working dir +RUN chown -R ${container_user}:${container_user} /home/${container_user} + +# select container user for all tasks +USER ${container_user_uid}:${container_user_gid} + +EXPOSE 9099 + +ENTRYPOINT [ "./configure_biosdk.sh" ] + +CMD echo $biosdk_bioapi_impl ; \ +java -Dloader.path="${loader_path_env}" -Dspring.cloud.config.label="${spring_config_label_env}" -Dspring.profiles.active="${active_profile_env}" -Dspring.cloud.config.uri="${spring_config_url_env}" -jar biosdk-services.jar diff --git a/biosdk-services/README.md b/biosdk-services/README.md index d5dae3cb..ae9737b5 100644 --- a/biosdk-services/README.md +++ b/biosdk-services/README.md @@ -23,7 +23,7 @@ java -Dloader.path= -Dbiosdk_bioapi_ For example: ```text -java -Dloader.path=mock-sdk.jar -Dbiosdk_bioapi_impl=io.mosip.mock.sdk.impl.SampleSDK -jar biosdk-services-1.1.3.jar +java -Dloader.path=mock-sdk-1.2.1-SNAPSHOT-jar-with-dependencies.jar -Dbiosdk_bioapi_impl=io.mosip.mock.sdk.impl.SampleSDKV2 -jar biosdk-services-1.2.1-SNAPSHOT.jar ``` ### Check service status diff --git a/biosdk-services/pom.xml b/biosdk-services/pom.xml index 857c16a5..3479ad9e 100644 --- a/biosdk-services/pom.xml +++ b/biosdk-services/pom.xml @@ -1,266 +1,309 @@ - - 4.0.0 + + 4.0.0 - biosdk-services - io.mosip.biosdk - 1.2.0.1-SNAPSHOT - biosdk-services - Sample implementation of biometrics SDK services - https://github.com/mosip/mosip-ref-impl - - - - MPL 2.0 - https://www.mozilla.org/en-US/MPL/2.0/ - - + biosdk-services + io.mosip.biosdk + 1.2.1-SNAPSHOT + biosdk-services + + + MPL 2.0 + https://www.mozilla.org/en-US/MPL/2.0/ + + + + scm:git:git://github.com/mosip/biosdk-services.git + scm:git:ssh://github.com:mosip/biosdk-services.git + https://github.com/mosip/biosdk-services + HEAD + + + + Mosip + mosip.emailnotifier@gmail.com + io.mosip + https://mosip.io + + + Sample implementation of biometrics SDK services + https://github.com/mosip/mosip-ref-impl + + 11 + + 11 + 11 + + 2.0.2.RELEASE + 2.0.2.RELEASE + 2.22.0 + 0.8.5 + 3.7.0.1746 - - scm:git:git://github.com/mosip/biosdk-services.git - scm:git:ssh://github.com:mosip/biosdk-services.git - https://github.com/mosip/biosdk-services - HEAD - - - - - Mosip - mosip.emailnotifier@gmail.com - io.mosip - https://github.com/mosip/biosdk-services - - - - - 2.0.2.RELEASE - 2.0.2.RELEASE - 2.22.0 - 0.8.5 - 3.7.0.1746 + + 1.18.8 - - 1.18.8 + + 2.9.2 - - 2.9.2 + + 1.2.0.1-B2 + 1.2.0.1-B1 + 1.2.0.1-B1 + + 2.0.2.RELEASE + - - 1.2.0 - 1.2.0.1-B1 - 1.2.0.1-B1 - + + + + org.springframework.boot + spring-boot-dependencies + ${spring.boot.version} + pom + import + + + org.springframework.boot + spring-boot-starter-json + + + + + com.fasterxml.jackson.core + jackson-databind + 2.11.0 + + + com.fasterxml.jackson.core + jackson-core + 2.11.0 + + + - - - - org.springframework.boot - spring-boot-dependencies - ${spring.boot.version} - pom - import - - - org.springframework.boot - spring-boot-starter-json - - - - - - - - org.springframework.cloud - spring-cloud-starter-config - ${spring-cloud-config.version} - - - org.springframework.boot - spring-boot-devtools - runtime - - - org.springframework.boot - spring-boot-starter-web - ${spring.boot.version} - - - org.springframework.boot - spring-boot-starter-json - - - - - org.springframework.boot - spring-boot-starter-security - ${spring.boot.version} - - - io.springfox - springfox-swagger2 - ${swagger.version} - compile - - - io.springfox - springfox-swagger-ui - ${swagger.version} - compile - - - io.mosip.kernel - kernel-biometrics-api - ${kernel.biometricsdk.version} - - - io.mosip.kernel - kernel-core - - - - - io.mosip.kernel - kernel-logger-logback - ${kernel.logger.logback.version} - - - io.mosip.kernel - kernel-core - ${kernel.core.version} - - - org.projectlombok - lombok - ${lombok.version} - compile - - - com.googlecode.json-simple - json-simple - 1.1.1 - - - com.google.code.gson - gson - 2.8.6 - + + + org.springframework.cloud + spring-cloud-starter-config + ${spring-cloud-config.version} + + + org.springframework.boot + spring-boot-devtools + runtime + + + org.springframework.boot + spring-boot-starter-web + ${spring.boot.version} + + + org.springframework.boot + spring-boot-starter-json + + + + + org.springframework.boot + spring-boot-starter-security + ${spring.boot.version} + + + org.springframework.boot + spring-boot-starter-actuator + ${spring.boot.version} + + + io.springfox + springfox-swagger2 + ${swagger.version} + compile + + + io.springfox + springfox-swagger-ui + ${swagger.version} + compile + + + io.mosip.kernel + kernel-biometrics-api + ${kernel.biometrics.api.version} + + + io.mosip.kernel + kernel-logger-logback + ${kernel.logger.logback.version} + + + io.mosip.kernel + kernel-core + ${kernel.core.version} + + + org.projectlombok + lombok + ${lombok.version} + compile + + + com.googlecode.json-simple + json-simple + 1.1.1 + + + com.google.code.gson + gson + 2.8.6 + - + - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven.surefire.plugin.version} - - ${skipTests} - false - - ${argLine} --add-opens java.xml/jdk.xml.internal=ALL-UNNAMED --illegal-access=permit - - - - + + - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - --pinentry-mode - loopback - - - - - - - - org.jacoco - jacoco-maven-plugin - ${maven.jacoco.plugin.version} - - - - prepare-agent - - - - report - prepare-package - - report - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 11 - 11 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - ZIP - true - - - - - build-info - repackage - - - - - - - - - sonar - - . - src/main/java/**,src/main/resources/** - ${sonar.coverage.exclusions} - https://sonarcloud.io - - - false - - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - ${maven.sonar.plugin.version} - - - verify - - sonar - - - - - - - - - + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven.surefire.plugin.version} + + ${skipTests} + false + + ${argLine} --add-opens + java.xml/jdk.xml.internal=ALL-UNNAMED + --illegal-access=permit + + + + + org.jacoco + jacoco-maven-plugin + ${maven.jacoco.plugin.version} + + + + prepare-agent + + + + report + prepare-package + + report + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + ${maven.compiler.source} + ${maven.compiler.target} + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + ZIP + true + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + build-info + repackage + + + + + + + + pl.project13.maven + git-commit-id-plugin + 3.0.1 + + + get-the-git-infos + + revision + + validate + + + + true + ${project.build.outputDirectory}/git.properties + + ^git.build.(time|version)$ + ^git.commit.id.(abbrev|full)$ + + full + ${project.basedir}/.git + + + + + + + + sonar + + . + src/main/java/**,src/main/resources/** + ${sonar.coverage.exclusions} + https://sonarcloud.io + + + false + + + + + org.sonarsource.scanner.maven + sonar-maven-plugin + ${maven.sonar.plugin.version} + + + verify + + sonar + + + + + + + + + \ No newline at end of file diff --git a/biosdk-services/run.bat b/biosdk-services/run.bat new file mode 100644 index 00000000..297b7f17 --- /dev/null +++ b/biosdk-services/run.bat @@ -0,0 +1 @@ +java -Dloader.path=mock-sdk-1.2.1-SNAPSHOT-jar-with-dependencies.jar -Dbiosdk_bioapi_impl=io.mosip.mock.sdk.impl.SampleSDKV2 -jar target/biosdk-services-1.2.1-SNAPSHOT.jar \ No newline at end of file diff --git a/biosdk-services/src/main/java/io/mosip/biosdk/services/config/BioSdkLibConfig.java b/biosdk-services/src/main/java/io/mosip/biosdk/services/config/BioSdkLibConfig.java index c6fdd7ae..a099b9f1 100644 --- a/biosdk-services/src/main/java/io/mosip/biosdk/services/config/BioSdkLibConfig.java +++ b/biosdk-services/src/main/java/io/mosip/biosdk/services/config/BioSdkLibConfig.java @@ -1,6 +1,6 @@ package io.mosip.biosdk.services.config; -import io.mosip.kernel.biometrics.spi.IBioApi; +import io.mosip.kernel.biometrics.spi.IBioApiV2; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,12 +35,12 @@ public void validateBioSdkLib() throws ClassNotFoundException { @Bean @Lazy - public IBioApi iBioApi() throws ClassNotFoundException, InstantiationException, IllegalAccessException { + public IBioApiV2 iBioApi() throws ClassNotFoundException, InstantiationException, IllegalAccessException { String sdkClass = this.env.getProperty("biosdk_bioapi_impl"); logger.info("Biosdk class: " + sdkClass); if (StringUtils.isNotBlank(sdkClass)) { logger.debug("instance of Bio SDK is created"); - return (IBioApi)Class.forName(sdkClass).newInstance(); + return (IBioApiV2)Class.forName(sdkClass).newInstance(); } else { logger.debug("no Bio SDK is provided"); throw new RuntimeException("No Bio SDK is provided"); diff --git a/biosdk-services/src/main/java/io/mosip/biosdk/services/config/LoggerConfig.java b/biosdk-services/src/main/java/io/mosip/biosdk/services/config/LoggerConfig.java index 0e700fa1..e40bbab9 100644 --- a/biosdk-services/src/main/java/io/mosip/biosdk/services/config/LoggerConfig.java +++ b/biosdk-services/src/main/java/io/mosip/biosdk/services/config/LoggerConfig.java @@ -1,7 +1,6 @@ package io.mosip.biosdk.services.config; import io.mosip.kernel.core.logger.spi.Logger; -import io.mosip.kernel.logger.logback.appender.RollingFileAppender; import io.mosip.kernel.logger.logback.factory.Logfactory; public final class LoggerConfig { @@ -13,24 +12,8 @@ private LoggerConfig() { } - - /** The mosip rolling file appender. */ - private final static RollingFileAppender MOSIP_ROLLING_APPENDER = new RollingFileAppender(); - - static { - MOSIP_ROLLING_APPENDER.setAppend(true); - MOSIP_ROLLING_APPENDER.setAppenderName("org.apache.log4j.RollingFileAppender"); - MOSIP_ROLLING_APPENDER.setFileName("./logs/biosdk-service.log"); - MOSIP_ROLLING_APPENDER.setFileNamePattern("./logs/biosdk-service-%d{yyyy-MM-dd}-%i.log"); - MOSIP_ROLLING_APPENDER.setImmediateFlush(true); - MOSIP_ROLLING_APPENDER.setMaxFileSize("50mb"); -// mosipRollingFileAppender.setMaxHistory(3); - MOSIP_ROLLING_APPENDER.setPrudent(false); -// mosipRollingFileAppender.setTotalCap("50mb"); - } - public static Logger logConfig(Class clazz) { - return Logfactory.getDefaultRollingFileLogger(MOSIP_ROLLING_APPENDER, clazz); + return Logfactory.getSlf4jLogger(clazz); } -} +} \ No newline at end of file diff --git a/biosdk-services/src/main/java/io/mosip/biosdk/services/controller/MainController.java b/biosdk-services/src/main/java/io/mosip/biosdk/services/controller/MainController.java index 752b87be..b1c478ff 100644 --- a/biosdk-services/src/main/java/io/mosip/biosdk/services/controller/MainController.java +++ b/biosdk-services/src/main/java/io/mosip/biosdk/services/controller/MainController.java @@ -9,7 +9,7 @@ import io.mosip.biosdk.services.factory.BioSdkServiceFactory; import io.mosip.biosdk.services.spi.BioSdkServiceProvider; import io.mosip.biosdk.services.utils.Utils; -import io.mosip.kernel.biometrics.spi.IBioApi; +import io.mosip.kernel.biometrics.spi.IBioApiV2; import io.mosip.kernel.core.logger.spi.Logger; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -46,7 +46,7 @@ public class MainController { private Utils serviceUtil; @Autowired - private IBioApi iBioApi; + private IBioApiV2 iBioApi; @Autowired private BioSdkServiceFactory bioSdkServiceFactory; @@ -61,8 +61,7 @@ public ResponseEntity status() { return ResponseEntity.status(HttpStatus.OK).body("Service is running... "+d.toString()); } - //@PreAuthorize("hasAnyRole('REGISTRATION_PROCESSOR')") - @PreAuthorize("hasAnyRole(@authorizedRoles.getGetservicestatus())") + @PreAuthorize("hasAnyRole('REGISTRATION_PROCESSOR')") @GetMapping(path = "/s") @ApiOperation(value = "Service status 1") @ApiResponses(value = { @ApiResponse(code = 200, message = "Service is running...") }) diff --git a/biosdk-services/src/main/java/io/mosip/biosdk/services/impl/spec_1_0/BioSdkServiceProviderImpl_V_1_0.java b/biosdk-services/src/main/java/io/mosip/biosdk/services/impl/spec_1_0/BioSdkServiceProviderImpl_V_1_0.java index 3e3a28ad..86a43185 100644 --- a/biosdk-services/src/main/java/io/mosip/biosdk/services/impl/spec_1_0/BioSdkServiceProviderImpl_V_1_0.java +++ b/biosdk-services/src/main/java/io/mosip/biosdk/services/impl/spec_1_0/BioSdkServiceProviderImpl_V_1_0.java @@ -4,9 +4,7 @@ import com.google.gson.GsonBuilder; import io.mosip.biosdk.services.config.LoggerConfig; import io.mosip.biosdk.services.constants.ErrorMessages; -import io.mosip.biosdk.services.dto.ErrorDto; import io.mosip.biosdk.services.dto.RequestDto; -import io.mosip.biosdk.services.dto.ResponseDto; import io.mosip.biosdk.services.exceptions.BioSDKException; import io.mosip.biosdk.services.impl.spec_1_0.dto.request.*; import io.mosip.biosdk.services.spi.BioSdkServiceProvider; @@ -14,33 +12,32 @@ import io.mosip.kernel.biometrics.entities.BiometricRecord; import io.mosip.kernel.biometrics.model.Response; import io.mosip.kernel.biometrics.model.SDKInfo; -import io.mosip.kernel.biometrics.spi.IBioApi; +import io.mosip.kernel.biometrics.spi.IBioApiV2; import io.mosip.kernel.core.logger.spi.Logger; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import java.util.ArrayList; - -import static io.mosip.biosdk.services.constants.AppConstants.LOGGER_IDTYPE; -import static io.mosip.biosdk.services.constants.AppConstants.LOGGER_SESSIONID; - +import static io.mosip.biosdk.services.constanimport tati @Component public class BioSdkServiceProviderImpl_V_1_0 implements BioSdkServiceProvider { private Logger logger = LoggerConfig.logConfig(BioSdkServiceProviderImpl_V_1_0.class); - private static final String BIOSDK_SERVICE_SPEC_VERSION = "1.0"; - private static final String BIOSDK_SPEC_VERSION = "0.9"; + private static final String BIOSDK_SERVICE_SPEC_VERSION = "1.0"; priate staic final Strig BIOSDK_SPEC_VERSION = "0.9"; private static final String publicKey = ""; private static final String privateKey = ""; @Autowired - private IBioApi iBioApi; + private IBioApiV2 iBioApi; @Autowired private Utils serviceUtil; private Gson gson = new GsonBuilder().serializeNulls().create(); + + @Value("${mosip.biosdk.log-request-response-enabled:false}") + private boolean isLogRequestResponse; @Override public String getSpecVersion() { @@ -55,7 +52,9 @@ public Object init(RequestDto request){ InitRequestDto initRequestDto = gson.fromJson(decryptedRequest, InitRequestDto.class); logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"init: ", "json to dto successful"); try { + logRequest(initRequestDto); sdkInfo = iBioApi.init(initRequestDto.getInitParams()); + logObject(sdkInfo); } catch (Throwable e){ e.printStackTrace(); logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,"init: ", e.toString()+" "+e.getMessage()); @@ -64,7 +63,7 @@ public Object init(RequestDto request){ return sdkInfo; } - @Override + @Override public Object checkQuality(RequestDto request) { Response response; String decryptedRequest = decode(request.getRequest()); @@ -72,13 +71,14 @@ public Object checkQuality(RequestDto request) { CheckQualityRequestDto checkQualityRequestDto = gson.fromJson(decryptedRequest, CheckQualityRequestDto.class); logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"checkQuality: ", "json to dto successful"); try { + logRequest(checkQualityRequestDto); response = iBioApi.checkQuality( checkQualityRequestDto.getSample(), checkQualityRequestDto.getModalitiesToCheck(), checkQualityRequestDto.getFlags() - ); - } catch (Throwable e){ - e.printStackTrace(); + + + } catch (Throwable e){ logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,"checkQuality: ", e.toString()+" "+e.getMessage()); throw new BioSDKException(ErrorMessages.BIOSDK_LIB_EXCEPTION.toString(), ErrorMessages.BIOSDK_LIB_EXCEPTION.getMessage()+": "+e.toString()+" "+e.getMessage()); } @@ -93,14 +93,15 @@ public Object match(RequestDto request) { MatchRequestDto matchRequestDto = gson.fromJson(decryptedRequest, MatchRequestDto.class); logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"match: ", "json to dto successful"); try { + logRequest(matchRequestDto); response = iBioApi.match( matchRequestDto.getSample(), matchRequestDto.getGallery(), matchRequestDto.getModalitiesToMatch(), matchRequestDto.getFlags() ); + logResponse(response); } catch (Throwable e){ - e.printStackTrace(); logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,"match: ", e.toString()+" "+e.getMessage()); throw new BioSDKException(ErrorMessages.BIOSDK_LIB_EXCEPTION.toString(), ErrorMessages.BIOSDK_LIB_EXCEPTION.getMessage()+": "+e.toString()+" "+e.getMessage()); } @@ -115,20 +116,21 @@ public Object extractTemplate(RequestDto request) { ExtractTemplateRequestDto extractTemplateRequestDto = gson.fromJson(decryptedRequest, ExtractTemplateRequestDto.class); logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"extractTemplate: ", "json to dto successful"); try { + logRequest(extractTemplateRequestDto); response = iBioApi.extractTemplate( extractTemplateRequestDto.getSample(), extractTemplateRequestDto.getModalitiesToExtract(), extractTemplateRequestDto.getFlags() ); + logResponse(response); } catch (Throwable e){ - e.printStackTrace(); logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,"extractTemplate: ", e.toString()+" "+e.getMessage()); throw new BioSDKException(ErrorMessages.BIOSDK_LIB_EXCEPTION.toString(), ErrorMessages.BIOSDK_LIB_EXCEPTION.getMessage()+": "+e.toString()+" "+e.getMessage()); } return response; } - @Override + @Override public Object segment(RequestDto request) { Response response; String decryptedRequest = decode(request.getRequest()); @@ -136,28 +138,30 @@ public Object segment(RequestDto request) { SegmentRequestDto segmentRequestDto = gson.fromJson(decryptedRequest, SegmentRequestDto.class); logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"segment: ", "json to dto successful"); try { + logRequest(segmentRequestDto); response = iBioApi.segment( segmentRequestDto.getSample(), segmentRequestDto.getModalitiesToSegment(), segmentRequestDto.getFlags() ); + logResponse(response); } catch (Throwable e){ - e.printStackTrace(); logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,"segment: ", e.toString()+" "+e.getMessage()); throw new BioSDKException(ErrorMessages.BIOSDK_LIB_EXCEPTION.toString(), ErrorMessages.BIOSDK_LIB_EXCEPTION.getMessage()+": "+e.toString()+" "+e.getMessage()); } return response; } - @Override + @Override public Object convertFormat(RequestDto request) { - BiometricRecord biometricRecord; - String decryptedRequest = decode(request.getRequest()); - logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"convertFormat: ", "decoding successful"); - ConvertFormatRequestDto convertFormatRequestDto = gson.fromJson(decryptedRequest, ConvertFormatRequestDto.class); + Response response; + + + ConvertFormatRequestDto convertFormatRequestDto = gson.fromJson(decryptedRequest, ConvertFormatRequestDto.class); logger.debug(LOGGER_SESSIONID, LOGGER_IDTYPE,"convertFormat: ", "json to dto successful"); try { - biometricRecord = iBioApi.convertFormat( + logRequest(convertFormatRequestDto); + response = iBioApi.convertFormatV2( convertFormatRequestDto.getSample(), convertFormatRequestDto.getSourceFormat(), convertFormatRequestDto.getTargetFormat(), @@ -165,21 +169,164 @@ public Object convertFormat(RequestDto request) { convertFormatRequestDto.getTargetParams(), convertFormatRequestDto.getModalitiesToConvert() ); + logResponse(response); } catch (Throwable e){ - e.printStackTrace(); logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,"convertFormat: ", e.toString()+" "+e.getMessage()); throw new BioSDKException(ErrorMessages.BIOSDK_LIB_EXCEPTION.toString(), ErrorMessages.BIOSDK_LIB_EXCEPTION.getMessage()+": "+e.toString()+" "+e.getMessage()); } - return biometricRecord; + return response; } - private String decode(String data){ - try { - return Utils.base64Decode(data); - } catch (RuntimeException e){ - e.printStackTrace(); - logger.error(LOGGER_SESSIONID, LOGGER_IDTYPE,ErrorMessages.INVALID_REQUEST_BODY.toString(), e.toString()+" "+e.getMessage()); - throw new BioSDKException(ErrorMessages.INVALID_REQUEST_BODY.toString(), ErrorMessages.INVALID_REQUEST_BODY.getMessage()+": "+e.toString()+" "+e.getMessage()); + private void logRequest(ExtractTemplateRequestDto extractTemplateRequestDto) { + if(isLogRequestResponse) { + logger.debug("REQUEST: " + serviceUtil.toString(extractTemplateRequestDto)); + } + } + + private void logRequest(MatchRequestDto matchRequestDto) { + if(isLogRequestResponse) { + gger.debug("REQUEST: " + serviceUtil.toString(matchRequestDto)); + } + } + + + private void logRequest(InitRequestDto initReques tDto) { + if(isLog + .debug("REQUEST: " + serviceUtil.toS + + } + + private void logRequest(CheckQualityRequestDto checkQualityRequestDto) { + if(isLogRequestResponse) { + logger.debug("REQUEST: " + serviceUtil.toString(checkQualityRequestDto)); + } + + private void logRequest(S egmentRequestDto segmentRequestDto) { + if(isLogRequestResponse) { + logger.debug("REQUEST: " + serviceUtil.toString(segmentRequestDto)); + + } + } + + + private void logRequest(ConvertFormatRequestDto convertFormatRequestDto) { + if(isLogRequestResponse + logger.debug("REQUEST: " + serviceUtil.toString(convertFormatRequestDto)); } } -} + + private void logObject(T response) { + if(isLogRequestResponse + logger.debug(response.getClass() + ": " + gson.toJson(response)); + + } + + private void logResponse(Response response) { + if (isLogRequestResponse) { + Object resp = response.getResponse(); + + + + } else { + logger.debug("Respons + } + + } + + private void logBiometricRecord(String prefix, BiometricRecord + if (isLogRequestResponse) { + logger.debug(prefix + serviceUtil.toString(biometricRecord)); + + } + + private String decode(String data){ + try { + return Utils.base64Decode(data); + + + + } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java b/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java index cf46a6f9..76ffcca9 100644 --- a/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java +++ b/biosdk-services/src/main/java/io/mosip/biosdk/services/utils/Utils.java @@ -1,32 +1,315 @@ package io.mosip.biosdk.services.utils; -import com.google.gson.Gson; -import io.mosip.biosdk.services.dto.RequestDto; -import io.mosip.kernel.core.util.DateUtils; +import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Base64; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.function.BiConsumer; + +import org.apache.commons.codec.digest.DigestUtils; import org.json.simple.parser.ParseException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.Date; +import com.google.gson.Gson; + +import io.mosip.biosdk.services.dto.RequestDto; +import io.mosip.biosdk.services.impl.spec_1_0.dto.request.CheckQualityRequestDto; +import io.mosip.biosdk.services.impl.spec_1_0.dto.request.ConvertFormatRequestDto; +import io.mosip.biosdk.services.impl.spec_1_0.dto.request.ExtractTemplateRequestDto; +import io.mosip.biosdk.services.impl.spec_1_0.dto.request.InitRequestDto; +import io.mosip.biosdk.services.impl.spec_1_0.dto.request.MatchRequestDto; +import io.mosip.biosdk.services.impl.spec_1_0.dto.request.SegmentRequestDto; +import io.mosip.kernel.biometrics.entities.BDBInfo; +import io.mosip.kernel.biometrics.entities.BIR; +import io.mosip.kernel.biometrics.entities.BIRInfo; +import io.mosip.kernel.biometrics.entities.BiometricRecord; +import io.mosip.kernel.core.util.DateUtils; @Component public class Utils { - @Autowired - private Gson gson; + @Autowired + private Gson gson; + + private String utcDateTimePattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + + public String getCurrentResponseTime() { + return DateUtils.formatDate(new Date(System.currentTimeMillis()), utcDateTimePattern); + } + + public RequestDto getRequestInfo(String request) throws ParseException { + return gson.fromJson(request, RequestDto.class); + } + + public static String base64Decode(String data) { + return new String(Base64.getDecoder().decode(data), StandardCharsets.UTF_8); + } + + public String toString(BiometricRecord biometricRecord) { + if (biometricRecord == null) { + return "null"; + } + + StringBuilder stringBuilder = new StringBuilder(); + appendString(biometricRecord, stringBuilder); + return stringBuilder.toString(); + } + + private void appendString(BiometricRecord biometricRecord, StringBuilder stringBuilder) { + if (biometricRecord == null) { + stringBuilder.append("null"); + } else { + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"BiometricRecord\""); + stringBuilder.append(", \"birInfo\": "); + stringBuilder.append(toString(biometricRecord.getBirInfo())); + stringBuilder.append(", \"cbeffversion\":"); + stringBuilder.append(stringOf(biometricRecord.getCbeffversion())); + stringBuilder.append(", \"version\":"); + stringBuilder.append(stringOf(biometricRecord.getVersion())); + stringBuilder.append(", \"segments\":"); + List segments = biometricRecord.getSegments(); + if (segments == null) { + stringBuilder.append("null"); + } else { + appendString(segments.stream().iterator(), stringBuilder, this::appendString); + } + stringBuilder.append(" }"); + } + } + + private String stringOf(Object obj) { + return obj == null ? "null" : gson.toJson(obj); + } + + private void appendString(Iterator iterator, StringBuilder stringBuilder, + BiConsumer appendBiConsumer) { + stringBuilder.append("[ "); + while (iterator.hasNext()) { + T element = iterator.next(); + appendBiConsumer.accept(element, stringBuilder); + if (iterator.hasNext()) { + stringBuilder.append(", "); + } + } + stringBuilder.append(" ]"); + } + + private void appendString(BIR bir, StringBuilder stringBuilder) { + if (bir == null) { + stringBuilder.append("null"); + } else { + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"BIR\""); + stringBuilder.append(", \"bdbInfo\": "); + stringBuilder.append(toString(bir.getBdbInfo())); + stringBuilder.append(", \"birInfo\": "); + stringBuilder.append(toString(bir.getBirInfo())); + stringBuilder.append(", \"cbeffversion\": "); + stringBuilder.append(stringOf(bir.getCbeffversion())); + stringBuilder.append(", \"others\": "); + stringBuilder.append(stringOf(bir.getOthers())); + stringBuilder.append(", \"sbHash\": "); + stringBuilder.append(getHashOfBytes(bir.getSb())); + stringBuilder.append(", \"sbInfo\": "); + stringBuilder.append(stringOf(bir.getSbInfo())); + stringBuilder.append(", \"version\": "); + stringBuilder.append(stringOf(bir.getVersion())); + stringBuilder.append(", \"bdbHash\": "); + stringBuilder.append(getHashOfBytes(bir.getBdb())); + stringBuilder.append(" }"); + } + } + + private static String getHashOfBytes(byte[] byteArray) { + return byteArray == null ? "null" : "\"" + DigestUtils.sha256Hex(byteArray) + "\""; + } + + public String toString(ExtractTemplateRequestDto extractTemplateRequestDto) { + if (extractTemplateRequestDto == null) { + return "null"; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"ExtractTemplateRequestDto\""); + stringBuilder.append(", \"flags\":"); + stringBuilder.append(stringOf(extractTemplateRequestDto.getFlags())); + stringBuilder.append(", \"modalitiesToExtract\": "); + stringBuilder.append(stringOf(extractTemplateRequestDto.getModalitiesToExtract())); + stringBuilder.append(", \"sample\": "); + appendString(extractTemplateRequestDto.getSample(), stringBuilder); + stringBuilder.append(" }"); + return stringBuilder.toString(); + } + + public String toString(MatchRequestDto matchRequestDto) { + if (matchRequestDto == null) { + return "null"; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"MatchRequestDto\""); + stringBuilder.append(", \"flags\":"); + stringBuilder.append(stringOf(matchRequestDto.getFlags())); + stringBuilder.append(", \"modalitiesToMatch\": "); + stringBuilder.append(stringOf(matchRequestDto.getModalitiesToMatch())); + stringBuilder.append(", \"sample\": "); + appendString(matchRequestDto.getSample(), stringBuilder); + stringBuilder.append(", \"gallery\": "); + appendString(Arrays.stream(matchRequestDto.getGallery()).iterator(), stringBuilder, this::appendString); + stringBuilder.append(" }"); + return stringBuilder.toString(); + } + + public String toString(InitRequestDto initRequestDto) { + if (initRequestDto == null) { + return "null"; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"InitRequestDto\""); + stringBuilder.append(", \"initParams\":"); + stringBuilder.append(stringOf(initRequestDto)); + stringBuilder.append(" }"); + return stringBuilder.toString(); + } + + public String toString(CheckQualityRequestDto checkQualityRequestDto) { + if (checkQualityRequestDto == null) { + return "null"; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"CheckQualityRequestDto\""); + stringBuilder.append(", \"flags\":"); + stringBuilder.append(stringOf(checkQualityRequestDto.getFlags())); + stringBuilder.append(", \"modalitiesToCheck\": "); + stringBuilder.append(stringOf(checkQualityRequestDto.getModalitiesToCheck())); + stringBuilder.append(", \"sample\": "); + appendString(checkQualityRequestDto.getSample(), stringBuilder); + stringBuilder.append(" }"); + return stringBuilder.toString(); + } + + public String toString(SegmentRequestDto segmentRequestDto) { + if (segmentRequestDto == null) { + return "null"; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"SegmentRequestDto\""); + stringBuilder.append(", \"flags\":"); + stringBuilder.append(stringOf(segmentRequestDto.getFlags())); + stringBuilder.append(", \"modalitiesToSegment\": "); + stringBuilder.append(stringOf(segmentRequestDto.getModalitiesToSegment())); + stringBuilder.append(", \"sample\": "); + appendString(segmentRequestDto.getSample(), stringBuilder); + stringBuilder.append(" }"); + return stringBuilder.toString(); + } + + public String toString(ConvertFormatRequestDto convertFormatRequestDto) { + if (convertFormatRequestDto == null) { + return "null"; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"ConvertFormatRequestDto\""); + stringBuilder.append(", \"sourceFormat\":"); + stringBuilder.append(stringOf(convertFormatRequestDto.getSourceFormat())); + stringBuilder.append(", \"targetFormat\": "); + stringBuilder.append(stringOf(convertFormatRequestDto.getTargetFormat())); + stringBuilder.append(", \"modalitiesToConvert\": "); + stringBuilder.append(stringOf(convertFormatRequestDto.getModalitiesToConvert())); + stringBuilder.append(", \"sample\": "); + appendString(convertFormatRequestDto.getSample(), stringBuilder); + stringBuilder.append(", \"sourceParams\":"); + stringBuilder.append(stringOf(convertFormatRequestDto.getSourceParams())); + stringBuilder.append(", \"targetParams\": "); + stringBuilder.append(stringOf(convertFormatRequestDto.getTargetParams())); + appendString(convertFormatRequestDto.getSample(), stringBuilder); + stringBuilder.append(" }"); + return stringBuilder.toString(); + } - private String utcDateTimePattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; + public String toString(BDBInfo bdbInfo) { + if (bdbInfo == null) { + return "null"; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"BDBInfo\""); + stringBuilder.append(", \"challengeResponseHash\":"); + stringBuilder.append(getHashOfBytes(bdbInfo.getChallengeResponse())); + stringBuilder.append(", \"index\": "); + stringBuilder.append(stringOf(bdbInfo.getIndex())); + stringBuilder.append(", \"format\": "); + stringBuilder.append(stringOf(bdbInfo.getFormat())); + stringBuilder.append(", \"encryption\":"); + stringBuilder.append(booleanAsString(bdbInfo.getEncryption())); + stringBuilder.append(", \"creationDate\": "); + stringBuilder.append(stringOf(dateAsString(bdbInfo.getCreationDate()))); + stringBuilder.append(", \"notValidBefore\": "); + stringBuilder.append(stringOf(dateAsString(bdbInfo.getNotValidBefore()))); + stringBuilder.append(", \"notValidAfter\": "); + stringBuilder.append(stringOf(dateAsString(bdbInfo.getNotValidAfter()))); + stringBuilder.append(", \"type\": "); + stringBuilder.append(stringOf(bdbInfo.getType())); + stringBuilder.append(", \"subtype\": "); + stringBuilder.append(stringOf(bdbInfo.getSubtype())); + stringBuilder.append(", \"level\": "); + stringBuilder.append(stringOf(bdbInfo.getLevel())); + stringBuilder.append(", \"product\": "); + stringBuilder.append(stringOf(bdbInfo.getProduct())); + stringBuilder.append(", \"captureDevice\": "); + stringBuilder.append(stringOf(bdbInfo.getCaptureDevice())); + stringBuilder.append(", \"featureExtractionAlgorithm\": "); + stringBuilder.append(stringOf(bdbInfo.getFeatureExtractionAlgorithm())); + stringBuilder.append(", \"comparisonAlgorithm\": "); + stringBuilder.append(stringOf(bdbInfo.getComparisonAlgorithm())); + stringBuilder.append(", \"compressionAlgorithm\": "); + stringBuilder.append(stringOf(bdbInfo.getCompressionAlgorithm())); + stringBuilder.append(", \"purpose\": "); + stringBuilder.append(stringOf(bdbInfo.getPurpose())); + stringBuilder.append(", \"quality\": "); + stringBuilder.append(stringOf(bdbInfo.getQuality())); + stringBuilder.append(" }"); + return stringBuilder.toString(); + } - public String getCurrentResponseTime() { - return DateUtils.formatDate(new Date(System.currentTimeMillis()), utcDateTimePattern); - } + public String toString(BIRInfo birInfo) { + if (birInfo == null) { + return "null"; + } + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("{"); + stringBuilder.append(" \"_modelClass\": \"BIRInfo\""); + stringBuilder.append(", \"creator\": "); + stringBuilder.append(stringOf(birInfo.getCreator())); + stringBuilder.append(", \"index\": "); + stringBuilder.append(stringOf(birInfo.getIndex())); + stringBuilder.append(", \"payloadHash\":"); + stringBuilder.append(getHashOfBytes(birInfo.getPayload())); + stringBuilder.append(", \"integrity\":"); + stringBuilder.append(booleanAsString(birInfo.getIntegrity())); + stringBuilder.append(", \"creationDate\": "); + stringBuilder.append(stringOf(dateAsString(birInfo.getCreationDate()))); + stringBuilder.append(", \"notValidBefore\": "); + stringBuilder.append(stringOf(dateAsString(birInfo.getNotValidBefore()))); + stringBuilder.append(", \"notValidAfter\": "); + stringBuilder.append(stringOf(dateAsString(birInfo.getNotValidAfter()))); + stringBuilder.append(" }"); + return stringBuilder.toString(); + } - public RequestDto getRequestInfo(String request) throws ParseException { - return gson.fromJson(request, RequestDto.class); - } + private String dateAsString(LocalDateTime localDateTime) { + return localDateTime == null ? "null" : DateUtils.formatToISOString(localDateTime); + } - public static String base64Decode(String data){ - return new String(Base64.getDecoder().decode(data), StandardCharsets.UTF_8); - } -} + private static String booleanAsString(Boolean bool) { + return bool == null ? "null" : Boolean.toString(bool); + } +} \ No newline at end of file diff --git a/biosdk-services/src/main/resources/application-local.properties b/biosdk-services/src/main/resources/application-local.properties new file mode 100644 index 00000000..f8651016 --- /dev/null +++ b/biosdk-services/src/main/resources/application-local.properties @@ -0,0 +1,10 @@ +#iam mock-sdk config +sdk_check_iso_timestamp_format=true +biosdk_class=io.mosip.mock.sdk.impl.SampleSDKV2 +mosip.role.biosdk.getservicestatus=REGISTRATION_PROCESSOR +biosdk_bioapi_impl=io.mosip.mock.sdk.impl.SampleSDKV2 + +#iam image-compressor config +mosip.bio.image.compressor.resize.factor.fx=0.25 +mosip.bio.image.compressor.resize.factor.fy=0.25 +mosip.bio.image.compressor.compression.ratio=50 \ No newline at end of file diff --git a/biosdk-services/src/main/resources/application.properties b/biosdk-services/src/main/resources/application.properties index 137e258c..60c3d459 100644 --- a/biosdk-services/src/main/resources/application.properties +++ b/biosdk-services/src/main/resources/application.properties @@ -1,6 +1,33 @@ server.port=9099 -spring.cloud.config.enabled=false +spring.cloud.config.enabled=true security.basic.enabled=false -#server.servlet.context-path=/biosdk-service +server.servlet.context-path=/biosdk-service +biosdk_bioapi_impl=io.mosip.mock.sdk.impl.SampleSDKV2 #logging.level.org.springframework=DEBUG +spring.application.name=biosdk-service +spring.cloud.config.name=application,biosdk-service +spring.profiles.active=default +spring.cloud.config.label=master + + +## Tomcat access logs +server.tomcat.accesslog.enabled=true +server.tomcat.accesslog.directory=/dev +server.tomcat.accesslog.prefix=stdout +server.tomcat.accesslog.buffered=false +server.tomcat.accesslog.suffix= +server.tomcat.accesslog.file-date-format= +server.tomcat.accesslog.pattern={"@timestamp":"%{yyyy-MM-dd'T'HH:mm:ss.SSS'Z'}t","level":"ACCESS","level_value":70000,"traceId":"%{X-B3-TraceId}i","statusCode":%s,"req.requestURI":"%U","bytesSent":%b,"timeTaken":%T,"appName":"${spring.application.name}","req.userAgent":"%{User-Agent}i","req.xForwardedFor":"%{X-Forwarded-For}i","req.referer":"%{Referer}i","req.method":"%m","req.remoteHost":"%a"} +server.tomcat.accesslog.className=io.mosip.kernel.core.logger.config.SleuthValve + + mosip.role.biosdk.getservicestatus=REGISTRATION_PROCESSOR +health.config.enabled=false +management.security.enable=false +management.endpoint.health.show-details=always +management.endpoints.web.exposure.include=info,health,refresh,mappings,env +management.endpoint.metrics.enabled=true +management.endpoint.prometheus.enabled=true +management.metrics.export.prometheus.enabled=true + +logging.level.root=INFO \ No newline at end of file diff --git a/biosdk-services/src/main/resources/bootstrap.properties b/biosdk-services/src/main/resources/bootstrap.properties new file mode 100644 index 00000000..d30aa7d5 --- /dev/null +++ b/biosdk-services/src/main/resources/bootstrap.properties @@ -0,0 +1,30 @@ +spring.cloud.config.uri=http://localhost:51000/config +spring.cloud.config.label=master +spring.profiles.active=default +spring.application.name=biosdk-service +spring.cloud.config.name=application,biosdk-service +server.port=9099 +security.basic.enabled=false +server.servlet.context-path=/biosdk-service + +spring.cloud.config.enabled=true +server.servlet.context-path=/biosdk-service +health.config.enabled=false +management.security.enable=false +management.endpoint.health.show-details=always +management.endpoints.web.exposure.include=info,health,refresh,mappings,env +management.endpoint.metrics.enabled=true +management.endpoint.prometheus.enabled=true +management.metrics.export.prometheus.enabled=true + +#logging.level.org.springframework=DEBUG + +#iam mock-sdk config +sdk_check_iso_timestamp_format=true +mosip.role.biosdk.getservicestatus=REGISTRATION_PROCESSOR +biosdk_bioapi_impl=io.mosip.mock.sdk.impl.SampleSDKV2 + +#iam image-compressor config +mosip.bio.image.compressor.resize.factor.fx=0.25 +mosip.bio.image.compressor.resize.factor.fy=0.25 +mosip.bio.image.compressor.compression.ratio=50