Added Key model

Mapped to a tenant
This commit is contained in:
Jarret Raim 2013-02-17 15:16:22 -06:00
parent 6eb2e0f651
commit 05781de964
2 changed files with 26 additions and 2 deletions

View File

@ -20,7 +20,7 @@ from flask.ext import login, wtf
from flask.ext.login import login_user
from barbican_api import api
from database import db_session, init_db
from models import User, Tenant
from models import User, Tenant, Key
app = Flask(__name__)
@ -30,6 +30,7 @@ app.register_blueprint(api)
admin = Admin(app, name="Barbican Admin")
admin.add_view(ModelView(User, db_session))
admin.add_view(ModelView(Tenant, db_session))
admin.add_view(ModelView(Key, db_session))
login_manager = login.LoginManager()
login_manager.init_app(app)

View File

@ -9,7 +9,9 @@
:license: Apache 2.0, see LICENSE for details
"""
from uuid import uuid4
from sqlalchemy import Column, Integer, String
from sqlalchemy import Column, Integer, String, DateTime, Text
from sqlalchemy.orm import relationship, backref
from sqlalchemy.schema import ForeignKey
from database import Base
@ -45,6 +47,7 @@ class Tenant(Base):
__tablename__ = 'tenants'
id = Column(Integer, primary_key=True)
uuid = Column(String(36), unique=True)
#keys = relationship('Key', backref='tenant', lazy='dynamic')
def __init__(self, uuid=None):
if uuid is None:
@ -52,3 +55,23 @@ class Tenant(Base):
def __repr__(self):
return '<Tenant %s>' % self.uuid
class Key(Base):
__tablename__ = 'keys'
id = Column(Integer, primary_key=True)
uuid = Column(String(36), unique=True)
filename = Column(String(128))
mime_type = Column(String(128))
expires = Column(DateTime)
secret = Column(Text)
tenant_id = Column(Integer, ForeignKey('tenants.id'))
tenant = relationship("Tenant", backref=backref('tenants', order_by=id))
def __init__(self, uuid=None):
if uuid is None:
self.uuid = str(uuid4())
def __repr__(self):
return '<Key %s >' % self.uuid