Completed
Pull Request — master (#423)
by
unknown
02:15
created

GetScanResults()   B

Complexity

Conditions 4

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 37
rs 8.5806
cc 4
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
def booleen2string(self, booleen):
19
    if booleen is True:
20
        return "true"
21
    else:
22
        return "false"
23
        
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
24
def GetScanResults (config, scan_id, new_vulns=False, new_ports=False):
0 ignored issues
show
Coding Style introduced by
No space allowed before bracket
def GetScanResults (config, scan_id, new_vulns=False, new_ports=False):
^
Loading history...
25
    """
26
    The template class for
27
28
    Returns: An blank Dict.
29
30
    Raises:
31
    ValueError: On lack of key in config.
32
    """
33
34
    results = {}
0 ignored issues
show
Unused Code introduced by
The variable results seems to be unused.
Loading history...
35
   
0 ignored issues
show
Coding Style introduced by
Trailing whitespace
Loading history...
36
    url = "https://{}/api/scan/v1/results/{}".format(config['api_host'],scan_exec_id)
0 ignored issues
show
Coding Style introduced by
Exactly one space required after comma
url = "https://{}/api/scan/v1/results/{}".format(config['api_host'],scan_exec_id)
^
Loading history...
Comprehensibility Best Practice introduced by
Undefined variable 'scan_exec_id'
Loading history...
37
38
    payload = {}
39
40
    # The API expects false and not False, so send strings not booleens
41
    payload = { 'new_vulns': booleen2string(new_vulns),
0 ignored issues
show
Coding Style introduced by
No space allowed after bracket
payload = { 'new_vulns': booleen2string(new_vulns),
^
Loading history...
Bug introduced by
It seems like a value for argument booleen is missing in the function call.
Loading history...
42
                'new_ports': booleen2string(new_ports) }
0 ignored issues
show
Coding Style introduced by
No space allowed before bracket
'new_ports': booleen2string(new_ports) }
^
Loading history...
Bug introduced by
It seems like a value for argument booleen is missing in the function call.
Loading history...
43
44
    headers = { "Accept": "application/json" }
0 ignored issues
show
Coding Style introduced by
No space allowed after bracket
headers = "Accept": "application/json"
^
Loading history...
Coding Style introduced by
No space allowed before bracket
headers = "Accept": "application/json"
^
Loading history...
45
46
    try:
47
        r = requests.get(url,
48
                         headers=headers,
49
                        auth=(self.config['api_key'], ''),
0 ignored issues
show
Comprehensibility Best Practice introduced by
Undefined variable 'self'
Loading history...
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