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
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,29 @@ The following software packages, or their equivalents, are expected to be instal

#### Environment variables - Local

| Variable | Default | Description |
|--------------------------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `AWS_ACCESS_KEY_ID` | `dummy_key` | AWS Access Key |
| `AWS_DEFAULT_REGION` | `eu-west-1` | AWS Region |
| `AWS_SECRET_ACCESS_KEY` | `dummy_secret` | AWS Secret Access Key |
| `DYNAMODB_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access DynamoDB |
| `S3_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access S3 |
| `ELIGIBILITY_TABLE_NAME` | `test_eligibility_datastore` | AWS DynamoDB table for person data. |
| `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) |
| `RULES_BUCKET_NAME` | `test-rules-bucket` | AWS S3 bucket from which to read rules. |
| Variable | Default | Description |
|-------------------------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `AWS_ACCESS_KEY_ID` | `dummy_key` | AWS Access Key |
| `AWS_DEFAULT_REGION` | `eu-west-1` | AWS Region |
| `AWS_SECRET_ACCESS_KEY` | `dummy_secret` | AWS Secret Access Key |
| `DYNAMODB_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access DynamoDB |
| `S3_ENDPOINT` | `http://localhost:4566` | Endpoint for the app to access S3 |
| `PERSON_TABLE_NAME` | `test_eligibility_datastore` | AWS DynamoDB table for person data. |
| `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) |
| `RULES_BUCKET_NAME` | `test-rules-bucket` | AWS S3 bucket from which to read rules. |

#### Environment variables - DEV, PROD or PRE-PROD

| Variable | Default | Description | Comments |
|--------------------------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `AWS_DEFAULT_REGION` | `eu-west-1` | AWS Region | |
| `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. |
| `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. |
| `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. |
| `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. |
| `ELIGIBILITY_TABLE_NAME` | `test_eligibility_datastore` | AWS DynamoDB table for person data. | |
| `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) | |
| `RULES_BUCKET_NAME` | `test-rules-bucket` | AWS S3 bucket from which to read rules. | |
| Variable | Default | Description | Comments |
|-------------------------|------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| `AWS_DEFAULT_REGION` | `eu-west-1` | AWS Region | |
| `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. |
| `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. |
| `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. |
| `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. |
| `PERSON_TABLE_NAME` | `test_eligibility_datastore` | AWS DynamoDB table for person data. | |
| `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) | |
| `RULES_BUCKET_NAME` | `test-rules-bucket` | AWS S3 bucket from which to read rules. | |

## Usage

Expand Down Expand Up @@ -201,8 +201,8 @@ graph TB
end
subgraph "Data Access Layer"
direction TB
RepoElig["repos/eligibility_repo.py"]
RepoRules["repos/rules_repo.py"]
PersonRepo["repos/person_repo.py"]
CampaignRepo["repos/campaign_repo.py"]
Factory["repos/factory.py, exceptions.py"]
end
subgraph "Models"
Expand All @@ -216,10 +216,10 @@ graph TB
App -->|injects| View
View -->|calls| Service
Service -->|calls| Operators
Service -->|calls| RepoElig
Service -->|calls| RepoRules
RepoElig -->|uses| DynamoDB
RepoRules -->|uses| S3Bucket
Service -->|calls| PersonRepo
Service -->|calls| CampaignRepo
PersonRepo -->|uses| DynamoDB
CampaignRepo -->|uses| S3Bucket
View -->|uses| ResponseModel
App -->|reads| Config
Service -->|uses| ModelElig
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/modules/lambda/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ resource "aws_lambda_function" "eligibility_signposting_lambda" {

environment {
variables = {
ELIGIBILITY_TABLE_NAME = var.eligibility_status_table_name,
PERSON_TABLE_NAME = var.eligibility_status_table_name,
RULES_BUCKET_NAME = var.eligibility_rules_bucket_name,
ENV = var.environment
}
Expand Down
10 changes: 5 additions & 5 deletions src/eligibility_signposting_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pythonjsonlogger.json import JsonFormatter
from yarl import URL

from eligibility_signposting_api.repos.eligibility_repo import TableName
from eligibility_signposting_api.repos.rules_repo import BucketName
from eligibility_signposting_api.repos.campaign_repo import BucketName
from eligibility_signposting_api.repos.person_repo import TableName

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

Expand All @@ -19,7 +19,7 @@

@cache
def config() -> dict[str, Any]:
eligibility_table_name = TableName(os.getenv("ELIGIBILITY_TABLE_NAME", "test_eligibility_datastore"))
person_table_name = TableName(os.getenv("PERSON_TABLE_NAME", "test_eligibility_datastore"))
rules_bucket_name = BucketName(os.getenv("RULES_BUCKET_NAME", "test-rules-bucket"))
aws_default_region = AwsRegion(os.getenv("AWS_DEFAULT_REGION", "eu-west-1"))
log_level = LOG_LEVEL
Expand All @@ -30,7 +30,7 @@ def config() -> dict[str, Any]:
"aws_default_region": aws_default_region,
"aws_secret_access_key": None,
"dynamodb_endpoint": None,
"eligibility_table_name": eligibility_table_name,
"person_table_name": person_table_name,
"s3_endpoint": None,
"rules_bucket_name": rules_bucket_name,
"log_level": log_level,
Expand All @@ -41,7 +41,7 @@ def config() -> dict[str, Any]:
"aws_default_region": aws_default_region,
"aws_secret_access_key": AwsSecretAccessKey(os.getenv("AWS_SECRET_ACCESS_KEY", "dummy_secret")),
"dynamodb_endpoint": URL(os.getenv("DYNAMODB_ENDPOINT", "http://localhost:4566")),
"eligibility_table_name": eligibility_table_name,
"person_table_name": person_table_name,
"s3_endpoint": URL(os.getenv("S3_ENDPOINT", "http://localhost:4566")),
"rules_bucket_name": rules_bucket_name,
"log_level": log_level,
Expand Down
6 changes: 3 additions & 3 deletions src/eligibility_signposting_api/repos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .eligibility_repo import EligibilityRepo
from .campaign_repo import CampaignRepo
from .exceptions import NotFoundError
from .rules_repo import RulesRepo
from .person_repo import PersonRepo

__all__ = ["EligibilityRepo", "NotFoundError", "RulesRepo"]
__all__ = ["CampaignRepo", "NotFoundError", "PersonRepo"]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@service
class RulesRepo:
class CampaignRepo:
"""Repository class for Campaign Rules, which we can use to calculate a person's eligibility for vaccination.

These rules are stored as JSON files in AWS S3."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
TableName = NewType("TableName", str)


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


@service
class EligibilityRepo:
class PersonRepo:
"""Repository class for the data held about a person which may be relevant to calculating their eligibility for
vaccination.

This data is held in a handful of records in a single Dynamodb table.
"""

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

Expand Down
Empty file.
Loading
Loading