~sircmpwn/meta.sr.ht

ref: 72548bd7545f78670878667674cc7645835a17bd meta.sr.ht/metasrht/types/pgpkey.py -rw-r--r-- 998 bytes
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
import pgpy
import pgpy.constants
import sqlalchemy as sa
import sqlalchemy_utils as sau
from enum import Enum
from jinja2 import Markup
from srht.database import Base, db
from srht.email import prepare_email

class PGPKey(Base):
    __tablename__ = 'pgpkey'
    id = sa.Column(sa.Integer, primary_key=True)
    created = sa.Column(sa.DateTime)
    user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id'))
    user = sa.orm.relationship('User',
            backref=sa.orm.backref('pgp_keys'),
            foreign_keys=[user_id])
    key = sa.Column(sa.String(32768))
    key_id = sa.Column(sa.String(512))
    email = sa.Column(sa.String(256))

    def __repr__(self):
        return '<PGPKey {} {}>'.format(self.id, self.key_id)

    def to_dict(self):
        return {
            "id": self.id,
            "key": self.key,
            "key_id": self.key_id,
            "email": self.email,
            "authorized": self.created,
            "owner": self.user.to_dict(short=True),
        }