-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BD-24] [TNL-7607] BB-3072: Move key and client management to model l…
…evel. (#113) * Move LTI 1.3 Key management to model This: - Removes the need to load the modulestore on every public keyset endpoint call. - Simplifies the block structure and parent method overrides. - Removes private key, client id and related parameters from XBlock fields It also includes a migration from the data stored in the block to the model. * Cleanup unused test helpers * Version bump * Addressing review comments
- Loading branch information
1 parent
3a54508
commit 9ac5fda
Showing
14 changed files
with
413 additions
and
208 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,34 @@ | ||
# Generated by Django 2.2.16 on 2020-10-24 11:47 | ||
from django.db import migrations, models | ||
|
||
import lti_consumer | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('lti_consumer', '0003_ltiagsscore'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='lticonfiguration', | ||
name='lti_1p3_internal_private_key', | ||
field=models.TextField(blank=True, help_text="Platform's generated Private key. Keep this value secret."), | ||
), | ||
migrations.AddField( | ||
model_name='lticonfiguration', | ||
name='lti_1p3_internal_private_key_id', | ||
field=models.CharField(blank=True, help_text="Platform's generated Private key ID", max_length=255), | ||
), | ||
migrations.AddField( | ||
model_name='lticonfiguration', | ||
name='lti_1p3_internal_public_jwk', | ||
field=models.TextField(blank=True, help_text="Platform's generated JWK keyset."), | ||
), | ||
migrations.AddField( | ||
model_name='lticonfiguration', | ||
name='lti_1p3_client_id', | ||
field=models.CharField(default=lti_consumer.models.generate_client_id, help_text='Client ID used by LTI tool', max_length=255), | ||
), | ||
] |
This file contains 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,62 @@ | ||
# Generated by Django 2.2.16 on 2020-10-24 11:47 | ||
|
||
from django.db import migrations, models, transaction | ||
|
||
|
||
def _load_block(location): | ||
""" | ||
Loads block from modulestore. | ||
""" | ||
from xmodule.modulestore.django import modulestore | ||
return modulestore().get_item(location) | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
""" | ||
Forward migration - copy client ID and save it in Model | ||
""" | ||
LtiConfiguration = apps.get_model("lti_consumer", "LtiConfiguration") | ||
db_alias = schema_editor.connection.alias | ||
|
||
lti_configs = LtiConfiguration.objects.select_for_update().filter( | ||
version="lti_1p3", | ||
) | ||
with transaction.atomic(): | ||
for lti_config in lti_configs: | ||
block = _load_block(lti_config.location) | ||
|
||
# If client_id exists, move it to model | ||
if hasattr(block, 'lti_1p3_client_id'): | ||
lti_config.lti_1p3_client_id = block.lti_1p3_client_id | ||
|
||
# If key exists, move it to model. Set kid as client_id, respecting | ||
# old implementation | ||
if hasattr(block, 'lti_1p3_block_key'): | ||
lti_config.lti_1p3_internal_private_key_id = block.lti_1p3_client_id | ||
lti_config.lti_1p3_internal_private_key = block.lti_1p3_block_key | ||
|
||
# Save if something changed | ||
lti_config.save() | ||
|
||
|
||
def reverse_func(apps, schema_editor): | ||
""" | ||
Reverse migration - No op. | ||
Leave XBlock to regenerate Client ID and secrets. | ||
""" | ||
pass | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('lti_consumer', '0004_keyset_mgmt_to_model'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython( | ||
forwards_func, | ||
reverse_func | ||
), | ||
] |
Oops, something went wrong.