diff --git a/authentik/core/api/sources.py b/authentik/core/api/sources.py index 0fb4bff31a..3cdae4ac13 100644 --- a/authentik/core/api/sources.py +++ b/authentik/core/api/sources.py @@ -26,6 +26,9 @@ class SourceSerializer(ModelSerializer, MetaNameSerializer): def get_component(self, obj: Source): """Get object component so that we know how to edit the object""" + # pyright: reportGeneralTypeIssues=false + if obj.__class__ == Source: + return "" return obj.component class Meta: diff --git a/authentik/core/apps.py b/authentik/core/apps.py index 830601a6d6..fe5660cca6 100644 --- a/authentik/core/apps.py +++ b/authentik/core/apps.py @@ -14,3 +14,4 @@ class AuthentikCoreConfig(AppConfig): def ready(self): import_module("authentik.core.signals") + import_module("authentik.core.managed") diff --git a/authentik/core/managed.py b/authentik/core/managed.py new file mode 100644 index 0000000000..f8c1b8a7de --- /dev/null +++ b/authentik/core/managed.py @@ -0,0 +1,16 @@ +"""Core managed objects""" +from authentik.core.models import Source +from authentik.managed.manager import EnsureExists, ObjectManager + + +class CoreManager(ObjectManager): + """Core managed objects""" + + def reconcile(self): + return [ + EnsureExists( + Source, + "goauthentik.io/sources/inbuilt", + name="authentik Built-in", + ), + ] diff --git a/authentik/core/migrations/0019_source_managed.py b/authentik/core/migrations/0019_source_managed.py new file mode 100644 index 0000000000..cef8e2748d --- /dev/null +++ b/authentik/core/migrations/0019_source_managed.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2 on 2021-04-09 14:06 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentik_core', '0018_auto_20210330_1345'), + ] + + operations = [ + migrations.AddField( + model_name='source', + name='managed', + field=models.TextField(default=None, help_text='Objects which are managed by authentik. These objects are created and updated automatically. This is flag only indicates that an object can be overwritten by migrations. You can still modify the objects via the API, but expect changes to be overwritten in a later update.', null=True, unique=True, verbose_name='Managed by authentik'), + ), + ] diff --git a/authentik/core/models.py b/authentik/core/models.py index 28900030aa..efd7ec686c 100644 --- a/authentik/core/models.py +++ b/authentik/core/models.py @@ -240,7 +240,7 @@ class Application(PolicyBindingModel): verbose_name_plural = _("Applications") -class Source(SerializerModel, PolicyBindingModel): +class Source(ManagedModel, SerializerModel, PolicyBindingModel): """Base Authentication source, i.e. an OAuth Provider, SAML Remote or LDAP Server""" name = models.TextField(help_text=_("Source's display Name.")) diff --git a/authentik/root/settings.py b/authentik/root/settings.py index 510d9e04a0..859434d755 100644 --- a/authentik/root/settings.py +++ b/authentik/root/settings.py @@ -132,7 +132,6 @@ INSTALLED_APPS = [ "django_prometheus", "channels", "dbbackup", - "authentik.managed.apps.AuthentikManagedConfig", ] GUARDIAN_MONKEY_PATCH = False @@ -482,6 +481,7 @@ if DEBUG: CELERY_TASK_ALWAYS_EAGER = True os.environ[ENV_GIT_HASH_KEY] = "dev" -INSTALLED_APPS.append("authentik.core.apps.AuthentikCoreConfig") +INSTALLED_APPS.append("authentik.core") +INSTALLED_APPS.append("authentik.managed") j_print("Booting authentik", version=__version__)