Skip to content

Feature/cdapi-78#36

Open
MohammadPatelNHS wants to merge 4 commits intomainfrom
feature/CDAPI-78-w-infra
Open

Feature/cdapi-78#36
MohammadPatelNHS wants to merge 4 commits intomainfrom
feature/CDAPI-78-w-infra

Conversation

@MohammadPatelNHS
Copy link
Contributor

Description

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming
  • Exceptions/Exclusions to coding standards (e.g. #noqa or #NOSONAR) are included within this Pull Request.

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) 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.

@github-actions
Copy link

github-actions bot commented Feb 19, 2026

Trivy gate: no Critical/High vulnerabilities.

Trivy Filesystem Scan Summary

Filesystem: /tmp/artifact

Severity Count
CRITICAL 0
HIGH 0
MEDIUM 0
LOW 0
UNKNOWN 0

✅ No vulnerabilities found.

@MohammadPatelNHS MohammadPatelNHS changed the title Feature/cdapi 78 w infrastructure changes Feature/cdapi-78 Feb 19, 2026
@MohammadPatelNHS MohammadPatelNHS force-pushed the feature/CDAPI-78-w-infra branch 3 times, most recently from 7595562 to a9f2f2f Compare March 2, 2026 13:41
@MohammadPatelNHS MohammadPatelNHS force-pushed the feature/CDAPI-78-w-infra branch from a9f2f2f to ae7f964 Compare March 3, 2026 10:20
@MohammadPatelNHS MohammadPatelNHS force-pushed the feature/CDAPI-78-w-infra branch 13 times, most recently from 9054c38 to 62ba4bc Compare March 4, 2026 12:17
@MohammadPatelNHS MohammadPatelNHS marked this pull request as ready for review March 4, 2026 12:25
@MohammadPatelNHS MohammadPatelNHS requested a review from a team as a code owner March 4, 2026 12:25
@MohammadPatelNHS MohammadPatelNHS force-pushed the feature/CDAPI-78-w-infra branch 3 times, most recently from 1732712 to 6c8de20 Compare March 6, 2026 12:20
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

Deployment Complete

Copy link
Collaborator

@nhsd-jack-wainwright nhsd-jack-wainwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍, just some minor comments

@@ -37,9 +43,15 @@
def forward_request(path_params):
app.logger.info("received request with data: %s", request.get_data(as_text=True))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to do with your changes. But given your updating this file as part of your changes would you mind removing this log line here, as this leads to a sonar issue due to us logging user provided text.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this now

app.logger.info("received request with data: %s", request.get_data(as_text=True))

if TARGET_CONTAINER == "MOCKS":
base_url = "http://mocks:8080" # NOSONAR python:S5332
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be cleaner here if the URL to forward traffic was provided as an environment variable rather than being dependent on the type of TARGET_CONTAINER.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this now


if TARGET_CONTAINER == "MOCKS":
base_url = "http://mocks:8080" # NOSONAR python:S5332
content_type = "application/x-www-form-urlencoded"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the content type be different here locally for the mocks? I think the request provided to the lambda will always be JSON from API gateway even if the request from the client is different?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing to see if it mattered for how the data is received, Ive just set it to be JSON now

@@ -0,0 +1,20 @@
import logging.config

logging.config.dictConfig(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than using the standard python logging library, does it make more sense to use the AWS lambda powertools logger like we are with the main pathology lambda?



def check_authenticated(token: str) -> bool:
dynamodb = boto3.resource("dynamodb")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very minor, but could this dynamodb client be moved out of this method just into the file to allow for the client to be reused across multiple authentication checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was planning a larger change to how we interact with aws resources in the PDM mock, ive left this as is for now but can be changed before merging if we dont want to wait Improvements in the PDM mock

),
],
)
def test_invalid_payload(self, payload: dict[str, Any], error_message: str) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be cleaner if these tests were executed against the public handle_request method? Mainly incase the private methods underneath the handle_request method are updated in the future.

Makefile Outdated
@mkdir -p infrastructure/images/pathology-api/resources/build
@cp -r pathology-api/target/pathology-api infrastructure/images/pathology-api/resources/build

@mkdir infrastructure/images/mocks/resources/build/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic should be updated to rely on just the mocks target directory, rather than unzipping the artifact.zip file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this to be the same as the pathology-api lambda now

Makefile Outdated
$(docker) run --platform linux/amd64 --name pathology-api -p 5001:8080 --network $(dockerNetwork) -d localhost/pathology-api-image
$(docker) run --platform linux/amd64 --name mocks -p 5003:8080 --network $(dockerNetwork) -d localhost/mocks-image
$(docker) run --name api-gateway-mock -p 5002:5000 --network $(dockerNetwork) -d localhost/api-gateway-mock-image
$(docker) run --name api-gateway-mock-2 -p 5005:5000 -e TARGET_CONTAINER='MOCKS' --network $(dockerNetwork) -d localhost/api-gateway-mock-image
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this mock should be named something like mocks-api-gateway rather than api-gateway-mock-2? If renaming this container it's probably worth renaming the existing api-gateway-mock container to be something like pathology-api-gateway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've renamed these now

with pytest.raises(ValueError, match=error_message):
_get_jwk_key_from_url_by_kid("TEST-1")

@pytest.mark.parametrize(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth including a scenario here where the expiry is too far in the future?

Comment on lines +67 to +68
_logger.debug("temp: %s", app.current_event.body)
_logger.debug("temp2: %s", app.current_event.decoded_body)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these log lines required? I think these logs will include the client_assertion which does include a secret value (though the secret is only being used in a secret context here).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was mostly using it for debugging, so its not really necessary to keep.
I think we could do with someway of logging what the body receives without logging any actual secret values if we need some help debugging in the future

@MohammadPatelNHS MohammadPatelNHS force-pushed the feature/CDAPI-78-w-infra branch from 6c8de20 to dbbce28 Compare March 10, 2026 15:08
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 95%)
9.0% Duplication on New Code (required ≤ 3%)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants