You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.7 KiB

import datetime
5 years ago
import sqlalchemy
from sqlalchemy import Integer, Column, DateTime
5 years ago
from sqlalchemy.orm import relationship, backref
from database import Base
5 years ago
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True, index=True)
email = Column(sqlalchemy.String, unique=True, index=True)
password = Column(sqlalchemy.String)
username = Column(sqlalchemy.String, unique=True)
full_name = Column(sqlalchemy.String)
role = Column(sqlalchemy.String)
class UserAPIKey(Base):
__tablename__ = "api_keys"
id = Column(Integer, primary_key=True, autoincrement=True)
key = Column(sqlalchemy.String, unique=True)
user_id = Column(Integer, sqlalchemy.ForeignKey('users.id', ondelete="CASCADE", onupdate="CASCADE"))
user = relationship("User", foreign_keys=[user_id])
created_date = Column(DateTime, default=datetime.datetime.utcnow)
5 years ago
class WGServer(Base):
__tablename__ = "server"
id = Column(Integer, primary_key=True, index=True)
interface = Column(sqlalchemy.String, unique=True, index=True)
subnet = Column(sqlalchemy.Integer, nullable=False)
5 years ago
address = Column(sqlalchemy.String, unique=True)
v6_address = Column(sqlalchemy.String, unique=True)
v6_subnet = Column(sqlalchemy.Integer, nullable=False)
5 years ago
listen_port = Column(sqlalchemy.String, unique=True)
private_key = Column(sqlalchemy.String)
public_key = Column(sqlalchemy.String)
endpoint = Column(sqlalchemy.String)
dns = Column(sqlalchemy.String)
allowed_ips = Column(sqlalchemy.String)
keep_alive = Column(sqlalchemy.Integer, default=0)
read_only = Column(sqlalchemy.Integer, default=0)
5 years ago
post_up = Column(sqlalchemy.String)
post_down = Column(sqlalchemy.String)
is_running = Column(sqlalchemy.Boolean)
5 years ago
configuration = Column(sqlalchemy.Text)
peers = relationship("WGPeer", cascade="all, delete", passive_deletes=True, lazy="joined")
class WGPeer(Base):
__tablename__ = "peer"
id = Column(Integer, primary_key=True, index=True)
name = Column(sqlalchemy.String, default="Unnamed")
address = Column(sqlalchemy.String)
v6_address = Column(sqlalchemy.String)
5 years ago
public_key = Column(sqlalchemy.String)
private_key = Column(sqlalchemy.String)
shared_key = Column(sqlalchemy.Text)
dns = Column(sqlalchemy.Text)
5 years ago
allowed_ips = Column(sqlalchemy.String)
keep_alive = Column(sqlalchemy.Integer, default=0)
read_only = Column(sqlalchemy.Integer, default=0)
5 years ago
server_id = Column(Integer, sqlalchemy.ForeignKey('server.id', ondelete="CASCADE", onupdate="CASCADE"))
server = relationship("WGServer", backref=backref("server"))
configuration = Column(sqlalchemy.Text)