Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion infrastructure/stacks/api-layer/api_gateway.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,24 @@ resource "aws_api_gateway_stage" "eligibility-signposting-api" {
# A subscription filter (see csoc_log_forwarding.tf) forwards these logs to CSOC
access_log_settings {
destination_arn = module.eligibility_signposting_api_gateway.cloudwatch_destination_arn
format = "{ \"requestId\":\"$context.requestId\", \"ip\": \"$context.identity.sourceIp\", \"caller\":\"$context.identity.caller\", \"user\":\"$context.identity.user\", \"requestTime\":\"$context.requestTime\", \"httpMethod\":\"$context.httpMethod\", \"resourcePath\":\"$context.resourcePath\", \"status\":\"$context.status\", \"protocol\":\"$context.protocol\", \"responseLength\":\"$context.responseLength\", \"accountId\":\"$context.accountId\", \"apiId\":\"$context.apiId\", \"stage\":\"$context.stage\", \"api_key\":\"$context.identity.apiKey\" }"
format = <<EOF
{
"accountId": "$context.accountId",
"apiId": "$context.apiId",
"api_key": "$context.identity.apiKey",
"caller": "$context.identity.caller",
"httpMethod": "$context.httpMethod",
"ip": "$context.identity.sourceIp",
"protocol": "$context.protocol",
"requestId": "$context.requestId",
"requestTime": "$context.requestTime",
"resourcePath": "$context.resourcePath",
"responseLength": "$context.responseLength",
"stage": "$context.stage",
"status": "$context.status",
"user": "$context.identity.user"
}
EOF
}

depends_on = [
Expand Down
1 change: 1 addition & 0 deletions src/eligibility_signposting_api/audit/audit_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def add_request_details(request: Request) -> None:
x_correlation_id=request.headers.get("X-Correlation-ID"),
nhsd_end_user_organisation_ods=request.headers.get("NHSD-End-User-Organisation-ODS"),
nhsd_application_id=request.headers.get("nhsd-application-id"),
nhse_product_id=request.headers.get("nhse-product-id"),
)
),
query_params=(
Expand Down
1 change: 1 addition & 0 deletions src/eligibility_signposting_api/audit/audit_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RequestAuditHeader(CamelCaseBaseModel):
x_correlation_id: str | None = None
nhsd_end_user_organisation_ods: str | None = None
nhsd_application_id: str | None = None
nhse_product_id: str | None = None


class RequestAuditQueryParams(CamelCaseBaseModel):
Expand Down
2 changes: 1 addition & 1 deletion src/eligibility_signposting_api/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
URL_PREFIX = "patient-check"
RULE_STOP_DEFAULT = False
NHS_NUMBER_HEADER = "nhs-login-nhs-number"
CONSUMER_ID = "nhsd-application-id" # "Nhsd-Application-Id"
CONSUMER_ID = "NHSE-Product-ID"
ALLOWED_CONDITIONS = Literal["COVID", "FLU", "MMR", "RSV"]
4 changes: 4 additions & 0 deletions src/eligibility_signposting_api/logging/logs_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from mangum.types import LambdaContext, LambdaEvent

from eligibility_signposting_api.config.constants import CONSUMER_ID

logger = logging.getLogger(__name__)


Expand All @@ -20,6 +22,8 @@ def wrapper(event: LambdaEvent, context: LambdaContext) -> dict[str, Any] | None
"x_request_id": headers.get("X-Request-ID"),
"x_correlation_id": headers.get("X-Correlation-ID"),
"gateway_request_id": gateway_request_id,
"nhse_product_id": headers.get(CONSUMER_ID),
"nhsd_application_id": headers.get("nhsd-application-id"),
},
)
return func(event, context)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
AWS_CURRENT_SECRET = "test_value" # noqa: S105
AWS_PREVIOUS_SECRET = "test_value_old" # noqa: S105

UNIQUE_CONSUMER_HEADER = "nhsd-application-id"
UNIQUE_CONSUMER_HEADER = "nhse-product-id"


@pytest.fixture(scope="session")
Expand Down
15 changes: 10 additions & 5 deletions tests/integration/lambda/test_app_running_as_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ def test_given_nhs_number_in_path_matches_with_nhs_number_in_headers_and_check_i
"x_request_id": "x_request_id",
"x_correlation_id": "x_correlation_id",
"nhsd_end_user_organisation_ods": "nhsd_end_user_organisation_ods",
"nhsd-application-id": consumer_id,
"nhsd-application-id": "nhsd-application-id",
"NHSE-Product-ID": consumer_id,
},
params={"includeActions": "Y"},
timeout=10,
Expand All @@ -229,7 +230,8 @@ def test_given_nhs_number_in_path_matches_with_nhs_number_in_headers_and_check_i
"xRequestId": "x_request_id",
"xCorrelationId": "x_correlation_id",
"nhsdEndUserOrganisationOds": "nhsd_end_user_organisation_ods",
"nhsdApplicationId": consumer_id,
"nhsdApplicationId": "nhsd-application-id",
"nhseProductId": consumer_id,
}
expected_query_params = {"category": None, "conditions": None, "includeActions": "Y"}

Expand Down Expand Up @@ -455,7 +457,8 @@ def test_given_person_has_unique_status_for_different_conditions_with_audit( #
"x_request_id": "x_request_id",
"x_correlation_id": "x_correlation_id",
"nhsd_end_user_organisation_ods": "nhsd_end_user_organisation_ods",
"nhsd_application_id": consumer_id,
"nhsd-application-id": "nhsd-application-id",
"NHSE-Product-ID": consumer_id,
},
params={"includeActions": "Y", "category": "VACCINATIONS", "conditions": "COVID,FLU,RSV"},
timeout=10,
Expand All @@ -475,7 +478,8 @@ def test_given_person_has_unique_status_for_different_conditions_with_audit( #
"xRequestId": "x_request_id",
"xCorrelationId": "x_correlation_id",
"nhsdEndUserOrganisationOds": "nhsd_end_user_organisation_ods",
"nhsdApplicationId": consumer_id,
"nhsdApplicationId": "nhsd-application-id",
"nhseProductId": consumer_id,
}
expected_query_params = {"category": "VACCINATIONS", "conditions": "COVID,FLU,RSV", "includeActions": "Y"}

Expand Down Expand Up @@ -597,7 +601,8 @@ def test_no_active_iteration_returns_empty_processed_suggestions(
"x_request_id": "x_request_id",
"x_correlation_id": "x_correlation_id",
"nhsd_end_user_organisation_ods": "nhsd_end_user_organisation_ods",
"nhsd_application_id": consumer_id,
"nhsd-application-id": "nhsd-application-id",
"NHSE-Product-ID": consumer_id,
},
params={"includeActions": "Y", "category": "VACCINATIONS", "conditions": "COVID,FLU,RSV"},
timeout=10,
Expand Down
Loading