From 680e07d2505ad20493e9ebbb30b3ad8e9bd00147 Mon Sep 17 00:00:00 2001 From: Ana Scolari <127357173+apsscolari@users.noreply.github.com> Date: Tue, 6 May 2025 19:24:16 -0700 Subject: [PATCH 1/2] Create sqli_ori_httprequest.py --- sqli_ori_httprequest.py | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sqli_ori_httprequest.py diff --git a/sqli_ori_httprequest.py b/sqli_ori_httprequest.py new file mode 100644 index 0000000..2fc8ec3 --- /dev/null +++ b/sqli_ori_httprequest.py @@ -0,0 +1,44 @@ +import re +from flask import Flask, request, jsonify + +app = Flask(__name__) + +@app.route('/run', methods=['POST']) +def main(): + # Read from JSON payload or form + data = request.get_json() or request.form + target_db = data.get('target_db', 'curated') + target_table = data.get('target_table', 'client_communication_preferences_journal') + as_of = data.get('as_of') + + # Validate the as_of parameter to ensure it matches the expected format (YYYYMMDD) + if not as_of or not re.match(r'^\d{8}$', as_of): + return jsonify({"error": "Invalid as_of format. Expected YYYYMMDD."}), 400 + + qry = f""" + WITH blueshift_active_email_client_agg AS ( + SELECT client_id, + MAX(last_opened_at) AS last_opened_at, + MIN(first_opened_at) AS first_opened_at + FROM blueshift.campaign_activity_kpis + WHERE DATE(last_opened_at) <= TO_DATE('{as_of}', 'yyyyMMdd') + OR last_opened_at IS NULL + OR DATE(first_opened_at) <= TO_DATE('{as_of}', 'yyyyMMdd') + GROUP BY 1 + ) + ... + """ + + df = sc.sql(qry).withColumn('start_date', f.col('start_date').cast('timestamp')) + + sc.save( + df=df, + database=target_db, + table=target_table, + journal_write=True, + journal_write_as_of=as_of, + ) + return jsonify({"status": "OK"}) + +if __name__ == "__main__": + app.run(debug=True) From daf49bcdef6713fdd83127dab543f2b22141bc24 Mon Sep 17 00:00:00 2001 From: Ana Scolari <127357173+apsscolari@users.noreply.github.com> Date: Tue, 6 May 2025 19:27:35 -0700 Subject: [PATCH 2/2] Potential fix for code scanning alert no. 20: Flask app is run in debug mode Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- sqli_ori_httprequest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sqli_ori_httprequest.py b/sqli_ori_httprequest.py index 2fc8ec3..54832e6 100644 --- a/sqli_ori_httprequest.py +++ b/sqli_ori_httprequest.py @@ -40,5 +40,8 @@ def main(): ) return jsonify({"status": "OK"}) +import os + if __name__ == "__main__": - app.run(debug=True) + debug_mode = os.getenv("FLASK_DEBUG", "false").lower() == "true" + app.run(debug=debug_mode)