Пример #1
0
class CVEGroupEntry(db.Model):

    __tablename__ = 'cve_group_entry'
    __versioned__ = {}

    id = db.Column(db.Integer(),
                   index=True,
                   unique=True,
                   primary_key=True,
                   autoincrement=True)
    group_id = db.Column(db.Integer(),
                         db.ForeignKey('cve_group.id', ondelete="CASCADE"),
                         nullable=False)
    cve_id = db.Column(db.String(15),
                       db.ForeignKey('cve.id', ondelete="CASCADE"),
                       nullable=False)

    group = db.relationship("CVEGroup", back_populates="issues")
    cve = db.relationship("CVE")

    __table_args__ = (db.Index('cve_group_entry__group_cve_idx',
                               group_id,
                               cve_id,
                               unique=True), )

    def __repr__(self):
        return '<CVEGroupEntry %r from %r referencing %r>' % (
            self.id, self.group_id, self.cve_id)
Пример #2
0
class Advisory(db.Model):
    WORKAROUND_LENGTH = 4096
    IMPACT_LENGTH = 4096
    CONTENT_LENGTH = 65536
    REFERENCE_LENGTH = 120

    __tablename__ = 'advisory'
    id = db.Column(db.String(15), index=True, unique=True, primary_key=True)
    group_package_id = db.Column(db.Integer(),
                                 db.ForeignKey('cve_group_package.id'),
                                 nullable=False,
                                 unique=True,
                                 index=True)
    advisory_type = db.Column(db.String(64),
                              default='multiple issues',
                              nullable=False)
    publication = db.Column(Publication.as_type(),
                            nullable=False,
                            default=Publication.scheduled)
    workaround = db.Column(db.String(WORKAROUND_LENGTH), nullable=True)
    impact = db.Column(db.String(IMPACT_LENGTH), nullable=True)
    content = db.Column(db.String(CONTENT_LENGTH), nullable=True)
    created = db.Column(db.DateTime,
                        default=datetime.utcnow,
                        nullable=False,
                        index=True)
    reference = db.Column(db.String(REFERENCE_LENGTH), nullable=True)

    group_package = db.relationship("CVEGroupPackage")

    def __repr__(self):
        return '<Advisory {}>'.format(self.id)
Пример #3
0
class User(db.Model):

    NAME_LENGTH = 32
    EMAIL_LENGTH = 128
    SALT_LENGTH = 20
    PASSWORD_LENGTH = 80
    TOKEN_LENGTH = 120
    IDP_ID_LENGTH = 255

    __tablename__ = 'user'
    id = db.Column(db.Integer(), index=True, unique=True, primary_key=True, autoincrement=True)
    name = db.Column(db.String(NAME_LENGTH), index=True, unique=True, nullable=False)
    email = db.Column(db.String(EMAIL_LENGTH), index=True, unique=True, nullable=False)
    salt = db.Column(db.String(SALT_LENGTH), nullable=False)
    password = db.Column(db.String(SALT_LENGTH), nullable=False)
    token = db.Column(db.String(TOKEN_LENGTH), index=True, unique=True, nullable=True)
    role = db.Column(UserRole.as_type(), nullable=False, default=UserRole.reporter)
    active = db.Column(db.Boolean(), nullable=False, default=True)
    idp_id = db.Column(db.String(IDP_ID_LENGTH), nullable=True, default=None, index=True, unique=True)

    is_authenticated = False
    is_anonymous = False

    @property
    def is_active(self):
        return self.active

    def get_id(self):
        return '{}'.format(self.token)

    def __str__(self):
        return self.name

    def __repr__(self):
        return '<User %r>' % (self.name)
Пример #4
0
class Package(db.Model):
    __tablename__ = 'package'
    id = db.Column(db.Integer(),
                   index=True,
                   unique=True,
                   primary_key=True,
                   autoincrement=True)
    name = db.Column(db.String(96), index=True, nullable=False)
    base = db.Column(db.String(96), index=True, nullable=False)
    version = db.Column(db.String(64), nullable=False)
    arch = db.Column(db.String(16), index=True, nullable=False)
    database = db.Column(db.String(32), index=True, nullable=False)
    description = db.Column(db.String(256), nullable=False)
    url = db.Column(db.String(192))
    filename = db.Column(db.String(128), nullable=False)
    md5sum = db.Column(db.String(32), nullable=False)
    sha256sum = db.Column(db.String(64), nullable=False)
    builddate = db.Column(db.Integer(), nullable=False)

    def __repr__(self):
        return '<pkgname: {}-{}>'.format(self.name, self.version)
Пример #5
0
class CVEGroup(db.Model):

    REFERENCES_LENGTH = 4096
    NOTES_LENGTH = 4096

    __versioned__ = {}
    __tablename__ = 'cve_group'

    id = db.Column(db.Integer(),
                   index=True,
                   unique=True,
                   primary_key=True,
                   autoincrement=True)
    status = db.Column(Status.as_type(),
                       nullable=False,
                       default=Status.unknown,
                       index=True)
    severity = db.Column(Severity.as_type(),
                         nullable=False,
                         default=Severity.unknown)
    affected = db.Column(db.String(32), nullable=False)
    fixed = db.Column(db.String(32))
    bug_ticket = db.Column(db.String(9))
    reference = db.Column(db.String(REFERENCES_LENGTH))
    notes = db.Column(db.String(NOTES_LENGTH))
    created = db.Column(db.DateTime,
                        default=datetime.utcnow,
                        nullable=False,
                        index=True)
    changed = db.Column(db.DateTime,
                        default=datetime.utcnow,
                        nullable=False,
                        index=True)
    advisory_qualified = db.Column(db.Boolean(), default=True, nullable=False)

    issues = db.relationship("CVEGroupEntry",
                             back_populates="group",
                             cascade="all,delete-orphan")
    packages = db.relationship("CVEGroupPackage",
                               back_populates="group",
                               cascade="all,delete-orphan")

    @property
    def name(self):
        return 'AVG-{}'.format(self.id)

    def __str__(self):
        return self.name

    def __repr__(self):
        return '<CVEGroup %r>' % (self.id)
Пример #6
0
class Task(db.Model):

    __tablename__ = 'tasks'

    id = db.Column(db.Integer, primary_key=True)
    uuid = db.Column(db.String(length=32), unique=True)
    title = db.Column(db.String(length=200))
    description = db.Column(db.Text())
    date = db.Column(db.Date)
    start_time = db.Column(db.TIMESTAMP)
    end_time = db.Column(db.TIMESTAMP)
    duration = db.Column(db.Integer())
    user_id = db.Column(db.Integer,
                        db.ForeignKey('users.id', ondelete="CASCADE"))

    user = db.relationship('User', backref=db.backref('tasks', lazy='dynamic'))

    @property
    def objects(self):
        return db_managers.TaskManager(self)

    def save(self):
        self.objects.save()