import requests import json import time base_url = "http://localhost:8000" # Authenticate print("1. Authenticating...") auth_response = requests.post( f"{base_url}/api/v1/auth/login", json={"username": "admin", "password": "admin123"} ) token = auth_response.json().get("access_token") headers = { "Content-Type": "application/json", "Authorization": f"Bearer {token}" } print(" [OK] Authenticated") # Count existing mappings print("\n2. Reading existing mappings...") read_response = requests.get( f"{base_url}/api/v1/configuration/action-mappings/export", headers=headers ) if read_response.status_code == 200: before_count = read_response.json().get("total_mappings", 0) print(f" [OK] Current mappings: {before_count}") else: print(f" [FAIL] Error: {read_response.status_code}") exit(1) # Create new mapping print("\n3. Creating new action mapping with binary append approach...") create_data = { "name": "Binary Append Test Mapping", "output_actions": [ { "action": "WriteLog", "parameters": { "Text": "Binary append test successful", "Level": "Info" } } ] } create_response = requests.post( f"{base_url}/api/v1/configuration/action-mappings", headers=headers, json=create_data ) print(f" Status: {create_response.status_code}") if create_response.status_code == 201: result = create_response.json() print(f" [OK] Success: {result.get('message', '')}") else: print(f" [FAIL] Error: {create_response.text}") exit(1) # Wait a moment for GeViServer to process print("\n4. Waiting 2 seconds for GeViServer to process...") time.sleep(2) # Read mappings again to verify persistence print("\n5. Reading mappings again to verify persistence...") verify_response = requests.get( f"{base_url}/api/v1/configuration/action-mappings/export", headers=headers ) if verify_response.status_code == 200: data = verify_response.json() after_count = data.get("total_mappings", 0) print(f" [OK] New mapping count: {after_count}") # Check if our new mapping exists found = False for mapping in data.get("mappings", []): if "Binary Append Test" in mapping.get("name", ""): found = True print(f"\n [SUCCESS!] New mapping found: '{mapping['name']}'") print(f" Actions: {len(mapping.get('output_actions', []))}") for action in mapping.get('output_actions', []): print(f" - {action.get('action', '')}") break if not found: print(f"\n [FAILURE!] Mapping count went from {before_count} to {after_count}") if after_count == before_count: print(" The mapping was NOT persisted to GeViServer") print(" Binary append approach still has issues") else: print(f" New mapping exists but name doesn't match") print(f" Last 3 mappings:") for m in data.get("mappings", [])[-3:]: print(f" - {m.get('name', '')}") else: print(f" [FAIL] Error reading mappings: {verify_response.status_code}")