Skip to content

Commit 6a67a48

Browse files
NPA-6139: Up Rate Limit, Update App Imports Plus Check for Allowed Li… (#81)
…st of URLs # Pull Request ## 🧾 Ticket Link https://nhsd-jira.digital.nhs.uk/browse/NPA-6139 --- ## 📄 Description/Summary of Changes <!-- Describe the changes made in this PR. Include the purpose/scope/impact/context of the changes --> - Up Rate Limit - Update App Imports - Check for Allowed List of URLs in application layer - Set base url per supplier for each environment which is passed in an environment variable --- ## 🧪 Developer Testing Carried Out <!-- Describe what tests (automated/unit/manual etc.) have been done for the ticket. Include: --> <!-- - Any tests added/updated --> <!-- - Evidence that each acceptance criterion from the Jira ticket is met --> - Unit tests added/updated - End to end tests added/updated --- ## ✅ Developer Checklist <!-- To be completed by the developer --> - [ ] I have set the PR title to follow the format: `NPA-XXXX: <short-description>` - [ ] My branch name follows the convention: `<type>/NPA-XXXX/<short-description>` - [ ] My commit messages follow the template: `NPA-XXXX: <short-description>` - [ ] I have updated the documentation accordingly - [ ] I have set assignees and added appropriate labels --- ## 👀 Reviewer Checklist <!-- To be completed by the reviewer --> - [ ] Changes meet the acceptance criteria of the Jira ticket - [ ] Code is able to be merged (no conflicts and adheres to coding standards) - [ ] Sufficient test evidence is provided (manual and/or automated) --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [ ] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.
1 parent f49804f commit 6a67a48

29 files changed

Lines changed: 230 additions & 93 deletions

.github/actions/build-container/action.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ inputs:
55
type_of_deployment:
66
description: "Type of deployment (app or sandbox)"
77
required: true
8-
use_mock:
9-
description: "Whether or not the mock for routing requests is on or off"
10-
type: string
11-
required: false
128

139
runs:
1410
using: "composite"
@@ -19,4 +15,3 @@ runs:
1915
env:
2016
PROXYGEN_DOCKER_REGISTRY_URL: example.com/${{ inputs.type_of_deployment }}
2117
CONTAINER_TAG: ${{ github.sha }}
22-
USE_MOCK: ${{ inputs.use_mock }}

.github/workflows/cicd-stage-1-deploy-to-internal-qa.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ jobs:
1313
with:
1414
environment: "internal-qa"
1515
type_of_deployment: "app"
16-
use_mock: "True"
16+
emis_base_url: https://nhs70apptest.emishealth.com
17+
tpp_base_url: https://systmonline2.tpp-uk.com
1718
secrets:
1819
PROXYGEN_CLIENT_ID: ${{ secrets.PROXYGEN_CLIENT_ID }}
1920
PROXYGEN_KEY_ID: ${{ secrets.PROXYGEN_KEY_ID }}

.github/workflows/cicd-stage-2-deploy-to-int-and-sandbox.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ jobs:
1212
with:
1313
environment: "int"
1414
type_of_deployment: "app"
15-
use_mock: "True"
15+
emis_base_url: https://nhs70apptest.emishealth.com
16+
tpp_base_url: https://systmonline2.tpp-uk.com
1617
secrets:
1718
PROXYGEN_CLIENT_ID: ${{ secrets.PROXYGEN_CLIENT_ID }}
1819
PROXYGEN_KEY_ID: ${{ secrets.PROXYGEN_KEY_ID }}

.github/workflows/pull-request-checks.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ jobs:
3232
environment: "internal-dev"
3333
type_of_deployment: "app"
3434
additional_path: "pr-${{ github.event.number }}"
35-
use_mock: "True"
35+
emis_base_url: https://nhs70apptest.emishealth.com
36+
tpp_base_url: https://systmonline2.tpp-uk.com
3637
secrets:
3738
PROXYGEN_CLIENT_ID: ${{ secrets.PROXYGEN_CLIENT_ID }}
3839
PROXYGEN_KEY_ID: ${{ secrets.PROXYGEN_KEY_ID }}

.github/workflows/reusable-core-code-checks.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,3 @@ jobs:
114114
uses: ./.github/actions/build-container
115115
with:
116116
type_of_deployment: "app"
117-
use_mock: "True"

.github/workflows/reusable-deploy.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ on:
1919
description: "Type of deployment, e.g. 'app', 'sandbox'"
2020
required: true
2121
type: string
22-
use_mock:
23-
description: "Whether or not the mock for routing requests is on or off"
22+
emis_base_url:
23+
description: "The base url to connect to to EMIS APIs"
24+
required: false
2425
type: string
26+
tpp_base_url:
27+
description: "The base url to connect to to TPP APIs"
2528
required: false
29+
type: string
2630

2731
outputs:
2832
environment_url:
@@ -48,7 +52,8 @@ permissions: {}
4852
env:
4953
CONTAINER_TAG: ${{inputs.type_of_deployment}}-${{ github.sha }}
5054
PROXYGEN_DOCKER_REGISTRY_URL: 958002497996.dkr.ecr.eu-west-2.amazonaws.com/im1-pfs-auth
51-
USE_MOCK: ${{ inputs.use_mock }}
55+
EMIS_BASE_URL: ${{ inputs.emis_base_url }}
56+
TPP_BASE_URL: ${{ inputs.tpp_base_url }}
5257

5358
jobs:
5459
validate-inputs:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ postman-test-pr-environment:
122122
app-build:
123123
cp pyproject.toml app/
124124
cp uv.lock app/
125-
docker buildx build -t "$(PROXYGEN_DOCKER_REGISTRY_URL):$(CONTAINER_TAG)" --build-arg USE_MOCK=$(USE_MOCK) --load app/
125+
docker buildx build -t "$(PROXYGEN_DOCKER_REGISTRY_URL):$(CONTAINER_TAG)" --build-arg EMIS_BASE_URL=$(EMIS_BASE_URL) --build-arg TPP_BASE_URL=$(TPP_BASE_URL) --load app/
126126

127127
app-push:
128128
proxygen docker get-login | bash

app/Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ RUN find /app -type d -name "test*" -exec rm -rf {} + && \
88
find /app -type f \( -name "*cache*" -o -name "*.cache*" -o -name ".pytest_cache*" -o -name ".ruff_cache*" \) -exec rm -f {} + && \
99
find /app -type d \( -name ".pytest_cache" -o -name ".ruff_cache" \) -exec rm -rf {} +
1010

11-
ARG USE_MOCK
12-
ENV USE_MOCK=${USE_MOCK}
11+
ARG EMIS_BASE_URL
12+
ARG TPP_BASE_URL
13+
14+
ENV EMIS_BASE_URL=${EMIS_BASE_URL}
15+
ENV TPP_BASE_URL=${TPP_BASE_URL}
16+
1317
WORKDIR /app
18+
ENV PYTHONPATH="/app:/"
1419

1520
RUN uv sync --project=app/pyproject.toml --only-group=app
1621
RUN rm pyproject.toml uv.lock Dockerfile
1722

1823
EXPOSE 9000
1924

20-
CMD ["uv", "run", "gunicorn", "api.app:app", "--bind=0.0.0.0:9000"]
25+
CMD ["uv", "run", "gunicorn", "app.api.app:app", "--bind=0.0.0.0:9000"]

app/api/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
from flask import Flask, Response, make_response, request
44

5-
from .application.forward_request import route_and_forward
6-
from .application.jwt import get_nhs_number_from_jwt_token
7-
from .domain.exception import ApiError, InternalServerError
8-
from .domain.forward_request_model import ForwardRequest
5+
from app.api.application.forward_request import route_and_forward
6+
from app.api.application.jwt import get_nhs_number_from_jwt_token
7+
from app.api.domain.exception import ApiError, InternalServerError
8+
from app.api.domain.forward_request_model import ForwardRequest
99

1010
app = Flask(__name__)
1111

app/api/application/forward_request.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
from ..domain.exception import ApiError, DownstreamError
2-
from ..domain.forward_request_model import ForwardRequest
3-
from ..domain.forward_response_model import ForwardResponse
4-
from ..infrastructure.emis.client import EmisClient
5-
from ..infrastructure.tpp.client import TPPClient
1+
from os import environ
62

7-
client_map = {"https://emis.com": EmisClient, "https://tpp.com": TPPClient}
3+
from app.api.domain.exception import ApiError, DownstreamError, InvalidValueError
4+
from app.api.domain.forward_request_model import ForwardRequest
5+
from app.api.domain.forward_response_model import ForwardResponse
6+
from app.api.infrastructure.emis.client import EmisClient
7+
from app.api.infrastructure.tpp.client import TPPClient
8+
9+
EMIS_BASE_URL = environ.get("EMIS_BASE_URL")
10+
TPP_BASE_URL = environ.get("TPP_BASE_URL")
11+
CLIENT_MAP = {EMIS_BASE_URL: EmisClient, TPP_BASE_URL: TPPClient}
812

913

1014
def route_and_forward(forward_request: ForwardRequest) -> ForwardResponse:
@@ -16,9 +20,12 @@ def route_and_forward(forward_request: ForwardRequest) -> ForwardResponse:
1620
ForwardResponse: Transformed response from client
1721
"""
1822
try:
19-
client = client_map[forward_request.forward_to](forward_request)
23+
client = CLIENT_MAP[forward_request.forward_to](forward_request)
2024
response = client.forward_request()
2125
return client.transform_response(response)
26+
except KeyError as exc:
27+
msg = "Invalid URL"
28+
raise InvalidValueError(msg) from exc
2229
except ApiError:
2330
raise
2431
except Exception as exc:

0 commit comments

Comments
 (0)