CloudConvert

Use the CloudConvert integration to convert your files to the desired format.

Utilities · Cloud Convert

Details

IDCloudConvert
ProviderLunaweb GmbH
CategoryUtilities
From Version5.0.0
Docker Imagedemisto/python3:3.12.13.10116658
Supported ModulesAgentix XSIAM

README

Use the CloudConvert integration to convert your files to the required format.
This integration was integrated and tested with version v2 of CloudConvert.

Configure CloudConvert in Cortex

Parameter Description Required
apikey API Key True
insecure Trust any certificate (not secure) False
proxy Use system proxy settings False

Commands

You can execute these commands from the CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

cloudconvert-upload


Uploads a file for conversion.

Base Command

cloudconvert-upload

Input

Argument Name Description Required
url The file’s URL. If an entry ID is supplied, do not use this argument. Optional
entry_id The file’s War Room entry ID. If a URL is supplied, do not use this argument. Optional

Context Output

Path Type Description
CloudConvert.Task.id String Unique task ID of the scanned file.
CloudConvert.Task.status String Status of the current task.
CloudConvert.Task.message String Response message from the API.
CloudConvert.Task.operation String The operation that was performed.
CloudConvert.Task.result.files.filename String The name of the uploaded file.
CloudConvert.Task.result.files.size Number The size of the uploaded file.
CloudConvert.Task.result.files.url String The URL of the uploaded file.
CloudConvert.Task.created_at Date Time the task was created.
CloudConvert.Task.started_at Date Start time of the task.
CloudConvert.Task.ended_at Date End time of the task.
CloudConvert.Task.host_name String Name of the host used for the task.
CloudConvert.Task.storage String Storage server used for the task.
CloudConvert.Task.links String API link for the task.

Command Example

cloudconvert-upload entry_id=@123

Human Readable Output

cloudconvert-convert


Converts an uploaded file to the required format.

Base Command

cloudconvert-convert

Input

Argument Name Description Required
task_id ID of the task that uploaded the file. Required
output_format The required output format for the given file. Required

Context Output

Path Type Description
CloudConvert.Task.id String Unique task ID of the scanned file.
CloudConvert.Task.status String Status of the current task.
CloudConvert.Task.message String Response message from the API.
CloudConvert.Task.operation String The task that was performed.
CloudConvert.Task.result.files.filename String The name of the converted file.
CloudConvert.Task.result.files.size Number The size of the converted file.
CloudConvert.Task.result.files.url String The URL of the converted file.
CloudConvert.Task.created_at Date Time the task was created.
CloudConvert.Task.started_at Date Start time of the task.
CloudConvert.Task.ended_at Date End time of the task.
CloudConvert.Task.host_name String Name of the host used for the task.
CloudConvert.Task.storage String Storage server used for the task.
CloudConvert.Task.depends_on_task_ids String The ID of the previous task that was conducted on this file.
CloudConvert.Task.links String API link for the task.

Command Example

cloudconvert-convert task_id=1 output_format=pdf

Human Readable Output

cloudconvert-check-status


Checks the status of an operation. Use the ‘create_war_room_entry’ argument to also create a war room entry of the file when checking on a download operation.

Base Command

cloudconvert-check-status

Input

Argument Name Description Required
task_id ID of the task used to convert the file. Required
create_war_room_entry Whether to create an entry in the War Room if the task is finished. Possible values are: “True” and “False”. Use this argument to be able to check on a download operation in the War Room. Optional

Context Output

Path Type Description
CloudConvert.Task.id String Unique task ID of the scanned file.
CloudConvert.Task.status String Status of the current task.
CloudConvert.Task.message String Response message from the API.
CloudConvert.Task.operation String The task that was performed.
CloudConvert.Task.result.files.filename String The name of the converted file.
CloudConvert.Task.result.files.size Number The size of the converted file.
CloudConvert.Task.result.files.url String The URL of the converted file.
CloudConvert.Task.created_at Date The time the task was created.
CloudConvert.Task.started_at Date Start time of the task.
CloudConvert.Task.ended_at Date End time of the task.
CloudConvert.Task.host_name String Name of the host used for the task.
CloudConvert.Task.storage String Storage server used for the task.
CloudConvert.Task.depends_on_task_ids String The ID of the previous task conducted on this file.
CloudConvert.Task.links String API link for the task.

