forked from uncloud/uncloud
[vpn] include vpn server public key
This commit is contained in:
parent
cd19c47fdb
commit
aec79cba74
3 changed files with 33 additions and 2 deletions
|
@ -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,
|
||||
),
|
||||
]
|
|
@ -24,6 +24,7 @@ class WireGuardVPNPool(models.Model):
|
|||
|
||||
vpn_server_hostname = models.CharField(max_length=256)
|
||||
wireguard_private_key = models.CharField(max_length=48)
|
||||
wireguard_public_key = models.CharField(max_length=48)
|
||||
|
||||
@property
|
||||
def max_pool_index(self):
|
||||
|
@ -60,6 +61,14 @@ class WireGuardVPN(models.Model):
|
|||
def network_mask(self):
|
||||
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
|
||||
def address(self):
|
||||
"""
|
||||
|
@ -77,6 +86,7 @@ class WireGuardVPN(models.Model):
|
|||
def __str__(self):
|
||||
return f"{self.address} ({self.pool_index})"
|
||||
|
||||
|
||||
class WireGuardVPNFreeLeases(models.Model):
|
||||
"""
|
||||
Previously used VPNNetworks
|
||||
|
|
|
@ -9,12 +9,14 @@ from .services import *
|
|||
|
||||
class WireGuardVPNSerializer(serializers.ModelSerializer):
|
||||
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()
|
||||
|
||||
class Meta:
|
||||
model = WireGuardVPN
|
||||
fields = [ 'wireguard_public_key', 'address', 'network_mask' ]
|
||||
read_only_fields = [ 'address ' ]
|
||||
fields = [ 'wireguard_public_key', 'address', 'network_mask', 'vpn_server',
|
||||
'vpn_server_public_key' ]
|
||||
|
||||
extra_kwargs = {
|
||||
'network_mask': {'write_only': True }
|
||||
|
|
Loading…
Reference in a new issue