Skip to content

Commit 8e9c2e2

Browse files
Merge pull request #88 from NHSDigital/refactor/rename_repos
Refactor/rename repos & extract calculator.
2 parents 5bde2e5 + 08d9946 commit 8e9c2e2

File tree

17 files changed

+476
-433
lines changed

17 files changed

+476
-433
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,29 @@ The following software packages, or their equivalents, are expected to be instal
7070
7171
#### Environment variables - Local
7272
73-
| Variable | Default | Description |
74-
|--------------------------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
75-
| `AWS_ACCESS_KEY_ID` | `dummy_key` | AWS Access Key |
76-
| `AWS_DEFAULT_REGION` | `eu-west-1` | AWS Region |
77-
| `AWS_SECRET_ACCESS_KEY` | `dummy_secret` | AWS Secret Access Key |
78-
| `DYNAMODB_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access DynamoDB |
79-
| `S3_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access S3 |
80-
| `ELIGIBILITY_TABLE_NAME` | `test_eligibility_datastore` | AWS DynamoDB table for person data. |
81-
| `LOG_LEVEL` | `WARNING` | Logging level. Must be one of `DEBUG`, `INFO`, `WARNING`, `ERROR` or `CRITICAL` as per [Logging Levels](https://docs.python.org/3/library/logging.html#logging-levels) |
82-
| `RULES_BUCKET_NAME` | `test-rules-bucket` | AWS S3 bucket from which to read rules. |
73+
| Variable | Default | Description |
74+
|-------------------------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
75+
| `AWS_ACCESS_KEY_ID` | `dummy_key` | AWS Access Key |
76+
| `AWS_DEFAULT_REGION` | `eu-west-1` | AWS Region |
77+
| `AWS_SECRET_ACCESS_KEY` | `dummy_secret` | AWS Secret Access Key |
78+
| `DYNAMODB_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access DynamoDB |
79+
| `S3_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access S3 |
80+
| `PERSON_TABLE_NAME` | `test_eligibility_datastore` | AWS DynamoDB table for person data. |
81+
| `LOG_LEVEL` | `WARNING` | Logging level. Must be one of `DEBUG`, `INFO`, `WARNING`, `ERROR` or `CRITICAL` as per [Logging Levels](https://docs.python.org/3/library/logging.html#logging-levels) |
82+
| `RULES_BUCKET_NAME` | `test-rules-bucket` | AWS S3 bucket from which to read rules. |
8383
8484
#### Environment variables - DEV, PROD or PRE-PROD
8585
86-
| Variable | Default | Description | Comments |
87-
|--------------------------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
88-
| `AWS_DEFAULT_REGION` | `eu-west-1` | AWS Region | |
89-
| `AWS_ACCESS_KEY_ID` | None | AWS Access Key | **AWS_ACCESS_KEY_ID** is set to None, <br/>because it is provided by the AWS environment automatically. |
90-
| `AWS_SECRET_ACCESS_KEY` | None | AWS Secret Access Key | **AWS_SECRET_ACCESS_KEY** is set to None, <br/>because it is provided by the AWS environment automatically. |
91-
| `DYNAMODB_ENDPOINT` | None | Endpoint for the app to access DynamoDB | **DYNAMODB_ENDPOINT** are set to None, <br/>since we are using aws service default endpoints which are provided automatically. |
92-
| `S3_ENDPOINT` | None | Endpoint for the app to access S3 | **S3_ENDPOINT** are set to None, <br/>since we are using aws service default endpoints which are provided automatically. |
93-
| `ELIGIBILITY_TABLE_NAME` | `test_eligibility_datastore` | AWS DynamoDB table for person data. | |
94-
| `LOG_LEVEL` | `WARNING` | Logging level. Must be one of `DEBUG`, `INFO`, `WARNING`, `ERROR` or `CRITICAL` as per [Logging Levels](https://docs.python.org/3/library/logging.html#logging-levels) | |
95-
| `RULES_BUCKET_NAME` | `test-rules-bucket` | AWS S3 bucket from which to read rules. | |
86+
| Variable | Default | Description | Comments |
87+
|-------------------------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
88+
| `AWS_DEFAULT_REGION` | `eu-west-1` | AWS Region | |
89+
| `AWS_ACCESS_KEY_ID` | None | AWS Access Key | **AWS_ACCESS_KEY_ID** is set to None, <br/>because it is provided by the AWS environment automatically. |
90+
| `AWS_SECRET_ACCESS_KEY` | None | AWS Secret Access Key | **AWS_SECRET_ACCESS_KEY** is set to None, <br/>because it is provided by the AWS environment automatically. |
91+
| `DYNAMODB_ENDPOINT` | None | Endpoint for the app to access DynamoDB | **DYNAMODB_ENDPOINT** are set to None, <br/>since we are using aws service default endpoints which are provided automatically. |
92+
| `S3_ENDPOINT` | None | Endpoint for the app to access S3 | **S3_ENDPOINT** are set to None, <br/>since we are using aws service default endpoints which are provided automatically. |
93+
| `PERSON_TABLE_NAME` | `test_eligibility_datastore` | AWS DynamoDB table for person data. | |
94+
| `LOG_LEVEL` | `WARNING` | Logging level. Must be one of `DEBUG`, `INFO`, `WARNING`, `ERROR` or `CRITICAL` as per [Logging Levels](https://docs.python.org/3/library/logging.html#logging-levels) | |
95+
| `RULES_BUCKET_NAME` | `test-rules-bucket` | AWS S3 bucket from which to read rules. | |
9696
9797
## Usage
9898
@@ -201,8 +201,8 @@ graph TB
201201
end
202202
subgraph "Data Access Layer"
203203
direction TB
204-
RepoElig["repos/eligibility_repo.py"]
205-
RepoRules["repos/rules_repo.py"]
204+
PersonRepo["repos/person_repo.py"]
205+
CampaignRepo["repos/campaign_repo.py"]
206206
Factory["repos/factory.py, exceptions.py"]
207207
end
208208
subgraph "Models"
@@ -216,10 +216,10 @@ graph TB
216216
App -->|injects| View
217217
View -->|calls| Service
218218
Service -->|calls| Operators
219-
Service -->|calls| RepoElig
220-
Service -->|calls| RepoRules
221-
RepoElig -->|uses| DynamoDB
222-
RepoRules -->|uses| S3Bucket
219+
Service -->|calls| PersonRepo
220+
Service -->|calls| CampaignRepo
221+
PersonRepo -->|uses| DynamoDB
222+
CampaignRepo -->|uses| S3Bucket
223223
View -->|uses| ResponseModel
224224
App -->|reads| Config
225225
Service -->|uses| ModelElig

infrastructure/modules/lambda/lambda.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ resource "aws_lambda_function" "eligibility_signposting_lambda" {
1414

1515
environment {
1616
variables = {
17-
ELIGIBILITY_TABLE_NAME = var.eligibility_status_table_name,
17+
PERSON_TABLE_NAME = var.eligibility_status_table_name,
1818
RULES_BUCKET_NAME = var.eligibility_rules_bucket_name,
1919
ENV = var.environment
2020
}

src/eligibility_signposting_api/config.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from pythonjsonlogger.json import JsonFormatter
88
from yarl import URL
99

10-
from eligibility_signposting_api.repos.eligibility_repo import TableName
11-
from eligibility_signposting_api.repos.rules_repo import BucketName
10+
from eligibility_signposting_api.repos.campaign_repo import BucketName
11+
from eligibility_signposting_api.repos.person_repo import TableName
1212

1313
LOG_LEVEL = logging.getLevelNamesMapping().get(os.getenv("LOG_LEVEL", ""), logging.WARNING)
1414

@@ -19,7 +19,7 @@
1919

2020
@cache
2121
def config() -> dict[str, Any]:
22-
eligibility_table_name = TableName(os.getenv("ELIGIBILITY_TABLE_NAME", "test_eligibility_datastore"))
22+
person_table_name = TableName(os.getenv("PERSON_TABLE_NAME", "test_eligibility_datastore"))
2323
rules_bucket_name = BucketName(os.getenv("RULES_BUCKET_NAME", "test-rules-bucket"))
2424
aws_default_region = AwsRegion(os.getenv("AWS_DEFAULT_REGION", "eu-west-1"))
2525
log_level = LOG_LEVEL
@@ -30,7 +30,7 @@ def config() -> dict[str, Any]:
3030
"aws_default_region": aws_default_region,
3131
"aws_secret_access_key": None,
3232
"dynamodb_endpoint": None,
33-
"eligibility_table_name": eligibility_table_name,
33+
"person_table_name": person_table_name,
3434
"s3_endpoint": None,
3535
"rules_bucket_name": rules_bucket_name,
3636
"log_level": log_level,
@@ -41,7 +41,7 @@ def config() -> dict[str, Any]:
4141
"aws_default_region": aws_default_region,
4242
"aws_secret_access_key": AwsSecretAccessKey(os.getenv("AWS_SECRET_ACCESS_KEY", "dummy_secret")),
4343
"dynamodb_endpoint": URL(os.getenv("DYNAMODB_ENDPOINT", "http://localhost:4566")),
44-
"eligibility_table_name": eligibility_table_name,
44+
"person_table_name": person_table_name,
4545
"s3_endpoint": URL(os.getenv("S3_ENDPOINT", "http://localhost:4566")),
4646
"rules_bucket_name": rules_bucket_name,
4747
"log_level": log_level,
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .eligibility_repo import EligibilityRepo
1+
from .campaign_repo import CampaignRepo
22
from .exceptions import NotFoundError
3-
from .rules_repo import RulesRepo
3+
from .person_repo import PersonRepo
44

5-
__all__ = ["EligibilityRepo", "NotFoundError", "RulesRepo"]
5+
__all__ = ["CampaignRepo", "NotFoundError", "PersonRepo"]

src/eligibility_signposting_api/repos/rules_repo.py renamed to src/eligibility_signposting_api/repos/campaign_repo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
@service
14-
class RulesRepo:
14+
class CampaignRepo:
1515
"""Repository class for Campaign Rules, which we can use to calculate a person's eligibility for vaccination.
1616
1717
These rules are stored as JSON files in AWS S3."""

src/eligibility_signposting_api/repos/eligibility_repo.py renamed to src/eligibility_signposting_api/repos/person_repo.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,25 @@
1313
TableName = NewType("TableName", str)
1414

1515

16-
@service(qualifier="eligibility_table")
17-
def eligibility_table_factory(
16+
@service(qualifier="person_table")
17+
def person_table_factory(
1818
dynamodb_resource: Annotated[ServiceResource, Inject(qualifier="dynamodb")],
19-
eligibility_table_name: Annotated[TableName, Inject(param="eligibility_table_name")],
19+
person_table_name: Annotated[TableName, Inject(param="person_table_name")],
2020
) -> Any:
21-
table = dynamodb_resource.Table(eligibility_table_name) # type: ignore[reportAttributeAccessIssue]
22-
logger.info("eligibility_table %r", table, extra={"table": table})
21+
table = dynamodb_resource.Table(person_table_name) # type: ignore[reportAttributeAccessIssue]
22+
logger.info("person_table %r", table, extra={"table": table})
2323
return table
2424

2525

2626
@service
27-
class EligibilityRepo:
27+
class PersonRepo:
2828
"""Repository class for the data held about a person which may be relevant to calculating their eligibility for
2929
vaccination.
3030
3131
This data is held in a handful of records in a single Dynamodb table.
3232
"""
3333

34-
def __init__(self, table: Annotated[Any, Inject(qualifier="eligibility_table")]) -> None:
34+
def __init__(self, table: Annotated[Any, Inject(qualifier="person_table")]) -> None:
3535
super().__init__()
3636
self.table = table
3737

src/eligibility_signposting_api/services/calculators/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)