Skip to content

Commit

Permalink
PI-1223 Create initial project for external-api-and-delius (#1922)
Browse files Browse the repository at this point in the history
* PI-1223 Create initial project for external-api-and-delius

* Appease the linter

* PI-1223

* Ignore info-level shellcheck issues

* Fix SC2046 - handle spaces in project names

---------

Co-authored-by: Marcus Aspin <[email protected]>
Co-authored-by: Anthony Britton <[email protected]>
Co-authored-by: Anthony Britton <[email protected]>
  • Loading branch information
4 people authored Jul 7, 2023
1 parent af789ec commit 2938156
Show file tree
Hide file tree
Showing 44 changed files with 689 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/actionlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
self-hosted-runner:
labels:
- moj-cloud-platform
1 change: 1 addition & 0 deletions .github/workflows/access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ on:
- '["custody-key-dates-and-delius"]'
- '["domain-events-and-delius"]'
- '["effective-proposal-framework-and-delius"]'
- '["external-api-and-delius"]'
- '["make-recall-decisions-and-delius"]'
- '["manage-pom-cases-and-delius"]'
- '["offender-events-and-delius"]'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
- custody-key-dates-and-delius
- domain-events-and-delius
- effective-proposal-framework-and-delius
- external-api-and-delius
- make-recall-decisions-and-delius
- manage-pom-cases-and-delius
- offender-events-and-delius
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ jobs:
VALIDATE_RUBY: true
VALIDATE_XML: true
VALIDATE_YAML: true
LINTER_RULES_PATH: /
GITHUB_ACTIONS_CONFIG_FILE: .github/actionlint.yml
GITHUB_ACTIONS_COMMAND_ARGS: -ignore=SC.+:info:.+
GITHUB_TOKEN: ${{ github.token }}
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ on:
- '["create-and-vary-a-licence-and-delius"]'
- '["custody-key-dates-and-delius"]'
- '["effective-proposal-framework-and-delius"]'
- '["external-api-and-delius"]'
- '["make-recall-decisions-and-delius"]'
- '["manage-pom-cases-and-delius"]'
- '["offender-events-and-delius"]'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ on:
- '["custody-key-dates-and-delius"]'
- '["domain-events-and-delius"]'
- '["effective-proposal-framework-and-delius"]'
- '["external-api-and-delius"]'
- '["make-recall-decisions-and-delius"]'
- '["manage-pom-cases-and-delius"]'
- '["offender-events-and-delius"]'
Expand Down Expand Up @@ -162,8 +163,7 @@ jobs:
run: |
mv artifacts/index/ tech-docs
mkdir -p tech-docs/projects
ls artifacts | xargs -I{} mv artifacts/{}/ tech-docs/projects/{}
find artifacts -mindepth 1 -maxdepth 1 -printf "%f\n" -print0 | xargs -0 -I{} mv 'artifacts/{}/' 'tech-docs/projects/{}/' \;
find projects -mindepth 1 -maxdepth 1 -execdir mv 'artifacts/{}/' 'tech-docs/projects/{}/' \;
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ on:
- '["custody-key-dates-and-delius"]'
- '["domain-events-and-delius"]'
- '["effective-proposal-framework-and-delius"]'
- '["external-api-and-delius"]'
- '["make-recall-decisions-and-delius"]'
- '["manage-pom-cases-and-delius"]'
- '["offender-events-and-delius"]'
Expand Down Expand Up @@ -97,7 +98,7 @@ jobs:
run: npx playwright install
- name: Run Playwright tests
id: tests
run: npx playwright test --reporter=html,junit,json,line $(echo '${{ env.projects }}' | jq -r 'join(" ")')
run: echo '${{ env.projects }}' | jq -r '.[]' | xargs npx playwright test --reporter=html,junit,json,line
env:
TZ: Europe/London
ENV: test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/schema-spy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
target-folder: schema-spy-report

- name: Add HTML report URL to the job summary
run: echo '[Schema Spy HTML Report](https://ministryofjustice.github.io/hmpps-probation-integration-services/schema-spy-report)' >> $GITHUB_STEP_SUMMARY
run: echo '[Schema Spy HTML Report](https://ministryofjustice.github.io/hmpps-probation-integration-services/schema-spy-report)' | tee -a "$GITHUB_STEP_SUMMARY"
1 change: 1 addition & 0 deletions .github/workflows/suppress-trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ on:
- custody-key-dates-and-delius
- domain-events-and-delius
- effective-proposal-framework-and-delius
- external-api-and-delius
- make-recall-decisions-and-delius
- manage-pom-cases-and-delius
- offender-events-and-delius
Expand Down
12 changes: 12 additions & 0 deletions .idea/runConfigurations/external_api_and_delius.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions doc/tech-docs/source/index.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ Follow these links to find out more about each of our integration services.
* [Tier To Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/tier-to-delius)
* [Unpaid Work And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/unpaid-work-and-delius)
* [Workforce Allocations To Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/workforce-allocations-to-delius)
* [External Api And Delius](https://ministryofjustice.github.io/hmpps-probation-integration-services/tech-docs/projects/external-api-and-delius)
<li style="display: none">^ add new projects here</li>

Empty file.
3 changes: 3 additions & 0 deletions projects/external-api-and-delius/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# external-api-and-delius

// TODO Describe the service
40 changes: 40 additions & 0 deletions projects/external-api-and-delius/applicationinsights.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"role": {
"name": "external-api-and-delius"
},
"customDimensions": {
"service.version": "${VERSION}",
"service.team": "probation-integration"
},
"instrumentation": {
"logging": {
"level": "DEBUG"
},
"springScheduling": {
"enabled": false
}
},
"selfDiagnostics": {
"destination": "console"
},
"sampling": {
"percentage": 100
},
"preview": {
"sampling": {
"overrides": [
{
"telemetryType": "request",
"attributes": [
{
"key": "http.url",
"value": "https?://[^/]+/health/?.*",
"matchType": "regexp"
}
],
"percentage": 0
}
]
}
}
}
37 changes: 37 additions & 0 deletions projects/external-api-and-delius/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import uk.gov.justice.digital.hmpps.extensions.ClassPathExtension

apply(plugin = "com.google.cloud.tools.jib")

dependencies {
implementation(project(":libs:audit"))
implementation(project(":libs:commons"))
implementation(project(":libs:oauth-client"))
implementation(project(":libs:oauth-server"))

implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation(libs.springdoc)

dev(project(":libs:dev-tools"))
dev("com.h2database:h2")
dev("org.testcontainers:oracle-xe")

runtimeOnly("com.oracle.database.jdbc:ojdbc11")

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation(libs.bundles.mockito)
}

configure<ClassPathExtension> {
jacocoExclusions = listOf(
"**/config/**",
"**/entity/**",
"**/AppKt.class"
)
}
13 changes: 13 additions & 0 deletions projects/external-api-and-delius/deploy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v2
appVersion: '1.0'
description: A Helm chart for Kubernetes
name: external-api-and-delius
version: 1.0.0

dependencies:
- name: generic-service
version: 2.6.0
repository: https://ministryofjustice.github.io/hmpps-helm-charts
- name: generic-prometheus-alerts
version: 1.3.0
repository: https://ministryofjustice.github.io/hmpps-helm-charts
9 changes: 9 additions & 0 deletions projects/external-api-and-delius/deploy/database/access.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
database:
access:
username_key: /external-api-and-delius/db-username
password_key: /external-api-and-delius/db-password

audit:
username: ExternalApiAndDelius
forename: External API
surname: Service
18 changes: 18 additions & 0 deletions projects/external-api-and-delius/deploy/values-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
enabled: false # TODO set this to true when you're ready to deploy your service

generic-service:
ingress:
host: external-api-and-delius-dev.hmpps.service.justice.gov.uk

scheduledDowntime:
enabled: true

env:
SENTRY_ENVIRONMENT: dev
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer

LOGGING_LEVEL_UK_GOV_DIGITAL_JUSTICE_HMPPS: DEBUG

generic-prometheus-alerts:
businessHoursOnly: true
16 changes: 16 additions & 0 deletions projects/external-api-and-delius/deploy/values-preprod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
enabled: false # TODO set this to true when you're ready to deploy your service

generic-service:
ingress:
host: external-api-and-delius-preprod.hmpps.service.justice.gov.uk

scheduledDowntime:
enabled: true

env:
SENTRY_ENVIRONMENT: preprod
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in-preprod.hmpps.service.justice.gov.uk/auth/issuer

generic-prometheus-alerts:
businessHoursOnly: true
10 changes: 10 additions & 0 deletions projects/external-api-and-delius/deploy/values-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enabled: false # TODO set this to true when you're ready to deploy your service

generic-service:
ingress:
host: external-api-and-delius.hmpps.service.justice.gov.uk

env:
SENTRY_ENVIRONMENT: prod
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/.well-known/jwks.json
SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI: https://sign-in.hmpps.service.justice.gov.uk/auth/issuer
22 changes: 22 additions & 0 deletions projects/external-api-and-delius/deploy/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Common values
generic-service:
nameOverride: external-api-and-delius

image:
repository: ghcr.io/ministryofjustice/hmpps-probation-integration-services/external-api-and-delius

ingress:
tlsSecretName: external-api-and-delius-cert

namespace_secrets:
common:
SPRING_DATASOURCE_URL: DB_URL
external-api-and-delius-database:
SPRING_DATASOURCE_USERNAME: DB_USERNAME
SPRING_DATASOURCE_PASSWORD: DB_PASSWORD
external-api-and-delius-sentry:
SENTRY_DSN: SENTRY_DSN

generic-prometheus-alerts:
targetApplication: external-api-and-delius

1 change: 1 addition & 0 deletions projects/external-api-and-delius/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "external-api-and-delius"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package uk.gov.justice.digital.hmpps.data

import jakarta.annotation.PostConstruct
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.ApplicationListener
import org.springframework.stereotype.Component
import uk.gov.justice.digital.hmpps.data.generator.UserGenerator
import uk.gov.justice.digital.hmpps.user.AuditUserRepository

@Component
@ConditionalOnProperty("seed.database")
class DataLoader(
private val auditUserRepository: AuditUserRepository
) : ApplicationListener<ApplicationReadyEvent> {

@PostConstruct
fun saveAuditUser() {
auditUserRepository.save(UserGenerator.AUDIT_USER)
}

override fun onApplicationEvent(are: ApplicationReadyEvent) {
// Perform dev/test database setup here, using JPA repositories and generator classes...
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package uk.gov.justice.digital.hmpps.data.generator

import uk.gov.justice.digital.hmpps.user.AuditUser

object UserGenerator {
val AUDIT_USER = AuditUser(IdGenerator.getAndIncrement(), "ExternalApiAndDelius")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDo3hw1/oChbttEOxEH4NUDrH+Y
n2x0DavAmDjMbhcSiQ6+/t8Nz/N03BauWzFOGBtftnQrHfnF+O7RAKj8zMjcbIq4
QrYeXEpnaFCGEwTtOBpxvSEWPrLEpr1gCarBQZDp67ag+SYqrDgkn2Vme/dMvMUQ
xUO3DT6jg9921J6TlwIDAQAB
-----END PUBLIC KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJwcm9iYXRpb24taW50ZWdyYXRpb24tZGV2IiwiZ3JhbnRfdHlwZSI6ImNsaWVudF9jcmVkZW50aWFscyIsInVzZXJfbmFtZSI6InByb2JhdGlvbi1pbnRlZ3JhdGlvbi1kZXYiLCJzY29wZSI6WyJyZWFkIiwid3JpdGUiXSwiYXV0aF9zb3VyY2UiOiJub25lIiwiaXNzIjoiaHR0cHM6Ly9zaWduLWluLWRldi5obXBwcy5zZXJ2aWNlLmp1c3RpY2UuZ292LnVrL2F1dGgvaXNzdWVyIiwiZXhwIjo5OTk5OTk5OTk5LCJhdXRob3JpdGllcyI6WyJST0xFX0VYQU1QTEUiLCJST0xFX1dPUktMT0FEX1JFQUQiLCJST0xFX0FMTE9DQVRJT05fQ09OVEVYVCJdLCJqdGkiOiIyNUR1Um4xLWh5SFpld0xjZEpKeHdWTDAzS1UiLCJjbGllbnRfaWQiOiJwcm9iYXRpb24taW50ZWdyYXRpb24tZGV2IiwiaWF0IjoxNjYzNzU3MzExfQ.5FTCUjA7QZMPxO_EMzkGNSM-IkPk2hfPXyzuNiAa7uuqYva_yCducrC5FdetAiC1W6XpUB7wfoMNDmbW2xepj5oRhcxDx18r92aLPYnKkxaA68hLQF90euMtTzfBzOPg-rKDTNIJKrUC-YoQlFKuCauw0Z5cw1XT6R9GIfi5Yx4",
"token_type": "bearer",
"expires_in": 9999999999,
"scope": "read write",
"sub": "probation-integration-dev",
"auth_source": "none",
"jti": "fN29JHJy1N7gcYvqe-8B_k5T0mA",
"iss": "https://sign-in-dev.hmpps.service.justice.gov.uk/auth/issuer"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"request": {
"method": "POST",
"urlPath": "/auth/oauth/token"
},
"response": {
"headers": {
"Content-Type": "application/json"
},
"status": 200,
"bodyFileName": "hmpps-auth-token-body.json"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package uk.gov.justice.digital.hmpps

import com.github.tomakehurst.wiremock.WireMockServer
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import uk.gov.justice.digital.hmpps.security.withOAuth2Token
import uk.gov.justice.digital.hmpps.telemetry.TelemetryService

@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = RANDOM_PORT)
internal class IntegrationTest {
@Autowired lateinit var mockMvc: MockMvc

@Autowired lateinit var wireMockServer: WireMockServer

@MockBean lateinit var telemetryService: TelemetryService

@Test
fun `API call retuns a success response`() {
mockMvc
.perform(get("/example/123").withOAuth2Token(wireMockServer))
.andExpect(status().is2xxSuccessful)
}
}
Loading

0 comments on commit 2938156

Please sign in to comment.