authentik.sources.saml.migrations.0013_samlsource_verification_kp_and_more

 1# Generated by Django 4.1.7 on 2023-05-19 21:55
 2
 3import django.db.models.deletion
 4from django.apps.registry import Apps
 5from django.db import migrations, models
 6from django.db.backends.base.schema import BaseDatabaseSchemaEditor
 7
 8
 9def migrate_verification_cert(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
10    """Migrate signing cert to verification_kp for backwards compat"""
11
12    SAMLSource = apps.get_model("authentik_sources_saml", "samlsource")
13    for source in SAMLSource.objects.using(schema_editor.connection.alias).all():
14        source.verification_kp = source.signing_kp
15        source.save()
16
17
18class Migration(migrations.Migration):
19    dependencies = [
20        ("authentik_crypto", "0004_alter_certificatekeypair_name"),
21        ("authentik_sources_saml", "0012_usersamlsourceconnection"),
22    ]
23
24    operations = [
25        migrations.AddField(
26            model_name="samlsource",
27            name="verification_kp",
28            field=models.ForeignKey(
29                blank=True,
30                default=None,
31                help_text="When selected, incoming assertion's Signatures will be validated against this certificate. To allow unsigned Requests, leave on default.",
32                null=True,
33                on_delete=django.db.models.deletion.SET_NULL,
34                related_name="+",
35                to="authentik_crypto.certificatekeypair",
36                verbose_name="Verification Certificate",
37            ),
38        ),
39        migrations.RunPython(migrate_verification_cert),
40        migrations.AlterField(
41            model_name="samlsource",
42            name="signing_kp",
43            field=models.ForeignKey(
44                blank=True,
45                default=None,
46                help_text="Keypair used to sign outgoing Responses going to the Identity Provider.",
47                null=True,
48                on_delete=django.db.models.deletion.SET_NULL,
49                to="authentik_crypto.certificatekeypair",
50                verbose_name="Signing Keypair",
51            ),
52        ),
53    ]
def migrate_verification_cert( apps: django.apps.registry.Apps, schema_editor: django.db.backends.base.schema.BaseDatabaseSchemaEditor):
10def migrate_verification_cert(apps: Apps, schema_editor: BaseDatabaseSchemaEditor):
11    """Migrate signing cert to verification_kp for backwards compat"""
12
13    SAMLSource = apps.get_model("authentik_sources_saml", "samlsource")
14    for source in SAMLSource.objects.using(schema_editor.connection.alias).all():
15        source.verification_kp = source.signing_kp
16        source.save()

Migrate signing cert to verification_kp for backwards compat

class Migration(django.db.migrations.migration.Migration):
19class Migration(migrations.Migration):
20    dependencies = [
21        ("authentik_crypto", "0004_alter_certificatekeypair_name"),
22        ("authentik_sources_saml", "0012_usersamlsourceconnection"),
23    ]
24
25    operations = [
26        migrations.AddField(
27            model_name="samlsource",
28            name="verification_kp",
29            field=models.ForeignKey(
30                blank=True,
31                default=None,
32                help_text="When selected, incoming assertion's Signatures will be validated against this certificate. To allow unsigned Requests, leave on default.",
33                null=True,
34                on_delete=django.db.models.deletion.SET_NULL,
35                related_name="+",
36                to="authentik_crypto.certificatekeypair",
37                verbose_name="Verification Certificate",
38            ),
39        ),
40        migrations.RunPython(migrate_verification_cert),
41        migrations.AlterField(
42            model_name="samlsource",
43            name="signing_kp",
44            field=models.ForeignKey(
45                blank=True,
46                default=None,
47                help_text="Keypair used to sign outgoing Responses going to the Identity Provider.",
48                null=True,
49                on_delete=django.db.models.deletion.SET_NULL,
50                to="authentik_crypto.certificatekeypair",
51                verbose_name="Signing Keypair",
52            ),
53        ),
54    ]

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.

dependencies = [('authentik_crypto', '0004_alter_certificatekeypair_name'), ('authentik_sources_saml', '0012_usersamlsourceconnection')]
operations = [<AddField model_name='samlsource', name='verification_kp', field=<django.db.models.fields.related.ForeignKey>>, <RunPython <function migrate_verification_cert>>, <AlterField model_name='samlsource', name='signing_kp', field=<django.db.models.fields.related.ForeignKey>>]