Add api_v2 app with ApiKey model and initial migration

This commit is contained in:
Eduardo Silva
2026-02-09 20:36:30 -03:00
parent 1bd4fee143
commit 533fed2bec
9 changed files with 65 additions and 1 deletions

0
api_v2/__init__.py Normal file
View File

1
api_v2/admin.py Normal file
View File

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

6
api_v2/apps.py Normal file
View File

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

View File

@@ -0,0 +1,33 @@
# Generated by Django 5.2.11 on 2026-02-09 23:31
import uuid
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
('wireguard', '0032_remove_peer_enabled_by_schedule'),
]
operations = [
migrations.CreateModel(
name='ApiKey',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=64, unique=True)),
('token', models.UUIDField(default=uuid.uuid4, unique=True)),
('allow_restart', models.BooleanField(default=True)),
('allow_reload', models.BooleanField(default=True)),
('allow_export', models.BooleanField(default=True)),
('enabled', models.BooleanField(default=True)),
('uuid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
('created', models.DateTimeField(auto_now_add=True)),
('updated', models.DateTimeField(auto_now=True)),
('allowed_instances', models.ManyToManyField(blank=True, related_name='api_keys', to='wireguard.wireguardinstance')),
],
),
]

View File

21
api_v2/models.py Normal file
View File

@@ -0,0 +1,21 @@
import uuid
from django.db import models
from wireguard.models import WireGuardInstance
class ApiKey(models.Model):
name = models.CharField(max_length=64, unique=True)
token = models.UUIDField(default=uuid.uuid4, unique=True)
allowed_instances = models.ManyToManyField(WireGuardInstance, blank=True, related_name='api_keys')
allow_restart = models.BooleanField(default=True)
allow_reload = models.BooleanField(default=True)
allow_export = models.BooleanField(default=True)
enabled = models.BooleanField(default=True)
uuid = models.UUIDField(default=uuid.uuid4, editable=False, unique=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name

1
api_v2/tests.py Normal file
View File

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

1
api_v2/views.py Normal file
View File

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

View File

@@ -49,7 +49,8 @@ INSTALLED_APPS = [
'cluster', 'cluster',
'api', 'api',
'routing_templates', 'routing_templates',
'scheduler.apps.SchedulerConfig' 'scheduler.apps.SchedulerConfig',
'api_v2'
] ]
MIDDLEWARE = [ MIDDLEWARE = [