Command Example

cloudconvert-check-status task_id=1

Human Readable Output

cloudconvert-download


Downloads a converted file as a URL or a War Room entry.

Base Command

cloudconvert-download

Input

Argument Name Description Required
download_as ‘Whether to download the converted file as a URL or as a War Room entry. Possible values are: “url” and “war_room_entry”. Note that if you download the file as a War Room entry, a URL of the file will also be generated.’ Required
task_id ID of the task that converted the file. Required

Context Output

Path Type Description
CloudConvert.Task.id String Unique task ID of the scanned file.
CloudConvert.Task.status String Status of the current task.
CloudConvert.Task.message String Response message from the API.
CloudConvert.Task.operation String The operation that was performed.
CloudConvert.Task.result.files.filename String The file name of the downloaded file.
CloudConvert.Task.result.files.size Number The size of the downloaded file.
CloudConvert.Task.result.files.url String The URL of the downloaded file.
CloudConvert.Task.created_at Date Time the task was created.
CloudConvert.Task.started_at Date Start time of the task.
CloudConvert.Task.ended_at Date End time of the task.
CloudConvert.Task.host_name String Name of the host used for the task.
CloudConvert.Task.storage String Storage server used for the task.
CloudConvert.Task.depends_on_task_ids String The ID of the previous task conducted on this file.
CloudConvert.Task.links String API link for the task.

Command Example

cloudconvert-download task_id=1 download_as=url

Human Readable Output

Configuration parameters

  • apikey — API Key
  • apikey_creds
  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings

Commands (4)

  • cloudconvert-check-status

    Checks the status of an operation. Use the create_war_room_entry argument to also create a war room entry of the file when checking on a download operation.

  • cloudconvert-convert

    Converts an uploaded file to the required format.

  • cloudconvert-download

    Downloads a converted file to a URL or a War Room entry.

  • cloudconvert-upload

    Uploads a file to convert.

import json

import demistomock as demisto
import pytest
from CloudConvert import Client, check_status_command, convert_command, download_command, modify_results_dict, upload_command
from CommonServerPython import remove_empty_elements, string_to_table_header, tableToMarkdown

MOCK_API_KEY = "a1b2c3d4e5"
MOCK_URL = "https://www.thisisamockurl.com"
MOCK_ENTRY_ID = "@123"


def create_client():
    headers = {"Authorization": f"Bearer {MOCK_API_KEY}"}
    return Client(headers=headers)


def util_load_json(path):
    with open(path, encoding="utf-8") as f:
        return json.loads(f.read())


def test_upload_valid_url(mocker):
    """

    Given:
        - Valid url of a file, str
    When:
        - When the user uploads a file for later conversion via url
    Then:
        - Returns the response data

    """
    client = create_client()
    mocker.patch.object(client, "upload_url", return_value=util_load_json("./test_data/upload_url_response.json"))
    results = upload_command(client, {"url": MOCK_URL})
    raw_response = util_load_json("./test_data/upload_url_response.json")
    raw_response["data"]["operation"] = "upload/url"
    readable_output = tableToMarkdown(
        "Upload Results",
        remove_empty_elements(raw_response.get("data")),
        headers=("id", "operation", "created_at", "status"),
        headerTransform=string_to_table_header,
    )

    assert results.outputs == remove_empty_elements(raw_response.get("data"))
    assert results.readable_output == readable_output


def test_upload_invalid_url(mocker):
    """

    Given:
        - Invalid url of a file, str
    When:
        - When the user uploads a file for later conversion via url
    Then:
        - Returns the response message of invalid input

    """
    client = create_client()
    mocker.patch.object(client, "upload_url", return_value=util_load_json("./test_data/upload_url_bad_url_response.json"))
    with pytest.raises(ValueError) as e:
        upload_command(client, {"url": MOCK_URL})
        if not e:
            pytest.fail()


