forked from yaleman/crowdstrike_api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hosts.py
60 lines (48 loc) · 1.95 KB
/
test_hosts.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
#!/usr/bin/env python3
""" tests the "hosts" endpoints """
import json
import os
import sys
# import tempfile
try:
from loguru import logger
from crowdstrike import CrowdstrikeAPI
except ImportError as import_error:
sys.exit(f"Error importing required library: {import_error}")
# grab config from the file or environment variable
try:
from config import CLIENT_ID, CLIENT_SECRET
except ImportError:
if os.environ.get('CLIENT_ID'):
logger.debug("Using Client ID from environment variable")
CLIENT_ID = os.environ.get('CLIENT_ID')
if os.environ.get('CLIENT_SECRET'):
logger.debug("Using Client Secret from environment variable")
CLIENT_SECRET = os.environ.get('CLIENT_SECRET')
if not CLIENT_ID and not CLIENT_SECRET:
sys.exit("you didn't set the config either via file or environment")
logger.enable("crowdstrike")
crowdstrike = CrowdstrikeAPI(CLIENT_ID, CLIENT_SECRET) # pylint: disable=invalid-name
def test_query_devices(crowdstrike_client=crowdstrike):
""" tests query_devices() """
logger.info("Testing hosts_query_devices()")
hosts = crowdstrike_client.hosts_query_devices(limit=5)
logger.debug(hosts)
assert hosts is not None
def test_hosts_query_devices(crowdstrike_client=crowdstrike):
""" test hosts_query_devices() """
logger.info("testing hosts_detail")
hosts = crowdstrike.hosts_query_devices(limit=5)
test = crowdstrike_client.hosts_detail(ids=hosts.get('resources'))
logger.debug(json.dumps(test))
assert hosts is not None
assert test is not None
# logger.debug("testing host_action")
# test = crowdstrike.host_action(action='lift_containment', ids=['123456789'])
# logger.debug(json.dumps(test, indent=2))
def test_hosts_hidden(crowdstrike_client=crowdstrike):
""" test hosts_hidden() """
logger.info('testing hosts_hidden()')
test = crowdstrike_client.hosts_hidden(limit=10)
logger.debug(json.dumps(test))
assert test is not None