~sircmpwn/meta.sr.ht

ref: 72548bd7545f78670878667674cc7645835a17bd meta.sr.ht/metasrht/types/auditlogentry.py -rw-r--r-- 1.2 KiB
72548bd7Drew DeVault API: Updates per core-go auth changes 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sqlalchemy as sa
import sqlalchemy_utils as sau
from enum import Enum
from srht.database import Base

class AuditLogEntry(Base):
    __tablename__ = 'audit_log_entry'
    id = sa.Column(sa.Integer, primary_key=True)
    created = sa.Column(sa.DateTime, nullable=False)
    user_id = sa.Column(sa.Integer,
            sa.ForeignKey('user.id'),
            nullable=False)
    user = sa.orm.relationship('User', backref=sa.orm.backref('audit_log'))
    ip_address = sa.Column(sau.IPAddressType, nullable=False)
    event_type = sa.Column(sa.String(256), nullable=False)
    details = sa.Column(sa.Unicode(512))

    def __init__(self, user_id, event_type, ip_address, details):
        self.user_id = user_id
        self.event_type = event_type
        self.ip_address = ip_address
        self.details = details

    def __repr__(self):
        return "<AuditLogEntry {} {} {}>".format(
                self.id, self.ip_address, self.event_type)

    def to_dict(self):
        return {
            "id": self.id,
            "ip": str(self.ip_address),
            "action": self.event_type,
            "details": self.details,
            "created": self.created,
        }