From 37c73c3f8f0912ec4c4f87921e097e35c5e7c350 Mon Sep 17 00:00:00 2001 From: soletsdev Date: Wed, 20 Mar 2024 15:23:38 -0700 Subject: [PATCH 1/5] quick fix for openshift alerts --- .github/workflows/deploy-to.openshift-dev.yml | 2 +- .github/workflows/deploy-to.openshift-prod.yml | 2 +- .github/workflows/deploy-to.openshift-test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-to.openshift-dev.yml b/.github/workflows/deploy-to.openshift-dev.yml index edf037ba..9b61edf4 100644 --- a/.github/workflows/deploy-to.openshift-dev.yml +++ b/.github/workflows/deploy-to.openshift-dev.yml @@ -34,7 +34,7 @@ env: COMMON_NAMESPACE: ${{ secrets.COMMON_NAMESPACE_NO_ENV }} TAG: "latest" MIN_REPLICAS_DEV: "1" - MAX_REPLICAS_DEV: "1" + MAX_REPLICAS_DEV: "2" MIN_CPU: "250m" MAX_CPU: "500m" MIN_MEM: "1Gi" diff --git a/.github/workflows/deploy-to.openshift-prod.yml b/.github/workflows/deploy-to.openshift-prod.yml index 361fd68e..5db12ebe 100644 --- a/.github/workflows/deploy-to.openshift-prod.yml +++ b/.github/workflows/deploy-to.openshift-prod.yml @@ -30,7 +30,7 @@ env: TAG: "latest" TARGET_ENV: "prod" MIN_REPLICAS: "3" - MAX_REPLICAS: "3" + MAX_REPLICAS: "4" MIN_CPU: "250m" MAX_CPU: "500m" MIN_MEM: "1Gi" diff --git a/.github/workflows/deploy-to.openshift-test.yml b/.github/workflows/deploy-to.openshift-test.yml index 3ccc4f57..25f9e874 100644 --- a/.github/workflows/deploy-to.openshift-test.yml +++ b/.github/workflows/deploy-to.openshift-test.yml @@ -33,7 +33,7 @@ env: COMMON_NAMESPACE: ${{ secrets.COMMON_NAMESPACE_NO_ENV }} TAG: ${{ github.event.inputs.tag }} MIN_REPLICAS_TEST: "2" - MAX_REPLICAS_TEST: "2" + MAX_REPLICAS_TEST: "3" MIN_CPU: "250m" MAX_CPU: "500m" MIN_MEM: "1Gi" From ef3f1d4d5d67d04657ab861f05878dde4b6da72b Mon Sep 17 00:00:00 2001 From: So Date: Wed, 25 Sep 2024 08:40:11 -0700 Subject: [PATCH 2/5] github actions update and fix to only gather active student registration contacts --- .github/dependabot.yml | 11 +++++++++++ .github/workflows/ci-api-build.and.test.yml | 12 ++++++------ .github/workflows/deploy-to.openshift-dev.yml | 9 ++++----- .github/workflows/deploy-to.openshift-prod.yml | 7 +++---- .github/workflows/deploy-to.openshift-test.yml | 4 ++-- .../tag-create.git.and.imagestream.tag.yml | 6 +++--- .../bc/gov/educ/penreg/api/rest/RestUtils.java | 9 ++++++++- .../gov/educ/penreg/api/rest/RestUtilsTest.java | 17 ++++++++++------- 8 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..0a53f11d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.github/workflows/ci-api-build.and.test.yml b/.github/workflows/ci-api-build.and.test.yml index d188064a..2787f03c 100644 --- a/.github/workflows/ci-api-build.and.test.yml +++ b/.github/workflows/ci-api-build.and.test.yml @@ -25,14 +25,14 @@ jobs: working-directory: api steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-java@v3 + - uses: actions/setup-java@v4 with: java-version: 17 distribution: oracle - - uses: actions/cache@v3 + - uses: actions/cache@v4 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} @@ -41,7 +41,7 @@ jobs: - name: Run unit tests run: mvn -f pom.xml clean package - name: Cache SonarCloud packages - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.sonar/cache key: ${{ runner.os }}-sonar @@ -54,7 +54,7 @@ jobs: env: GITHUB_TOKEN: ${{ github.token }} - name: Run Trivy vulnerability scanner in repo mode - uses: aquasecurity/trivy-action@0.10.0 + uses: aquasecurity/trivy-action@0.24.0 with: scan-type: 'fs' ignore-unfixed: true @@ -63,6 +63,6 @@ jobs: severity: 'CRITICAL' - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@v3 with: sarif_file: 'trivy-results.sarif' diff --git a/.github/workflows/deploy-to.openshift-dev.yml b/.github/workflows/deploy-to.openshift-dev.yml index ba74118f..188b5c4b 100644 --- a/.github/workflows/deploy-to.openshift-dev.yml +++ b/.github/workflows/deploy-to.openshift-dev.yml @@ -49,7 +49,6 @@ on: jobs: build-and-deploy-dev: name: Build and deploy to OpenShift DEV - # ubuntu-20.04 can also be used. runs-on: ubuntu-22.04 environment: dev @@ -59,7 +58,7 @@ jobs: steps: - name: Check for required secrets - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: script: | const secrets = { @@ -93,14 +92,14 @@ jobs: core.info(`✅ All the required secrets are set`); } - name: Check out repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Determine image tags if: env.IMAGE_TAGS == '' run: | echo "IMAGE_TAGS=latest ${GITHUB_SHA::12}" | tee -a $GITHUB_ENV - name: Login to Docker Hub - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ${{ env.DOCKER_ARTIFACTORY_REPO }} username: ${{ secrets.DOCKER_HUB_USERNAME }} @@ -138,7 +137,7 @@ jobs: oc: 4 # https://github.com/redhat-actions/oc-login#readme - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Deploy API run: | diff --git a/.github/workflows/deploy-to.openshift-prod.yml b/.github/workflows/deploy-to.openshift-prod.yml index 1f02e5fb..527a9747 100644 --- a/.github/workflows/deploy-to.openshift-prod.yml +++ b/.github/workflows/deploy-to.openshift-prod.yml @@ -43,7 +43,6 @@ on: jobs: openshift-ci-cd: name: Deploy to OpenShift PROD - # ubuntu-20.04 can also be used. runs-on: ubuntu-22.04 environment: production @@ -53,7 +52,7 @@ jobs: steps: - name: Check for required secrets - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: script: | const secrets = { @@ -91,7 +90,7 @@ jobs: } - name: Check out repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Get latest tag uses: actions-ecosystem/action-get-latest-tag@v1 @@ -103,7 +102,7 @@ jobs: oc: 4 # https://github.com/redhat-actions/oc-login#readme - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Deploy API run: | diff --git a/.github/workflows/deploy-to.openshift-test.yml b/.github/workflows/deploy-to.openshift-test.yml index 06c71389..69fec820 100644 --- a/.github/workflows/deploy-to.openshift-test.yml +++ b/.github/workflows/deploy-to.openshift-test.yml @@ -60,7 +60,7 @@ jobs: steps: - name: Check for required secrets - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: script: | const secrets = { @@ -98,7 +98,7 @@ jobs: } - name: Check out repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install oc uses: redhat-actions/openshift-tools-installer@v1 diff --git a/.github/workflows/tag-create.git.and.imagestream.tag.yml b/.github/workflows/tag-create.git.and.imagestream.tag.yml index 57b1f8a8..64c6cb6f 100644 --- a/.github/workflows/tag-create.git.and.imagestream.tag.yml +++ b/.github/workflows/tag-create.git.and.imagestream.tag.yml @@ -33,10 +33,10 @@ jobs: steps: - name: Check out repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Create tag - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: script: | github.rest.git.createRef({ @@ -52,7 +52,7 @@ jobs: oc: 4 # https://github.com/redhat-actions/oc-login#readme - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Tag in OpenShift run: | set -eux diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java index cc7fcf76..d05d6371 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java @@ -14,6 +14,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.Sets; +import java.time.*; +import java.time.format.*; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import lombok.val; @@ -399,7 +401,12 @@ public List getStudentRegistrationContactList(final String mincod throw new PenRegAPIRuntimeException("API call to Institute API received null response when getting student registration contacts, contact the Ministry for more info."); } - return schoolContactSearchWrapper.getContent(); + List activeStudentRegistrationContacts = schoolContactSearchWrapper.getContent().stream().filter(contact -> { + final String expiryDate = contact.getExpiryDate(); + return contact.getExpiryDate() == null || (expiryDate != null && LocalDate.parse(expiryDate, DateTimeFormatter.ISO_LOCAL_DATE).isAfter(LocalDate.now())); + }).toList(); + + return activeStudentRegistrationContacts; }catch(Exception e){ log.error("API call to Institute API failure getting student registration contacts :: {}", e.getMessage()); throw new PenRegAPIRuntimeException("API call to Institute API failure getting student registration contacts, contact the Ministry for more info."); diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java index 30612bd2..6905f66e 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.nats.client.Message; import java.net.*; +import java.time.*; import java.util.*; import lombok.val; import org.junit.Before; @@ -108,8 +109,10 @@ private GradeCode[] createGradeCodeArray() { private SchoolContactSearchWrapper createSchoolContactSearchWrapper() { SchoolContactSearchWrapper schoolSearchWrapper = new SchoolContactSearchWrapper(); - schoolSearchWrapper.setContent(Arrays.asList(SchoolContact.builder().email("pen@email.com").firstName("Joe").lastName("Blow").build(), - SchoolContact.builder().email("2@email.com").firstName("2").lastName("2").build())); + schoolSearchWrapper.setContent(Arrays.asList( + SchoolContact.builder().email("expired@email.com").firstName("Joe").lastName("Blow").expiryDate(LocalDate.now().minusDays(1).toString()).build(), + SchoolContact.builder().email("active@email.com").firstName("2").lastName("2").expiryDate(null).build(), + SchoolContact.builder().email("active@email.com").firstName("Joe").lastName("Blow").expiryDate(LocalDate.now().plusDays(1).toString()).build())); return schoolSearchWrapper; } @@ -234,7 +237,7 @@ public void testGetGradeCode_shouldReturnData() { } @Test - public void testGetStudentRegistrationContacts_shouldReturnData() { + public void testGetStudentRegistrationContacts_withExpiredContacts_shouldReturnData() { when(this.webClient.get()).thenReturn(this.requestHeadersUriMock); when(this.requestHeadersUriMock.uri(any(URI.class))) .thenReturn(this.requestHeadersMock); @@ -246,10 +249,10 @@ public void testGetStudentRegistrationContacts_shouldReturnData() { final var result = this.restUtils.getStudentRegistrationContactList("10200001"); assertThat(result).hasSize(2); - assertThat(result.get(0).getEmail()).isEqualTo("pen@email.com"); - assertThat(result.get(0).getFirstName()).isEqualTo("Joe"); - assertThat(result.get(1).getEmail()).isEqualTo("2@email.com"); - assertThat(result.get(1).getFirstName()).isEqualTo("2"); + assertThat(result.get(0).getEmail()).isEqualTo("active@email.com"); + assertThat(result.get(0).getFirstName()).isEqualTo("2"); + assertThat(result.get(1).getEmail()).isEqualTo("active@email.com"); + assertThat(result.get(1).getFirstName()).isEqualTo("Joe"); } private WebClient.RequestBodySpec returnMockBodySpec() { From 3e24f1acf9a07b9f37b47cd710d4ad7e486db818 Mon Sep 17 00:00:00 2001 From: soletsdev Date: Wed, 25 Sep 2024 08:59:50 -0700 Subject: [PATCH 3/5] fixing test and changing to localDateTime --- .../penreg/api/batch/processor/PenRegBatchProcessorTest.java | 2 +- .../java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessorTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessorTest.java index 9f8b9ca5..1da551c1 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessorTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/batch/processor/PenRegBatchProcessorTest.java @@ -713,7 +713,7 @@ public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolCloseDate @Transactional public void testProcessPenRegBatchFileFromTSW_GivenmincodeInvalidSchoolOpenDate_ShouldCreateRecordLOADFAILInDB() throws IOException { final School school = this.createMockSchool(); - school.setOpenedDate("2024-09-01T00:00:00"); + school.setOpenedDate(LocalDateTime.now().plusYears(1).toString()); when(this.restUtils.getSchoolByMincode(anyString())).thenReturn(Optional.of(school)); final File file = new File(Objects.requireNonNull(this.getClass().getClassLoader().getResource("sample_5_K12_OK.txt")).getFile()); final byte[] bFile = Files.readAllBytes(file.toPath()); diff --git a/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java b/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java index 6905f66e..2cbaa479 100644 --- a/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java +++ b/api/src/test/java/ca/bc/gov/educ/penreg/api/rest/RestUtilsTest.java @@ -110,9 +110,9 @@ private GradeCode[] createGradeCodeArray() { private SchoolContactSearchWrapper createSchoolContactSearchWrapper() { SchoolContactSearchWrapper schoolSearchWrapper = new SchoolContactSearchWrapper(); schoolSearchWrapper.setContent(Arrays.asList( - SchoolContact.builder().email("expired@email.com").firstName("Joe").lastName("Blow").expiryDate(LocalDate.now().minusDays(1).toString()).build(), + SchoolContact.builder().email("expired@email.com").firstName("Joe").lastName("Blow").expiryDate(LocalDateTime.now().minusDays(1).toString()).build(), SchoolContact.builder().email("active@email.com").firstName("2").lastName("2").expiryDate(null).build(), - SchoolContact.builder().email("active@email.com").firstName("Joe").lastName("Blow").expiryDate(LocalDate.now().plusDays(1).toString()).build())); + SchoolContact.builder().email("active@email.com").firstName("Joe").lastName("Blow").expiryDate(LocalDateTime.now().plusDays(1).toString()).build())); return schoolSearchWrapper; } From 6dbce1655c5bcb9d05cd670fcb94733df0d3b2ac Mon Sep 17 00:00:00 2001 From: soletsdev Date: Wed, 25 Sep 2024 09:05:37 -0700 Subject: [PATCH 4/5] test fix using date time formatter --- api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java index d05d6371..b4f01764 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java @@ -403,7 +403,7 @@ public List getStudentRegistrationContactList(final String mincod List activeStudentRegistrationContacts = schoolContactSearchWrapper.getContent().stream().filter(contact -> { final String expiryDate = contact.getExpiryDate(); - return contact.getExpiryDate() == null || (expiryDate != null && LocalDate.parse(expiryDate, DateTimeFormatter.ISO_LOCAL_DATE).isAfter(LocalDate.now())); + return contact.getExpiryDate() == null || (expiryDate != null && LocalDate.parse(expiryDate, DateTimeFormatter.ISO_DATE_TIME).isAfter(LocalDate.now())); }).toList(); return activeStudentRegistrationContacts; From fd1266f81dfc6117f0950c0b98439c3ded393fb7 Mon Sep 17 00:00:00 2001 From: soletsdev Date: Wed, 25 Sep 2024 09:11:48 -0700 Subject: [PATCH 5/5] addressesing sonar cloud --- .../main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java index b4f01764..758d1689 100644 --- a/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java +++ b/api/src/main/java/ca/bc/gov/educ/penreg/api/rest/RestUtils.java @@ -401,12 +401,10 @@ public List getStudentRegistrationContactList(final String mincod throw new PenRegAPIRuntimeException("API call to Institute API received null response when getting student registration contacts, contact the Ministry for more info."); } - List activeStudentRegistrationContacts = schoolContactSearchWrapper.getContent().stream().filter(contact -> { + return schoolContactSearchWrapper.getContent().stream().filter(contact -> { final String expiryDate = contact.getExpiryDate(); return contact.getExpiryDate() == null || (expiryDate != null && LocalDate.parse(expiryDate, DateTimeFormatter.ISO_DATE_TIME).isAfter(LocalDate.now())); }).toList(); - - return activeStudentRegistrationContacts; }catch(Exception e){ log.error("API call to Institute API failure getting student registration contacts :: {}", e.getMessage()); throw new PenRegAPIRuntimeException("API call to Institute API failure getting student registration contacts, contact the Ministry for more info.");