Skip to content

Commit 0602595

Browse files
authored
Merge pull request #35372 from dims/simplify-swagger-url-read-in-kubernetes_api_analysis.py
simplify swagger url read in kubernetes_api_analysis.py
2 parents 786d775 + b9c8228 commit 0602595

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

experiment/audit/kubernetes_api_analysis.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,9 @@ def extract_swagger_operations(swagger_url, output_file):
5757
print(f"Output file: {output_file}")
5858

5959
try:
60-
# Check if it's a URL or local file path
61-
if swagger_url.startswith(('http://', 'https://')):
62-
print("Downloading swagger specification...")
63-
with urllib.request.urlopen(swagger_url) as response:
64-
swagger_data = json.loads(response.read().decode())
65-
else:
66-
# Local file path
67-
if not os.path.exists(swagger_url):
68-
print(f"Error: Swagger file not found at {swagger_url}")
69-
sys.exit(1)
70-
with open(swagger_url, 'r') as f:
71-
swagger_data = json.load(f)
60+
print("Downloading swagger specification...")
61+
with urllib.request.urlopen(swagger_url) as response:
62+
swagger_data = json.loads(response.read().decode())
7263
except (json.JSONDecodeError, IOError, urllib.error.URLError) as e:
7364
print(f"Error reading swagger specification: {e}")
7465
sys.exit(1)

0 commit comments

Comments
 (0)