Skip to content

Commit d2d16c8

Browse files
committed
Fixed email, ai & tools parsing app bugs
1 parent c3b3585 commit d2d16c8

File tree

5 files changed

+124
-7
lines changed

5 files changed

+124
-7
lines changed

email/1.3.0/src/app.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,19 @@ def parse_email_file(self, file_id, extract_attachments=False):
409409
"reason": "Couldn't get file with ID %s" % file_id
410410
}
411411

412+
#print("PRE: ", file_path)
413+
414+
# Check if data is in base64 and decode it
415+
# If it ends with = then it may be bas64
416+
417+
if str(file_path["data"]).endswith("="):
418+
try:
419+
file_path["data"] = base64.b64decode(file_path["data"])
420+
except Exception as e:
421+
print(f"Failed to decode base64: {e}")
422+
423+
#print("POST: ", file_path)
424+
412425
#print("File: %s" % file_path)
413426
print('working with .eml file? %s' % file_path["filename"])
414427

shuffle-ai/1.0.0/api.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ actions:
9898
returns:
9999
schema:
100100
type: string
101+
- name: run_schemaless
102+
description: Runs an automatically translated action
103+
parameters:
104+
- name: category
105+
description: The category the action is in
106+
required: true
107+
multiline: false
108+
schema:
109+
type: string
110+
- name: action
111+
description: The action label to run
112+
required: true
113+
multiline: false
114+
schema:
115+
type: string
116+
- name: app_name
117+
description: The app to run the action in
118+
required: false
119+
multiline: false
120+
schema:
121+
type: string
122+
- name: fields
123+
description: The additional fields to add
124+
required: false
125+
multiline: false
126+
schema:
127+
type: string
128+
returns:
129+
schema:
130+
type: string
101131
- name: transcribe_audio
102132
description: Returns text from audio
103133
parameters:

shuffle-ai/1.0.0/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pytesseract
22
pdf2image
33
pypdf2
4+
requests

shuffle-ai/1.0.0/src/app.py

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import pytesseract
2-
from pdf2image import convert_from_path
3-
import PyPDF2
41
import json
2+
import PyPDF2
53
import tempfile
4+
import requests
5+
import pytesseract
6+
from pdf2image import convert_from_path
67

78
from walkoff_app_sdk.app_base import AppBase
89

@@ -59,10 +60,6 @@ def generate_report(self, apikey, input_data, report_title, report_name="generat
5960
report_name = report_name + ".html"
6061

6162
report_name = report_name.replace(" ", "_", -1)
62-
63-
if not formatting:
64-
formatting = "auto"
65-
6663
output_formatting= "Format the following text into an HTML report with relevant graphs and tables. Title of the report should be {report_title}."
6764
ret = requests.post(
6865
"https://shuffler.io/api/v1/conversation",
@@ -217,5 +214,79 @@ def gpt(self, input_text):
217214
"reason": "Not implemented yet"
218215
}
219216

217+
def run_schemaless(self, category, action, app_name="", fields=""):
218+
"""
219+
action := shuffle.CategoryAction{
220+
Label: step.Name,
221+
Category: step.Category,
222+
AppName: step.AppName,
223+
Fields: step.Fields,
224+
225+
Environment: step.Environment,
226+
227+
SkipWorkflow: true,
228+
}
229+
"""
230+
231+
data = {
232+
"label": action,
233+
"category": category,
234+
235+
"app_name": "",
236+
"fields": [],
237+
238+
"skip_workflow": True,
239+
}
240+
241+
if app_name:
242+
data["app_name"] = app_name
243+
244+
if fields:
245+
if isinstance(fields, list):
246+
data["fields"] = fields
247+
248+
elif isinstance(fields, dict):
249+
for key, value in fields.items():
250+
data["fields"].append({
251+
"key": key,
252+
"value": str(value),
253+
})
254+
255+
else:
256+
try:
257+
loadedfields = json.loads(fields)
258+
for key, value in loadedfields.items():
259+
data["fields"].append({
260+
"key": key,
261+
"value": value,
262+
})
263+
264+
except Exception as e:
265+
print("[ERROR] Failed to load fields as JSON: %s" % e)
266+
return json.dumps({
267+
"success": False,
268+
"reason": "Ensure Fields are valid JSON",
269+
"type": type(fields),
270+
"details": "%s" % e,
271+
})
272+
273+
274+
baseurl = "%s/api/v1/apps/categories/run" % self.base_url
275+
baseurl += "?execution_id=%s&authorization=%s" % (self.current_execution_id, self.authorization)
276+
277+
print("[DEBUG] Running schemaless action with URL '%s', category %s and action label %s" % (baseurl, category, action))
278+
279+
headers = {}
280+
request = requests.post(
281+
baseurl,
282+
json=data,
283+
headers=headers,
284+
)
285+
286+
try:
287+
return request.json()
288+
except:
289+
return request.text
290+
220291
if __name__ == "__main__":
221292
Tools.run()

shuffle-tools/1.2.0/src/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,8 @@ def parse_ioc(self, input_string, input_type="all"):
23942394
input_type = input_type.split(",")
23952395
for item in input_type:
23962396
item = item.strip()
2397+
if not item.endswith("s"):
2398+
item = "%ss" % item
23972399

23982400
ioc_types = input_type
23992401

0 commit comments

Comments
 (0)