2022-03-17 17:06:00 +00:00
|
|
|
import datetime
|
|
|
|
|
|
|
|
from sqlalchemy import (Boolean, Column, DateTime, ForeignKey, Integer, String,
|
|
|
|
UniqueConstraint)
|
2022-03-17 22:47:31 +00:00
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
2022-03-17 17:06:00 +00:00
|
|
|
from sqlalchemy.orm import relationship
|
|
|
|
|
2022-03-17 22:47:31 +00:00
|
|
|
ORMBaseModel = declarative_base()
|
2022-03-17 17:06:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
class User(ORMBaseModel):
|
|
|
|
__tablename__ = "users"
|
|
|
|
|
|
|
|
name = Column(String, primary_key=True, index=True)
|
|
|
|
password = Column(String)
|
|
|
|
|
|
|
|
capabilities = relationship("UserCapability")
|
|
|
|
certificates = relationship("Certificate")
|
|
|
|
|
|
|
|
|
|
|
|
class UserCapability(ORMBaseModel):
|
|
|
|
__tablename__ = "user_capabilities"
|
|
|
|
|
|
|
|
user_name = Column(
|
|
|
|
String,
|
|
|
|
ForeignKey("users.name"),
|
|
|
|
primary_key=True,
|
|
|
|
index=True,
|
|
|
|
)
|
|
|
|
capability = Column(String, primary_key=True)
|
|
|
|
|
|
|
|
|
|
|
|
class DistinguishedName(ORMBaseModel):
|
|
|
|
__tablename__ = "distinguished_names"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
|
|
|
cn_only = Column(Boolean, default=True)
|
|
|
|
country = Column(String(2))
|
|
|
|
state = Column(String)
|
|
|
|
city = Column(String)
|
|
|
|
organization = Column(String)
|
|
|
|
organizational_unit = Column(String)
|
|
|
|
email = Column(String)
|
|
|
|
common_name = Column(String)
|
|
|
|
|
|
|
|
certificates = relationship("Certificate")
|
|
|
|
|
|
|
|
UniqueConstraint(
|
|
|
|
country,
|
|
|
|
state,
|
|
|
|
city,
|
|
|
|
organization,
|
|
|
|
organizational_unit,
|
|
|
|
email,
|
|
|
|
common_name,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class Certificate(ORMBaseModel):
|
|
|
|
__tablename__ = "certificates"
|
|
|
|
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
|
|
|
|
|
|
owner_name = Column(String, ForeignKey("users.name"))
|
|
|
|
dn_id = Column(Integer, ForeignKey("distinguished_names.id"))
|
|
|
|
expiry = Column(DateTime, default=datetime.datetime.now)
|