Skip to content

Commit 01e2f1c

Browse files
yurasavinn2ygk
authored andcommitted
Issue 1295. Added a warning log
1 parent af9ce73 commit 01e2f1c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

oauth2_provider/migrations/0006_alter_application_client_secret.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
import logging
2+
13
from django.db import migrations
2-
from oauth2_provider import settings
4+
35
import oauth2_provider.generators
46
import oauth2_provider.models
7+
from oauth2_provider import settings
8+
9+
10+
logger = logging.getLogger()
511

612

713
def forwards_func(apps, schema_editor):
@@ -14,6 +20,13 @@ def forwards_func(apps, schema_editor):
1420
application.save(update_fields=['client_secret'])
1521

1622

23+
def reverse_func(apps, schema_editor):
24+
warning_color_code = "\033[93m"
25+
end_color_code = "\033[0m"
26+
msg = f"\n{warning_color_code}The previously hashed client_secret cannot be reverted, and it remains hashed{end_color_code}"
27+
logger.warning(msg)
28+
29+
1730
class Migration(migrations.Migration):
1831

1932
dependencies = [
@@ -26,5 +39,5 @@ class Migration(migrations.Migration):
2639
name='client_secret',
2740
field=oauth2_provider.models.ClientSecretField(blank=True, db_index=True, default=oauth2_provider.generators.generate_client_secret, help_text='Hashed on Save. Copy it now if this is a new secret.', max_length=255),
2841
),
29-
migrations.RunPython(forwards_func, migrations.RunPython.noop),
42+
migrations.RunPython(forwards_func, reverse_func),
3043
]

0 commit comments

Comments
 (0)