示例#1
0
class Interface(db.Model):
    """
    represents an interface a biobox or task can implement.
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True, nullable=False)
    tasks = db.relationship('Task', backref='interface', lazy='dynamic')
示例#2
0
class Role(db.Model):
    """
    roles a user can assume.

    admin, trusted, common and base
    """

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, unique=True, nullable=False)
    description = db.Column(db.String)
示例#3
0
class Source(db.Model):
    """
    represents a source from where bioboxes are loaded.
    """

    id = db.Column(db.Integer, primary_key=True)
    url = db.Column(db.String, unique=True, nullable=False)
    name = db.Column(db.String, unique=True, nullable=False)
    bioboxes = db.relationship('Biobox',
                               cascade='all, delete-orphan',
                               backref='source',
                               lazy='dynamic')
示例#4
0
class Task(db.Model):
    """
    represents the tasks a biobox can perform.
    """

    KEY_NAME = 'name'
    KEY_INTERFACE = 'interface'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    interface_id = db.Column(db.Integer,
                             db.ForeignKey('interface.id'),
                             nullable=False)
示例#5
0
class Image(db.Model):
    """
    represents the image part of a biobox.

    existence is based solely on the quest for conformity with the schema.
    """

    KEY_CONTAINER_URI = 'dockerhub'
    KEY_REPO_URL = 'repo'
    KEY_SRC_URL = 'source'

    id = db.Column(db.Integer, primary_key=True)
    dockerhub = db.Column(db.String, unique=True, nullable=False)
    repo = db.Column(db.String, unique=True, nullable=False)
    source = db.Column(db.String)
    biobox_id = db.Column(db.Integer,
                          db.ForeignKey("biobox.pmid"),
                          nullable=False)
    biobox = db.relationship("Biobox", back_populates='image', uselist=False)
示例#6
0
class Biobox(db.Model):
    """
    represents a standard biobox.
    """

    KEY_IMAGE = 'image'
    KEY_ID = 'pmid'
    KEY_HOME_PAGE = 'homepage'
    KEY_MAILING_LIST = 'mailing_list'
    KEY_DESCRIPTION = 'description'
    KEY_TASKS = 'tasks'
    KEY_TITLE = 'title'

    pmid = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String, unique=True, nullable=False)
    homepage = db.Column(db.String)
    mailing_list = db.Column(db.String)
    description = db.Column(db.String, nullable=False)
    tasks = db.relationship('Task', cascade='all', secondary=biobox_tasks)
    image = db.relationship('Image',
                            cascade='all',
                            uselist=False,
                            back_populates='biobox')
    source_id = db.Column(db.Integer,
                          db.ForeignKey('source.id'),
                          nullable=False)
示例#7
0
class User(db.Model):
    """
    user representation
    """

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String, unique=True, nullable=False)
    email = db.Column(db.String, unique=True, nullable=False)
    password_hash = db.Column(db.String, nullable=False)
    active = db.Column(db.Boolean())
    confirmed_at = db.Column(db.DateTime())
    roles = db.relationship('Role',
                            secondary=roles_users,
                            backref=db.backref('users', lazy='dynamic'))

    def hash_password(self, password):
        """
        creates a password hash.
        """
        self.password_hash = pwd_context.encrypt(password)

    def verify_password(self, password):
        """
        verifies the password of the user.
        """
        return pwd_context.verify(password, self.password_hash)

    def generate_auth_token(self, expiration=600):
        """
        generates a new authentication token for the user.
        """
        s = Serializer(SECRET_KEY, expires_in=expiration)
        return s.dumps({'id': self.id})

    @staticmethod
    def verify_auth_token(token):
        """
        verifies the authentication token of the user.
        """
        s = Serializer(SECRET_KEY)
        data = s.loads(token)
        user = User.query.get(data['id'])
        return user
示例#8
0
import json
import os.path

import requests
import yaml
from itsdangerous import (TimedJSONWebSignatureSerializer as Serializer)
from jsonschema import validate
from passlib.apps import custom_app_context as pwd_context

from bioboxgui import db
from config import basedir, SECRET_KEY

# linking bioboxes with tasks since 2016.
biobox_tasks = db.Table(
    'association', db.Model.metadata,
    db.Column('biobox_id', db.Integer, db.ForeignKey('biobox.pmid')),
    db.Column('task_id', db.Integer, db.ForeignKey('task.id')))

# many to many relationship between users and roles.
roles_users = db.Table(
    'roles_users', db.Column('user_id', db.Integer, db.ForeignKey('user.id')),
    db.Column('role_id', db.Integer, db.ForeignKey('role.id')))


class Role(db.Model):
    """
    roles a user can assume.

    admin, trusted, common and base
    """