Added Authentik TF code
This commit is contained in:
143
.github/scripts/generate-apps-wiki.py
vendored
Normal file
143
.github/scripts/generate-apps-wiki.py
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Script for generating Wiki page with applications list from Terraform outputs
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
def generate_markdown_table(apps_data):
|
||||
"""Generates Markdown table for applications"""
|
||||
|
||||
# Combine all applications
|
||||
all_apps = []
|
||||
|
||||
if 'proxy_apps' in apps_data:
|
||||
for key, app in apps_data['proxy_apps'].items():
|
||||
all_apps.append({
|
||||
'key': key,
|
||||
'name': app['name'],
|
||||
'type': app['type'],
|
||||
'url': app['url'],
|
||||
'group': app['group'],
|
||||
'description': app['description'],
|
||||
'icon': app['icon'],
|
||||
'slug': app['slug']
|
||||
})
|
||||
|
||||
if 'oauth_apps' in apps_data:
|
||||
for key, app in apps_data['oauth_apps'].items():
|
||||
all_apps.append({
|
||||
'key': key,
|
||||
'name': app['name'],
|
||||
'type': app['type'],
|
||||
'url': app['url'],
|
||||
'group': app['group'],
|
||||
'description': app['description'],
|
||||
'icon': app['icon'],
|
||||
'slug': app['slug']
|
||||
})
|
||||
|
||||
# Sort by groups, then by name
|
||||
all_apps.sort(key=lambda x: (x['group'], x['name']))
|
||||
|
||||
# Generate Markdown
|
||||
markdown = []
|
||||
markdown.append("# Authentik Applications")
|
||||
markdown.append("")
|
||||
markdown.append(f"*Automatically generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S UTC')}*")
|
||||
markdown.append("")
|
||||
markdown.append("## All Applications")
|
||||
markdown.append("")
|
||||
|
||||
# Table
|
||||
markdown.append("| Icon | Name | Type | URL | Group | Description |")
|
||||
markdown.append("|------|------|------|-----|-------|-------------|")
|
||||
|
||||
for app in all_apps:
|
||||
icon = f"" if app['icon'] else "📱"
|
||||
url_link = f"[🔗 Open]({app['url']})" if app['url'] else "-"
|
||||
description = app['description'] if app['description'] else "-"
|
||||
|
||||
markdown.append(f"| {icon} | **{app['name']}** | {app['type']} | {url_link} | {app['group']} | {description} |")
|
||||
|
||||
markdown.append("")
|
||||
|
||||
# Statistics
|
||||
proxy_count = len(apps_data.get('proxy_apps', {}))
|
||||
oauth_count = len(apps_data.get('oauth_apps', {}))
|
||||
total_count = proxy_count + oauth_count
|
||||
|
||||
markdown.append("## Statistics")
|
||||
markdown.append("")
|
||||
markdown.append(f"- **Total applications**: {total_count}")
|
||||
markdown.append(f"- **Proxy applications**: {proxy_count}")
|
||||
markdown.append(f"- **OAuth2/OpenID applications**: {oauth_count}")
|
||||
markdown.append("")
|
||||
|
||||
# Grouping by types
|
||||
groups = {}
|
||||
for app in all_apps:
|
||||
group = app['group']
|
||||
if group not in groups:
|
||||
groups[group] = {'proxy': 0, 'oauth': 0}
|
||||
if app['type'] == 'Proxy':
|
||||
groups[group]['proxy'] += 1
|
||||
else:
|
||||
groups[group]['oauth'] += 1
|
||||
|
||||
markdown.append("## Applications by Groups")
|
||||
markdown.append("")
|
||||
for group, counts in sorted(groups.items()):
|
||||
total = counts['proxy'] + counts['oauth']
|
||||
markdown.append(f"- **{group}**: {total} applications (Proxy: {counts['proxy']}, OAuth: {counts['oauth']})")
|
||||
|
||||
markdown.append("")
|
||||
markdown.append("---")
|
||||
markdown.append("*This page is automatically generated via Terraform CI/CD*")
|
||||
|
||||
return "\n".join(markdown)
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python3 generate-apps-wiki.py <terraform-output-json>")
|
||||
sys.exit(1)
|
||||
|
||||
output_file = sys.argv[1]
|
||||
|
||||
try:
|
||||
with open(output_file, 'r') as f:
|
||||
terraform_output = json.load(f)
|
||||
|
||||
# Извлекаем данные приложений
|
||||
apps_data = terraform_output.get('applications_for_wiki', {}).get('value', {})
|
||||
|
||||
if not apps_data:
|
||||
print("ERROR: No applications_for_wiki output found in Terraform output")
|
||||
sys.exit(1)
|
||||
|
||||
# Генерируем Markdown
|
||||
markdown_content = generate_markdown_table(apps_data)
|
||||
|
||||
# Записываем результат
|
||||
wiki_file = "Applications.md"
|
||||
with open(wiki_file, 'w', encoding='utf-8') as f:
|
||||
f.write(markdown_content)
|
||||
|
||||
print(f"✅ Wiki page generated: {wiki_file}")
|
||||
print(f"📊 Total applications: {len(apps_data.get('proxy_apps', {})) + len(apps_data.get('oauth_apps', {}))}")
|
||||
|
||||
except FileNotFoundError:
|
||||
print(f"ERROR: File {output_file} not found")
|
||||
sys.exit(1)
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"ERROR: Invalid JSON in {output_file}: {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"ERROR: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user