Skip to content

Commit 71b7b89

Browse files
committed
remove manual parsing in audit_log_parser.py
1 parent afc6aa4 commit 71b7b89

File tree

1 file changed

+12
-66
lines changed

1 file changed

+12
-66
lines changed

experiment/audit/audit_log_parser.py

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@
3535
import urllib.request
3636
from collections import Counter
3737
from pathlib import Path
38-
39-
try:
40-
import yaml
41-
42-
HAS_YAML = True
43-
except ImportError:
44-
HAS_YAML = False
38+
import yaml
4539

4640

4741
def load_endpoint_list_from_yaml(url, endpoint_type="endpoints"):
@@ -60,21 +54,17 @@ def load_endpoint_list_from_yaml(url, endpoint_type="endpoints"):
6054
with urllib.request.urlopen(url, timeout=30) as response:
6155
content = response.read().decode()
6256

63-
# Parse YAML content - use PyYAML if available, otherwise manual parsing
64-
if HAS_YAML:
65-
try:
66-
yaml_data = yaml.safe_load(content)
67-
return _process_yaml_data(yaml_data, endpoint_type)
68-
except yaml.YAMLError as e:
69-
print(f"Error: Failed to parse YAML content from {url}")
70-
print(f"YAML parsing error: {e}")
71-
print(f"Content preview (first 500 chars):")
72-
print(content[:500])
73-
print(f"Cannot proceed with malformed YAML for {endpoint_type}")
74-
sys.exit(1)
75-
else:
76-
print(f"Warning: PyYAML not available, using manual YAML parsing for {endpoint_type}")
77-
return _manual_yaml_parse(content, endpoint_type)
57+
# Parse YAML content using PyYAML
58+
try:
59+
yaml_data = yaml.safe_load(content)
60+
return _process_yaml_data(yaml_data, endpoint_type)
61+
except yaml.YAMLError as e:
62+
print(f"Error: Failed to parse YAML content from {url}")
63+
print(f"YAML parsing error: {e}")
64+
print(f"Content preview (first 500 chars):")
65+
print(content[:500])
66+
print(f"Cannot proceed with malformed YAML for {endpoint_type}")
67+
sys.exit(1)
7868

7969
except urllib.error.URLError as e:
8070
print(f"Error: Failed to download {endpoint_type} from {url}")
@@ -121,50 +111,6 @@ def _process_yaml_data(yaml_data, endpoint_type):
121111
return endpoints
122112

123113

124-
def _manual_yaml_parse(content, endpoint_type):
125-
"""
126-
Manual YAML parsing for simple structures when PyYAML is not available.
127-
128-
Handles two formats:
129-
1. List of objects: - endpoint: name
130-
2. Simple list: - name
131-
132-
Args:
133-
content (str): YAML content as string
134-
endpoint_type (str): Type of endpoints being loaded
135-
136-
Returns:
137-
set: Set of endpoint operation IDs
138-
"""
139-
endpoints = set()
140-
141-
for line in content.split('\n'):
142-
line = line.strip()
143-
144-
# Skip empty lines, comments, and document separators
145-
if not line or line.startswith('#') or line == '---':
146-
continue
147-
148-
if line.startswith('- endpoint:'):
149-
# Format: - endpoint: endpointName (ineligible_endpoints.yaml)
150-
endpoint = line.replace('- endpoint:', '').strip()
151-
if endpoint:
152-
endpoints.add(endpoint)
153-
elif line.startswith('- ') and ':' not in line:
154-
# Format: - endpointName (pending_eligible_endpoints.yaml)
155-
# Only if no colon (to avoid matching other object keys)
156-
endpoint = line.replace('- ', '').strip()
157-
if endpoint:
158-
endpoints.add(endpoint)
159-
160-
if not endpoints:
161-
print(f"Warning: No endpoints found using manual YAML parsing for {endpoint_type}")
162-
print("This might indicate a parsing issue or unexpected YAML format")
163-
164-
print(f"Loaded {len(endpoints)} {endpoint_type} (manual parsing)")
165-
return endpoints
166-
167-
168114
def load_ineligible_endpoints(ineligible_endpoints_url=None):
169115
"""
170116
Load the list of ineligible endpoints from URL or local file.

0 commit comments

Comments
 (0)