gatekeeper and app_gateway first commit

This commit is contained in:
Eduardo Silva
2026-03-11 16:35:43 -03:00
parent 7677ddc851
commit 1b51ced8bd
17 changed files with 415 additions and 1 deletions

0
gatekeeper/__init__.py Normal file
View File

1
gatekeeper/admin.py Normal file
View File

@@ -0,0 +1 @@
# Register your models here.

6
gatekeeper/apps.py Normal file
View File

@@ -0,0 +1,6 @@
from django.apps import AppConfig
class GatekeeperConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'gatekeeper'

View File

@@ -0,0 +1,97 @@
# Generated by Django 5.2.12 on 2026-03-11 19:35
import uuid
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='AuthMethod',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.SlugField(max_length=64, unique=True)),
('auth_type', models.CharField(choices=[('local_password', 'Local Password'), ('totp', 'TOTP'), ('oidc', 'OIDC')], max_length=32)),
('totp_secret', models.CharField(blank=True, help_text='Shared/global TOTP secret key', max_length=255)),
('oidc_provider', models.CharField(blank=True, max_length=64)),
('oidc_client_id', models.CharField(blank=True, max_length=255)),
('oidc_client_secret', models.CharField(blank=True, max_length=255)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
],
options={
'ordering': ['name'],
},
),
migrations.CreateModel(
name='GatekeeperUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.SlugField(max_length=64, unique=True)),
('email', models.EmailField(max_length=254, unique=True)),
('password', models.CharField(blank=True, help_text='Password for local authentication (leave blank if not using)', max_length=128)),
('totp_secret', models.CharField(blank=True, help_text='Per-user TOTP secret key', max_length=255)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
],
options={
'verbose_name': 'Gatekeeper User',
'verbose_name_plural': 'Gatekeeper Users',
'ordering': ['username'],
},
),
migrations.CreateModel(
name='GatekeeperGroup',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.SlugField(max_length=64, unique=True)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('users', models.ManyToManyField(blank=True, related_name='groups', to='gatekeeper.gatekeeperuser')),
],
options={
'verbose_name': 'Gatekeeper Group',
'verbose_name_plural': 'Gatekeeper Groups',
'ordering': ['name'],
},
),
migrations.CreateModel(
name='AuthMethodAllowedDomain',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('domain', models.CharField(max_length=255)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('auth_method', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allowed_domains', to='gatekeeper.authmethod')),
],
options={
'unique_together': {('auth_method', 'domain')},
},
),
migrations.CreateModel(
name='AuthMethodAllowedEmail',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email', models.EmailField(max_length=254)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('auth_method', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='allowed_emails', to='gatekeeper.authmethod')),
],
options={
'unique_together': {('auth_method', 'email')},
},
),
]

View File

97
gatekeeper/models.py Normal file
View File

@@ -0,0 +1,97 @@
import uuid
from django.db import models
from django.utils.translation import gettext_lazy as _
class AuthMethod(models.Model):
name = models.SlugField(max_length=64, unique=True)
auth_type = models.CharField(max_length=32, choices=(('local_password', _('Local Password')), ('totp', _('TOTP')), ('oidc', _('OIDC'))))
# TOTP-specific fields
totp_secret = models.CharField(
max_length=255, blank=True,
help_text="Shared/global TOTP secret key"
)
# OIDC-specific fields
oidc_provider = models.CharField(max_length=64, blank=True)
oidc_client_id = models.CharField(max_length=255, blank=True)
oidc_client_secret = models.CharField(max_length=255, blank=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
def __str__(self):
return f"{self.name} ({self.get_auth_type_display()})"
class Meta:
ordering = ['name']
class AuthMethodAllowedDomain(models.Model):
auth_method = models.ForeignKey(AuthMethod, on_delete=models.CASCADE, related_name='allowed_domains')
domain = models.CharField(max_length=255)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
def __str__(self):
return self.domain
class Meta:
unique_together = [('auth_method', 'domain')]
class AuthMethodAllowedEmail(models.Model):
auth_method = models.ForeignKey(AuthMethod, on_delete=models.CASCADE, related_name='allowed_emails')
email = models.EmailField()
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
def __str__(self):
return self.email
class Meta:
unique_together = [('auth_method', 'email')]
class GatekeeperUser(models.Model):
username = models.SlugField(max_length=64, unique=True)
email = models.EmailField(unique=True)
password = models.CharField(blank=True, max_length=128, help_text=_("Password for local authentication (leave blank if not using)"))
totp_secret = models.CharField(max_length=255, blank=True, help_text=_("Per-user TOTP secret key"))
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
def __str__(self):
return self.username
class Meta:
ordering = ['username']
verbose_name = 'Gatekeeper User'
verbose_name_plural = 'Gatekeeper Users'
class GatekeeperGroup(models.Model):
name = models.SlugField(max_length=64, unique=True)
users = models.ManyToManyField(GatekeeperUser, blank=True, related_name='groups')
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False)
def __str__(self):
return self.name
class Meta:
ordering = ['name']
verbose_name = 'Gatekeeper Group'
verbose_name_plural = 'Gatekeeper Groups'

1
gatekeeper/tests.py Normal file
View File

@@ -0,0 +1 @@
# Create your tests here.

1
gatekeeper/views.py Normal file
View File

@@ -0,0 +1 @@
# Create your views here.