Beispiel #1
0
def get_outputs(script):
    """
    Gets script outputs.
    :param script: the script object.
    :return: list of outputs and list of errors.
    """
    errors = []
    outputs = []

    if not script.get('outputs'):
        return {}, []

    for arg in script.get('outputs'):
        if not arg.get('description'):
            errors.append(
                'Error! You are missing description in script output {}'.
                format(arg.get('contextPath')))

        outputs.append({
            'Path':
            arg.get('contextPath'),
            'Description':
            stringEscapeMD(arg.get('description', '')),
            'Type':
            arg.get('type', 'Unknown')
        })

    return outputs, errors
def get_outputs(playbook):
    """
    Gets playbook outputs.
    :param playbook: the playbook object.
    :return: list of outputs and list of errors.
    """
    errors = []
    outputs = []

    if not playbook.get('outputs'):
        return {}, []

    for output in playbook.get('outputs'):
        if not output.get('description'):
            errors.append(
                'Error! You are missing description in playbook output {}'.format(output.get('contextPath')))

        output_type = output.get('type')
        if not output_type:
            output_type = 'unknown'

        outputs.append({
            'Path': output.get('contextPath'),
            'Description': stringEscapeMD(output.get('description', '')),
            'Type': output_type
        })

    return outputs, errors
def get_inputs(playbook):
    """
    Gets playbook inputs.
    :param playbook: the playbook object.
    :return: list of inputs and list of errors.
    """
    errors = []
    inputs = []

    if not playbook.get('inputs'):
        return {}, []

    for _input in playbook.get('inputs'):
        if not _input.get('description'):
            errors.append(
                'Error! You are missing description in playbook input {}'.format(_input.get('key')))

        required_status = 'Required' if _input.get('required') else 'Optional'
        _value, source = get_input_data(_input)

        inputs.append({
            'Name': _input.get('key'),
            'Description': stringEscapeMD(_input.get('description', '')),
            'Default Value': _value,
            'Source': source,
            'Required': required_status,
        })

    return inputs, errors
Beispiel #4
0
def get_inputs(script):
    """
    Gets script inputs.
    :param script: the script object.
    :return: list of inputs and list of errors.
    """
    errors = []
    inputs = []

    if not script.get('args'):
        return {}, []

    for arg in script.get('args'):
        if not arg.get('description'):
            errors.append(
                'Error! You are missing description in script input {}'.format(
                    arg.get('name')))

        inputs.append({
            'Argument Name': arg.get('name'),
            'Description': stringEscapeMD(arg.get('description', ''))
        })

    return inputs, errors
def generate_single_command_section(cmd: dict, example_dict: dict, command_permissions_dict):
    cmd_example = example_dict.get(cmd['name'])
    if command_permissions_dict:
        cmd_permission_example = ['##### Required Permissions', command_permissions_dict.get(cmd['name'])]
    elif isinstance(command_permissions_dict, dict) and not command_permissions_dict:
        cmd_permission_example = ['##### Required Permissions', '**FILL IN REQUIRED PERMISSIONS HERE**']
    else:  # no permissions for this command
        cmd_permission_example = ['', '']

    errors = []
    section = [
        '### {}'.format(cmd['name']),
        '***',
        cmd.get('description', ' '),
        cmd_permission_example[0],
        cmd_permission_example[1],
        '##### Base Command',
        '', '`{}`'.format(cmd['name']),
        '##### Input',
        ''
    ]

    # Inputs
    arguments = cmd.get('arguments')
    if arguments is None:
        section.append('There are no input arguments for this command.')
    else:
        section.extend([
            '| **Argument Name** | **Description** | **Required** |',
            '| --- | --- | --- |',
        ])
        for arg in arguments:
            if not arg.get('description'):
                errors.append(
                    'Error! You are missing description in input {} of command {}'.format(arg['name'], cmd['name']))
            required_status = 'Required' if arg.get('required') else 'Optional'
            section.append('| {} | {} | {} | '.format(arg['name'], stringEscapeMD(arg.get('description', ''),
                                                                                  True, True), required_status))
        section.append('')

    # Context output
    section.extend([
        '',
        '##### Context Output',
        '',
    ])
    outputs = cmd.get('outputs')
    if outputs is None:
        section.append('There is no context output for this command.')
    else:
        section.extend([
            '| **Path** | **Type** | **Description** |',
            '| --- | --- | --- |'
        ])
        for output in outputs:
            if not output.get('description'):
                errors.append(
                    'Error! You are missing description in output {} of command {}'.format(output['contextPath'],
                                                                                           cmd['name']))
            section.append(
                '| {} | {} | {} | '.format(output['contextPath'], output.get('type', 'unknown'),
                                           output.get('description')))
        section.append('')

    # Raw output:
    example_section, example_errors = generate_command_example(cmd, cmd_example)
    section.extend(example_section)
    errors.extend(example_errors)

    return section, errors