def test_upload_valid_entry(mocker):
    """

    Given:
        - Valid entry id of a file, str
    When:
        - When the user uploads a file for later conversion via entry
    Then:
        - Returns the response data

    """

    client = create_client()
    mocker.patch.object(client, "upload_entry_id", return_value=util_load_json("./test_data/upload_entry_response.json"))
    results = upload_command(client, {"entry_id": MOCK_ENTRY_ID})
    raw_response = util_load_json("./test_data/upload_entry_response.json")
    raw_response["data"]["operation"] = "upload/entry"
    readable_output = tableToMarkdown(
        "Upload Results",
        remove_empty_elements(raw_response.get("data")),
        headers=("id", "operation", "created_at", "status"),
        headerTransform=string_to_table_header,
    )

    assert results.outputs == remove_empty_elements(raw_response.get("data"))
    assert results.readable_output == readable_output


def test_upload_invalid_entry(mocker):
    """

    Given:
        - Invalid entry id of a file, str
    When:
        - When the user uploads a file for later conversion via entry
    Then:
        - Returns the response message of invalid input

    """

    client = create_client()
    mocker.patch.object(demisto, "getFilePath", return_value=None)
    with pytest.raises(ValueError) as e:
        upload_command(client, {"entry_id": MOCK_ENTRY_ID})
        if not e:
            pytest.fail()


def test_convert_valid_format_and_id(mocker):
    """

    Given:
        - Valid destination format for given file
    When:
        - When the user converts a file that was priorly uploaded
    Then:
        - Returns the response data

    """
    client = create_client()
    mocker.patch.object(client, "convert", return_value=util_load_json("test_data/convert_valid_format_and_id_response.json"))
    results = convert_command(client, {"task_id": "id", "output_format": "pdf"})
    readable_output = tableToMarkdown(
        "Convert Results",
        remove_empty_elements(util_load_json("test_data/convert_valid_format_and_id_response.json").get("data")),
        headers=("id", "operation", "created_at", "status", "depends_on_task_ids"),
        headerTransform=string_to_table_header,
    )
    assert results.outputs == remove_empty_elements(
        util_load_json("test_data/convert_valid_format_and_id_response.json").get("data")
    )
    assert results.readable_output == readable_output


def test_convert_invalid_format_or_id(mocker):
    """

    Given:
        - Inalid destination format for given file
    When:
        - When the user converts a file that was priorly uploaded
    Then:
        - Returns the response message of invalid input

    """
    client = create_client()
    mocker.patch.object(client, "convert", return_value=util_load_json("test_data/convert_invalid_format_or_id_response.json"))
    with pytest.raises(ValueError) as e:
        convert_command(client, {"task_id": "ff", "output_format": "ff"})
        if not e:
            pytest.fail()


def test_check_status_invalid_id(mocker):
    """

    Given:
        - Inalid task id for given file
    When:
        - When the user checks the status of a task that was priorly done
    Then:
        - Returns the response message of invalid input

    """
    client = create_client()
    mocker.patch.object(client, "check_status", return_value=util_load_json("test_data/check_status_bad_id_response.json"))
    with pytest.raises(ValueError) as e:
        check_status_command(client, {"task_id": "ff"})
        if not e:
            pytest.fail()


