Exemplo n.º 1
0
 async def get_matched_paths(path: str, db: AsyncIOMotorCollection):
     matches = []
     async for ctx in db.find({}):
         if pydash.has(ctx, 'path'):
             match = re.match(ctx['path'], path)
             match and matches.append(pydash.merge(
                 ctx, {'regex_groups': match.groups()}))
     return matches
Exemplo n.º 2
0
 async def find(self,
                entityName: str,
                query: dict = None,
                projection: dict = None,
                collection: AsyncIOMotorCollection = None) -> List[dict]:
     if collection is None:
         collection = await self._getCollection(entityName)
     return [d async for d in collection.find(query, projection=projection)]
Exemplo n.º 3
0
    async def get_all(db: AsyncIOMotorCollection):
        """
        gets all circuit breakers

        @param db: mongo instance
        """
        res = db.find({})
        return await res.to_list(100)
Exemplo n.º 4
0
    async def get_all(db: AsyncIOMotorCollection):
        """
        gets all insights

        @param db: mongo collection instance
        """
        res = db.find({})
        return await res.to_list(100)
Exemplo n.º 5
0
    async def get_all(db: AsyncIOMotorCollection):
        """
        Gets all request validation entries

        @param db: (object) db connection
        @return: the documents with the provided serviceId
        """
        res = db.find({})
        return await res.to_list(100)
Exemplo n.º 6
0
    async def get_by_status_code(status_code: int, db: AsyncIOMotorCollection):
        """
        gets insights by status code

        @param status_code: (str) status_code to get insights by
        @param db: mongo collection instance
        """
        res = db.find({'status_code': status_code})
        return await res.to_list(100)
Exemplo n.º 7
0
    async def get_by_circuit_breaker_id(_id: str, db: AsyncIOMotorCollection):
        """
        gets event by circuit breaker id

        @param id: (str) circuit breaker id to get event by
        @param db: mongo collection instance
        """
        res = db.find({'circuit_breaker_id': _id})
        return await res.to_list(100)
Exemplo n.º 8
0
    async def get_by_method(method: str, db: AsyncIOMotorCollection):
        """
        gets cirbuit breaker by method

        @param metod: (str) method of cirbuit breaker
        @param db: mongo instance
        """
        res = db.find({'method': method})
        return await res.to_list(100)
Exemplo n.º 9
0
    async def get_by_threshold(threshold: float, db: AsyncIOMotorCollection):
        """
        gets cirbuit breaker by threshold

        @param threshold: (float) threshold of cirbuit breaker
        @param db: mongo instance
        """
        res = db.find({'threshold': threshold})
        return await res.to_list(100)
Exemplo n.º 10
0
    async def get_by_service_id(service_id: str, db: AsyncIOMotorCollection):
        """
        gets cirbuit breaker by service id

        @param service_id: (str) service id of cirbuit breaker
        @param db: mongo instance
        """
        res = db.find({'service_id': service_id})
        return await res.to_list(100)
Exemplo n.º 11
0
    async def get_by_status_code(status_code: int, db: AsyncIOMotorCollection):
        """
        gets cirbuit breaker by status code

        @param status_code: (int) status code of cirbuit breaker
        @param db: mongo instance
        """
        res = db.find({'status_code': status_code})
        return await res.to_list(100)
Exemplo n.º 12
0
    async def get_by_path(path: str, db: AsyncIOMotorCollection):
        """
        gets insights by path

        @param path: (str) path to get insights by
        @param db: mongo collection instance
        """
        res = db.find({'path': path})
        return await res.to_list(100)
Exemplo n.º 13
0
    async def get_by_method(method: str, db: AsyncIOMotorCollection):
        """
        gets insights by method

        @param method: (str) method to get insights by
        @param db: mongo collection instance
        """
        res = db.find({'method': method})
        return await res.to_list(100)
