@@ -369,10 +369,55 @@ def dumpJson(self):
369369 print ("ERROR: no Ziti identity provided, set INPUT_ZITIID or INPUT_ZITIJWT" )
370370 exit (1 )
371371
372+ def generate_json_schema (obj , max_depth = 10 , current_depth = 0 ):
373+ """Generate a schema representation of a JSON object by inferring types from values."""
374+ if current_depth >= max_depth :
375+ return "<max_depth_reached>"
376+
377+ if obj is None :
378+ return "null"
379+ elif isinstance (obj , bool ):
380+ return "boolean"
381+ elif isinstance (obj , int ):
382+ return "integer"
383+ elif isinstance (obj , float ):
384+ return "number"
385+ elif isinstance (obj , str ):
386+ return "string"
387+ elif isinstance (obj , list ):
388+ if len (obj ) == 0 :
389+ return "array[]"
390+ # Get schema of first element as representative
391+ element_schema = generate_json_schema (obj [0 ], max_depth , current_depth + 1 )
392+ return f"array[{ element_schema } ]"
393+ elif isinstance (obj , dict ):
394+ schema = {}
395+ for key , value in obj .items ():
396+ schema [key ] = generate_json_schema (value , max_depth , current_depth + 1 )
397+ return schema
398+ else :
399+ return f"unknown_type({ type (obj ).__name__ } )"
400+
401+ # Validate zitiId as JSON
402+ try :
403+ zitiIdJson = json .loads (zitiId )
404+ except Exception as e :
405+ print (f"ERROR: zitiId is not valid JSON: { e } " )
406+ print (f"zitiId content: { zitiId } " )
407+ exit (1 )
408+
372409 idFilename = "id.json"
373410 with open (idFilename , 'w' ) as f :
374411 f .write (zitiId )
412+
413+ # Load the identity file after it's been written and closed
414+ try :
375415 openziti .load (idFilename )
416+ except Exception as e :
417+ print (f"ERROR: Failed to load Ziti identity: { e } " )
418+ schema = generate_json_schema (zitiIdJson )
419+ print (f"DEBUG: zitiId schema for troubleshooting: { json .dumps (schema , indent = 2 )} " )
420+ raise e
376421
377422 # Create webhook body
378423 try :
0 commit comments