Skip to content

Commit

Permalink
fix pyparsing issue + sort sigma versions in api response
Browse files Browse the repository at this point in the history
  • Loading branch information
M3NIX committed Nov 6, 2024
1 parent 0888a9f commit 2619363
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
7 changes: 7 additions & 0 deletions backend/setup-sigma-versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ for VERSION in $SIGMA_VERSIONS; do

# remove if installed because of https://github.com/redsand/pySigma-backend-hawk/issues/1
uv -q remove pySigma-backend-hawk

# TODO: some problems with kusto backend, disable for now
uv -q remove pySigma-backend-kusto

# remove unused pyparsing imports in older version, see https://github.com/SigmaHQ/pySigma/pull/289#issuecomment-2410153076
find ./ -iwholename "*sigma/conversion/base.py" -exec sed -i "/from pyparsing import Set/d" {} +
find ./ -iwholename "*sigma/exceptions.py" -exec sed -i "/from pyparsing import List/d" {} +
cd ..
done
45 changes: 28 additions & 17 deletions frontend/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,63 @@
from flask import Flask, render_template, request, jsonify

app = Flask(__name__)
sigma_versions = [os.path.basename(it.path) for it in os.scandir('../backend/') if it.is_dir()]
sigma_versions = [
os.path.basename(it.path) for it in os.scandir("../backend/") if it.is_dir()
]


def version_key(version):
return tuple(map(int, version.split(".")))


def get_port_from_version(version):
pattern = r'^\d+\.\d+\.\d+$'
pattern = r"^\d+\.\d+\.\d+$"
if re.match(pattern, version):
return int(f'8{version.replace(".","")}')
return int(f'8{version.replace(".", "")}')
else:
return None


@app.route("/")
def home():
versions = sigma_versions
latest_version = sigma_versions[-1:][0]
port = get_port_from_version(latest_version)
targets = requests.get(f'http://localhost:{port}/api/v1/targets').json()
formats = requests.get(f'http://localhost:{port}/api/v1/formats').json()
pipelines = requests.get(f'http://localhost:{port}/api/v1/pipelines').json()
return render_template("index.html")

return render_template(
"index.html"
)

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


@app.route("/api/v1/<version>/targets", methods=["GET"])
def get_targets(version):
port = get_port_from_version(version)
return requests.get(f'http://localhost:{port}/api/v1/targets', params=dict(request.args)).json()
return requests.get(
f"http://localhost:{port}/api/v1/targets", params=dict(request.args)
).json()


@app.route("/api/v1/<version>/formats", methods=["GET"])
def get_formats(version):
port = get_port_from_version(version)
return requests.get(f'http://localhost:{port}/api/v1/formats', params=dict(request.args)).json()
return requests.get(
f"http://localhost:{port}/api/v1/formats", params=dict(request.args)
).json()


@app.route("/api/v1/<version>/pipelines", methods=["GET"])
def get_pipelines(version):
port = get_port_from_version(version)
return requests.get(f'http://localhost:{port}/api/v1/pipelines', params=dict(request.args)).json()
return requests.get(
f"http://localhost:{port}/api/v1/pipelines", params=dict(request.args)
).json()


@app.route("/api/v1/<version>/convert", methods=["POST"])
def convert(version):
port = get_port_from_version(version)
payload = request.json
return requests.post(f'http://localhost:{port}/api/v1/convert', json=payload).text
return requests.post(f"http://localhost:{port}/api/v1/convert", json=payload).text


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

0 comments on commit 2619363

Please sign in to comment.