Skip to content

Commit 2619363

Browse files
committed
fix pyparsing issue + sort sigma versions in api response
1 parent 0888a9f commit 2619363

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

backend/setup-sigma-versions.sh

+7
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@ for VERSION in $SIGMA_VERSIONS; do
1717

1818
# remove if installed because of https://github.com/redsand/pySigma-backend-hawk/issues/1
1919
uv -q remove pySigma-backend-hawk
20+
21+
# TODO: some problems with kusto backend, disable for now
22+
uv -q remove pySigma-backend-kusto
23+
24+
# remove unused pyparsing imports in older version, see https://github.com/SigmaHQ/pySigma/pull/289#issuecomment-2410153076
25+
find ./ -iwholename "*sigma/conversion/base.py" -exec sed -i "/from pyparsing import Set/d" {} +
26+
find ./ -iwholename "*sigma/exceptions.py" -exec sed -i "/from pyparsing import List/d" {} +
2027
cd ..
2128
done

frontend/frontend.py

+28-17
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,63 @@
66
from flask import Flask, render_template, request, jsonify
77

88
app = Flask(__name__)
9-
sigma_versions = [os.path.basename(it.path) for it in os.scandir('../backend/') if it.is_dir()]
9+
sigma_versions = [
10+
os.path.basename(it.path) for it in os.scandir("../backend/") if it.is_dir()
11+
]
12+
13+
14+
def version_key(version):
15+
return tuple(map(int, version.split(".")))
16+
1017

1118
def get_port_from_version(version):
12-
pattern = r'^\d+\.\d+\.\d+$'
19+
pattern = r"^\d+\.\d+\.\d+$"
1320
if re.match(pattern, version):
14-
return int(f'8{version.replace(".","")}')
21+
return int(f'8{version.replace(".", "")}')
1522
else:
1623
return None
1724

25+
1826
@app.route("/")
1927
def home():
20-
versions = sigma_versions
21-
latest_version = sigma_versions[-1:][0]
22-
port = get_port_from_version(latest_version)
23-
targets = requests.get(f'http://localhost:{port}/api/v1/targets').json()
24-
formats = requests.get(f'http://localhost:{port}/api/v1/formats').json()
25-
pipelines = requests.get(f'http://localhost:{port}/api/v1/pipelines').json()
28+
return render_template("index.html")
2629

27-
return render_template(
28-
"index.html"
29-
)
3030

3131
@app.route("/api/v1/sigma-versions", methods=["GET"])
3232
def get_versions():
33-
return jsonify(sigma_versions[::-1])
33+
return jsonify(sorted(sigma_versions, key=version_key, reverse=True))
34+
3435

3536
@app.route("/api/v1/<version>/targets", methods=["GET"])
3637
def get_targets(version):
3738
port = get_port_from_version(version)
38-
return requests.get(f'http://localhost:{port}/api/v1/targets', params=dict(request.args)).json()
39+
return requests.get(
40+
f"http://localhost:{port}/api/v1/targets", params=dict(request.args)
41+
).json()
42+
3943

4044
@app.route("/api/v1/<version>/formats", methods=["GET"])
4145
def get_formats(version):
4246
port = get_port_from_version(version)
43-
return requests.get(f'http://localhost:{port}/api/v1/formats', params=dict(request.args)).json()
47+
return requests.get(
48+
f"http://localhost:{port}/api/v1/formats", params=dict(request.args)
49+
).json()
50+
4451

4552
@app.route("/api/v1/<version>/pipelines", methods=["GET"])
4653
def get_pipelines(version):
4754
port = get_port_from_version(version)
48-
return requests.get(f'http://localhost:{port}/api/v1/pipelines', params=dict(request.args)).json()
55+
return requests.get(
56+
f"http://localhost:{port}/api/v1/pipelines", params=dict(request.args)
57+
).json()
58+
4959

5060
@app.route("/api/v1/<version>/convert", methods=["POST"])
5161
def convert(version):
5262
port = get_port_from_version(version)
5363
payload = request.json
54-
return requests.post(f'http://localhost:{port}/api/v1/convert', json=payload).text
64+
return requests.post(f"http://localhost:{port}/api/v1/convert", json=payload).text
65+
5566

5667
if __name__ == "__main__":
5768
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 8000)))

0 commit comments

Comments
 (0)