authentik.sources.oauth.migrations.0004_auto_20210417_1900
1# Generated by Django 3.2 on 2021-04-17 19:00 2from django.apps.registry import Apps 3from django.db import migrations, models 4from django.db.backends.base.schema import BaseDatabaseSchemaEditor 5 6 7def update_empty_urls(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 8 OAuthSource = apps.get_model("authentik_sources_oauth", "oauthsource") 9 10 db_alias = schema_editor.connection.alias 11 12 for source in OAuthSource.objects.using(db_alias).all(): 13 changed = False 14 if source.access_token_url == "": # nosec 15 source.access_token_url = None 16 changed = True 17 if source.authorization_url == "": 18 source.authorization_url = None 19 changed = True 20 if source.profile_url == "": 21 source.profile_url = None 22 changed = True 23 if source.request_token_url == "": # nosec 24 source.request_token_url = None 25 changed = True 26 27 if changed: 28 source.save() 29 30 31class Migration(migrations.Migration): 32 dependencies = [ 33 ("authentik_sources_oauth", "0003_auto_20210416_0726"), 34 ] 35 36 operations = [ 37 migrations.AlterField( 38 model_name="oauthsource", 39 name="access_token_url", 40 field=models.CharField( 41 help_text="URL used by authentik to retrieve tokens.", 42 max_length=255, 43 null=True, 44 verbose_name="Access Token URL", 45 ), 46 ), 47 migrations.AlterField( 48 model_name="oauthsource", 49 name="authorization_url", 50 field=models.CharField( 51 help_text="URL the user is redirect to to conest the flow.", 52 max_length=255, 53 null=True, 54 verbose_name="Authorization URL", 55 ), 56 ), 57 migrations.AlterField( 58 model_name="oauthsource", 59 name="profile_url", 60 field=models.CharField( 61 help_text="URL used by authentik to get user information.", 62 max_length=255, 63 null=True, 64 verbose_name="Profile URL", 65 ), 66 ), 67 migrations.AlterField( 68 model_name="oauthsource", 69 name="request_token_url", 70 field=models.CharField( 71 help_text=( 72 "URL used to request the initial token. This URL is only required for OAuth 1." 73 ), 74 max_length=255, 75 null=True, 76 verbose_name="Request Token URL", 77 ), 78 ), 79 migrations.RunPython(update_empty_urls), 80 ]
def
update_empty_urls( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
8def update_empty_urls(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): 9 OAuthSource = apps.get_model("authentik_sources_oauth", "oauthsource") 10 11 db_alias = schema_editor.connection.alias 12 13 for source in OAuthSource.objects.using(db_alias).all(): 14 changed = False 15 if source.access_token_url == "": # nosec 16 source.access_token_url = None 17 changed = True 18 if source.authorization_url == "": 19 source.authorization_url = None 20 changed = True 21 if source.profile_url == "": 22 source.profile_url = None 23 changed = True 24 if source.request_token_url == "": # nosec 25 source.request_token_url = None 26 changed = True 27 28 if changed: 29 source.save()
class
Migration(django.db.migrations.migration.Migration):
32class Migration(migrations.Migration): 33 dependencies = [ 34 ("authentik_sources_oauth", "0003_auto_20210416_0726"), 35 ] 36 37 operations = [ 38 migrations.AlterField( 39 model_name="oauthsource", 40 name="access_token_url", 41 field=models.CharField( 42 help_text="URL used by authentik to retrieve tokens.", 43 max_length=255, 44 null=True, 45 verbose_name="Access Token URL", 46 ), 47 ), 48 migrations.AlterField( 49 model_name="oauthsource", 50 name="authorization_url", 51 field=models.CharField( 52 help_text="URL the user is redirect to to conest the flow.", 53 max_length=255, 54 null=True, 55 verbose_name="Authorization URL", 56 ), 57 ), 58 migrations.AlterField( 59 model_name="oauthsource", 60 name="profile_url", 61 field=models.CharField( 62 help_text="URL used by authentik to get user information.", 63 max_length=255, 64 null=True, 65 verbose_name="Profile URL", 66 ), 67 ), 68 migrations.AlterField( 69 model_name="oauthsource", 70 name="request_token_url", 71 field=models.CharField( 72 help_text=( 73 "URL used to request the initial token. This URL is only required for OAuth 1." 74 ), 75 max_length=255, 76 null=True, 77 verbose_name="Request Token URL", 78 ), 79 ), 80 migrations.RunPython(update_empty_urls), 81 ]
The base class for all migrations.
Migration files will import this from django.db.migrations.Migration and subclass it as a class called Migration. It will have one or more of the following attributes:
- operations: A list of Operation instances, probably from django.db.migrations.operations
- dependencies: A list of tuples of (app_path, migration_name)
- run_before: A list of tuples of (app_path, migration_name)
- replaces: A list of migration_names
Note that all migrations come out of migrations and into the Loader or Graph as instances, having been initialized with their app label and name.
operations =
[<AlterField model_name='oauthsource', name='access_token_url', field=<django.db.models.fields.CharField>>, <AlterField model_name='oauthsource', name='authorization_url', field=<django.db.models.fields.CharField>>, <AlterField model_name='oauthsource', name='profile_url', field=<django.db.models.fields.CharField>>, <AlterField model_name='oauthsource', name='request_token_url', field=<django.db.models.fields.CharField>>, <RunPython <function update_empty_urls>>]