[vpn] include vpn server public key

This commit is contained in:
Nico Schottelius 2020-12-13 18:05:48 +01:00
parent cd19c47fdb
commit aec79cba74
3 changed files with 33 additions and 2 deletions

View file

@ -0,0 +1,19 @@
# Generated by Django 3.1 on 2020-12-13 17:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('uncloud_net', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='wireguardvpnpool',
name='wireguard_public_key',
field=models.CharField(default='', max_length=48),
preserve_default=False,
),
]

View file

@ -24,6 +24,7 @@ class WireGuardVPNPool(models.Model):
vpn_server_hostname = models.CharField(max_length=256) vpn_server_hostname = models.CharField(max_length=256)
wireguard_private_key = models.CharField(max_length=48) wireguard_private_key = models.CharField(max_length=48)
wireguard_public_key = models.CharField(max_length=48)
@property @property
def max_pool_index(self): def max_pool_index(self):
@ -60,6 +61,14 @@ class WireGuardVPN(models.Model):
def network_mask(self): def network_mask(self):
return self.vpnpool.subnetwork_mask return self.vpnpool.subnetwork_mask
@property
def vpn_server(self):
return self.vpnpool.vpn_server_hostname
@property
def vpn_server_public_key(self):
return self.vpnpool.wireguard_public_key
@property @property
def address(self): def address(self):
""" """
@ -77,6 +86,7 @@ class WireGuardVPN(models.Model):
def __str__(self): def __str__(self):
return f"{self.address} ({self.pool_index})" return f"{self.address} ({self.pool_index})"
class WireGuardVPNFreeLeases(models.Model): class WireGuardVPNFreeLeases(models.Model):
""" """
Previously used VPNNetworks Previously used VPNNetworks

View file

@ -9,12 +9,14 @@ from .services import *
class WireGuardVPNSerializer(serializers.ModelSerializer): class WireGuardVPNSerializer(serializers.ModelSerializer):
address = serializers.CharField(read_only=True) address = serializers.CharField(read_only=True)
vpn_server = serializers.CharField(read_only=True)
vpn_server_public_key = serializers.CharField(read_only=True)
network_mask = serializers.IntegerField() network_mask = serializers.IntegerField()
class Meta: class Meta:
model = WireGuardVPN model = WireGuardVPN
fields = [ 'wireguard_public_key', 'address', 'network_mask' ] fields = [ 'wireguard_public_key', 'address', 'network_mask', 'vpn_server',
read_only_fields = [ 'address ' ] 'vpn_server_public_key' ]
extra_kwargs = { extra_kwargs = {
'network_mask': {'write_only': True } 'network_mask': {'write_only': True }