Skip to content

Commit ab866a4

Browse files
committed
emit identity json schema if failed loading with py sdk
1 parent 0eae81c commit ab866a4

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

zhook.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,38 @@ def dumpJson(self):
414414
print("ERROR: no Ziti identity provided, set INPUT_ZITIID or INPUT_ZITIJWT")
415415
exit(1)
416416

417-
# Validate zitiId as JSON and print debug logs for top-level keys
417+
def generate_json_schema(obj, max_depth=10, current_depth=0):
418+
"""Generate a schema representation of a JSON object by inferring types from values."""
419+
if current_depth >= max_depth:
420+
return "<max_depth_reached>"
421+
422+
if obj is None:
423+
return "null"
424+
elif isinstance(obj, bool):
425+
return "boolean"
426+
elif isinstance(obj, int):
427+
return "integer"
428+
elif isinstance(obj, float):
429+
return "number"
430+
elif isinstance(obj, str):
431+
return "string"
432+
elif isinstance(obj, list):
433+
if len(obj) == 0:
434+
return "array[]"
435+
# Get schema of first element as representative
436+
element_schema = generate_json_schema(obj[0], max_depth, current_depth + 1)
437+
return f"array[{element_schema}]"
438+
elif isinstance(obj, dict):
439+
schema = {}
440+
for key, value in obj.items():
441+
schema[key] = generate_json_schema(value, max_depth, current_depth + 1)
442+
return schema
443+
else:
444+
return f"unknown_type({type(obj).__name__})"
445+
446+
# Validate zitiId as JSON
418447
try:
419448
zitiIdJson = json.loads(zitiId)
420-
print(f"DEBUG: zitiId top-level keys: {list(zitiIdJson.keys())}")
421449
except Exception as e:
422450
print(f"ERROR: zitiId is not valid JSON: {e}")
423451
print(f"zitiId content: {zitiId}")
@@ -426,7 +454,15 @@ def dumpJson(self):
426454
idFilename = "id.json"
427455
with open(idFilename, 'w') as f:
428456
f.write(zitiId)
429-
openziti.load(idFilename)
457+
458+
# Load the identity file after it's been written and closed
459+
try:
460+
openziti.load(idFilename)
461+
except Exception as e:
462+
print(f"ERROR: Failed to load Ziti identity: {e}")
463+
schema = generate_json_schema(zitiIdJson)
464+
print(f"DEBUG: zitiId schema for troubleshooting: {json.dumps(schema, indent=2)}")
465+
raise e
430466

431467
# Create webhook body
432468
try:

0 commit comments

Comments
 (0)