47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
"""Customer records service. Planted for the scan regression."""
|
|
|
|
import hashlib
|
|
import os # noqa-free on purpose: ruff reports this unused import (F401)
|
|
import subprocess
|
|
|
|
import yaml
|
|
from flask import Flask, request
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
@app.route("/import", methods=["POST"])
|
|
def import_records():
|
|
# Unsafe deserialisation: the loader executes tags in the payload.
|
|
records = yaml.load(request.data, Loader=yaml.Loader)
|
|
# Personal data written to the log (GDPR pattern).
|
|
for record in records:
|
|
app.logger.info(
|
|
"imported %s <%s> national_id=%s",
|
|
record["full_name"],
|
|
record["email"],
|
|
record["national_id"],
|
|
)
|
|
return {"imported": len(records)}
|
|
|
|
|
|
@app.route("/report")
|
|
def report():
|
|
name = request.args.get("customer", "")
|
|
# Shell command built from request input.
|
|
out = subprocess.check_output("report-for " + name, shell=True)
|
|
return out
|
|
|
|
|
|
def fingerprint(value: str) -> str:
|
|
# Weak hash used as an identifier.
|
|
return hashlib.md5(value.encode()).hexdigest()
|
|
|
|
|
|
def load_settings(path: str) -> dict:
|
|
try:
|
|
with open(path) as handle:
|
|
return yaml.safe_load(handle)
|
|
except: # ruff reports the bare except (E722)
|
|
return {}
|