-
Notifications
You must be signed in to change notification settings - Fork 10
Refactor: Eligibility API config models #3232
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
thekaveman
wants to merge
12
commits into
main
Choose a base branch
from
refactor/eligibility-api-config
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
12 commits
Select commit
Hold shift + click to select a range
8781c82
feat(models): define EligibilityApiVerificationRequest
thekaveman 8edbdba
refactor(models): redefine and reimplement data helper props
thekaveman 255693c
refactor(views): use api_request prop
thekaveman 403691a
refactor(eligibility): use api_request props
thekaveman fa019cf
refactor(oauth/middleware): use helper prop
thekaveman 0b25c7b
feat(admin): define EligibilityApiVerificationRequest ModelAdmin
thekaveman cfd85fc
feat(models): define EligibilityApiConfig
thekaveman 2d24438
fix(tests): correct model_TransitAgency fixture construction
thekaveman 61e0af4
feat(admin): define EligibilityApiConfig ModelAdmin
thekaveman ca15ab8
refactor(models): proxy to eligibility_api_config fields
thekaveman 01b0728
refactor(eligibility): use eligibility_api_config field
thekaveman 38d75d3
chore: update local_fixtures with new models/fields
thekaveman 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
205 changes: 205 additions & 0 deletions
205
benefits/core/migrations/0065_refactor_eligibilityapiverificationrequest.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,205 @@ | ||
| # Generated by Django 5.2.7 on 2025-10-08 17:40 | ||
|
|
||
| import benefits.core.models.common | ||
| import benefits.secrets | ||
| import django.db.models.deletion | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| def migrate_agency_data(apps, schema_editor): | ||
| TransitAgency = apps.get_model("core", "TransitAgency") | ||
| EligibilityApiConfig = apps.get_model("core", "EligibilityApiConfig") | ||
|
|
||
| agencies = ["cst", "mst", "sbmtd"] | ||
|
|
||
| for agency in TransitAgency.objects.all(): | ||
| if agency.slug in agencies: | ||
| config = EligibilityApiConfig.objects.create( | ||
| api_id=agency.eligibility_api_id, | ||
| api_private_key=agency.eligibility_api_private_key, | ||
| api_public_key=agency.eligibility_api_public_key, | ||
| ) | ||
| config.save() | ||
|
|
||
| agency.eligibility_api_config = config | ||
| agency.save() | ||
|
|
||
|
|
||
| def migrate_flow_data(apps, schema_editor): | ||
| EnrollmentFlow = apps.get_model("core", "EnrollmentFlow") | ||
| EligibilityApiVerificationRequest = apps.get_model("core", "EligibilityApiVerificationRequest") | ||
|
|
||
| api_systems = ["agency_card", "courtesy_card", "mobility_pass"] | ||
|
|
||
| for flow in EnrollmentFlow.objects.all(): | ||
| if flow.system_name in api_systems: | ||
| api_request = EligibilityApiVerificationRequest.objects.create( | ||
| label=flow.system_name, | ||
| api_url=flow.eligibility_api_url, | ||
| api_auth_header=flow.eligibility_api_auth_header, | ||
| api_auth_key_secret_name=flow.eligibility_api_auth_key_secret_name, | ||
| api_jwe_cek_enc=flow.eligibility_api_jwe_cek_enc, | ||
| api_jwe_encryption_alg=flow.eligibility_api_jwe_encryption_alg, | ||
| api_jws_signing_alg=flow.eligibility_api_jws_signing_alg, | ||
| api_public_key=flow.eligibility_api_public_key, | ||
| ) | ||
| api_request.save() | ||
|
|
||
| flow.api_request = api_request | ||
| flow.save() | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("core", "0064_transitagency_supported_card_schemes"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="EligibilityApiVerificationRequest", | ||
| fields=[ | ||
| ("id", models.AutoField(primary_key=True, serialize=False)), | ||
| ( | ||
| "label", | ||
| models.SlugField(help_text="A human readable label, used as the display text in Admin."), | ||
| ), | ||
| ( | ||
| "api_url", | ||
| models.URLField(help_text="Fully qualified URL for an Eligibility API server."), | ||
| ), | ||
| ( | ||
| "api_auth_header", | ||
| models.CharField(help_text="The auth header to send in Eligibility API requests.", max_length=50), | ||
| ), | ||
| ( | ||
| "api_auth_key_secret_name", | ||
| benefits.core.models.common.SecretNameField( | ||
| help_text="The name of a secret containing the value of the auth header to send in Eligibility API requests.", # noqa: E501 | ||
| max_length=127, | ||
| validators=[benefits.secrets.SecretNameValidator()], | ||
| ), | ||
| ), | ||
| ( | ||
| "api_jwe_cek_enc", | ||
| models.CharField( | ||
| help_text="The JWE-compatible Content Encryption Key (CEK) key-length and mode to use in Eligibility API requests.", # noqa: E501 | ||
| max_length=50, | ||
| ), | ||
| ), | ||
| ( | ||
| "api_jwe_encryption_alg", | ||
| models.CharField( | ||
| help_text="The JWE-compatible encryption algorithm to use in Eligibility API requests.", | ||
| max_length=50, | ||
| ), | ||
| ), | ||
| ( | ||
| "api_jws_signing_alg", | ||
| models.CharField( | ||
| help_text="The JWS-compatible signing algorithm to use in Eligibility API requests.", | ||
| max_length=50, | ||
| ), | ||
| ), | ||
| ( | ||
| "api_public_key", | ||
| models.ForeignKey( | ||
| help_text="The public key used to encrypt Eligibility API requests and to verify signed Eligibility API responses.", # noqa: E501 | ||
| on_delete=django.db.models.deletion.PROTECT, | ||
| related_name="+", | ||
| to="core.pemdata", | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| migrations.AddField( | ||
| model_name="enrollmentflow", | ||
| name="api_request", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| help_text="The Eligibility API request details for this flow.", | ||
| null=True, | ||
| on_delete=django.db.models.deletion.PROTECT, | ||
| to="core.eligibilityapiverificationrequest", | ||
| ), | ||
| ), | ||
| migrations.RunPython(migrate_flow_data), | ||
| migrations.RemoveField( | ||
| model_name="enrollmentflow", | ||
| name="eligibility_api_auth_header", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="enrollmentflow", | ||
| name="eligibility_api_auth_key_secret_name", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="enrollmentflow", | ||
| name="eligibility_api_jwe_cek_enc", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="enrollmentflow", | ||
| name="eligibility_api_jwe_encryption_alg", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="enrollmentflow", | ||
| name="eligibility_api_jws_signing_alg", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="enrollmentflow", | ||
| name="eligibility_api_public_key", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="enrollmentflow", | ||
| name="eligibility_api_url", | ||
| ), | ||
| migrations.CreateModel( | ||
| name="EligibilityApiConfig", | ||
| fields=[ | ||
| ("id", models.AutoField(primary_key=True, serialize=False)), | ||
| ("api_id", models.SlugField(help_text="The identifier for this agency used in Eligibility API calls.")), | ||
| ( | ||
| "api_private_key", | ||
| models.ForeignKey( | ||
| help_text="Private key used to sign Eligibility API tokens created on behalf of this Agency.", | ||
| on_delete=django.db.models.deletion.PROTECT, | ||
| related_name="+", | ||
| to="core.pemdata", | ||
| ), | ||
| ), | ||
| ( | ||
| "api_public_key", | ||
| models.ForeignKey( | ||
| help_text="Public key corresponding to the agency's private key, used by Eligibility Verification servers to encrypt responses.", # noqa: E501 | ||
| on_delete=django.db.models.deletion.PROTECT, | ||
| related_name="+", | ||
| to="core.pemdata", | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| migrations.AddField( | ||
| model_name="transitagency", | ||
| name="eligibility_api_config", | ||
| field=models.ForeignKey( | ||
| blank=True, | ||
| default=None, | ||
| help_text="The Eligibility API configuration for this transit agency.", | ||
| null=True, | ||
| on_delete=django.db.models.deletion.PROTECT, | ||
| to="core.eligibilityapiconfig", | ||
| ), | ||
| ), | ||
| migrations.RunPython(migrate_agency_data), | ||
| migrations.RemoveField( | ||
| model_name="transitagency", | ||
| name="eligibility_api_id", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="transitagency", | ||
| name="eligibility_api_private_key", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="transitagency", | ||
| name="eligibility_api_public_key", | ||
| ), | ||
| ] |
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.
Uh oh!
There was an error while loading. Please reload this page.