当前位置: 首页>>代码示例>>Python>>正文


Python ResourceReference.from_string_reference方法代码示例

本文整理汇总了Python中st2common.models.system.common.ResourceReference.from_string_reference方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceReference.from_string_reference方法的具体用法?Python ResourceReference.from_string_reference怎么用?Python ResourceReference.from_string_reference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.models.system.common.ResourceReference的用法示例。


在下文中一共展示了ResourceReference.from_string_reference方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_trigger_db

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def get_trigger_db(trigger):
    # TODO: This method should die in a fire
    if isinstance(trigger, str) or isinstance(trigger, unicode):
        # Assume reference was passed in
        ref_obj = ResourceReference.from_string_reference(ref=trigger)
        return _get_trigger_db_by_name_and_pack(name=ref_obj.name,
                                                pack=ref_obj.pack)
    if isinstance(trigger, dict):
        name = trigger.get('name', None)
        pack = trigger.get('pack', None)

        if name and pack:
            return _get_trigger_db_by_name_and_pack(name=name, pack=pack)

        return _get_trigger_db(type=trigger['type'],
                               parameters=trigger.get('parameters', {}))

    if isinstance(trigger, object):
        name = getattr(trigger, 'name', None)
        pack = getattr(trigger, 'pack', None)
        parameters = getattr(trigger, 'parameters', {})

        trigger_db = None
        if name and pack:
            trigger_db = _get_trigger_db_by_name_and_pack(name=name, pack=pack)
        else:
            trigger_db = _get_trigger_db(type=trigger.type,
                                         parameters=parameters)
        return trigger_db
    else:
        raise Exception('Unrecognized object')
开发者ID:bjoernbessert,项目名称:st2,代码行数:33,代码来源:triggers.py

示例2: dispatch

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
    def dispatch(self, actionexec_db):
        action_ref = ResourceReference.from_string_reference(ref=actionexec_db.action)
        (action_db, _) = get_action_by_dict(
            {'name': action_ref.name, 'pack': action_ref.pack})
        runnertype_db = get_runnertype_by_name(action_db.runner_type['name'])
        runner_type = runnertype_db.name

        LOG.info('Dispatching runner for Action "%s"', actionexec_db)
        LOG.debug('    liverunner_type: %s', runner_type)
        LOG.debug('    RunnerType: %s', runnertype_db)
        LOG.debug('    ActionExecution: %s', actionexec_db)

        # Get runner instance.
        runner = self._get_runner(runnertype_db)
        LOG.debug('Runner instance for RunnerType "%s" is: %s', runnertype_db.name, runner)

        # Invoke pre_run, run, post_run cycle.
        result, actionexec_db = self._do_run(runner, runnertype_db, action_db, actionexec_db)
        LOG.debug('runner do_run result: %s', result)

        actionsensor.post_trigger(actionexec_db)
        LOG.audit('ActionExecution complete.',
                  extra={'actionexecution': actionexec_db.to_serializable_dict()})

        return result
开发者ID:nagyist,项目名称:StackStorm-st2,代码行数:27,代码来源:base.py

示例3: user_has_rule_action_permission

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def user_has_rule_action_permission(user_db, action_ref):
    """
    Check that the currently logged-in has necessary permissions on the action used / referenced
    inside the rule.

    Note: Rules can reference actions which don't yet exist in the system.
    """
    if not cfg.CONF.rbac.enable:
        return True

    action_db = action_utils.get_action_by_ref(ref=action_ref)

    if not action_db:
        # We allow rules to be created for actions which don't yet exist in the
        # system
        ref = ResourceReference.from_string_reference(ref=action_ref)
        action_db = ActionDB(pack=ref.pack, name=ref.name, ref=action_ref)

    action_resolver = resolvers.get_resolver_for_resource_type(ResourceType.ACTION)
    has_action_permission = action_resolver.user_has_resource_db_permission(
        user_db=user_db, resource_db=action_db, permission_type=PermissionType.ACTION_EXECUTE)

    if has_action_permission:
        return True

    return False
开发者ID:lyandut,项目名称:st2,代码行数:28,代码来源:utils.py

示例4: _get_trigger_instance_db_from_file

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
    def _get_trigger_instance_db_from_file(self, file_path):
        data = self._meta_loader.load(file_path=file_path)
        instance = TriggerInstanceDB(**data)

        trigger_ref = ResourceReference.from_string_reference(instance['trigger'])
        trigger_db = TriggerDB(pack=trigger_ref.pack, name=trigger_ref.name, type=trigger_ref.ref)
        return instance, trigger_db
开发者ID:automotola,项目名称:st2,代码行数:9,代码来源:tester.py

示例5: get_by_ref

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
    def get_by_ref(cls, ref):
        if not ref:
            return None

        ref_obj = ResourceReference.from_string_reference(ref=ref)
        result = cls.query(name=ref_obj.name,
                           pack=ref_obj.pack).first()
        return result
开发者ID:Pulsant,项目名称:st2,代码行数:10,代码来源:base.py

示例6: _get_by_ref

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
    def _get_by_ref(self, resource_ref):
        try:
            ref = ResourceReference.from_string_reference(ref=resource_ref)
        except Exception:
            return None

        resource_db = self.access.query(name=ref.name, pack=ref.pack).first()
        return resource_db
开发者ID:ojacques,项目名称:st2,代码行数:10,代码来源:resource.py

