Commit 088d522c authored by Marco Schmiedel's avatar Marco Schmiedel

fix

parent c72b60bb
...@@ -18,7 +18,7 @@ from models.base_base import BaseBase ...@@ -18,7 +18,7 @@ from models.base_base import BaseBase
from models.option_opti import OptionOpti from models.option_opti import OptionOpti
from config.MauiConfig import EECCX_TOKEN_URL, EECCX_API_URL, EECCX_CLIENT_ID, EECCX_CLIENT_SECRET, EECCX_CF_CLIENT_ID, EECCX_CF_CLIENT_SECRET, EECCX_HDL_NR, EECCX_PROV_HDL_NR from config.MauiConfig import EECCX_TOKEN_URL, EECCX_API_URL, EECCX_CLIENT_ID, EECCX_CLIENT_SECRET, EECCX_CF_CLIENT_ID, EECCX_CF_CLIENT_SECRET, EECCX_HDL_NR, EECCX_PROV_HDL_NR
# A warning is disabled so selfsigned certificate usage does not flood the log in development environments. # A warning is disabled so self-signed certificate usage does not flood the log in development environments.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# The constant TOKEN_URL stores the identity provider endpoint used for OAuth authentication. # The constant TOKEN_URL stores the identity provider endpoint used for OAuth authentication.
...@@ -27,7 +27,7 @@ TOKEN_URL = EECCX_TOKEN_URL ...@@ -27,7 +27,7 @@ TOKEN_URL = EECCX_TOKEN_URL
# The constant API_URL stores the partner API endpoint that generates the PDF. # The constant API_URL stores the partner API endpoint that generates the PDF.
API_URL = EECCX_API_URL API_URL = EECCX_API_URL
# The constant CLIENT_ID stores the OAuth client identifier for the backend application. # The constant CLIENT_ID stores the OAuth client identifier for the back-end application.
CLIENT_ID = EECCX_CLIENT_ID CLIENT_ID = EECCX_CLIENT_ID
# The constant CLIENT_SECRET stores the OAuth client secret matching the client identifier. # The constant CLIENT_SECRET stores the OAuth client secret matching the client identifier.
...@@ -59,22 +59,23 @@ def _json_error(message: str, status_code: int = 502) -> Response: ...@@ -59,22 +59,23 @@ def _json_error(message: str, status_code: int = 502) -> Response:
# A JSON payload is assembled with status "ERROR" and the provided message. # A JSON payload is assembled with status "ERROR" and the provided message.
payload = json.dumps({"status": "ERROR", "message": message}, ensure_ascii=False) payload = json.dumps({"status": "ERROR", "message": message}, ensure_ascii=False)
return Response(payload, status=status_code, mimetype="application/json") # Always return HTTP 200 to prevent Cloudflare from replacing the response with its own 5XX page.
return Response(payload, status=200, mimetype="application/json")
# The function extracts the option identifiers from the query string and normalises commaseparated values into a list. # The function extracts the option identifiers from the query string and normalises comma-separated values into a list.
def _extract_options() -> List[str]: def _extract_options() -> List[str]:
# The raw option list is read from the query argument list to handle multiple "options" parameters. # The raw option list is read from the query argument list to handle multiple "options" parameters.
raw = request.args.getlist("options") raw = request.args.getlist("options")
# The following conditional branch handles the special case in which a single commaseparated value has been supplied instead of repeated parameters. # The following conditional branch handles the special case in which a single comma-separated value has been supplied instead of repeated parameters.
if len(raw) == 1 and "," in raw[0]: if len(raw) == 1 and "," in raw[0]:
# The value is split on commas and stripped so empty strings are removed from the final list. # The value is split on commas and stripped so empty strings are removed from the final list.
return [opt.strip() for opt in raw[0].split(",") if opt.strip()] return [opt.strip() for opt in raw[0].split(",") if opt.strip()]
return [opt for opt in raw if opt] return [opt for opt in raw if opt]
# The function builds a unique hash from tarif_id, the option list, and the current timestamp so the uploaded PDF file name is collisionfree. # The function builds a unique hash from tarif_id, the option list, and the current timestamp so the uploaded PDF file name is collision-free.
def _hash_id_options(tarif_id: str, options: List[str]) -> str: def _hash_id_options(tarif_id: str, options: List[str]) -> str:
# The key string concatenates tarif_id, the sorted option list, and the current Unix timestamp. # The key string concatenates tarif_id, the sorted option list, and the current Unix timestamp.
...@@ -118,7 +119,7 @@ def _get_token() -> Tuple[str | None, str | None]: ...@@ -118,7 +119,7 @@ def _get_token() -> Tuple[str | None, str | None]:
# The function assembles the partner API payload, performs the HTTP PUT request, and returns either the JSON result or an error message. # The function assembles the partner API payload, performs the HTTP PUT request, and returns either the JSON result or an error message.
def _partner_api(token: str, tarif_id: str, options: List[str]) -> Tuple[dict | None, str | None]: def _partner_api(token: str, tarif_id: str, options: List[str]) -> Tuple[dict | None, str | None]:
# The headers dictionary includes OAuth, Cloudflare, and contenttype information required by the partner API. # The headers dictionary includes OAuth, Cloudflare, and content-type information required by the partner API.
headers = { headers = {
"Authorization": f"Bearer {token}", "Authorization": f"Bearer {token}",
"CF-Access-Client-Id": CF_CLIENT_ID, "CF-Access-Client-Id": CF_CLIENT_ID,
...@@ -244,7 +245,7 @@ def _partner_api(token: str, tarif_id: str, options: List[str]) -> Tuple[dict | ...@@ -244,7 +245,7 @@ def _partner_api(token: str, tarif_id: str, options: List[str]) -> Tuple[dict |
# An error tuple is returned when the response is not valid JSON. # An error tuple is returned when the response is not valid JSON.
return None, "Antwort der Partner-API ist kein JSON." return None, "Antwort der Partner-API ist kein JSON."
# The err_val variable is inspected for API‑level error information that must be mapped to a user‑friendly string. # The err_val variable is inspected for API-level error information that must be mapped to a user-friendly string.
err_val = data.get("error") err_val = data.get("error")
# The following conditional branch returns an error tuple when the API embedded error information in its JSON body. # The following conditional branch returns an error tuple when the API embedded error information in its JSON body.
...@@ -310,7 +311,7 @@ def eeccx_pdf(tarif_id: str): ...@@ -310,7 +311,7 @@ def eeccx_pdf(tarif_id: str):
if err: if err:
return _json_error(err, 502) return _json_error(err, 502)
# A unique hash is generated so the temporary file and the S3 object name are collisionfree. # A unique hash is generated so the temporary file and the S3 object name are collision-free.
hash_name = _hash_id_options(tarif_id, options) hash_name = _hash_id_options(tarif_id, options)
# A temporary file is opened so the PDF can be written to disk for uploading. # A temporary file is opened so the PDF can be written to disk for uploading.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment