Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f8d110d
eli-98 changing sandbox to use prism, removing old code
eddalmond1 Feb 27, 2025
3c9b591
eli-98 .yaml linting
eddalmond1 Feb 27, 2025
fc545c7
eli-98 adding additional examples
eddalmond1 Feb 28, 2025
eef3e33
removing securitySchemes and changing guid type to string as this was…
eddalmond1 Mar 5, 2025
aff990b
eli-98 linting spec file
eddalmond1 Mar 5, 2025
377dd16
eli-176 adding basic functionality from https://github.com/stoplighti…
eddalmond1 Mar 11, 2025
d22e024
eli-176 adding secrets scan fix
eddalmond1 Mar 11, 2025
f2a8156
eli-176 adding sonarcube linting fixes
eddalmond1 Mar 12, 2025
e9f4a7d
eli-176 addressing sonarcloud issues
eddalmond1 Mar 12, 2025
e89b13e
eli-176 added script protection for npm install in dockerfile
eddalmond1 Mar 12, 2025
d40568c
Merge remote-tracking branch 'origin/main' into feature/eja-eli-176-e…
eddalmond1 Mar 12, 2025
022a42c
eli-176 re-adding in gitignore content which was conflicted
eddalmond1 Mar 12, 2025
0ed9755
eli-176 adding in John's initial suggestions - code in general needs …
eddalmond1 Mar 12, 2025
7ebaf1a
eli-176 reformatting app.py to make more sensible (first pass) and up…
eddalmond1 Mar 13, 2025
c57e0df
eli-176 changing dependency management to poetry, linting specification
eddalmond1 Mar 13, 2025
497f131
eli0176 adding tests, omitting from main test runs at moment
eddalmond1 Mar 13, 2025
fcaad4f
eli-176 amending spec with examples
eddalmond1 Mar 13, 2025
23e42e8
eli-176 markdown linting
eddalmond1 Mar 13, 2025
83429af
eli-176 testing whether sandbox tests get picked up by CI/CD
eddalmond1 Mar 13, 2025
46b9b0f
eli-176 unexposing port 5000 and ensuring the container is only expos…
eddalmond1 Mar 14, 2025
4886953
Merge branch 'main' into feature/eja-eli-176-extending-prism-for-sandbox
eddalmond1 Mar 14, 2025
4a6669e
eli-176 updating pyproject.toml and poetry.lock
eddalmond1 Mar 14, 2025
c8b8b42
Merge branch 'main' into feature/eja-eli-176-extending-prism-for-sandbox
eddalmond1 Mar 14, 2025
e26582c
Merge branch 'main' into feature/eja-eli-176-extending-prism-for-sandbox
eddalmond1 Mar 17, 2025
db11303
eli-176 playing with sonarcube test runs
eddalmond1 Mar 18, 2025
4eef23b
eli-176 more playing with sonarcube
eddalmond1 Mar 18, 2025
8126a8e
eli-176 amending sonarcube properties
eddalmond1 Mar 18, 2025
916f3b8
eli-176 reverting sonarcube test changes
eddalmond1 Mar 18, 2025
0435284
Merge branch 'main' into feature/eja-eli-176-extending-prism-for-sandbox
eddalmond1 Mar 18, 2025
9bd6cdb
eli-176 trying something a bit convoluted to fix paths in the coverag…
eddalmond1 Mar 18, 2025
7bad44f
eli-176 reverting convoluted change, seeing if using default path for…
eddalmond1 Mar 18, 2025
1388732
eli-176 reverting all changes for sonarcube, back to how it was now!
eddalmond1 Mar 18, 2025
9efea21
eli-176 potential path mismatch in config?
eddalmond1 Mar 18, 2025
6f08f91
eli-176 adding extra documentation for sandbox
eddalmond1 Mar 25, 2025
755b7e8
eli-176 amending port in readme instruction
eddalmond1 Mar 25, 2025
c078020
eli-176 adding mkdir for sandbox/specification
eddalmond1 Mar 25, 2025
7ab13c2
Make sandbox/specification/ if it's not there already.
acerathereinspirative-nhs-nvir Mar 25, 2025
20455e7
Merge remote-tracking branch 'origin/main' into feature/eja-eli-176-e…
eddalmond1 Mar 25, 2025
552b5ab
eli-176 resolving merge conflict
eddalmond1 Mar 25, 2025
00fd1ed
eli-176 including sandbox unit tests in test runs
eddalmond1 Mar 25, 2025
9b76f01
eli-176 adding unit tests + coverage
eddalmond1 Mar 25, 2025
cce72bb
eli-176 removing sandbox unit tests from coverage report
eddalmond1 Mar 26, 2025
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ __pycache__/
.venv/

smoketest-report.xml
env
.env
.dir-locals.el
*.pyc
*/package-lock.json
test-report.xml
.coverage

