Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import logging
def pretty_json(j):
return json.dumps(j,sort_keys=True,indent=4)
def import_dep_info(file_path, endpoint_keys):
with open(file_path) as f:
data = json.load(f)
endpoints = {}
for key,value in data['output'].items():
if "_ip" in key:
if isinstance(value, str):
endpoints[value] = {22}
if endpoint_keys != "None":
list_endpoints = endpoint_keys.split(',')
for key in data['outputs'].keys():
if key in list_endpoints:
endpoint = str(data['outputs'][key])
prefix,url = endpoint.split("://")
if ":" in url:
host,port = url.split(":")
else:
host = url
if prefix == "https":
port = '443'
elif prefix == 'http':
port = '80'
else:
raise Exception(f"Impossible to parse the endpoint port. Endpoint: {endpoint}")
logging.info(f"Endpoint: {host}:{port}")
if host not in endpoints:
endpoints[host] = {port}
else:
endpoints[host].add(port)
for host,ports in endpoints.items():
endpoints[host] = sorted(list(ports))
return endpoints