This commit is contained in:
@@ -100,12 +100,27 @@ def generate_markdown_table(apps_data):
|
||||
|
||||
return "\n".join(markdown)
|
||||
|
||||
def parse_terraform_output(output_data):
|
||||
"""Parse Terraform output JSON structure"""
|
||||
# Check if this is a full terraform output (with value, type, sensitive fields)
|
||||
if isinstance(output_data, dict) and 'applications_for_wiki' in output_data:
|
||||
# This is full terraform output format
|
||||
app_output = output_data.get('applications_for_wiki', {})
|
||||
if isinstance(app_output, dict) and 'value' in app_output:
|
||||
return app_output['value']
|
||||
else:
|
||||
return app_output
|
||||
else:
|
||||
# This is already the value extracted
|
||||
return output_data
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python3 generate-apps-wiki.py <terraform-output-json>")
|
||||
if len(sys.argv) < 2:
|
||||
print("Usage: python3 generate-apps-wiki.py <terraform-output-json> [--debug]")
|
||||
sys.exit(1)
|
||||
|
||||
output_file = sys.argv[1]
|
||||
debug = "--debug" in sys.argv
|
||||
|
||||
try:
|
||||
# Check if file exists and has content
|
||||
@@ -120,10 +135,12 @@ def main():
|
||||
|
||||
print(f"📄 Reading Terraform output file: {output_file} ({file_size} bytes)")
|
||||
|
||||
# Read and show first few chars for debugging
|
||||
# Read file content
|
||||
with open(output_file, 'r') as f:
|
||||
content = f.read()
|
||||
print(f"🔍 File content preview: {content[:100]}...")
|
||||
|
||||
if debug:
|
||||
print(f"🔍 File content preview: {content[:200]}...")
|
||||
|
||||
# Clean content - remove command line if present
|
||||
if content.startswith('[command]'):
|
||||
@@ -131,7 +148,8 @@ def main():
|
||||
lines = content.split('\n', 1)
|
||||
if len(lines) > 1:
|
||||
content = lines[1]
|
||||
print(f"🔍 Cleaned content preview: {content[:100]}...")
|
||||
if debug:
|
||||
print(f"🔍 Cleaned content preview: {content[:200]}...")
|
||||
else:
|
||||
print("ERROR: File contains only command line, no JSON data")
|
||||
sys.exit(1)
|
||||
@@ -141,21 +159,35 @@ def main():
|
||||
terraform_output = json.loads(content)
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"ERROR: Invalid JSON in {output_file}: {e}")
|
||||
print(f"Content starts with: {content[:50]}")
|
||||
sys.exit(1)
|
||||
print(f"Content starts with: {repr(content[:100])}")
|
||||
# Try to find where JSON starts
|
||||
json_start = content.find('{')
|
||||
if json_start > 0:
|
||||
print(f"Found JSON starting at position {json_start}, retrying...")
|
||||
content = content[json_start:]
|
||||
try:
|
||||
terraform_output = json.loads(content)
|
||||
except json.JSONDecodeError as e2:
|
||||
print(f"ERROR: Still invalid JSON: {e2}")
|
||||
sys.exit(1)
|
||||
else:
|
||||
sys.exit(1)
|
||||
|
||||
# Extract application data - now terraform_output IS the value
|
||||
apps_data = terraform_output
|
||||
# Extract application data using helper function
|
||||
apps_data = parse_terraform_output(terraform_output)
|
||||
|
||||
if not apps_data:
|
||||
print("ERROR: No applications data found in Terraform output")
|
||||
print(f"Output content: {terraform_output}")
|
||||
if debug:
|
||||
print(f"Full output structure: {json.dumps(terraform_output, indent=2)[:500]}...")
|
||||
sys.exit(1)
|
||||
|
||||
# Check if we have correct structure
|
||||
if 'proxy_apps' not in apps_data and 'oauth_apps' not in apps_data:
|
||||
print("ERROR: Expected 'proxy_apps' or 'oauth_apps' in output")
|
||||
print(f"Available keys: {list(apps_data.keys())}")
|
||||
if debug and apps_data:
|
||||
print(f"Data structure: {json.dumps(apps_data, indent=2)[:500]}...")
|
||||
sys.exit(1)
|
||||
|
||||
print(f"📊 Found {len(apps_data.get('proxy_apps', {}))} proxy apps, {len(apps_data.get('oauth_apps', {}))} oauth apps")
|
||||
|
||||
Reference in New Issue
Block a user