generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
ELI-578 consumer_id - campaign_config mapping #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Karthikeyannhs
wants to merge
64
commits into
main
Choose a base branch
from
ELI-578/consumer-campaign-config-mappings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
09ffcff
ELI-578 consumer_id - campaign_config mapping
Karthikeyannhs dfcff79
ELI-578 added dummy consumer id
Karthikeyannhs 18736fa
ELI-578 local stack configuration
Karthikeyannhs b9fe63b
ELI-578 wip test
Karthikeyannhs bcd1d8d
ELI-578 unit test fixed
Karthikeyannhs 60b4954
ELI-578 consumer_id error validation
Karthikeyannhs d840389
ELI-578 intergation testing
Karthikeyannhs b7561a0
ELI-578 lambda
Karthikeyannhs aefbe33
ELI-578 integration test
Karthikeyannhs 8f4e28a
ELI-578 Integration test to check if consumer has campaign mappings
Karthikeyannhs 4afb122
ELI-578 Unit tests
Karthikeyannhs 2dacd5e
added test : customer requesting for campaign that is not mapped
Karthikeyannhs 72f6d0c
consumer with no campaign mapping is valid
Karthikeyannhs bcee4b1
ELI-578 consumer_id - campaign_config mapping
Karthikeyannhs 6029398
ELI-578 added dummy consumer id
Karthikeyannhs 714433d
ELI-578 local stack configuration
Karthikeyannhs fcc68be
ELI-578 wip test
Karthikeyannhs 510df8d
ELI-578 unit test fixed
Karthikeyannhs 91a2a09
ELI-578 consumer_id error validation
Karthikeyannhs 4089abc
ELI-578 intergation testing
Karthikeyannhs 1279f2d
ELI-578 lambda
Karthikeyannhs 425f6e7
ELI-578 integration test
Karthikeyannhs 3b58fc9
ELI-578 Integration test to check if consumer has campaign mappings
Karthikeyannhs 7812be0
ELI-578 Unit tests
Karthikeyannhs 569dc5f
added test : customer requesting for campaign that is not mapped
Karthikeyannhs fbb902d
consumer with no campaign mapping is valid
Karthikeyannhs d30b4df
revert
Karthikeyannhs 6591256
Merge remote-tracking branch 'origin/ELI-578/consumer-campaign-config…
Karthikeyannhs bca6215
linting
Karthikeyannhs 5160d98
Merge branch 'main' into ELI-578/consumer-campaign-config-mappings
ayeshalshukri1-nhs 92dd24e
removed unused code
Karthikeyannhs f25e29e
added CONSUMER_ID_NOT_PROVIDED_ERROR back
Karthikeyannhs 80704fe
more test cases
Karthikeyannhs 5407820
hardcodes values are converted to fixtures
Karthikeyannhs ca0aef8
fixtures
Karthikeyannhs 3f30502
fixtures
Karthikeyannhs 7751ae8
linting
Karthikeyannhs b6b9242
Merge branch 'main' into ELI-578/consumer-campaign-config-mappings
ayeshalshukri1-nhs 4fea2dc
more scenarios
Karthikeyannhs 34827d1
added consumer-id header to the requests in unit tests
Karthikeyannhs 3d1b970
linting
Karthikeyannhs a14db73
Added vacc request placeholder in tests.
ayeshalshukri1-nhs 1b10f85
fixed linting.
ayeshalshukri1-nhs 45522f8
added sample consumer-mapping file
Karthikeyannhs c507ee2
Merge branch 'main' into ELI-578/consumer-campaign-config-mappings
Karthikeyannhs 926edc8
test_valid_response_when_consumer_has_a_valid_campaign_config_mapping…
Karthikeyannhs cbbae6f
multiple campaigns for same target
Karthikeyannhs f525d01
multiple campaigns for same target
Karthikeyannhs fa80df6
consumer config structure modification
Karthikeyannhs dbef36c
Merge branch 'main' into ELI-578/consumer-campaign-config-mappings
Karthikeyannhs 82ee079
lint fix
Karthikeyannhs 2045e08
consumer mapping - schema
Karthikeyannhs 5fff049
Terraform consumer mapping bucket
Karthikeyannhs bcadb02
Terraform consumer mapping bucket policy
Karthikeyannhs 6eaca30
more linting
Karthikeyannhs a1ad018
fix s3
Karthikeyannhs 6c70813
Merge branch 'main' into ELI-578/consumer-campaign-config-mappings
Karthikeyannhs 3d6b127
fix s3
Karthikeyannhs 8afefa9
revert to S3ReadAccess
Karthikeyannhs 34073c6
iam permissions
Karthikeyannhs bd8b5c2
more tests
Karthikeyannhs 0e6c784
name correction
Karthikeyannhs fe9a2da
one more test scenario
Karthikeyannhs e7d8862
one more test scenario
Karthikeyannhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from typing import NewType | ||
|
|
||
| from pydantic import BaseModel, Field, RootModel | ||
|
|
||
| from eligibility_signposting_api.model.campaign_config import CampaignID | ||
|
|
||
| ConsumerId = NewType("ConsumerId", str) | ||
|
|
||
|
|
||
| class ConsumerCampaign(BaseModel): | ||
| campaign: CampaignID = Field(alias="Campaign") | ||
| description: str | None = Field(default=None, alias="Description") | ||
|
|
||
|
|
||
| class ConsumerMapping(RootModel[dict[ConsumerId, list[ConsumerCampaign]]]): | ||
| def get(self, key: ConsumerId, default: list[ConsumerCampaign] | None = None) -> list[ConsumerCampaign] | None: | ||
| return self.root.get(key, default) |
43 changes: 43 additions & 0 deletions
43
src/eligibility_signposting_api/repos/consumer_mapping_repo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import json | ||
| from typing import Annotated, NewType | ||
|
|
||
| from botocore.client import BaseClient | ||
| from wireup import Inject, service | ||
|
|
||
| from eligibility_signposting_api.model.campaign_config import CampaignID | ||
| from eligibility_signposting_api.model.consumer_mapping import ConsumerId, ConsumerMapping | ||
|
|
||
| BucketName = NewType("BucketName", str) | ||
|
|
||
|
|
||
| @service | ||
| class ConsumerMappingRepo: | ||
| """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.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| s3_client: Annotated[BaseClient, Inject(qualifier="s3")], | ||
| bucket_name: Annotated[BucketName, Inject(param="consumer_mapping_bucket_name")], | ||
| ) -> None: | ||
| super().__init__() | ||
| self.s3_client = s3_client | ||
| self.bucket_name = bucket_name | ||
|
|
||
| def get_permitted_campaign_ids(self, consumer_id: ConsumerId) -> list[CampaignID] | None: | ||
| objects = self.s3_client.list_objects(Bucket=self.bucket_name).get("Contents") | ||
|
|
||
| if not objects: | ||
| return None | ||
|
|
||
| consumer_mappings_obj = objects[0] | ||
| response = self.s3_client.get_object(Bucket=self.bucket_name, Key=consumer_mappings_obj["Key"]) | ||
| body = response["Body"].read() | ||
|
|
||
| mapping_result = ConsumerMapping.model_validate(json.loads(body)).get(consumer_id) | ||
|
|
||
| if mapping_result is None: | ||
| return None | ||
|
|
||
| return [item.campaign for item in mapping_result] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / checkov
Ensure IAM policies does not allow permissions management / resource exposure without constraints Warning