core: make Source model managed, add inbuilt source

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-09 16:20:59 +02:00
parent 43ad4f58ac
commit 5dd29d45d8
6 changed files with 41 additions and 3 deletions

View File

@ -26,6 +26,9 @@ class SourceSerializer(ModelSerializer, MetaNameSerializer):
def get_component(self, obj: Source): def get_component(self, obj: Source):
"""Get object component so that we know how to edit the object""" """Get object component so that we know how to edit the object"""
# pyright: reportGeneralTypeIssues=false
if obj.__class__ == Source:
return ""
return obj.component return obj.component
class Meta: class Meta:

View File

@ -14,3 +14,4 @@ class AuthentikCoreConfig(AppConfig):
def ready(self): def ready(self):
import_module("authentik.core.signals") import_module("authentik.core.signals")
import_module("authentik.core.managed")

16
authentik/core/managed.py Normal file
View File

@ -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",
),
]

View File

@ -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'),
),
]

View File

@ -240,7 +240,7 @@ class Application(PolicyBindingModel):
verbose_name_plural = _("Applications") 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""" """Base Authentication source, i.e. an OAuth Provider, SAML Remote or LDAP Server"""
name = models.TextField(help_text=_("Source's display Name.")) name = models.TextField(help_text=_("Source's display Name."))

View File

@ -132,7 +132,6 @@ INSTALLED_APPS = [
"django_prometheus", "django_prometheus",
"channels", "channels",
"dbbackup", "dbbackup",
"authentik.managed.apps.AuthentikManagedConfig",
] ]
GUARDIAN_MONKEY_PATCH = False GUARDIAN_MONKEY_PATCH = False
@ -482,6 +481,7 @@ if DEBUG:
CELERY_TASK_ALWAYS_EAGER = True CELERY_TASK_ALWAYS_EAGER = True
os.environ[ENV_GIT_HASH_KEY] = "dev" 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__) j_print("Booting authentik", version=__version__)