Ejemplo n.º 1
0
def register_rule_types():
    LOG.debug('Start : register default RuleTypes.')

    for rule_type in RULE_TYPES:
        rule_type = copy.deepcopy(rule_type)

        try:
            rule_type_db = RuleType.get_by_name(rule_type['name'])
            update = True
        except ValueError:
            rule_type_db = None
            update = False

        rule_type_api = RuleTypeAPI(**rule_type)
        rule_type_api.validate()
        rule_type_model = RuleTypeAPI.to_model(rule_type_api)

        if rule_type_db:
            rule_type_model.id = rule_type_db.id

        try:
            rule_type_db = RuleType.add_or_update(rule_type_model)

            extra = {'rule_type_db': rule_type_db}
            if update:
                LOG.audit('RuleType updated. RuleType %s', rule_type_db, extra=extra)
            else:
                LOG.audit('RuleType created. RuleType %s', rule_type_db, extra=extra)
        except Exception:
            LOG.exception('Unable to register RuleType %s.', rule_type['name'])

    LOG.debug('End : register default RuleTypes.')
Ejemplo n.º 2
0
 def __get_by_id(id):
     try:
         return RuleType.get_by_id(id)
     except (ValueError, ValidationError) as e:
         msg = 'Database lookup for id="%s" resulted in exception. %s' % (id, e)
         LOG.exception(msg)
         abort(http_client.NOT_FOUND, msg)
Ejemplo n.º 3
0
 def __get_by_id(id):
     try:
         return RuleType.get_by_id(id)
     except (ValueError, ValidationError) as e:
         msg = 'Database lookup for id="%s" resulted in exception. %s' % (id, e)
         LOG.exception(msg)
         abort(http_client.NOT_FOUND, msg)
Ejemplo n.º 4
0
 def __get_by_name(name):
     try:
         return [RuleType.get_by_name(name)]
     except ValueError as e:
         LOG.debug(
             'Database lookup for name="%s" resulted in exception : %s.', name, e
         )
         return []
Ejemplo n.º 5
0
    def get_all(self):
        """
            List all RuleType objects.

            Handles requests:
                GET /ruletypes/
        """
        ruletype_dbs = RuleType.get_all()
        ruletype_apis = [RuleTypeAPI.from_model(runnertype_db)
                         for runnertype_db in ruletype_dbs]
        return ruletype_apis
Ejemplo n.º 6
0
    def get_all(self):
        """
            List all RuleType objects.

            Handles requests:
                GET /ruletypes/
        """
        ruletype_dbs = RuleType.get_all()
        ruletype_apis = [RuleTypeAPI.from_model(runnertype_db)
                         for runnertype_db in ruletype_dbs]
        return ruletype_apis
Ejemplo n.º 7
0
def register_rule_types():
    LOG.debug('Start : register default RuleTypes.')
    registered_count = 0

    for rule_type in RULE_TYPES:
        rule_type = copy.deepcopy(rule_type)

        try:
            rule_type_db = RuleType.get_by_name(rule_type['name'])
            update = True
        except StackStormDBObjectNotFoundError:
            rule_type_db = None
            update = False

        rule_type_api = RuleTypeAPI(**rule_type)
        rule_type_api.validate()
        rule_type_model = RuleTypeAPI.to_model(rule_type_api)

        if rule_type_db:
            rule_type_model.id = rule_type_db.id

        try:
            rule_type_db = RuleType.add_or_update(rule_type_model)

            extra = {'rule_type_db': rule_type_db}
            if update:
                LOG.audit('RuleType updated. RuleType %s',
                          rule_type_db,
                          extra=extra)
            else:
                LOG.audit('RuleType created. RuleType %s',
                          rule_type_db,
                          extra=extra)
        except Exception:
            LOG.exception('Unable to register RuleType %s.', rule_type['name'])
        else:
            registered_count += 1

    LOG.debug('End : register default RuleTypes.')

    return registered_count
Ejemplo n.º 8
0
 def __get_by_name(name):
     try:
         return [RuleType.get_by_name(name)]
     except ValueError as e:
         LOG.debug('Database lookup for name="%s" resulted in exception : %s.', name, e)
         return []