Skip to content

Commit

Permalink
Merge pull request #285 from fbrousse/patch-1
Browse files Browse the repository at this point in the history
try to parse REQ_PAYLOAD as json to avoid unexpected quoting

increments #patch
  • Loading branch information
jekkel authored May 24, 2023
2 parents 13c64f6 + 69576d9 commit 72336e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import signal
import sys
import traceback
import json
from collections import defaultdict
from multiprocessing import Process
from time import sleep
Expand Down Expand Up @@ -54,6 +55,14 @@ def signal_handler(signum, frame):

signal.signal(signal.SIGTERM, signal_handler)

def prepare_payload(payload):
"""Prepare payload as dict for request."""
try:
payload_dict = json.loads(payload)
return payload_dict
except ValueError as err:
logger.warning(f"Payload will be posted as quoted json")
return payload

def _get_file_data_and_name(full_filename, content, enable_5xx, content_type=CONTENT_TYPE_TEXT):
if content_type == CONTENT_TYPE_BASE64_BINARY:
Expand Down
3 changes: 3 additions & 0 deletions src/sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def main():

request_method = os.getenv(REQ_METHOD)
request_url = os.getenv(REQ_URL)

request_payload = os.getenv(REQ_PAYLOAD)
if request_payload:
request_payload = prepare_payload(os.getenv(REQ_PAYLOAD))
script = os.getenv(SCRIPT)

_initialize_kubeclient_configuration()
Expand Down

0 comments on commit 72336e6

Please sign in to comment.