-
Notifications
You must be signed in to change notification settings - Fork 11
Refactor: merge fields from EligibilityApiConfig into EligibilityApiVerificationRequest #3441
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
05b6bde
refactor(models): move EV server encryption key fields
lalver1 8c52561
refactor(models): move EV server encryption key data getters
lalver1 245b617
refactor(models): remove api_id field from EligibilityApiConfig
lalver1 4c3809d
refactor(models): remove eligibility_api_config from TransitAgency
lalver1 4804317
refactor(models): remove EligibilityApiConfig models/instances
lalver1 e30b073
chore: clean up fixtures and rename migration
lalver1 974a217
chore(isort): apply isort formatting
lalver1 db33935
chore(models): remove unnecessary deletion of instances
lalver1 69746f7
chore(models): simplify field names for clarity
lalver1 d832b65
chore(models): remove unnecessary deletion of fields
lalver1 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
61 changes: 61 additions & 0 deletions
61
...fits/core/migrations/0072_move_fields_from_eligapiconfig_to_eligapiverificationrequest.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,61 @@ | ||
| # Generated by Django 5.2.7 on 2026-01-15 20:50 | ||
|
|
||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def migrate_eligibility_api_config_data(apps, schema_editor): | ||
| EligibilityApiConfig = apps.get_model("core", "EligibilityApiConfig") | ||
| EligibilityApiVerificationRequest = apps.get_model("core", "EligibilityApiVerificationRequest") | ||
|
|
||
| eligibility_api_config = EligibilityApiConfig.objects.first() | ||
|
|
||
| for request in EligibilityApiVerificationRequest.objects.all(): | ||
| request.client_private_key = eligibility_api_config.api_private_key | ||
| request.client_public_key = eligibility_api_config.api_public_key | ||
| request.save() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("core", "0071_remove_enrollmentflow_selection_label_template_override"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="eligibilityapiverificationrequest", | ||
| name="client_private_key", | ||
| field=models.ForeignKey( | ||
| default=None, | ||
| help_text="Private key used to sign Eligibility API tokens created on behalf of the Benefits client.", | ||
| null=True, | ||
| on_delete=django.db.models.deletion.PROTECT, | ||
| related_name="+", | ||
| to="core.pemdata", | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="eligibilityapiverificationrequest", | ||
| name="client_public_key", | ||
| field=models.ForeignKey( | ||
| default=None, | ||
| help_text=( | ||
| "Public key corresponding to the Benefits client's private key, used by " | ||
| "Eligibility Verification servers to encrypt responses." | ||
| ), | ||
| null=True, | ||
| on_delete=django.db.models.deletion.PROTECT, | ||
| related_name="+", | ||
| to="core.pemdata", | ||
| ), | ||
| ), | ||
| migrations.RunPython(migrate_eligibility_api_config_data), | ||
| migrations.RemoveField( | ||
| model_name="transitagency", | ||
| name="eligibility_api_config", | ||
| ), | ||
| migrations.DeleteModel( | ||
| name="EligibilityApiConfig", | ||
| ), | ||
| ] |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's interesting how the change in this PR affects this view/URL.
First, as seen from this code,
eligibility_api_public_key_datais not agency-related, so the URL<agency:agency>/publickeydoes not really need theagencyargument anymore. I didn't remove it (yet) because I wanted to double check if there are any other systems (like eligibility server GH Actions, for example) that would still expect to include theagencyargument. If there are none, the URL can be simplified.The second thing, I think that this indirectly also shows that the
api_client_public_key(andapi_client_private_key) fields can even be removed fromEligibilityApiVerificationRequestbecause they don't depend on the EV server instance Benefits communicates with, these 2 fields are used by the whole Benefits application, so maybe we can just use thePemDatamodel directly? If it makes sense, it could be a followup refactor.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are both great points and I think we can simplify this significantly. I'd argue a follow-up issue/PR probably makes the most sense but open to doing it here as well.
We can see in the config files on the MST and SBMTD EV servers this is a simple path:
And going to a simpler top-level approach seems pretty easy to do, and also reduces code
Since we don't have an "app configuration" model (something we have kicked around in the past, but not totally necessary at least for this) we'll just want to be careful with how the query for
PemDataworks, to ensure we always get exactly just the public key version.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this feels more related to the merging of those 2 models into
EligibilityApiVerificationRequestit definitely feels in scope to me to do it as part of this PR. FWIW.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for talking through these points with me @thekaveman. We agreed that addressing the two observations from the comment above (#3441 (comment)) wouldn't do much good at this point, we can keep the organization as-is.
On observation 1, it's not wrong to keep the
agencyargument in the URL. Conceptually this is still correct, it's just that the client public key is shared among all agencies, so it's ok to request a key to a particular agency, even if the view associated with the URL does not end up using theagencyargument. A small clarification was added as an in-line comment on this point.On observation 2, an "app configuration" model is not necessary at this point since it would only hold 2 fields, and it seems to add more complication and not much benefit. Without this extra model, we couldn't identify a way to select the correct
PemDatainstance corresponding to the encryption key we need to fetch. Because of this, we should keep the client API encryption keys inEligibilityApiVerificationRequestalong with the EV server's public key. They are neatly organized under the same model.