1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
import requests |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
def booleen2string(booleen): |
20
|
|
|
if booleen is True: |
21
|
|
|
return "true" |
22
|
|
|
else: |
23
|
|
|
return "false" |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
def GetScanResults(config, scan_exec_id, new_vulns=False, new_ports=False): |
27
|
|
|
""" |
28
|
|
|
The template class for |
29
|
|
|
|
30
|
|
|
Returns: An blank Dict. |
31
|
|
|
|
32
|
|
|
Raises: |
33
|
|
|
ValueError: On lack of key in config. |
34
|
|
|
""" |
35
|
|
|
|
36
|
|
|
url = "https://{}/api/scan/v1/results/{}".format(config['api_host'], scan_exec_id) |
37
|
|
|
|
38
|
|
|
payload = {} |
39
|
|
|
|
40
|
|
|
# The API expects false and not False, so send strings not booleens |
41
|
|
|
payload = {'new_vulns': booleen2string(new_vulns), |
42
|
|
|
'new_ports': booleen2string(new_ports)} |
43
|
|
|
|
44
|
|
|
headers = {"Accept": "application/json"} |
45
|
|
|
|
46
|
|
|
try: |
47
|
|
|
r = requests.get(url, |
48
|
|
|
headers=headers, |
49
|
|
|
auth=(config['api_key'], ''), |
50
|
|
|
params=payload) |
51
|
|
|
r.raise_for_status() |
52
|
|
|
except: |
53
|
|
|
raise ValueError("HTTP error: %s" % r.status_code) |
54
|
|
|
|
55
|
|
|
try: |
56
|
|
|
data = r.json() |
57
|
|
|
except: |
58
|
|
|
raise ValueError("Invalid JSON") |
59
|
|
|
else: |
60
|
|
|
return data |
61
|
|
|
|