class Grant(Entity, Base): __tablename__ = 'grants' TYPES = enum('PASSWORD') access_token = sa.Column(OAUTH_TOKEN, primary_key=True) refresh_token = sa.Column(OAUTH_TOKEN) grant_type = sa.Column(VARCHAR(16), nullable=False, index=True) user_id = sa.Column(PUBLIC_ID, sa.ForeignKey(User.id), index=True) expires_at = sa.Column(UTC_TIMESTAMP, nullable=False) user_agent = sa.Column(VARCHAR) ip_addr = sa.Column(VARCHAR) data = sa.Column(JSONB, default={}, server_default='{}') grantee = relationship(User, backref='grants') def __init__(self, *args, **kwargs): Base.__init__(self, *args, **kwargs) Entity.__init__(self) self.access_token = OAUTH_TOKEN.next_token() def __json__(self, request=None): grant_json = {'type': self.grant_type} if self.grant_type == self.TYPES.PASSWORD: grant_json.update({ 'id': self.id, 'access_token': self.access_token, 'expires_at': self.expires_at, 'type': self.grant_type.lower(), }) return grant_json @classmethod def new_password_grant(cls, grantee, user_agent, ip_addr): grant = cls(grant_type=cls.TYPES.PASSWORD, user_agent=user_agent, ip_addr=ip_addr) grant.grantee = grantee grant.expires_at = grant.created_at + timedelta(days=60) return grant
import re from concur.collections import enum DATABASE_URL = 'postgresql+psycopg2://http:foo@localhost/concur' SUCCESS = {'success': True} RE_BEARER_AUTH_HEADER = re.compile(r'bearer ([a-zA-Z0-9]{50})', re.I) ROLES = enum('CREATOR')
from concur.collections import enum PERMISSIONS = enum(''' CREATE READ UPDATE DELETE ''')
from concur.collections import enum PERMISSIONS = enum( """ CREATE READ UPDATE DELETE """ )