From a0fbe2d6ed9b5a9b510c95193c6e4bb1deaf46ca Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 24 Dec 2020 17:26:53 +0100 Subject: [PATCH] [wireguard] add unique constrain for keys in pool --- .../migrations/0006_auto_20201224_1626.py | 17 +++++++++++++++++ uncloud_net/models.py | 7 +++++++ 2 files changed, 24 insertions(+) create mode 100644 uncloud_net/migrations/0006_auto_20201224_1626.py diff --git a/uncloud_net/migrations/0006_auto_20201224_1626.py b/uncloud_net/migrations/0006_auto_20201224_1626.py new file mode 100644 index 0000000..c0dd2ef --- /dev/null +++ b/uncloud_net/migrations/0006_auto_20201224_1626.py @@ -0,0 +1,17 @@ +# Generated by Django 3.1 on 2020-12-24 16:26 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('uncloud_net', '0005_auto_20201220_1837'), + ] + + operations = [ + migrations.AddConstraint( + model_name='wireguardvpn', + constraint=models.UniqueConstraint(fields=('vpnpool', 'wireguard_public_key'), name='wg_key_unique_per_pool'), + ), + ] diff --git a/uncloud_net/models.py b/uncloud_net/models.py index d0dd60b..0c8b02a 100644 --- a/uncloud_net/models.py +++ b/uncloud_net/models.py @@ -84,6 +84,13 @@ class WireGuardVPN(models.Model): wireguard_public_key = models.CharField(max_length=48, unique=True) + class Meta: + constraints = [ + models.UniqueConstraint(fields=['vpnpool', 'wireguard_public_key'], + name='wg_key_unique_per_pool') + ] + + @property def network_mask(self): return self.vpnpool.subnetwork_mask