Exemple #1
0
def register(name, display_name, category, mimetype_regexp, session):
    try:
        probe = Probe.get_by_name(name, session)
        log.info(
            "probe %s already registred "
            "updating parameters: "
            "[display_name:%s cat:%s regexp:%s]", name, display_name, category,
            mimetype_regexp)
        probe.display_name = display_name
        probe.category = category
        probe.mimetype_regexp = mimetype_regexp
        probe.online = True
        probe.update(['category', 'mimetype_regexp', 'online'], session)
    except IrmaDatabaseResultNotFound:
        log.info(
            "register probe %s"
            " with parameters: "
            "[display_name:%s cat:%s regexp:%s]", name, display_name, category,
            mimetype_regexp)
        probe = Probe(name=name,
                      display_name=display_name,
                      category=category,
                      mimetype_regexp=mimetype_regexp,
                      online=True)
        probe.save(session)
        return
Exemple #2
0
def register(name, display_name, category, mimetype_regexp, session):
    try:
        probe = Probe.get_by_name(name, session)
        log.info(
            "probe %s already registred "
            "updating parameters: "
            "[display_name:%s cat:%s regexp:%s]", name, display_name, category,
            mimetype_regexp)
        session.query(Probe)\
            .filter_by(id=probe.id)\
            .update({'category': category, 'mimetype_regexp': mimetype_regexp,
                     'online': True, 'display_name': display_name})
    except IrmaDatabaseResultNotFound:
        log.info(
            "register probe %s"
            " with parameters: "
            "[display_name:%s cat:%s regexp:%s]", name, display_name, category,
            mimetype_regexp)
        probe = Probe(name=name,
                      display_name=display_name,
                      category=category,
                      mimetype_regexp=mimetype_regexp,
                      online=True)
        session.add(probe)
        return
Exemple #3
0
def create_error_results(probename, error, session):
    try:
        probe = Probe.get_by_name(probename, session)
        display_name = probe.display_name
        category = probe.category
    except IrmaDatabaseError:
        display_name = probename
        category = "unknown"
    result = PluginResult(name=display_name, type=category, error=error)
    return result
Exemple #4
0
def create_error_results(probename, error, session):
    try:
        probe = Probe.get_by_name(probename, session)
        display_name = probe.display_name
        category = probe.category
    except IrmaDatabaseError:
        display_name = probename
        category = "unknown"
    result = PluginResult(name=display_name, type=category, error=error)
    return result
def job_error(parent_taskid, frontend_scan_id, filename, probename):
    try:
        log.info("scanid %s: filename:%s probe %s", frontend_scan_id, filename,
                 probename)
        with session_query() as session:
            probe = Probe.get_by_name(probename, session)
            result = {}
            result['status'] = -1
            result['name'] = probe.display_name
            result['type'] = probe.category
            result['error'] = "job error"
            result['duration'] = None
            celery_frontend.scan_result(frontend_scan_id, filename, probe,
                                        result)
    except Exception as e:
        log.exception(e)
        raise job_error.retry(countdown=5, max_retries=3, exc=e)
Exemple #6
0
def register(name, display_name, category, mimetype_regexp, session):
    try:
        probe = Probe.get_by_name(name, session)
        log.info("probe %s already registred "
                 "updating parameters: "
                 "[display_name:%s cat:%s regexp:%s]",
                 name, display_name, category, mimetype_regexp)
        session.query(Probe)\
            .filter_by(id=probe.id)\
            .update({'category': category, 'mimetype_regexp': mimetype_regexp,
                     'online': True, 'display_name': display_name})
    except IrmaDatabaseResultNotFound:
        log.info("register probe %s"
                 " with parameters: "
                 "[display_name:%s cat:%s regexp:%s]",
                 name, display_name, category, mimetype_regexp)
        probe = Probe(name=name,
                      display_name=display_name,
                      category=category,
                      mimetype_regexp=mimetype_regexp,
                      online=True)
        session.add(probe)
        return
Exemple #7
0
def register(name, display_name, category, mimetype_regexp, session):
    try:
        probe = Probe.get_by_name(name, session)
        log.info("probe %s already registred "
                 "updating parameters: "
                 "[display_name:%s cat:%s regexp:%s]",
                 name, display_name, category, mimetype_regexp)
        probe.display_name = display_name
        probe.category = category
        probe.mimetype_regexp = mimetype_regexp
        probe.online = True
        probe.update(['category', 'mimetype_regexp', 'online'], session)
    except IrmaDatabaseResultNotFound:
        log.info("register probe %s"
                 " with parameters: "
                 "[display_name:%s cat:%s regexp:%s]",
                 name, display_name, category, mimetype_regexp)
        probe = Probe(name=name,
                      display_name=display_name,
                      category=category,
                      mimetype_regexp=mimetype_regexp,
                      online=True)
        probe.save(session)
        return
 def test004_get_by_name_multiple_found(self):
     self.session.query.side_effect = MultipleResultsFound
     with self.assertRaises(IrmaDatabaseError):
         Probe.get_by_name("whatever", self.session)
 def test003_get_by_name_not_found(self):
     self.session.query.side_effect = NoResultFound
     with self.assertRaises(IrmaDatabaseResultNotFound):
         Probe.get_by_name("whatever", self.session)
 def test002_get_by_name(self):
     Probe.get_by_name("whatever", self.session)
     self.session.query.assert_called_once_with(Probe)
     m_filter = self.session.query().filter
     m_filter.assert_called_once()
     m_filter().one.assert_called_once()