示例7: _get_trigger_dict_given_rule

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def _get_trigger_dict_given_rule(rule):
    trigger = rule.trigger
    trigger_dict = {}
    triggertype_ref = ResourceReference.from_string_reference(trigger.get('type'))
    trigger_dict['pack'] = trigger_dict.get('pack', triggertype_ref.pack)
    trigger_dict['type'] = triggertype_ref.ref
    trigger_dict['parameters'] = rule.trigger.get('parameters', {})

    return trigger_dict
开发者ID:ruslantum,项目名称:st2,代码行数:11,代码来源:triggers.py

示例8: get_action_by_ref

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def get_action_by_ref(action_ref):
    if (not isinstance(action_ref, str) and not isinstance(action_ref, unicode)
            and not isinstance(action_ref, ResourceReference)):
        raise Exception('Action reference has to be either str or ResourceReference.')

    if isinstance(action_ref, str) or isinstance(action_ref, unicode):
        action_ref = ResourceReference.from_string_reference(ref=action_ref)

    return _get_action_by_pack_and_name(name=action_ref.name, pack=action_ref.pack)
开发者ID:bjoernbessert,项目名称:st2,代码行数:11,代码来源:action_db.py

示例9: get_reference

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
    def get_reference(self):
        """
        Retrieve referene object for this model.

        :rtype: :class:`ResourceReference`
        """
        if getattr(self, 'ref', None):
            ref = ResourceReference.from_string_reference(ref=self.ref)
        else:
            ref = ResourceReference(pack=self.pack, name=self.name)

        return ref
开发者ID:nzlosh,项目名称:st2,代码行数:14,代码来源:stormbase.py

示例10: test_resource_reference_success

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
    def test_resource_reference_success(self):
        value = 'pack1.name1'
        ref = ResourceReference.from_string_reference(ref=value)

        self.assertEqual(ref.pack, 'pack1')
        self.assertEqual(ref.name, 'name1')
        self.assertEqual(ref.ref, value)

        ref = ResourceReference(pack='pack1', name='name1')
        self.assertEqual(ref.ref, 'pack1.name1')

        ref = ResourceReference(pack='pack1', name='name1.name2')
        self.assertEqual(ref.ref, 'pack1.name1.name2')
开发者ID:StackStorm,项目名称:st2,代码行数:15,代码来源:test_resource_reference.py

示例11: _get_trigger_api_given_rule

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def _get_trigger_api_given_rule(rule):
    trigger = rule.trigger
    triggertype_ref = ResourceReference.from_string_reference(trigger.get('type'))
    trigger_dict = {}
    trigger_name = trigger.get('name', None)
    if trigger_name:
        trigger_dict['name'] = trigger_name
    trigger_dict['pack'] = triggertype_ref.pack
    trigger_dict['type'] = triggertype_ref.ref
    trigger_dict['parameters'] = rule.trigger.get('parameters', {})
    trigger_api = TriggerAPI(**trigger_dict)

    return trigger_api
开发者ID:bjoernbessert,项目名称:st2,代码行数:15,代码来源:triggers.py

示例12: _to_trigger

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
    def _to_trigger(self, body):
        trigger = body.get('trigger', '')
        trigger_ref = None
        try:
            trigger_ref = ResourceReference.from_string_reference(ref=trigger)
        except InvalidResourceReferenceError:
            LOG.debug('Unable to parse reference.', exc_info=True)

        return {
            'name': trigger_ref.name if trigger_ref else None,
            'pack': trigger_ref.pack if trigger_ref else None,
            'type': body.get('type', ''),
            'parameters': {}
        }, body['payload']
开发者ID:bjoernbessert,项目名称:st2,代码行数:16,代码来源:st2_webhook_sensor.py

示例13: _get_by_ref

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
    def _get_by_ref(self, resource_ref, exclude_fields=None, include_fields=None):
        if exclude_fields and include_fields:
            msg = ('exclude_fields and include_fields arguments are mutually exclusive. '
                   'You need to provide either one or another, but not both.')
            raise ValueError(msg)

        try:
            ref = ResourceReference.from_string_reference(ref=resource_ref)
        except Exception:
            return None

        resource_db = self.access.query(name=ref.name, pack=ref.pack,
                                        exclude_fields=exclude_fields,
                                        only_fields=include_fields).first()
        return resource_db
开发者ID:lyandut,项目名称:st2,代码行数:17,代码来源:resource.py

示例14: get_model_by_resource_ref

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
def get_model_by_resource_ref(db_api, ref):
    """
    Retrieve a DB model based on the resource reference.

    :param db_api: Class of the object to retrieve.
    :type db_api: ``object``

    :param ref: Resource reference.
    :type ref: ``str``

    :return: Retrieved object.
    """
    ref_obj = ResourceReference.from_string_reference(ref=ref)
    result = db_api.query(name=ref_obj.name, pack=ref_obj.pack).first()
    return result
开发者ID:lyandut,项目名称:st2,代码行数:17,代码来源:reference.py

示例15: _get_filters

# 需要导入模块: from st2common.models.system.common import ResourceReference [as 别名]
# 或者: from st2common.models.system.common.ResourceReference import from_string_reference [as 别名]
    def _get_filters(self, **kwargs):
        filters = copy.deepcopy(kwargs)
        ref = filters.get('ref', None)

        if ref:
            try:
                ref_obj = ResourceReference.from_string_reference(ref=ref)
            except InvalidResourceReferenceError:
                raise

            filters['name'] = ref_obj.name
            filters['pack'] = ref_obj.pack
            del filters['ref']

        return filters
开发者ID:tonybaloney,项目名称:st2,代码行数:17,代码来源:resource.py


注:本文中的st2common.models.system.common.ResourceReference.from_string_reference方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。