-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathstatus_check.py
90 lines (82 loc) · 3.14 KB
/
status_check.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
# Copyright © 2020 Red Hat Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Author: Yusuf Zainee <[email protected]>
#
"""Status check for registry of all the supported ecosystems."""
from f8a_utils.versions import get_versions_for_ep
from datetime import datetime
from f8a_utils.golang_utils import GolangUtils
from helper import Helper
class StatusCheck:
def __init__(self):
self.result_format = {
"failure": False,
"last_checked": "",
"maven": {
"status_check": False
},
"npm": {
"status_check": False
},
"pypi": {
"status_check": False
},
"golang": {
"status_check": False
},
"comments": ""
}
self.helper = Helper()
def status_check(self):
"""Check different status and generate report."""
self.result_format['last_checked'] = datetime.now().strftime("%d-%m-%Y::%H:%M")
self.__check_status("pypi", "requests")
self.__check_status("npm", "lodash")
self.__check_status("maven", "io.vertx:vertx-web")
self.__check_golang_status("github.com/grafana/grafana")
if self.result_format['failure']:
filename = "Failed_Status.json"
else:
filename = "Success_Status.json"
self.helper.store_json_content(self.result_format, "snyk-feed/status/" + filename)
return True
def __check_status(self, eco, pkg):
"""Check the status of pypi, npm, maven ecosystem."""
try:
res = get_versions_for_ep(eco, pkg)
except Exception as e:
self.result_format['comments'] = str(e) + "\n"
res = []
if len(res) <= 0:
self.result_format['comments'] += "Could not fetch details for {} " \
"ecosystem.".format(eco)
self.result_format['failure'] = True
else:
self.result_format[eco]['status_check'] = True
def __check_golang_status(self, pkg):
"""Check the status of golang ecosystem."""
try:
go_utils = GolangUtils(pkg)
gh = go_utils.get_gh_link()
lic = go_utils.get_license()
except Exception as e:
self.result_format['comments'] = str(e) + "\n"
gh = None
lic = None
if not (gh and lic):
self.result_format['comments'] += "Could not fetch details for Golang ecosystem."
self.result_format['failure'] = True
else:
self.result_format['golang']['status_check'] = True