|
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 GetScanList(config, customer_id=None, active_only=False): |
|
20
|
|
|
""" |
|
21
|
|
|
The template class for |
|
22
|
|
|
|
|
23
|
|
|
Returns: An blank Dict. |
|
24
|
|
|
|
|
25
|
|
|
Raises: |
|
26
|
|
|
ValueError: On lack of key in config. |
|
27
|
|
|
""" |
|
28
|
|
|
|
|
29
|
|
|
results = {} |
|
30
|
|
|
|
|
31
|
|
|
url = "https://{}/api/scan/v1/scans".format(config['api_host']) |
|
32
|
|
|
payload = None |
|
33
|
|
|
headers = {"Accept": "application/json"} |
|
34
|
|
|
|
|
35
|
|
|
if customer_id is not None: |
|
36
|
|
|
payload = {} |
|
37
|
|
|
payload['customer_id'] = customer_id |
|
38
|
|
|
|
|
39
|
|
|
try: |
|
40
|
|
|
r = requests.get(url, |
|
41
|
|
|
headers=headers, |
|
42
|
|
|
auth=(config['api_key'], ''), |
|
43
|
|
|
params=payload) |
|
44
|
|
|
r.raise_for_status() |
|
45
|
|
|
except: |
|
46
|
|
|
raise ValueError("HTTP error: %s on %s" % (r.status_code, r.url)) |
|
47
|
|
|
|
|
48
|
|
|
try: |
|
49
|
|
|
data = r.json() |
|
50
|
|
|
except: |
|
51
|
|
|
raise ValueError("Invalid JSON") |
|
52
|
|
|
else: |
|
53
|
|
|
for item in data: |
|
54
|
|
|
if item["active"] is False and active_only is True: |
|
55
|
|
|
continue |
|
56
|
|
|
|
|
57
|
|
|
results[item['title']] = {"active": item["active"], |
|
58
|
|
|
"id": item["id"], |
|
59
|
|
|
"type": item["type"]} |
|
60
|
|
|
return results |
|
61
|
|
|
|