コード例 #1
0
    def generate_readme_for_pack_content_item(self,
                                              yml_path: str,
                                              is_contribution: bool = False
                                              ) -> None:
        """ Runs the demisto-sdk's generate-docs command on a pack content item

        Args:
            yml_path: str: Content item yml path.
            is_contribution: bool: Check if the content item is a new integration contribution or not.
        """
        file_type = find_type(yml_path)
        file_type = file_type.value if file_type else file_type
        if file_type == 'integration':
            generate_integration_doc(yml_path, is_contribution=is_contribution)
        if file_type == 'script':
            generate_script_doc(input_path=yml_path, examples=[])
        if file_type == 'playbook':
            generate_playbook_doc(yml_path)

        dir_output = os.path.dirname(os.path.realpath(yml_path))
        if file_type == 'playbook':
            readme_path = yml_path.replace('.yml', '_README.md')
        else:
            readme_path = os.path.join(dir_output, 'README.md')
        self.readme_files.append(readme_path)
コード例 #2
0
def test_generate_script_doc(tmp_path, mocker):
    d = tmp_path / "script_doc_out"
    d.mkdir()
    in_script = os.path.join(FILES_PATH, 'docs_test', 'script-Set.yml')
    id_set_file = os.path.join(FILES_PATH, 'docs_test', 'id_set.json')
    with open(id_set_file, 'r') as f:
        id_set = json.load(f)
    patched = mocker.patch.object(IDSetCreator, 'create_id_set', return_value=id_set)
    generate_script_doc(in_script, '', str(d), verbose=True)
    patched.assert_called()
    readme = d / "README.md"
    with open(readme) as f:
        text = f.read()
        assert 'Sample usage of this script can be found in the following playbooks and scripts' in text
コード例 #3
0
ファイル: __main__.py プロジェクト: ashishsecdev/demisto-sdk
def generate_doc(**kwargs):
    input_path = kwargs.get('input')
    output_path = kwargs.get('output')

    # validate inputs
    if input_path and not os.path.isfile(input_path):
        print_error(F'Input file {input_path} was not found.')
        return 1

    if not input_path.lower().endswith('.yml'):
        print_error(F'Input {input_path} is not a valid yml file.')
        return 1

    if output_path and not os.path.isdir(output_path):
        print_error(F'Output directory {output_path} was not found.')
        return 1

    file_type = find_type(kwargs.get('input', ''))
    if file_type not in ["integration", "script", "playbook"]:
        print_error(F'File is not an Integration, Script or a Playbook.')
        return 1

    print(f'Start generating {file_type} documentation...')
    if file_type == 'integration':
        return generate_integration_doc(**kwargs)
    elif file_type == 'script':
        return generate_script_doc(**kwargs)
    elif file_type == 'playbook':
        return generate_playbook_doc(**kwargs)
    else:
        print_error(f'File type {file_type} is not supported.')
        return 1
コード例 #4
0
    def generate_readme_for_pack_content_item(self, yml_path: str) -> None:
        """ Runs the demisto-sdk's generate-docs command on a pack content item

        Args:
            yml_path: str: Content item yml path.
        """
        file_type = find_type(yml_path)
        file_type = file_type.value if file_type else file_type
        if file_type == 'integration':
            generate_integration_doc(yml_path)
        if file_type == 'script':
            generate_script_doc(input_path=yml_path, examples=[])
        if file_type == 'playbook':
            generate_playbook_doc(yml_path)

        dir_output = os.path.dirname(os.path.realpath(yml_path))
        readme_path = os.path.join(dir_output, 'README.md')
        self.readme_files.append(readme_path)
コード例 #5
0
ファイル: __main__.py プロジェクト: cckronos/demisto-sdk
def generate_doc(**kwargs):
    input_path = kwargs.get('input')
    output_path = kwargs.get('output')
    command = kwargs.get('command')
    examples = kwargs.get('examples')
    permissions = kwargs.get('permissions')
    limitations = kwargs.get('limitations')
    insecure = kwargs.get('insecure')
    verbose = kwargs.get('verbose')

    # validate inputs
    if input_path and not os.path.isfile(input_path):
        print_error(F'Input file {input_path} was not found.')
        return 1

    if not input_path.lower().endswith('.yml'):
        print_error(F'Input {input_path} is not a valid yml file.')
        return 1

    if output_path and not os.path.isdir(output_path):
        print_error(F'Output directory {output_path} was not found.')
        return 1

    if command:
        if output_path and (not os.path.isfile(os.path.join(output_path, "README.md")))\
                or (not output_path)\
                and (not os.path.isfile(os.path.join(os.path.dirname(os.path.realpath(input_path)), "README.md"))):
            print_error("The `command` argument must be presented with existing `README.md` docs.")
            return 1

    file_type = find_type(kwargs.get('input', ''))
    if file_type not in ["integration", "script", "playbook"]:
        print_error('File is not an Integration, Script or a Playbook.')
        return 1

    print(f'Start generating {file_type} documentation...')
    if file_type == 'integration':
        use_cases = kwargs.get('use_cases')
        command_permissions = kwargs.get('command_permissions')
        return generate_integration_doc(input=input_path, output=output_path, use_cases=use_cases,
                                        examples=examples, permissions=permissions,
                                        command_permissions=command_permissions, limitations=limitations,
                                        insecure=insecure, verbose=verbose, command=command)
    elif file_type == 'script':
        return generate_script_doc(input=input_path, output=output_path, examples=examples, permissions=permissions,
                                   limitations=limitations, insecure=insecure, verbose=verbose)
    elif file_type == 'playbook':
        return generate_playbook_doc(input=input_path, output=output_path, permissions=permissions,
                                     limitations=limitations, verbose=verbose)
    else:
        print_error(f'File type {file_type} is not supported.')
        return 1