コード例 #1
0
class Test(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    test_suite = StringField(validate=validate.Length(max=100), required=True)
    test_cases = ListField(StringField(validate=validate.Length(max=100)))
    variables = DictField()
    path = StringField(validate=validate.Length(max=300), default='')
    author = ReferenceField('User')
    create_date = DateTimeField()
    update_date = DateTimeField()
    organization = ReferenceField('Organization')
    team = ReferenceField('Team')
    staled = BooleanField(default=False)
    package = ReferenceField('Package')
    package_version = StringField()

    class Meta:
        collection_name = 'tests'

    def __eq__(self, other):
        for key, value in self.items():
            if key == 'id':
                continue
            if key == 'create_date' or key == 'update_date':
                continue
            if value != other[key]:
                # missing is substituted to None in __getitem__, ie. other[key]
                if value is missing and other[key] is None:
                    continue
                return False
        return True

    def __hash__(self):
        return hash(str(self.pk))
コード例 #2
0
class Event(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    code = IntField(required=True)
    message = DictField()
    organization = ReferenceField('Organization', required=True)
    team = ReferenceField('Team', default=None)
    status = StringField(validate=validate.Length(max=10), default='Triggered')
    date = DateTimeField(default=datetime.datetime.utcnow)

    class Meta:
        collection_name = 'events'
コード例 #3
0
class User(Document):
	name = StringField(required = True)
	username = StringField(required = True)
	password = StringField(required = True)
	email = EmailField(required = True , unique = True)
	joined_on = DateTimeField(default = datetime.utcnow() + timedelta(hours=5,minutes=30))

	def set_password(self, password):
		self.password = pbkdf2_sha512.hash(password)

	def verify_password(self, password):
		return pbkdf2_sha512.verify(password, self.password)
コード例 #4
0
ファイル: TimeAttackData.py プロジェクト: tylovejoy/dfpk-bot
class TimeAttackData(Document):
    """TournamentData database document."""

    posted_by = IntegerField(required=True, unique=True)
    name = StringField(required=True)
    record = FloatField(required=True)
    attachment_url = StringField(required=True)

    class Meta:
        """MongoDb database collection name."""

        collection_name = "TimeAttackData"
コード例 #5
0
class Endpoint(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    name = StringField(validate=validate.Length(max=100))
    tests = ListField(ReferenceField('Test'))
    status = StringField(default='Offline', validate=validate.Length(max=20))
    enable = BooleanField(default=True)
    last_run_date = DateTimeField()
    organization = ReferenceField('Organization')
    team = ReferenceField('Team')
    uid = UUIDField()

    class Meta:
        collection_name = 'endpoints'
コード例 #6
0
class TestResult(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    test_case = StringField(validate=validate.Length(max=100), required=True)
    test_site = StringField(validate=validate.Length(max=50))
    task = ReferenceField('Task')
    test_date = DateTimeField(default=datetime.datetime.utcnow)
    duration = IntField()
    summary = StringField(validate=validate.Length(max=200))
    status = StringField(validate=validate.Length(max=10), default='FAIL')
    more_result = DictField()

    class Meta:
        collection_name = 'test_results'
コード例 #7
0
ファイル: MapData.py プロジェクト: tylovejoy/dfpk-bot
class MapData(Document):
    """MapData database document."""

    code = StringField(required=True, unique=True)
    creator = StringField(required=True)
    map_name = StringField(required=True)
    posted_by = IntegerField(required=True)
    type = ListField(StringField(), required=True)
    desc = StringField()

    class Meta:
        """MongoDb database collection name."""

        collection_name = "MapData"
コード例 #8
0
ファイル: documents.py プロジェクト: hinha/microservice-auth
class Permission(Document):
    codename = StringField(
        unique=True,
        allow_none=False,
        required=True,
        validate=validate.Regexp(
            r'^[a-z\-\.]+$',
            error="Field value can contain only 'a'-'z', '.', '-' characters.")
    )
    description = StringField(allow_none=True)

    class Meta:
        indexes = [
            '$codename',
        ]
コード例 #9
0
ファイル: Schedule.py プロジェクト: tylovejoy/dfpk-bot
class Schedule(Document):
    """MapData database document."""

    schedule = DateTimeField(required=True)
    mentions = StringField(required=True)

    title = StringField(required=True)

    start_time = DateTimeField(required=False)
    embed_dict = DictField(required=False)

    class Meta:
        """MongoDb database collection name."""

        collection_name = "Schedule"
コード例 #10
0
class Team(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    name = StringField(validate=validate.Length(max=100), required=True)
    email = EmailField()
    registered_on = DateTimeField(default=datetime.datetime.utcnow)
    owner = ReferenceField('User')
    members = ListField(ReferenceField('User'), default=[])
    editors = ListField(ReferenceField('User'), default=[])
    introduction = StringField(validate=validate.Length(max=500))
    avatar = StringField(validate=validate.Length(max=100))
    organization = ReferenceField('Organization')
    path = StringField()

    class Meta:
        collection_name = 'teams'
コード例 #11
0
ファイル: documents.py プロジェクト: hinha/microservice-auth
class Microservice(Document):
    name = StringField(unique=True, allow_none=False, required=True)
    version = StringField(
        unique=False,
        allow_none=False,
        required=True,
        validate=validate.Regexp(
            r'^\d+\.\d+\.\d+$',
            error="Field value must match the `major.minor.patch` version semantics."
        )
    )
    permissions = ListField(ReferenceField(Permission))

    class Meta:
        indexes = ['$name', ]
コード例 #12
0
class EventQueue(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    events = ListField(ReferenceField('Event'), default=[])
    rw_lock = BooleanField(default=False)

    class Meta:
        collection_name = 'event_queues'

    async def acquire_lock(self):
        for i in range(LOCK_TIMEOUT):
            if await self.collection.find_one_and_update(
                {
                    '_id': self.pk,
                    'rw_lock': False
                }, {'$set': {
                    'rw_lock': True
                }}):
                return True
            await asyncio.sleep(0.1)
        else:
            return False

    async def release_lock(self):
        await self.collection.find_one_and_update({'_id': self.pk},
                                                  {'$set': {
                                                      'rw_lock': False
                                                  }})

    async def pop(self):
        if not await self.acquire_lock():
            return None
        await self.reload()
        if len(self.events) == 0:
            await self.release_lock()
            return None
        event = self.events.pop(0)
        event = await event.fetch()
        await self.commit()
        await self.release_lock()
        return event

    async def push(self, event):
        if not await self.acquire_lock():
            raise RuntimeError('failed to acquire queue lock')
        self.events.append(event)
        await self.commit()
        await self.release_lock()

    async def flush(self, cancelled=False):
        if not await self.acquire_lock():
            raise RuntimeError('failed to acquire queue lock')
        if cancelled:
            for event in self.events:
                event.status = 'Cancelled'
                await event.commit()
        self.events = []
        await self.commit()
        await self.release_lock()
        return True
コード例 #13
0
class Documentation(Document):
    schema_version = StringField(max_length=10, default='1')
    filename = StringField(required=True)
    path = StringField(required=True)
    uploader = ReferenceField(User)
    upload_date = DateTimeField(default=datetime.datetime.utcnow)
    last_modifier = ReferenceField(User)
    last_modified = DateTimeField(default=datetime.datetime.utcnow)
    organization = ReferenceField(Organization)
    team = ReferenceField(Team)
    view_times = IntField(default=0)
    proprietary = BooleanField(default=False)
    locked = BooleanField(default=False)
    language = StringField(default='en')

    class Meta:
        collection_name = 'documents'
コード例 #14
0
class User(Document):
    username = StringField(unique=True, allow_none=False, required=True)
    password = StringField(allow_none=False, required=True)
    groups = ListField(ReferenceField(Group))

    class Meta:
        indexes = [
            '$username',
        ]

    def set_password(self, password):
        self.password = hash_password(password)

    def verify_password(self, password):
        return self.password and verify_password(password, self.password)

    async def pre_insert(self):
        self.set_password(self.password)
コード例 #15
0
class User(Document):
    chat_id = IntField(unique=True)
    first_name = StringField(allow_none=True)
    username = StringField(allow_none=True)
    last_name = StringField(allow_none=True)
    locale = StringField(allow_none=True)
    rooms = ListField(StringField())
    hotel_login = StringField()
    hotel_password = StringField()
コード例 #16
0
class Task(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    test = ReferenceField('Test')
    test_suite = StringField(
        validate=validate.Length(max=100))  # embedded document from Test
    testcases = ListField(StringField())
    schedule_date = DateTimeField(default=datetime.datetime.utcnow)
    run_date = DateTimeField()
    status = StringField(validate=validate.Length(max=50), default='waiting')
    comment = StringField(validate=validate.Length(max=1000))
    kickedoff = IntField(validate=validate.Range(min=0), default=0)
    endpoint_list = ListField(UUIDField())
    parallelization = BooleanField(default=False)
    endpoint_run = ReferenceField('Endpoint')
    priority = IntField(validate=validate.Range(min=QUEUE_PRIORITY_MIN,
                                                max=QUEUE_PRIORITY_MAX),
                        default=QUEUE_PRIORITY_DEFAULT)
    variables = DictField()
    tester = ReferenceField('User')
    upload_dir = StringField(validate=validate.Length(max=100))
    test_results = ListField(ReferenceField('TestResult'))
    organization = ReferenceField(
        'Organization')  # embedded document from Test
    team = ReferenceField('Team')  # embedded document from Test

    class Meta:
        collection_name = 'tasks'
コード例 #17
0
class Movies(Document):
    name = StringField(required=True, allow_none=False)
    popularity = IntegerField()
    director = StringField(required=True, allow_none=False)
    genre = ListField(StringField(required=True, allow_none=False))
    imdb_score = IntegerField()
    movie_id = StringField(required=True, allow_none=False)
    insert_datetime = StringField(required=True, allow_none=False)
    update_datetime = StringField(required=True, allow_none=True)

    def pre_delete(self):
        print("Pre delete called")
コード例 #18
0
class PackageFile(Document):
    schema_version = StringField(max_length=10, default='1')
    filename = StringField(required=True)
    name = StringField(required=True)
    description = StringField()
    long_description = StringField()
    uploader = ReferenceField(User)
    upload_date = DateTimeField()
    download_times = IntField(default=0)
    version = StringField(default='0.0.1')

    class Meta:
        collection_name = 'package_files'
コード例 #19
0
class Organization(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    name = StringField(validate=validate.Length(max=50), required=True)
    fullname = StringField(validate=validate.Length(max=100))
    email = EmailField()
    registered_on = DateTimeField(default=datetime.datetime.utcnow)
    teams = ListField(ReferenceField('Team'), default=[])
    introduction = StringField(validate=validate.Length(max=500))
    website = URLField()
    owner = ReferenceField('User')
    members = ListField(ReferenceField('User'), default=[])
    editors = ListField(ReferenceField('User'), default=[])
    region = StringField()
    avatar = StringField(validate=validate.Length(max=100))
    path = StringField()
    personal = BooleanField(default=False)

    class Meta:
        collection_name = 'organizations'
コード例 #20
0
class BlacklistToken(Document):
    """
    Token Model for storing JWT tokens
    """
    token = StringField(validate=validate.Length(max=500),
                        required=True,
                        unique=True)
    blacklisted_on = DateTimeField(default=datetime.datetime.utcnow)

    class Meta:
        collection_name = 'blacklist_tokens'

    def __repr__(self):
        return '<id: token: {}'.format(self.token)

    @staticmethod
    async def check_blacklist(auth_token):
        # check whether auth token has been blacklisted
        res = await BlacklistToken.find_one({'token': str(auth_token)})
        if res is None:
            return False
        return True
コード例 #21
0
class Artist(Document):
    name = StringField(required=True, allow_none=False)
コード例 #22
0
ファイル: chat.py プロジェクト: cpg1111/demo-maestro-app
class Chats(Document):
    collection_name = "chats"

    title = StringField(required=True)
    users = ListField(ReferenceField('Users'))
    messages = ListField(ReferenceField('Messages'))
コード例 #23
0
class GameServer(Document):
    host = StringField(allow_none=False, required=True)
    port = IntegerField(allow_none=False, required=True)
    available_slots = IntegerField(allow_none=False, required=True)
    credentials = DictField(allow_none=False, required=False, default={})
    game_mode = StringField(allow_none=False, required=True)
コード例 #24
0
class Artist(Document):
    name = StringField(required=True, allow_none=False)
    toplam_sayi = IntegerField()
コード例 #25
0
class TaskQueue(Document):
    '''
    Per endpoint per priority queue
    '''
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    priority = IntField(validate=validate.Range(min=QUEUE_PRIORITY_MIN,
                                                max=QUEUE_PRIORITY_MAX),
                        default=QUEUE_PRIORITY_DEFAULT)
    tasks = ListField(ReferenceField('Task'), default=[])
    endpoint = ReferenceField('Endpoint')
    running_task = ReferenceField('Task', allow_none=True, default=missing)
    rw_lock = BooleanField(default=False)
    organization = ReferenceField('Organization')
    team = ReferenceField('Team')
    to_delete = BooleanField(default=False)

    class Meta:
        collection_name = 'task_queues'

    async def acquire_lock(self):
        for i in range(LOCK_TIMEOUT):
            if await self.collection.find_one_and_update(
                {
                    '_id': self.pk,
                    'rw_lock': False
                }, {'$set': {
                    'rw_lock': True
                }}):
                return True
            await asyncio.sleep(0.1)
        else:
            return False

    async def release_lock(self):
        await self.collection.find_one_and_update({'_id': self.pk},
                                                  {'$set': {
                                                      'rw_lock': False
                                                  }})

    async def pop(self):
        if not await self.acquire_lock():
            return None
        await self.reload()
        if len(self.tasks) == 0:
            await self.release_lock()
            return None
        task = self.tasks.pop(0)
        task = await task.fetch()
        self.running_task = task
        await self.commit()
        await self.release_lock()
        return task

    async def push(self, task):
        if not await self.acquire_lock():
            raise RuntimeError('failed to acquire queue lock')
        self.tasks.append(task)
        await self.commit()
        await self.release_lock()

    async def flush(self, cancelled=False):
        if not await self.acquire_lock():
            raise RuntimeError('failed to acquire queue lock')
        if cancelled:
            for task in self.tasks:
                task.status = 'cancelled'
                await task.commit()
        self.tasks = []
        await self.commit()
        await self.release_lock()
        return True
コード例 #26
0
class Task(Document):
	user = ReferenceField(User)
	title = StringField(required = True, max_length = 100)
	desc = StringField(required = True)
	mark_as = StringField(max_length = 8)
コード例 #27
0
class Users(Document):
    username = StringField(required=True, allow_none=False)
    password = StringField(required=True, allow_none=False)
    role = StringField(required=True, allow_none=False)
コード例 #28
0
class User(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    email = EmailField(required=True, unique=True)
    registered_on = DateTimeField(default=datetime.datetime.utcnow)
    name = StringField(validate=validate.Length(max=50))
    password_hash = StringField(validate=validate.Length(max=100))
    roles = ListField(StringField(validate=validate.Length(max=50)))
    avatar = StringField(validate=validate.Length(max=100))
    introduction = StringField(validate=validate.Length(max=500))
    organizations = ListField(ReferenceField('Organization'), default=[])
    teams = ListField(ReferenceField('Team'), default=[])
    region = StringField()

    class Meta:
        collection_name = 'users'

    @property
    def password(self):
        raise AttributeError('password: write-only field')

    @password.setter
    def password(self, password):
        self.password_hash = bcrypt.generate_password_hash(password).decode(
            'utf-8')

    def check_password(self, password):
        return bcrypt.check_password_hash(self.password_hash, password)

    @staticmethod
    def encode_auth_token(user_id):
        """
        Generates the Auth Token
        :return: string
        """
        try:
            payload = {
                'exp':
                datetime.datetime.utcnow() +
                datetime.timedelta(days=1, seconds=5),
                'iat':
                datetime.datetime.utcnow(),
                'sub':
                user_id
            }
            return jwt.encode(payload, key, algorithm='HS256')
        except Exception as e:
            logger.exception(e)
            return None

    @staticmethod
    async def decode_auth_token(auth_token):
        """
        Decodes the auth token
        :param auth_token:
        :return: dict|string
        """
        try:
            payload = jwt.decode(auth_token, key)
            is_blacklisted_token = await BlacklistToken.check_blacklist(
                auth_token)
            if is_blacklisted_token:
                return 'Token blacklisted. Please log in again.'
            else:
                return payload
        except jwt.ExpiredSignatureError:
            return 'Signature expired. Please log in again.'
        except jwt.InvalidTokenError:
            return 'Invalid token. Please log in again.'

    def is_collaborator(self):
        return 'collaborator' in self.roles

    def is_admin(self):
        return 'admin' in self.roles

    def __repr__(self):
        return "<User '{}'>".format(self.name)
コード例 #29
0
class Package(Document):
    schema_version = StringField(validate=validate.Length(max=10), default='1')
    package_type = StringField(required=True)
    name = StringField(required=True)
    index_url = URLField(default='http://127.0.0.1:5000/pypi')
    files = ListField(ReferenceField(PackageFile), default=[])
    proprietary = BooleanField(default=True)
    description = StringField()
    long_description = StringField()
    rating = FloatField(default=4)
    rating_times = IntField(default=1)
    download_times = IntField(default=0)
    organization = ReferenceField('Organization')
    team = ReferenceField('Team')
    uploader = ReferenceField('User')
    py_packages = ListField(
        StringField(),
        default=[])  # python packages defined by the test package
    upload_date = DateTimeField()
    modified = BooleanField(default=False)

    version_re = re.compile(r"^(?P<name>.+?)(-(?P<ver>\d.+?))-.*$").match

    class Meta:
        collection_name = 'packages'

    async def get_package_by_version(self, version=None):
        if version is None and len(self.files) > 0:
            return await self.files[0].fetch()
        for f in self.files:
            f = await f.fetch()
            if f.version == version:
                return f
        return None

    @async_property
    async def versions(self):
        return [(await f.fetch()).version for f in self.files]

    async def sort(self):
        files = [await f.fetch() for f in self.files]
        versions = [f.version for f in files]
        pairs = [(f, v) for f, v in zip(files, versions)]
        pairs.sort(key=lambda x: parse_version(x[1]), reverse=True)
        self.files = [f for f, v in pairs]
        await self.commit()

    @property
    def stars(self):
        return round(self.rating)

    @property
    def package_name(self):
        return self.name.replace('-', '_').replace(' ', '_')

    @property
    def latest_version(self):
        if len(self.files) > 0:
            return self.files[0].version
        return None

    def __hash__(self):
        return hash(str(self.pk))

    def __repr__(self):
        return self.package_name
コード例 #30
0
class User(Document):
    username = StringField(required=True, allow_none=False, unique=True)
    password = StringField(required=True, allow_none=False)
    usertype = StringField(required=True, allow_none=False, default="worker")
    salt = StringField(required=True, unique=True, allow_none=False)