Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FileToBase64List] Remove "runeonce: true" #35481

Merged
merged 23 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Packs/CommonScripts/ReleaseNotes/1_15_49.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#### Scripts

##### FileToBase64List

- Improved implementation to prevent the script from running in a new docker container for each call.
- Updated the Docker image to: *demisto/python3:3.11.9.107902*.
32 changes: 17 additions & 15 deletions Packs/CommonScripts/Scripts/FileToBase64List/FileToBase64List.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,41 @@
import zlib


def get_file_data(file_path, zip=False):
def get_file_data(file_path: str, is_zip: bool = False):
with open(file_path, 'rb') as f:
data = f.read()
if zip:
data = zlib.compress(data)

if is_zip:
data = zlib.compress(data)
return base64.b64encode(data).decode('utf-8')


def main():
LIST_NAME = demisto.args()['listName']
TO_ZIP = (demisto.args()['zipFile'] == 'true')

list_name = demisto.args()['listName']
is_zip = (demisto.args()['zipFile'] == 'true')
entry_id = demisto.args()['entryId']

res = demisto.getFilePath(entry_id)
if not res:
return_error("Entry {} not found".format(entry_id))
return_error(f"Entry {entry_id} not found")
file_path = res['path']

file_base64 = get_file_data(file_path, TO_ZIP)
file_base64 = get_file_data(file_path, is_zip)

res = demisto.executeCommand("createList", {"listName": LIST_NAME, "listData": file_base64})
res = demisto.executeCommand("createList", {"listName": list_name, "listData": file_base64})
if isError(res):
return res

return {
'Contents': file_base64,
'ContentsFormat': formats['text'],
'HumanReadable': tableToMarkdown('Success store file in list', {
'File Entry ID': entry_id,
'List Name': LIST_NAME,
'Size': len(file_base64)
}),
'HumanReadable': tableToMarkdown(
'File successfully stored in list',
{
'File Entry ID': entry_id,
'List Name': list_name,
'Size': len(file_base64)
}
),
'HumanReadableFormat': formats['markdown'],
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ timeout: '0'
type: python
subtype: python3
runas: DBotWeakRole
runonce: true
tests:
- No Test
fromversion: 5.0.0
dockerimage: demisto/python3:3.10.13.83255
dockerimage: demisto/python3:3.11.9.107902
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
TEST_FILE_PATH = os.path.join('test_data', 'file.txt')


def executeCommand(name, args=None):
if name == 'createList':
def executeCommand(command, args=None):
if command == 'createList':
return [
{
'Type': entryTypes['note'],
'Contents': 'List created successfully'
}
]
else:
raise ValueError('Unimplemented command called: {}'.format(name))
raise ValueError(f'Unimplemented command called: {command}')


def test_file_to_base64_list(mocker):
Expand All @@ -32,7 +31,8 @@ def test_file_to_base64_list(mocker):
mocker.patch.object(demisto, 'executeCommand', side_effect=executeCommand)
mocker.patch.object(demisto, 'results')
result_entry = main()
assert 'Success' in result_entry['HumanReadable'] and 'Size' in result_entry['HumanReadable']
assert result_entry['HumanReadable'] == (
'### File successfully stored in list\n|File Entry ID|List Name|Size|\n|---|---|---|\n| 1 | test | 28 |\n')
assert len(result_entry['Contents']) > 0


Expand Down
2 changes: 1 addition & 1 deletion Packs/CommonScripts/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Common Scripts",
"description": "Frequently used scripts pack.",
"support": "xsoar",
"currentVersion": "1.15.48",
"currentVersion": "1.15.49",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
Loading