|
23 | 23 | from django.views.decorators.csrf import csrf_exempt
|
24 | 24 | from django.views.decorators.http import require_POST
|
25 | 25 | from pylti1p3.contrib.django import DjangoOIDCLogin, DjangoMessageLaunch, \
|
26 |
| - DjangoCacheDataStorage |
| 26 | + DjangoCacheDataStorage, DjangoDbToolConf |
27 | 27 | from pylti1p3.tool_config import ToolConfDict
|
28 | 28 |
|
29 | 29 | from dashboard.common.db_util import canvas_id_to_incremented_id
|
@@ -68,38 +68,42 @@ def __str__(self):
|
68 | 68 | def get_tool_conf():
|
69 | 69 | lti_config = settings.LTI_CONFIG
|
70 | 70 |
|
71 |
| - try: |
72 |
| - config = ToolConfDict(lti_config) |
73 |
| - except Exception as error: |
74 |
| - return error |
75 |
| - |
76 |
| - # There should be one key per platform |
77 |
| - # and the name relay on platforms generic domain not institution specific |
78 |
| - platform_domain = list(lti_config.keys())[0] |
79 |
| - platform_config = lti_config[platform_domain][0] |
80 |
| - client_id = platform_config['client_id'] |
81 |
| - |
82 |
| - try: |
83 |
| - with open(platform_config.get( |
84 |
| - 'private_key_file', '/secrets/private.key'), |
85 |
| - 'r') as private_key_file: |
86 |
| - config.set_private_key( |
87 |
| - platform_domain, private_key_file.read(), client_id) |
88 |
| - |
89 |
| - with open(platform_config.get( |
90 |
| - 'public_key_file', '/secrets/public.key'), |
91 |
| - 'r') as public_key_file: |
92 |
| - config.set_public_key( |
93 |
| - platform_domain, public_key_file.read(), client_id) |
94 |
| - |
95 |
| - except OSError as error: |
96 |
| - return error |
| 71 | + # If there are configurations for lti_config, use that otherwise use the database config |
| 72 | + if lti_config: |
| 73 | + try: |
| 74 | + config = ToolConfDict(lti_config) |
| 75 | + except Exception as error: |
| 76 | + return error |
| 77 | + |
| 78 | + # There should be one key per platform |
| 79 | + # and the name relay on platforms generic domain not institution specific |
| 80 | + platform_domain = list(lti_config.keys())[0] |
| 81 | + platform_config = lti_config[platform_domain][0] |
| 82 | + client_id = platform_config['client_id'] |
| 83 | + |
| 84 | + try: |
| 85 | + with open(platform_config.get( |
| 86 | + 'private_key_file', '/secrets/private.key'), |
| 87 | + 'r') as private_key_file: |
| 88 | + config.set_private_key( |
| 89 | + platform_domain, private_key_file.read(), client_id) |
| 90 | + |
| 91 | + with open(platform_config.get( |
| 92 | + 'public_key_file', '/secrets/public.key'), |
| 93 | + 'r') as public_key_file: |
| 94 | + config.set_public_key( |
| 95 | + platform_domain, public_key_file.read(), client_id) |
| 96 | + |
| 97 | + except OSError as error: |
| 98 | + return error |
97 | 99 |
|
| 100 | + else: |
| 101 | + config = DjangoDbToolConf() |
98 | 102 | return config
|
99 | 103 |
|
100 | 104 |
|
101 | 105 | def is_config_valid(config: ToolConfDict):
|
102 |
| - if isinstance(config, ToolConfDict): |
| 106 | + if isinstance(config, (ToolConfDict, DjangoDbToolConf)): |
103 | 107 | logger.info('LTI configuration valid.')
|
104 | 108 | return True
|
105 | 109 | else:
|
|
0 commit comments