Conversation
730f22c to
4093d6a
Compare
db4de43 to
a19eef9
Compare
4093d6a to
8a8d338
Compare
89ed95e to
75d0e29
Compare
nhsd-jack-wainwright
left a comment
There was a problem hiding this comment.
LGTM 👍. Just a few minor comments / suggestions 🙂
|
|
||
| COPY /resources/build/mocks ${LAMBDA_TASK_ROOT} | ||
|
|
||
| # RUN mkdir -p /.aws |
There was a problem hiding this comment.
Should this commented out logic be removed?
There was a problem hiding this comment.
removed this,I think we will have a proper way of including or grabbing credentials in the future
mocks/src/apim_mock/auth_check.py
Outdated
| KeyConditionExpression=Key("ddb_index").eq(BRANCH_NAME), | ||
| FilterExpression=Attr("access_token").eq(token) | ||
| & Attr("expiresAt").gt(int(time())), | ||
| def check_authenticated(token: str) -> bool: |
There was a problem hiding this comment.
Rather than returning a boolean here, I wonder if it would be nicer to return some sort of typed exception that's declared within the mock logic (maybe something like AuthenticatorError for example). That way we could add in an exception handler to provide the standard APIM response within the top level handler, rather than each mock endpoint needing to define this response?
There was a problem hiding this comment.
This function no longer returns anything but will raise an exception when not authenticated, which gets caught by a handler exception at the lambda handler level
| pass | ||
|
|
||
|
|
||
| class DynamoHelper: |
There was a problem hiding this comment.
Very minor, but I wonder if its worth renaming this helper just to abstract away that we're using dynamo for storage? Maybe it could just be something like StorageHelper?
There was a problem hiding this comment.
this have been renamed now
|
|
||
| return cast("BaseMockItem", response.get("Item")) | ||
|
|
||
| def query_by_ddb_index(self, filter_expression: Any) -> list[BaseMockItem]: |
There was a problem hiding this comment.
As above with the class name, is it worth renaming this method to be something that's more generic? Maybe this method could just be called find for example that accepts an expression?
I wonder if it's worth always appending the TTL check here also as I think we'd always want to apply that condition as part of looking something up?
There was a problem hiding this comment.
I have renamed the function and put a ttl check inside the function to be appended to any filter expression we use
| self.branch_name = branch_name | ||
| self.table_resource_created = False | ||
|
|
||
| def _set_up_resource(self) -> None: |
There was a problem hiding this comment.
Could this logic not be included as part of the constructor call above? That way other methods within this class don't need to worry about making sure this method is called?
There was a problem hiding this comment.
I have changed the way we create the resource now
mocks/src/pdm_mock/handler.py
Outdated
| auth_token = pdm_routes.current_event.headers.get("Authorization", "").replace( | ||
| "Bearer ", "" | ||
| ) |
There was a problem hiding this comment.
As this logic will be common across all authentication, I think it's worth including this logic as part of the check_authenticated method.
There was a problem hiding this comment.
I have moved this logic into check_authenticated
mocks/src/pdm_mock/logging.py
Outdated
There was a problem hiding this comment.
I don't think this module should be required, as I think the same logging module should be used across all mocks within the lambda. Could the existing logging module as part of the apim_mock instead be moved up a level so it's at the root of the mock? That way each mock can just depend on the same module.
There was a problem hiding this comment.
the logging setup is now part of the common module
mocks/src/pdm_mock/test_handler.py
Outdated
| } | ||
|
|
||
| # @patch("boto3.resource") | ||
| # def test_get_request_no_document_found( |
There was a problem hiding this comment.
I think this test should be included?
There was a problem hiding this comment.
I originally thought this test was a bit redundant but its different from the other one I've written from the lambda_handler level. Ive reinstated this test
mocks/pyproject.toml
Outdated
| packages = [ | ||
| {include = "apim_mock", from = "src"}, | ||
| {include = "pdm_mock", from = "src"}, | ||
| {include = "aws_helpers", from = "src"} |
There was a problem hiding this comment.
Maybe instead of having a aws_helpers package here we could instead have a common package which then includes the following modules:
storage- Includes the currentDynamoHelperclasslogging- Includes the logger configuration so it can be reused across all mocks
There was a problem hiding this comment.
package has been renamed
There was a problem hiding this comment.
Now that we've separated out the endpoints for individual mocks out of the top level lambda_handler I wonder if these tests can be a bit simpler? I think these tests only really need to verify the behaviour housed within the lambda_handler.py file itself, perhaps also verifying that the routers from the individual mock modules are registered?
There was a problem hiding this comment.
the tests in this file have been moved to the relevant handler files
75d0e29 to
8c72967
Compare
nhsd-jack-wainwright
left a comment
There was a problem hiding this comment.
Looks good to me 👍, just a couple extra minor comments.
|
|
||
| class TestStorageHelper: | ||
| # @patch("boto3.resource") | ||
| # def test_resource_set_up_once(self, mock_boto_resource: MagicMock) -> None: |
There was a problem hiding this comment.
Should this commented out test be included?
|
|
||
| self.table = self.dynamodb.Table(self.table_name) | ||
|
|
||
| def get_item_by_session_id(self, session_id: str) -> BaseMockItem: |
There was a problem hiding this comment.
I think this method could still be implemented with a generic?
| def get_item_by_session_id(self, session_id: str) -> BaseMockItem: | |
| def get_item_by_session_id[T: BaseMockItem](self, session_id: str, required_type: type[T]) -> T: | |
| ... | |
| item = response.get("Item") | |
| if not isinstance(item, required_type): | |
| raise ItemNotFoundException(f"Item found but was not expected type. item={item}") | |
| return item |
8c72967 to
d2ff798
Compare
d2ff798 to
b0c9d80
Compare
|
|
Deployment Complete
|



Description
Context
Type of changes
Checklist
Sensitive Information Declaration
To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.