Skip to content

Commit 87fd9e6

Browse files
authored
Merge pull request #6 from quackscience/actions
actions
2 parents 1bae7ee + 9f8bb54 commit 87fd9e6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

main.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,21 @@ def handle_404(e):
309309
flight_port = int(os.getenv('FLIGHT_PORT', 8815))
310310
path = os.getenv('DATA', '.duckdb_data')
311311

312+
def parse_ticket(ticket):
313+
try:
314+
# Try to decode the ticket as a JSON object
315+
ticket_obj = json.loads(ticket.ticket.decode("utf-8"))
316+
if isinstance(ticket_obj, str):
317+
# If the JSON object is a string, parse it again
318+
ticket_obj = json.loads(ticket_obj)
319+
if "query" in ticket_obj:
320+
return ticket_obj["query"]
321+
except (json.JSONDecodeError, AttributeError):
322+
# If decoding fails or "query" is not in the object, return the ticket as a string
323+
return ticket.ticket.decode("utf-8")
324+
325+
326+
# Patch the main function where the ticket is processed
312327
if __name__ == '__main__':
313328
# Set up signal handlers
314329
signal.signal(signal.SIGINT, signal_handler)
@@ -334,12 +349,12 @@ def call_completed(self, exception=None):
334349

335350
class HeaderMiddlewareFactory(flight.ServerMiddlewareFactory):
336351
def start_call(self, info, headers):
352+
logger.debug(f"Info received: {info}")
337353
logger.debug(f"Headers received: {headers}")
338354
if "authorization" in headers:
339355
# Get first value from list
340356
auth = headers["authorization"][0]
341357
auth = auth[7:] if auth.startswith('Bearer ') else auth
342-
logger.info(f"Authorization header found: {auth}")
343358
middleware = HeaderMiddleware()
344359
middleware.authorization = auth
345360
return middleware
@@ -425,7 +440,7 @@ def do_get(self, context, ticket):
425440
except Exception as e:
426441
logger.debug(f"Middleware access error: {e}")
427442

428-
query = ticket.ticket.decode("utf-8")
443+
query = parse_ticket(ticket)
429444
logger.info(f"Executing query: {query}")
430445
try:
431446
result_table = self.conn.execute(query).fetch_arrow_table()

0 commit comments

Comments
 (0)