Skip to content
This repository was archived by the owner on May 12, 2022. It is now read-only.

Commit 3821ccd

Browse files
author
german.ramos.garcia
committed
feat(demisto-pack): zip file support
1 parent 6ec63c2 commit 3821ccd

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

demisto-pack/MistLang/Integrations/MistLang/MistLang.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from mist.action_run import execute_from_text
44
from mist.lang.config import config
55
import asyncio, json
6+
from zipfile import ZipFile
7+
from io import BytesIO
8+
import os
69

710
# Disable insecure warnings
811
requests.packages.urllib3.disable_warnings() # pylint: disable=no-member
@@ -25,8 +28,14 @@ def baseintegration_dummy(self, url, params) -> Tuple[str, dict]:
2528
req = requests.get(url)
2629
if req.status_code == 200:
2730
try:
28-
#TODO: option to download zip files with multple files programs and then download
29-
mist_content = req.content.decode("utf-8", "ignore")
31+
if url.endswith(".zip"):
32+
zipfile = ZipFile(BytesIO(req.content))
33+
zipfile.extractall("./mist_tmp_zip")
34+
os.chdir('./mist_tmp_zip')
35+
with open("main.mist") as f:
36+
mist_content = f.read()
37+
else:
38+
mist_content = req.content.decode("utf-8", "ignore")
3039
output = asyncio.run(execute_from_text(mist_content, fn_params=params))
3140
result = {"url": url, "raw_output": output}
3241
try:
@@ -38,6 +47,10 @@ def baseintegration_dummy(self, url, params) -> Tuple[str, dict]:
3847
return "ok", result
3948
except Exception as e:
4049
return "mist file error", {"url": url, "output": str(e)}
50+
finally:
51+
if os.path.abspath(os.path.curdir).endswith("mist_tmp_zip"):
52+
os.chdir('..')
53+
os.system("rm -rf ./mist_tmp_zip")
4154
return "network error", {"url": url, "output": str(req.status_code)}
4255

4356

demisto-pack/MistLang/Integrations/MistLang/MistLang_test.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,26 @@ def test_baseintegration_dummy_with_params():
9393
assert response[1]["raw_output"] == '{"output_message1": "bar", "output_message2": "foo"}\n'
9494
assert response[1]["output_message1"] == "bar"
9595
assert response[1]["output_message2"] == "foo"
96+
97+
def test_baseintegration_dummy_zip():
98+
"""Tests helloworld-say-hello command function.
99+
100+
Checks the output of the command function with the expected output.
101+
102+
No mock is needed here because the say_hello_command does not call
103+
any external API.
104+
"""
105+
from MistLang import Client, baseintegration_dummy_command
106+
107+
client = Client(base_url='some_mock_url', verify=False)
108+
args = {
109+
'url': 'https://raw.githubusercontent.com/BBVA/mist/master/examples/multi_file.zip',
110+
}
111+
response = baseintegration_dummy_command(client, **args)
112+
113+
assert response[0] == "ok"
114+
assert response[1]["raw_output"] == '{"message": "hello"}\n'
115+
assert response[1]["message"] == "hello"
116+
117+
118+

0 commit comments

Comments
 (0)