@pytest.mark.parametrize("create_war_room_entry", [True, False])
def test_check_status_valid_id_non_download(mocker, create_war_room_entry):
    """

    Given:
        - A valid task id, of a non-download operation
    When:
        - When the user checks the status of a task that was priorly done, and it is not download.
        the purpose here is to make sure that the extra argument, 'create_war_room_entry', only makes a difference
         when the id is of an actual download operation.
    Then:
        - Returns the response

    """
    client = create_client()
    mocker.patch.object(client, "check_status", return_value=util_load_json("test_data/check_status_non_download_response.json"))
    results = check_status_command(client, {"task_id": "id", "create_war_room_entry": create_war_room_entry})
    raw_response_data = util_load_json("test_data/check_status_non_download_response.json").get("data")
    modify_results_dict(raw_response_data)
    readable_output = tableToMarkdown(
        "Check Status Results",
        remove_empty_elements(raw_response_data),
        headers=("id", "operation", "created_at", "status", "depends_on_task_ids", "file_name", "url"),
        headerTransform=string_to_table_header,
    )
    modify_results_dict(raw_response_data)
    assert results.outputs == remove_empty_elements(raw_response_data)
    assert results.readable_output == readable_output


@pytest.mark.parametrize("create_war_room_entry", [True, False])
def test_check_status_valid_id_download(mocker, create_war_room_entry):
    """

    Given:
        - A valid task id, of an download operation
    When:
        - When the user checks the status of a task that was priorly done, and it is an download operation.

    Then:
        - When checking on a download operation and the argument 'create_war_room_entry' is set to True, the output is a
        warroom entry. if set to False, then a regular response is retrieved.

    """
    import CloudConvert

    client = create_client()
    mocker.patch.object(client, "check_status", return_value=util_load_json("test_data/check_status_download_response.json"))
    mocker.patch.object(client, "get_file_from_url", return_value="")
    file_name = (
        util_load_json("test_data/check_status_download_response.json").get("data").get("result").get("files")[0].get("filename")
    )
    mocker.patch.object(CloudConvert, "fileResult", return_value={"File": file_name})
    results = check_status_command(client, {"task_id": "id", "create_war_room_entry": create_war_room_entry})
    raw_response_data = util_load_json("test_data/check_status_download_response.json").get("data")
    modify_results_dict(raw_response_data)
    if create_war_room_entry:
        raw_response_data["operation"] = "download/entry"
        assert results.get("File") == file_name

    else:
        raw_response_data["operation"] = "download/url"
        assert results.outputs == remove_empty_elements(raw_response_data)
        readable_output = tableToMarkdown(
            "Check Status Results",
            remove_empty_elements(raw_response_data),
            headers=("id", "operation", "created_at", "status", "depends_on_task_ids", "file_name", "url"),
            headerTransform=string_to_table_header,
        )
        assert results.readable_output == readable_output


@pytest.mark.parametrize("download_as", ["war_room_entry", "url"])
def test_download_invalid_id(mocker, download_as):
    """

    Given:
        - Invalid task id for given file
    When:
        - When the user wants to download a file that was priorly uploaded
    Then:
        - Returns the response message of invalid input

    """
    client = create_client()
    mocker.patch.object(client, "download_url", return_value=util_load_json("test_data/download_invalid_id_response.json"))
    with pytest.raises(ValueError) as e:
        download_command(client, {"task_id": "id", "download_as": download_as})
        if not e:
            pytest.fail()


@pytest.mark.parametrize("download_as", ["war_room_entry", "url"])
def test_download_valid_id(mocker, download_as):
    """

    Given:
        - Valid task id for given file
    When:
        - When the user wants to download a file that was priorly uploaded
    Then:
        - Returns the response message of invalid input

    """
    client = create_client()
    mocker.patch.object(client, "download_url", return_value=util_load_json("test_data/download_valid_id_response.json"))

    results = download_command(client, {"task_id": "id", "download_as": download_as})
    raw_response = util_load_json("test_data/download_valid_id_response.json")
    if download_as == "url":
        raw_response["data"]["operation"] = "download/url"
        readable_output = tableToMarkdown(
            "Download Results",
            remove_empty_elements(raw_response.get("data")),
            headers=("id", "operation", "created_at", "status", "depends_on_task_ids"),
            headerTransform=string_to_table_header,
        )
        assert results.outputs == remove_empty_elements(raw_response.get("data"))
        assert results.readable_output == readable_output

    else:
        raw_response["data"]["operation"] = "download/entry"
        assert results.outputs == remove_empty_elements(raw_response.get("data"))