Ejemplo n.º 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)))
Ejemplo n.º 2
0
def _transform_action_param(action_ref, param_name, param_value):
    if isinstance(param_value, list):
        param_value = [
            _transform_action_param(action_ref, param_name, value)
            for value in param_value
        ]

    if isinstance(param_value, dict):
        param_value = {
            name: _transform_action_param(action_ref, name, value)
            for name, value in six.iteritems(param_value)
        }

    if isinstance(param_value, six.string_types):
        st2kv_matches = JINJA_REGEX_WITH_ST2KV_PTRN.findall(param_value)
        local_ctx_matches = JINJA_REGEX_WITH_LOCAL_CTX_PTRN.findall(
            param_value)

        if st2kv_matches and local_ctx_matches:
            raise WorkflowDefinitionException(
                'Parameter "%s" for action "%s" containing '
                'references to both local context (i.e. _.var1) '
                'and st2kv (i.e. st2kv.system.var1) is not '
                'supported.' % (param_name, action_ref))

        if st2kv_matches:
            param_value = '{% raw %}' + param_value + '{% endraw %}'

    return param_value
Ejemplo n.º 3
0
def _transform_action(name, spec):

    action_key, input_key = None, None

    for spec_type, spec_meta in six.iteritems(SPEC_TYPES):
        if spec_meta['action_key'] in spec:
            action_key = spec_meta['action_key']
            input_key = spec_meta['input_key']
            break

    if not action_key:
        return

    if spec[action_key] == 'st2.callback':
        raise WorkflowDefinitionException('st2.callback is deprecated.')

    # Convert parameters that are inline (i.e. action: some_action var1={$.value1} var2={$.value2})
    # and split it to action name and input dict as illustrated below.
    #
    # action: some_action
    # input:
    #   var1: <% $.value1 %>
    #   var2: <% $.value2 %>
    #
    # This step to separate the action name and the input parameters is required
    # to wrap them with the st2.action proxy.
    #
    # action: st2.action
    # input:
    #   ref: some_action
    #   parameters:
    #     var1: <% $.value1 %>
    #     var2: <% $.value2 %>
    _eval_inline_params(spec, action_key, input_key)

    transformed = (spec[action_key] == 'st2.action')

    action_ref = spec[input_key]['ref'] if transformed else spec[action_key]

    action = None

    # Identify if action is a registered StackStorm action.
    if action_ref and ResourceReference.is_resource_reference(action_ref):
        action = action_utils.get_action_by_ref(ref=action_ref)

    # If action is a registered StackStorm action, then wrap the
    # action with the st2 proxy and validate the action input.
    if action:
        if not transformed:
            spec[action_key] = 'st2.action'
            action_input = spec.get(input_key)
            spec[input_key] = {'ref': action_ref}
            if action_input:
                spec[input_key]['parameters'] = action_input

        action_input = spec.get(input_key, {})
        action_params = action_input.get('parameters', {})
        _validate_action_parameters(name, action, action_params)