def _register_policy(self, pack, policy): content = self._meta_loader.load(policy) pack_field = content.get('pack', None) if not pack_field: content['pack'] = pack pack_field = pack if pack_field != pack: raise Exception('Model is in pack "%s" but field "pack" is different: %s' % (pack, pack_field)) policy_api = PolicyAPI(**content) policy_api.validate() policy_db = PolicyAPI.to_model(policy_api) try: policy_db.id = Policy.get_by_name(policy_api.name).id except ValueError: LOG.debug('Policy "%s" is not found. Creating new entry.', policy) try: policy_db = Policy.add_or_update(policy_db) extra = {'policy_db': policy_db} LOG.audit('Policy "%s" is updated.', policy_db.ref, extra=extra) except Exception: LOG.exception('Failed to create policy %s.', policy_api.name) raise
def _register_policy(self, pack, policy): content = self._meta_loader.load(policy) pack_field = content.get('pack', None) if not pack_field: content['pack'] = pack pack_field = pack if pack_field != pack: raise Exception( 'Model is in pack "%s" but field "pack" is different: %s' % (pack, pack_field)) policy_api = PolicyAPI(**content) policy_api = policy_api.validate() policy_db = PolicyAPI.to_model(policy_api) try: policy_db.id = Policy.get_by_name(policy_api.name).id except StackStormDBObjectNotFoundError: LOG.debug('Policy "%s" is not found. Creating new entry.', policy) try: policy_db = Policy.add_or_update(policy_db) extra = {'policy_db': policy_db} LOG.audit('Policy "%s" is updated.', policy_db.ref, extra=extra) except Exception: LOG.exception('Failed to create policy %s.', policy_api.name) raise
def _register_policy(self, pack, policy): content = self._meta_loader.load(policy) pack_field = content.get("pack", None) if not pack_field: content["pack"] = pack pack_field = pack if pack_field != pack: raise Exception( 'Model is in pack "%s" but field "pack" is different: %s' % (pack, pack_field)) # Add in "metadata_file" attribute which stores path to the pack metadata file relative to # the pack directory metadata_file = content_utils.get_relative_path_to_pack_file( pack_ref=pack, file_path=policy, use_pack_cache=True) content["metadata_file"] = metadata_file policy_api = PolicyAPI(**content) policy_api = policy_api.validate() policy_db = PolicyAPI.to_model(policy_api) try: policy_db.id = Policy.get_by_name(policy_api.name).id except StackStormDBObjectNotFoundError: LOG.debug('Policy "%s" is not found. Creating new entry.', policy) try: policy_db = Policy.add_or_update(policy_db) extra = {"policy_db": policy_db} LOG.audit('Policy "%s" is updated.', policy_db.ref, extra=extra) except Exception: LOG.exception("Failed to create policy %s.", policy_api.name) raise
def _register_policy(self, pack, policy): content = self._meta_loader.load(policy) pack_field = content.get('pack', None) if not pack_field: content['pack'] = pack pack_field = pack if pack_field != pack: raise Exception('Model is in pack "%s" but field "pack" is different: %s' % (pack, pack_field)) # Add in "metadata_file" attribute which stores path to the pack metadata file relative to # the pack directory metadata_file = content_utils.get_relative_path_to_pack_file(pack_ref=pack, file_path=policy, use_pack_cache=True) content['metadata_file'] = metadata_file policy_api = PolicyAPI(**content) policy_api = policy_api.validate() policy_db = PolicyAPI.to_model(policy_api) try: policy_db.id = Policy.get_by_name(policy_api.name).id except StackStormDBObjectNotFoundError: LOG.debug('Policy "%s" is not found. Creating new entry.', policy) try: policy_db = Policy.add_or_update(policy_db) extra = {'policy_db': policy_db} LOG.audit('Policy "%s" is updated.', policy_db.ref, extra=extra) except Exception: LOG.exception('Failed to create policy %s.', policy_api.name) raise