-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_endpoints.py
executable file
·66 lines (48 loc) · 1.85 KB
/
get_endpoints.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python3
import requests
import json
import argparse
import logging
import csv
import sys
from configuration import Configuration
def do_http(url):
cert = config.get("cert")
key = config.get("key")
if cert is None or key is None:
logging.error("The configuration doesn't specify authentication certificate or private key")
raise Exception("Both cert and key must be specified")
verify = config.get("cadir") if config.get("cadir") is not None else True
requests_logger = logging.getLogger("urllib3")
requests_logger.setLevel(logging.ERROR)
response = requests.get(url, verify=verify, cert=(cert, key))
if response.status_code != 200:
logging.error("Failed to get response from %s: (%d: %s)" %
(url, response.status_code, response.reason))
raise Exception("Failed to get HTTP response")
return(response.text)
def get_endpoints():
endpoints=dict()
with open(config.get("services_endpoints"), 'r') as f:
reader = csv.DictReader(f)
for row in reader:
endpoints[row["saml_entity_id"]] = row["accounting_endpoint"]
services = do_http(config.get("services_url"))
js = json.loads(services)
for service in js:
if not service in endpoints:
print("Service '%s' doesn't have a known endpoint (check %s)" % (service, config.get("services_endpoints")),
file=sys.stderr)
continue
js[service]["endpoint"] = endpoints[service]
print(json.dumps(js))
def parse_args():
parser = argparse.ArgumentParser(
description="Obtain the endpoints to gather accounting data from")
return parser.parse_args()
config = Configuration()
if __name__ == '__main__':
args = parse_args()
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
get_endpoints()