oidc_provider: fix error trying to create RSA Key before migrations are run

This commit is contained in:
Jens Langhammer 2019-07-05 15:27:04 +02:00
parent 23d277eaf1
commit 8623a2c3fc
1 changed files with 11 additions and 7 deletions

View File

@ -2,6 +2,7 @@
from logging import getLogger
from django.apps import AppConfig
from django.db.utils import InternalError, OperationalError, ProgrammingError
from django.urls import include, path
LOGGER = getLogger(__name__)
@ -14,6 +15,7 @@ class PassbookOIDCProviderConfig(AppConfig):
verbose_name = 'passbook OIDC Provider'
def ready(self):
try:
from Cryptodome.PublicKey import RSA
from oidc_provider.models import RSAKey
if not RSAKey.objects.exists():
@ -21,6 +23,8 @@ class PassbookOIDCProviderConfig(AppConfig):
rsakey = RSAKey(key=key.exportKey('PEM').decode('utf8'))
rsakey.save()
LOGGER.info("Created key")
except (OperationalError, ProgrammingError, InternalError):
pass
from passbook.root import urls
urls.urlpatterns.append(
path('application/oidc/', include('oidc_provider.urls', namespace='oidc_provider')),