def dao_fetch_service_by_id_with_api_keys(service_id, only_active=False): query = db.on_reader().query(Service).filter_by(id=service_id).options( joinedload('api_keys')) if only_active: query = query.filter(Service.active) return query.one()
def get_notification_by_id(notification_id, service_id=None, _raise=False): filters = [Notification.id == notification_id] if service_id: filters.append(Notification.service_id == service_id) query = db.on_reader().query(Notification).filter(*filters) return query.one() if _raise else query.first()
def dao_get_template_by_id_and_service_id(template_id, service_id, version=None): if version is not None: return TemplateHistory.query.filter_by(id=template_id, hidden=False, service_id=service_id, version=version).one() return db.on_reader().query(Template).filter_by( id=template_id, hidden=False, service_id=service_id).one()
def dao_get_notification_by_reference(reference): return db.on_reader().query(Notification).filter( Notification.reference == reference ).one()
def get_api_key_by_secret(secret): return db.on_reader().query(ApiKey).filter_by( _secret=encryption.encrypt(str(secret))).options( joinedload('service')).one()