Exemplo n.º 14
0
    async def get_by_target(target: str, db: AsyncIOMotorCollection):
        """
        gets event by target

        @param target: (str) target to get event by
        @param db: mongo collection instance
        """
        res = db.find({'target': target})
        return await res.to_list(100)
Exemplo n.º 15
0
    async def get_by_remote_ip(remote_ip: str, db: AsyncIOMotorCollection):
        """
        gets insights by remote ip

        @param remote_id: (str) remote_ip to get insights by
        @param db: mongo collection instance
        """
        res = db.find({'remote_ip': remote_ip})
        return await res.to_list(100)
Exemplo n.º 16
0
    async def get_by_scheme(scheme: str, db: AsyncIOMotorCollection):
        """
        gets insights by scheme

        @param scheme: (str) scheme to get insights by
        @param db: mongo collection instance
        """
        res = db.find({'scheme': scheme})
        return await res.to_list(100)
Exemplo n.º 17
0
    async def get_by_service_id(_id: str, db: AsyncIOMotorCollection):
        """
        gets insights by service id

        @param id: (str) id to get insights by
        @param db: mongo collection instance
        """
        res = db.find({'service_id': _id})
        return await res.to_list(100)
Exemplo n.º 18
0
    async def get_by_service_id(service_id: str, db: AsyncIOMotorCollection):
        """
        Gets a request validation entry by the service_id provided

        @param service_id: (string) ID for the service which the request is (coming from? targeting?)
        @param db: (object) db connection
        @return: the documents with the provided serviceId
        """
        res = db.find({"service_id": service_id})
        return await res.to_list(100)
Exemplo n.º 19
0
    async def get_by_method(method: str, db: AsyncIOMotorCollection):
        """
        Gets a request validation entry by the method provided

        @param method: (string) HTTP method that the request is transmitted by
        @param db: (object) db connection
        @return: the documents using the provided method
        """
        res = db.find({"method": method})
        return await res.to_list(100)
Exemplo n.º 20
0
async def get_active_leaves(
        history: AsyncIOMotorCollection,
        current_date: date,
) -> List[Dict]:
    current_datetime = datetime.combine(current_date, time.min)
    return await (
        history.find({
            'date_from': {'$lte': current_datetime},
            'date_to': {'$gte': current_datetime},
            'approval_status': 'approved'
        }).to_list(None)
    )
Exemplo n.º 21
0
    async def list(cls, collection: AsyncIOMotorCollection, projection_model: Type[BaseModel], request: Request,
                   page: int, records_per_page: int, search_fields: Set[str], keyword: Optional[str] = None,
                   sort: Optional[List[Tuple[str, int]]] = None) -> DataList:
        """List documents.

        :param collection: Collection reference
        :param projection_model: Projection model
        :param request: HTTP request
        :param page: Page number
        :param records_per_page: Records per page
        :param search_fields: Search fields
        :param keyword: Keyword for searching data
        :param sort: Sort ( Default is [("updated_at", pymongo.DESCENDING)]. )
        :return: A list of documents
        :raises HTTPResponseException: If there were some errors during the database operation.
        """
        if sort is None:
            sort = [("updated_at", pymongo.DESCENDING)]

        query: dict = {} if keyword is None else await cls.__get_regex_filters(keyword, search_fields)

        try:
            documents: AsyncIOMotorCursor = collection.find(
                filter=query,
                sort=sort,
                skip=(page - 1) * records_per_page,
                limit=records_per_page,
                projection=await cls.__get_projection(projection_model)
            )
            pagination: dict = await cls._get_pagination(request, page, records_per_page,
                                                         await collection.count_documents(query)
                                                         )

            pagination.update({"data": await documents.to_list(length=records_per_page)})

            return pagination
        except PyMongoError as database_server_error:
            await cls._handle_database_server_error(database_server_error)
Exemplo n.º 22
0
 async def init_async(cls, remote_collection: AsyncIOMotorCollection):
     cursor = remote_collection.find({})
     collection = {doc['_id']: Document(doc) async for doc in cursor}
     return cls(collection, remote_collection)