localstack_data/
sandbox/specification/*
/volume/*
/coverage.xml
/specification/tmp/*
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ install-python:
#Installs dependencies using npm.
install-node:
npm install --legacy-peer-deps
cd sandbox && npm install --legacy-peer-deps

#Configures Git Hooks, which are scripts that run given a specified event.
.git/hooks/pre-commit:
Expand All @@ -34,8 +33,9 @@ format: ## Format and fix code
#Creates the fully expanded OAS spec in json
publish: clean
mkdir -p build
mkdir -p sandbox/specification
npm run publish 2> /dev/null

cp build/eligibility-signposting-api.json sandbox/specification/eligibility-signposting-api.json
#Files to loop over in release
_dist_include="pytest.ini poetry.lock poetry.toml pyproject.toml Makefile build/. tests"

Expand All @@ -48,9 +48,6 @@ dependencies: # Install dependencies needed to build and test the project @Pipel
build: # Build lambda in dist
poetry build-lambda -vv

publish: # Publish the project artefact @Pipeline
# TODO: Implement the artefact publishing step

deploy: # Deploy the project artefact to the target environment @Pipeline
# TODO: Implement the artefact deployment step

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ The software will only be used for signposting an individual to an appropriate s
- [Setup](#setup)
- [Prerequisites](#prerequisites)
- [Configuration](#configuration)
- [Environment variables](#environment-variables)
- [Usage](#usage)
- [Testing](#testing)
- [Sandbox](#sandbox)
- [Conflict with yanai](#conflict-with-yanai)
- [Design](#design)
- [Diagrams](#diagrams)
- [Modularity](#modularity)
Expand Down Expand Up @@ -88,6 +91,10 @@ make precommit

There are `make` tasks for you to configure to run your tests. Run `make test` to see how they work. You should be able to use the same entry points for local development as in your CI pipeline.

## Sandbox

There is a minimalist sandbox environment in `/sandbox` with an accompanying README with instructions on how to run it locally.

## Conflict with yanai

If you have previously built [yanai](https://nhsd-confluence.digital.nhs.uk/pages/viewpage.action?pageId=48826732), which is the platform we use to supply data to this project, that uses an old version of localstack that does not support our Python version. We have pinned the correct version here and yanai have their version pinned as well so it should work fine, but sometimes issues can arise - if so then removing the docker image can solve that, before then rebuilding.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ log_date_format = "%Y-%m-%d %H:%M:%S"
[tool.coverage.run]
relative_files = true
branch = true
source = ["src"]
source = ["src", "sandbox"]

[tool.coverage.report]
show_missing = true
Expand Down
2 changes: 0 additions & 2 deletions sandbox/.dockerignore

This file was deleted.

17 changes: 0 additions & 17 deletions sandbox/.eslintrc.js

This file was deleted.

4 changes: 0 additions & 4 deletions sandbox/.mocharc.yml

This file was deleted.

39 changes: 33 additions & 6 deletions sandbox/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
FROM node:12
# First Stage: Build Proxy service
FROM python:3.13-alpine AS deps

COPY . /sandbox
# Install poetry
RUN pip install poetry

WORKDIR /sandbox
# Install python dependencies in /.venv
COPY pyproject.toml poetry.lock ./
RUN poetry config virtualenvs.in-project true && poetry install --no-root

RUN npm install
FROM deps AS runtime

EXPOSE 9000
# Copy virtual env from python-deps stage
COPY --from=deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"

# Create and switch to a new user
RUN addgroup -S appgroup && \
adduser -S appuser -G appgroup && \
mkdir /home/appuser/app
WORKDIR /home/appuser/app
USER appuser

CMD ["npm", "start"]
# Install application into container
COPY app.py __init__.py /home/appuser/app/
# Copy supervisord configuration
COPY supervisord.conf /etc/supervisord.conf
# Install Prism
USER root
RUN apk add --no-cache nodejs npm && \
npm install --ignore-scripts -g @stoplight/prism-cli && \
apk add --no-cache supervisor

# Expose ports
EXPOSE 9000
ENV UPSTREAM_HOST=http://localhost:5000
# Run supervisord
CMD ["supervisord", "-c", "/etc/supervisord.conf"]
21 changes: 21 additions & 0 deletions sandbox/HealthStatusEndpoint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"/_status": {
"get": {
"operationId": "healthcheck",
"summary": "healthcheck endpoint",
"responses": {
"200": {
"description": "Successful Operation",
"content": {
"application/text": {
"schema": {
"type": "string"
},
"example": "OK"
}
}
}
}
}
}
}
18 changes: 14 additions & 4 deletions sandbox/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
SHELL := /bin/bash
dirname := $(notdir $(patsubst %/,%,$(CURDIR)))
project_name = eligibility-signposting-api

list:
@grep '^[^#[:space:]].*:' Makefile

build:
docker build .
docker-compose -f docker-compose.yaml build

up: build
docker-compose -f docker-compose.yaml up -d

down:
docker-compose -f docker-compose.yaml down

clean:
rm -rf ./node_modules
Expand All @@ -16,8 +23,11 @@ install:
update:
npm update

spec:
mkdir -p specification
make -C .. publish

test:
NODE_ENV=test npx mocha --reporter spec
UPSTREAM_HOST=test poetry run pytest

test-report:
NODE_ENV=test npx mocha --reporter mocha-junit-reporter --reporter-options mochaFile=../../reports/tests/$(dirname).xml || true
.PHONY: build run spec test
34 changes: 34 additions & 0 deletions sandbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Sandbox environment

The sandbox environment uses:

* [OpenAPI Generator CLI](https://github.com/OpenAPITools/openapi-generator-cli) to validate the specification and convert it from .yaml to .json for use in the sandbox.
* [Prism](https://stoplight.io/open-source/prism) as a mock server.
* A flask proxy to allow us to inject specific examples based on request attributes.

## Developer instructions

Run the following command to start the sandbox environment:

```bash
make spec
make up
```

This will start the sandbox environment on localhost port 5000.

```bash
make down
```

This will stop the sandbox environment.

### Example curl calls

patient 0000000001 is a patient eligible and bookable for a Flu vaccination.

```bash
curl -X GET "http://0.0.0.0:9000/eligibility?patient=0000000001" -H "Accept: application/json" -H "Authorization: Bearer sdvsd"
```

See [app.py](app.py) for more examples.
Empty file added sandbox/__init__.py
Empty file.
133 changes: 0 additions & 133 deletions sandbox/app.js

This file was deleted.

Loading
Loading