コード例 #1
0
def _validate_action_parameters(name, action, action_params):
    requires, unexpected = action_param_utils.validate_action_parameters(action.ref, action_params)

    if requires:
        raise WorkflowDefinitionException('Missing required parameters in "%s" for action "%s": '
                                          '"%s"' % (name, action.ref, '", "'.join(requires)))

    if unexpected:
        raise WorkflowDefinitionException('Unexpected parameters in "%s" for action "%s": '
                                          '"%s"' % (name, action.ref, '", "'.join(unexpected)))
コード例 #2
0
ファイル: workflows.py プロジェクト: danielhneville/st2
def inspect_task_contents(wf_spec):
    result = []
    spec_path = 'tasks'
    schema_path = 'properties.tasks.patternProperties.^\\w+$'
    action_schema_path = schema_path + '.properties.action'
    action_input_schema_path = schema_path + '.properties.input'

    def is_action_an_expression(action):
        if isinstance(action, six.string_types):
            for name, evaluator in six.iteritems(expressions.get_evaluators()):
                if evaluator.has_expressions(action):
                    return True

    for task_name, task_spec in six.iteritems(wf_spec.tasks):
        action_ref = getattr(task_spec, 'action', None)
        action_spec_path = spec_path + '.' + task_name + '.action'
        action_input_spec_path = spec_path + '.' + task_name + '.input'

        # Move on if action is empty or an expression.
        if not action_ref or is_action_an_expression(action_ref):
            continue

        # Check that the format of the action is a valid resource reference.
        if not sys_models.ResourceReference.is_resource_reference(action_ref):
            entry = {
                'type':
                'content',
                'message':
                'The action reference "%s" is not formatted correctly.' %
                action_ref,
                'spec_path':
                action_spec_path,
                'schema_path':
                action_schema_path
            }

            result.append(entry)
            continue

        # Check that the action is registered in the database.
        if not action_utils.get_action_by_ref(ref=action_ref):
            entry = {
                'type': 'content',
                'message':
                'The action "%s" is not registered in the database.' %
                action_ref,
                'spec_path': action_spec_path,
                'schema_path': action_schema_path
            }

            result.append(entry)
            continue

        # Check the action parameters.
        params = getattr(task_spec, 'input', None) or {}

        if params and not isinstance(params, dict):
            continue

        requires, unexpected = action_param_utils.validate_action_parameters(
            action_ref, params)

        for param in requires:
            message = 'Action "%s" is missing required input "%s".' % (
                action_ref, param)

            entry = {
                'type': 'content',
                'message': message,
                'spec_path': action_input_spec_path,
                'schema_path': action_input_schema_path
            }

            result.append(entry)

        for param in unexpected:
            message = 'Action "%s" has unexpected input "%s".' % (action_ref,
                                                                  param)

            entry = {
                'type':
                'content',
                'message':
                message,
                'spec_path':
                action_input_spec_path + '.' + param,
                'schema_path':
                action_input_schema_path + '.patternProperties.^\\w+$'
            }

            result.append(entry)

    return result
コード例 #3
0
    def test_validate_action_inputs(self):
        requires, unexpected = action_param_utils.validate_action_parameters(
            self.action_db.ref, {'foo': 'bar'})

        self.assertListEqual(requires, ['actionstr'])
        self.assertListEqual(unexpected, ['foo'])
コード例 #4
0
    def test_validate_action_inputs(self):
        requires, unexpected = action_param_utils.validate_action_parameters(
            self.action_db.ref, {'foo': 'bar'})

        self.assertListEqual(requires, ['actionstr'])
        self.assertListEqual(unexpected, ['foo'])
コード例 #5
0
    def test_validate_overridden_action_inputs(self):
        requires, unexpected = action_param_utils.validate_action_parameters(
            self.action_dbs['action-3'].ref, {'k1': 'foo'})

        self.assertListEqual(requires, [])
        self.assertListEqual(unexpected, [])
コード例 #6
0
    def test_validate_overridden_action_inputs(self):
        requires, unexpected = action_param_utils.validate_action_parameters(
            self.action_dbs['action-3'].ref, {'k1': 'foo'})

        self.assertListEqual(requires, [])
        self.assertListEqual(unexpected, [])
コード例 #7
0
    def test_validate_overridden_action_inputs(self):
        requires, unexpected = action_param_utils.validate_action_parameters(
            self.action_dbs["action-3"].ref, {"k1": "foo"})

        self.assertListEqual(requires, [])
        self.assertListEqual(unexpected, [])
コード例 #8
0
    def test_validate_action_inputs(self):
        requires, unexpected = action_param_utils.validate_action_parameters(
            self.action_dbs["action-1"].ref, {"foo": "bar"})

        self.assertListEqual(requires, ["actionstr"])
        self.assertListEqual(unexpected, ["foo"])
コード例 #9
0
ファイル: workflows.py プロジェクト: nzlosh/st2
def inspect_task_contents(wf_spec):
    result = []
    spec_path = 'tasks'
    schema_path = 'properties.tasks.patternProperties.^\\w+$'
    action_schema_path = schema_path + '.properties.action'
    action_input_schema_path = schema_path + '.properties.input'

    def is_action_an_expression(action):
        if isinstance(action, six.string_types):
            for name, evaluator in six.iteritems(expressions.get_evaluators()):
                if evaluator.has_expressions(action):
                    return True

    for task_name, task_spec in six.iteritems(wf_spec.tasks):
        action_ref = getattr(task_spec, 'action', None)
        action_spec_path = spec_path + '.' + task_name + '.action'
        action_input_spec_path = spec_path + '.' + task_name + '.input'

        # Move on if action is empty or an expression.
        if not action_ref or is_action_an_expression(action_ref):
            continue

        # Check that the format of the action is a valid resource reference.
        if not sys_models.ResourceReference.is_resource_reference(action_ref):
            entry = {
                'type': 'content',
                'message': 'The action reference "%s" is not formatted correctly.' % action_ref,
                'spec_path': action_spec_path,
                'schema_path': action_schema_path
            }

            result.append(entry)
            continue

        # Check that the action is registered in the database.
        if not action_utils.get_action_by_ref(ref=action_ref):
            entry = {
                'type': 'content',
                'message': 'The action "%s" is not registered in the database.' % action_ref,
                'spec_path': action_spec_path,
                'schema_path': action_schema_path
            }

            result.append(entry)
            continue

        # Check the action parameters.
        params = getattr(task_spec, 'input', None) or {}

        if params and not isinstance(params, dict):
            continue

        requires, unexpected = action_param_utils.validate_action_parameters(action_ref, params)

        for param in requires:
            message = 'Action "%s" is missing required input "%s".' % (action_ref, param)

            entry = {
                'type': 'content',
                'message': message,
                'spec_path': action_input_spec_path,
                'schema_path': action_input_schema_path
            }

            result.append(entry)

        for param in unexpected:
            message = 'Action "%s" has unexpected input "%s".' % (action_ref, param)

            entry = {
                'type': 'content',
                'message': message,
                'spec_path': action_input_spec_path + '.' + param,
                'schema_path': action_input_schema_path + '.patternProperties.^\\w+$'
            }

            result.append(entry)

    return result