-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintegrity_checker.py
More file actions
executable file
·109 lines (87 loc) · 3.3 KB
/
Copy pathintegrity_checker.py
File metadata and controls
executable file
·109 lines (87 loc) · 3.3 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/python3
from link_checker import check_links
from wiki_text_checker import check_wiki_text
from table_generator import generate_table
from send_mail import send_mail
import requests
import json
import os
import sys
# Get environamental values needed for operation
try:
API_TOKEN = 'Basic ' + os.environ["API_TOKEN"]
except KeyError:
print("[ERR]: API_TOKEN not provided as environmental variable. Exiting ...")
sys.exit(1)
try:
# This value disables the generation of the table
# as well as seding it via email
TABLE_DISABLED = os.environ["DISABLE_TABLE"].lower()
except KeyError:
print("[INFO] DISABLE_TABLE not provided as environmental variable. Setting default: false")
TABLE_DISABLED = "false"
try:
LINK_CHECKER_DISABLED = os.environ["DISABLE_LINK_CHECKER"].lower()
except KeyError:
print("[INFO] DISABLE_LINK_CHECKER not provided as environmental variable. Setting default: false")
LINK_CHECKER_DISABLED = "false"
try:
WIKI_CHECKER_DISABLED = os.environ["DISABLE_WIKI_CHECKER"].lower()
except KeyError:
print("[INFO] DISABLE_WIKI_CHECKER not provided as environmental variable. Setting default: false")
WIKI_CHECKER_DISABLED = "false"
print()
base_url = "https://liquidebleiben.codebeamer.com/api/v3"
request = "/trackers/2221/reports/3017/items?page=1&pageSize=500"
headers = {'Authorization': API_TOKEN, 'Content-Type': 'application/json'}
def parse_items_to_named_dict(content):
print("[INFO]: Parsing json data ...")
items = {}
for i in content:
item = i['item']
fields = {}
for field in item['customFields']:
name = field['name']
del field['name']
fields[name] = field
items[item['name']] = {
'id': item['id'],
'fields': fields
}
print("[INFO]: Parsing successfull ...")
return items
def main():
print("[INFO]: ############################################################")
print("[INFO]: # Starting integirty checker")
print("[INFO]: ############################################################\n")
print("[INFO]: Sending request ...")
answer = requests.get(base_url+request, headers=headers)
if answer.status_code == 200:
print("[INFO]: Request successfull...")
else:
print("[ERR]: Request failed! Received {0} status code from codebeamer".format(answer.status_code))
sys.exit(1)
content = json.loads(answer.content)
items = parse_items_to_named_dict(content['items'])
if TABLE_DISABLED == 'true':
print("[INFO]: Skipping table generation ...")
else:
generate_table(items)
message = ""
if LINK_CHECKER_DISABLED == 'true':
print("[INFO]: Skipping link checker ...")
else:
message += check_links(items)
if WIKI_CHECKER_DISABLED == 'true':
print("[INFO]: Skipping wiki checker ...")
else:
message += check_wiki_text(items)
print("[INFO]: Displaying message to be send ...")
print(message)
print("[INFO]: End of message ...")
send_mail(TABLE_DISABLED, message)
print("[INFO]: ############################################################")
print("[INFO]: # Integirty checker finished")
print("[INFO]: ############################################################\n")
if __name__ == "__main__":
main()