Skip to content

Commit bae0555

Browse files
authored
Merge branch 'main' into feature/eja-eli-173-create-postman-collection-automagically
2 parents 87a158f + 6c245ff commit bae0555

File tree

7 files changed

+44
-25
lines changed

7 files changed

+44
-25
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ make precommit
8080
8181
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.
8282

83+
## Conflict with yanai
84+
85+
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.
86+
87+
```shell
88+
docker rmi localstack/localstack
89+
```
90+
8391
## Design
8492

8593
We'll be separating our [presentation](https://martinfowler.com/eaaDev/SeparatedPresentation.html) layer (where API logic lives, in [`views/`](src/eligibility_signposting_api/views)), [business services](https://martinfowler.com/eaaCatalog/serviceLayer.html) layer (where business logic lives, in [`services/`](src/eligibility_signposting_api/services)) and [repository](https://martinfowler.com/eaaCatalog/repository.html) layer (where database logic lives, [`repos/`](src/eligibility_signposting_api/repos)). We will be using [wireup](https://pypi.org/project/wireup/) for [dependency injection](https://pinboard.in/u:brunns/t:dependency-injection), so services get their dependencies given to them ("injection"), and wireup takes care of that. (We'll usually use the [`@service` annotation](https://maldoinc.github.io/wireup/latest/services/), but [factory functions](https://maldoinc.github.io/wireup/latest/factory_functions/) will be used where necessary, typically for creating resources from 3rd party libraries.) We'll be using [Pydantic](https://pypi.org/project/pydantic/) for both response models and database models.

poetry.lock

Lines changed: 16 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ botocore = "^1.37.3"
3131
eval-type-backport = "^0.2.2"
3232
mangum = "^0.19.0"
3333
wireup = "^0.16.0"
34+
python-json-logger = "^3.3.0"
3435

3536
[tool.poetry.group.dev.dependencies]
3637
ruff = "^0.11.0"

scripts/config/vale/styles/config/vocabularies/words/accept.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ pyenv
2121
colima
2222
wireup
2323
Pydantic
24+
yanai

scripts/tests/lint.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
cd "$(git rev-parse --show-toplevel)"
6+
7+
make dependencies install-python lint

src/eligibility_signposting_api/app.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from eligibility_signposting_api.views.eligibility import eligibility
1414
from eligibility_signposting_api.views.hello import hello
1515

16+
init_logging()
17+
logger = logging.getLogger(__name__)
18+
1619

1720
def main() -> None: # pragma: no cover
1821
"""Run the Flask app as a local process."""
@@ -27,10 +30,8 @@ def lambda_handler(event: LambdaEvent, context: LambdaContext) -> dict[str, Any]
2730

2831

2932
def create_app() -> Flask:
30-
init_logging()
31-
3233
app = Flask(__name__)
33-
app.logger.info("app created")
34+
logger.info("app created")
3435

3536
# Register views & error handler
3637
app.register_blueprint(eligibility, url_prefix="/eligibility")
@@ -41,7 +42,7 @@ def create_app() -> Flask:
4142
container = wireup.create_container(service_modules=[services, repos], parameters=config())
4243
wireup.integration.flask.setup(container, app, import_flask_config=True)
4344

44-
app.logger.info("app ready")
45+
logger.info("app ready")
4546
return app
4647

4748

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import logging
22
import os
3-
from logging.config import dictConfig
43
from typing import Any, NewType
54

5+
from pythonjsonlogger.json import JsonFormatter
66
from yarl import URL
77

8-
LOG_LEVEL = logging.DEBUG
8+
LOG_LEVEL = logging.getLevelNamesMapping().get(os.getenv("LOG_LEVEL", ""), logging.WARNING)
99

1010
AwsRegion = NewType("AwsRegion", str)
1111
AwsAccessKey = NewType("AwsAccessKey", str)
@@ -22,22 +22,8 @@ def config() -> dict[str, Any]:
2222

2323

2424
def init_logging() -> None:
25-
level = logging.getLevelName(LOG_LEVEL)
2625
log_format = "%(asctime)s %(levelname)-8s %(name)s %(module)s.py:%(funcName)s():%(lineno)d %(message)s"
27-
dictConfig(
28-
{
29-
"version": 1,
30-
"formatters": {
31-
"default": {
32-
"format": log_format,
33-
}
34-
},
35-
"handlers": {
36-
"wsgi": {"class": "logging.StreamHandler", "stream": "ext://sys.stdout", "formatter": "default"}
37-
},
38-
"root": {"level": level, "handlers": ["wsgi"]},
39-
"loggers": {
40-
"eligibility_signposting_api.app": {"level": level, "handlers": ["wsgi"], "propagate": False},
41-
},
42-
}
43-
)
26+
formatter = JsonFormatter(log_format)
27+
handler = logging.StreamHandler()
28+
handler.setFormatter(formatter)
29+
logging.basicConfig(level=LOG_LEVEL, format=log_format, handlers=[handler])

0 commit comments

Comments
 (0)