示例#1
0
文件: users.py 项目: mferon/depc
class Grant(BaseModel):
    __tablename__ = "grants"

    user_id = db.Column(UUIDType(binary=False), db.ForeignKey("users.id"))
    user = db.relationship("User", backref="grants")

    role = db.Column(db.Enum(RoleNames), nullable=False, unique=False)

    team_id = db.Column(UUIDType(binary=False), db.ForeignKey("teams.id"))
    team = db.relationship("Team", backref="grants")

    def __repr__(self):
        return "<Grant '{0}' is {1} of {2}>".format(self.user.name,
                                                    self.role.value,
                                                    self.team.name)
示例#2
0
文件: configs.py 项目: mferon/depc
class Config(BaseModel):

    __tablename__ = "configs"
    __repr_fields__ = ("id", "team")

    team_id = db.Column(UUIDType(binary=False),
                        db.ForeignKey("teams.id"),
                        nullable=False)
    team = db.relationship("Team", back_populates="configs")

    data = db.Column(MutableDict.as_mutable(JSONType),
                     default={},
                     nullable=False)
示例#3
0
文件: variables.py 项目: mferon/depc
class Variable(BaseModel):

    __tablename__ = "variables"
    __repr_fields__ = ("name", "value", "type")

    name = db.Column(db.String(255), nullable=False)
    value = db.Column(db.String(), nullable=False)
    type = db.Column(db.String(255), nullable=False)

    rule_id = db.Column(UUIDType(binary=False),
                        db.ForeignKey("rules.id"),
                        nullable=True)
    team_id = db.Column(UUIDType(binary=False),
                        db.ForeignKey("teams.id"),
                        nullable=False)
    source_id = db.Column(UUIDType(binary=False),
                          db.ForeignKey("sources.id"),
                          nullable=True)
    check_id = db.Column(UUIDType(binary=False),
                         db.ForeignKey("checks.id"),
                         nullable=True)

    @property
    def level(self):
        if self.check_id:
            return "check"
        elif self.source_id:
            return "source"
        elif self.rule_id:
            return "rule"
        else:
            return "team"

    @property
    def expression(self):
        exp = "depc.{level}['{name}']" if " " in self.name else "depc.{level}.{name}"
        return exp.format(level=self.level, name=self.name)
示例#4
0
class Check(BaseModel):

    __tablename__ = "checks"
    __repr_fields__ = ("name",)

    name = db.Column(db.String(255), nullable=False)

    source_id = db.Column(
        UUIDType(binary=False), db.ForeignKey("sources.id"), nullable=False
    )
    source = db.relationship(
        "Source", backref=db.backref("source_checks", uselist=True)
    )

    type = db.Column(db.String(255), nullable=False)
    parameters = db.Column(MutableDict.as_mutable(JSONType), default={}, nullable=True)

    variables = db.relationship("Variable", backref="check")
示例#5
0
class Worst(BaseModel):

    __tablename__ = "worst"
    __table_args__ = (UniqueConstraint("team_id",
                                       "label",
                                       "date",
                                       "period",
                                       name="team_label_date_period_uc"), )
    __repr_fields__ = ("team", "label", "date", "period")

    team_id = db.Column(UUIDType(binary=False),
                        db.ForeignKey("teams.id"),
                        nullable=False)
    team = db.relationship("Team", back_populates="worst")
    date = db.Column(db.DateTime(timezone=True), nullable=False)
    label = db.Column(db.String(255), nullable=False)
    period = db.Column(db.Enum(Periods), nullable=False, unique=False)
    data = db.Column(MutableDict.as_mutable(JSONType),
                     default={},
                     nullable=False)
示例#6
0
文件: sources.py 项目: mferon/depc
class Source(BaseModel):

    __tablename__ = "sources"
    __repr_fields__ = ("name", "plugin")

    name = db.Column(db.String(255), nullable=False)

    plugin = db.Column(db.String(255), nullable=False)
    configuration = db.Column(EncryptedDict, default={}, nullable=True)

    checks = db.relationship("Check", back_populates="source")

    team_id = db.Column(UUIDType(binary=False),
                        db.ForeignKey("teams.id"),
                        nullable=True)
    team = db.relationship("Team", back_populates="sources")

    variables = db.relationship(
        "Variable",
        primaryjoin="and_(Source.id==Variable.source_id, "
        "Variable.rule_id==None, "
        "Variable.check_id==None)",
        backref="source",
    )
示例#7
0
from sqlalchemy.schema import UniqueConstraint
from sqlalchemy_utils import UUIDType

from depc.extensions import db
from depc.models import BaseModel


users_news_association_table = db.Table(
    "users_news",
    db.Column(
        "user_id", UUIDType(binary=False), db.ForeignKey("users.id"), primary_key=True
    ),
    db.Column(
        "news_id", UUIDType(binary=False), db.ForeignKey("news.id"), primary_key=True
    ),
    UniqueConstraint("user_id", "news_id", name="users_news_uix"),
)


class News(BaseModel):

    __tablename__ = "news"

    title = db.Column(db.String(100), nullable=False)
    message = db.Column(db.String(), nullable=False)
    users = db.relationship(
        "User", backref=db.backref("news", uselist=True), secondary="users_news"
    )