""" Deep investigation of GSC and G-Core server actions This script will: 1. Download complete configuration from GeViServer 2. Analyze action mapping structure 3. Identify all GSC and G-Core specific actions 4. Test edit/upload scenarios """ import requests import json from typing import Dict, List, Any BASE_URL = "http://localhost:8000" def authenticate() -> str: """Get authentication token""" response = requests.post(f'{BASE_URL}/api/v1/auth/login', json={ 'username': 'admin', 'password': 'admin123' }) if response.status_code != 200: raise Exception(f"Authentication failed: {response.status_code}") return response.json()['access_token'] def download_configuration(token: str) -> Dict[str, Any]: """Download complete configuration from GeViServer""" headers = {'Authorization': f'Bearer {token}'} print("="*80) print("DOWNLOADING COMPLETE CONFIGURATION") print("="*80) print() # Get action mappings response = requests.get( f'{BASE_URL}/api/v1/configuration/action-mappings', headers=headers ) if response.status_code != 200: raise Exception(f"Failed to download mappings: {response.status_code}") return response.json() def analyze_actions(config: Dict[str, Any]) -> Dict[str, Any]: """Analyze all actions to identify GSC and G-Core specific ones""" print("ANALYZING ACTION STRUCTURE") print("-"*80) print() mappings = config.get('mappings', []) # Categorize actions base_actions = set() gcore_actions = set() gsc_actions = set() # Categorize by action name patterns and parameters for mapping in mappings: for action in mapping.get('output_actions', []): action_name = action.get('action', '') parameters = action.get('parameters', {}) # Check if action has server parameters has_gcore_param = 'GCoreServer' in parameters has_gsc_param = 'GscServer' in parameters if has_gcore_param: gcore_actions.add(action_name) elif has_gsc_param: gsc_actions.add(action_name) else: base_actions.add(action_name) print(f"Base Actions: {len(base_actions)}") print(f"G-Core Actions: {len(gcore_actions)}") print(f"GSC Actions: {len(gsc_actions)}") print() # Show examples if gcore_actions: print("G-Core Actions (examples):") for action in sorted(list(gcore_actions))[:10]: print(f" - {action}") print() if gsc_actions: print("GSC Actions (examples):") for action in sorted(list(gsc_actions))[:10]: print(f" - {action}") print() return { 'base_actions': sorted(list(base_actions)), 'gcore_actions': sorted(list(gcore_actions)), 'gsc_actions': sorted(list(gsc_actions)) } def examine_server_specific_mappings(config: Dict[str, Any]): """Look at actual action mappings that use server parameters""" print("="*80) print("EXAMINING SERVER-SPECIFIC ACTION MAPPINGS") print("="*80) print() mappings = config.get('mappings', []) gcore_mappings = [] gsc_mappings = [] for mapping in mappings: mapping_name = mapping.get('name', 'Unnamed') for action in mapping.get('output_actions', []): action_name = action.get('action', '') parameters = action.get('parameters', {}) if 'GCoreServer' in parameters: gcore_mappings.append({ 'mapping': mapping_name, 'action': action_name, 'server': parameters['GCoreServer'], 'all_params': parameters }) if 'GscServer' in parameters: gsc_mappings.append({ 'mapping': mapping_name, 'action': action_name, 'server': parameters['GscServer'], 'all_params': parameters }) print(f"Found {len(gcore_mappings)} G-Core action mappings") print(f"Found {len(gsc_mappings)} GSC action mappings") print() # Show detailed examples if gcore_mappings: print("G-Core Mapping Examples:") for mapping in gcore_mappings[:5]: print(f"\n Mapping: {mapping['mapping']}") print(f" Action: {mapping['action']}") print(f" Server: {mapping['server']}") print(f" Parameters:") for key, value in mapping['all_params'].items(): print(f" - {key}: {value}") if gsc_mappings: print("\nGSC Mapping Examples:") for mapping in gsc_mappings[:5]: print(f"\n Mapping: {mapping['mapping']}") print(f" Action: {mapping['action']}") print(f" Server: {mapping['server']}") print(f" Parameters:") for key, value in mapping['all_params'].items(): print(f" - {key}: {value}") print() return gcore_mappings, gsc_mappings def main(): try: # Authenticate print("Authenticating...") token = authenticate() print("[OK] Authenticated") print() # Download configuration config = download_configuration(token) print(f"[OK] Downloaded {len(config.get('mappings', []))} action mappings") print() # Analyze actions analysis = analyze_actions(config) # Examine server-specific mappings gcore_mappings, gsc_mappings = examine_server_specific_mappings(config) # Save results results = { 'analysis': analysis, 'gcore_mappings': gcore_mappings, 'gsc_mappings': gsc_mappings } with open('server_actions_analysis.json', 'w') as f: json.dump(results, f, indent=2) print("="*80) print("RESULTS SAVED TO: server_actions_analysis.json") print("="*80) except Exception as e: print(f"[ERROR] {str(e)}") import traceback traceback.print_exc() if __name__ == '__main__': main()