[wireguard] add unique constrain for keys in pool

This commit is contained in:
Nico Schottelius 2020-12-24 17:26:53 +01:00
parent 858aabb5ba
commit a0fbe2d6ed
2 changed files with 24 additions and 0 deletions

View file

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

View file

@ -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