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.')
def get_one(self, id): """ List RuleType objects by id. Handle: GET /ruletypes/1 """ ruletype_db = RuleTypesController.__get_by_id(id) ruletype_api = RuleTypeAPI.from_model(ruletype_db) return ruletype_api
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
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