Skip to content

Commit 7cd7fdb

Browse files
committed
extensive updates as requested by Becca, including splitting some source files,
renaming methods, rebuilding tests, and changing examples to match
1 parent cd213c1 commit 7cd7fdb

32 files changed

+2044
-2601
lines changed

examples/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Running the Example Scripts
2+
3+
To run the example scripts, first set up the CBAPI with either the `pip install cbapi` or `python setup.py develop`
4+
commands as detailed in the top-level `README.md` file. You may also set your `PYTHONPATH` environment variable to
5+
point to the `{cbapi}/src` directory, where `{cbapi}` refers to the top-level directory where you have cloned
6+
the CBAPI repository.
7+
8+
You should also have an API key and have set up a `credentials` file as detailed in the "API Token" section of the
9+
top-level `README.md` file.
10+
11+
Once you have done so, you should be able to run any example script with the command:
12+
13+
python scriptname.py [arguments]
14+
15+
Executing any script with the `--help` argument should give you a detailed message about the arguments that can
16+
be supplied to the script when it is executed.

examples/psc/bulk_update_alerts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from time import sleep
55
from cbapi.example_helpers import build_cli_parser, get_cb_psc_object
66
from cbapi.psc.models import BaseAlert, WorkflowStatus
7-
from alertsv6common import setup_parser_with_basic_criteria, load_basic_criteria
7+
from helpers.alertsv6 import setup_parser_with_basic_criteria, load_basic_criteria
88

99

1010
def main():

examples/psc/bulk_update_cbanalytics_alerts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from time import sleep
55
from cbapi.example_helpers import build_cli_parser, get_cb_psc_object
66
from cbapi.psc.models import CBAnalyticsAlert, WorkflowStatus
7-
from alertsv6common import setup_parser_with_cbanalytics_criteria, load_cbanalytics_criteria
7+
from helpers.alertsv6 import setup_parser_with_cbanalytics_criteria, load_cbanalytics_criteria
88

99

1010
def main():

examples/psc/bulk_update_vmware_alerts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from time import sleep
55
from cbapi.example_helpers import build_cli_parser, get_cb_psc_object
66
from cbapi.psc.models import VMwareAlert, WorkflowStatus
7-
from alertsv6common import setup_parser_with_vmware_criteria, load_vmware_criteria
7+
from helpers.alertsv6 import setup_parser_with_vmware_criteria, load_vmware_criteria
88

99

1010
def main():

examples/psc/bulk_update_watchlist_alerts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from time import sleep
55
from cbapi.example_helpers import build_cli_parser, get_cb_psc_object
66
from cbapi.psc.models import WatchlistAlert, WorkflowStatus
7-
from alertsv6common import setup_parser_with_watchlist_criteria, load_watchlist_criteria
7+
from helpers.alertsv6 import setup_parser_with_watchlist_criteria, load_watchlist_criteria
88

99

1010
def main():

examples/psc/download_device_list.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ def main():
2626
if args.query:
2727
query = query.where(args.query)
2828
if args.ad_group_id:
29-
query = query.ad_group_ids(args.ad_group_id)
29+
query = query.set_ad_group_ids(args.ad_group_id)
3030
if args.policy_id:
31-
query = query.policy_ids(args.policy_id)
31+
query = query.set_policy_ids(args.policy_id)
3232
if args.status:
33-
query = query.status(args.status)
33+
query = query.set_status(args.status)
3434
if args.priority:
35-
query = query.target_priorities(args.priority)
35+
query = query.set_target_priorities(args.priority)
3636
if args.sort_by:
3737
direction = "DESC" if args.reverse else "ASC"
3838
query = query.sort_by(args.sort_by, direction)

examples/psc/alertsv6common.py renamed to examples/psc/helpers/alertsv6.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,78 +82,78 @@ def load_basic_criteria(query, args):
8282
if args.query:
8383
query = query.where(args.query)
8484
if args.category:
85-
query = query.categories(args.category)
85+
query = query.set_categories(args.category)
8686
if args.deviceid:
87-
query = query.device_ids(args.deviceid)
87+
query = query.set_device_ids(args.deviceid)
8888
if args.devicename:
89-
query = query.device_names(args.devicename)
89+
query = query.set_device_names(args.devicename)
9090
if args.os:
91-
query = query.device_os(args.os)
91+
query = query.set_device_os(args.os)
9292
if args.osversion:
93-
query = query.device_os_version(args.osversion)
93+
query = query.set_device_os_versions(args.osversion)
9494
if args.username:
95-
query = query.device_username(args.username)
95+
query = query.set_device_username(args.username)
9696
if args.group:
97-
query = query.group_results(True)
97+
query = query.set_group_results(True)
9898
if args.alertid:
99-
query = query.alert_ids(args.alertid)
99+
query = query.set_alert_ids(args.alertid)
100100
if args.legacyalertid:
101-
query = query.legacy_alert_ids(args.legacyalertid)
101+
query = query.set_legacy_alert_ids(args.legacyalertid)
102102
if args.severity:
103-
query = query.minimum_severity(args.severity)
103+
query = query.set_minimum_severity(args.severity)
104104
if args.policyid:
105-
query = query.policy_ids(args.policyid)
105+
query = query.set_policy_ids(args.policyid)
106106
if args.policyname:
107-
query = query.policy_names(args.policyname)
107+
query = query.set_policy_names(args.policyname)
108108
if args.processname:
109-
query = query.process_names(args.processname)
109+
query = query.set_process_names(args.processname)
110110
if args.processhash:
111-
query = query.process_sha256(args.processhash)
111+
query = query.set_process_sha256(args.processhash)
112112
if args.reputation:
113-
query = query.reputations(args.reputation)
113+
query = query.set_reputations(args.reputation)
114114
if args.tag:
115-
query = query.tags(args.tag)
115+
query = query.set_tags(args.tag)
116116
if args.priority:
117-
query = query.target_priorities(args.priority)
117+
query = query.set_target_priorities(args.priority)
118118
if args.threatid:
119-
query = query.threat_ids(args.threatid)
119+
query = query.set_threat_ids(args.threatid)
120120
if args.type:
121-
query = query.types(args.type)
121+
query = query.set_types(args.type)
122122
if args.workflow:
123-
query = query.workflows(args.workflow)
123+
query = query.set_workflows(args.workflow)
124124

125125

126126
def load_cbanalytics_criteria(query, args):
127127
load_basic_criteria(query, args)
128128
if args.blockedthreat:
129-
query = query.blocked_threat_categories(args.blockedthreat)
129+
query = query.set_blocked_threat_categories(args.blockedthreat)
130130
if args.location:
131-
query = query.device_locations(args.location)
131+
query = query.set_device_locations(args.location)
132132
if args.killchain:
133-
query = query.kill_chain_statuses(args.killchain)
133+
query = query.set_kill_chain_statuses(args.killchain)
134134
if args.notblockedthreat:
135-
query = query.not_blocked_threat_categories(args.notblockedthreat)
135+
query = query.set_not_blocked_threat_categories(args.notblockedthreat)
136136
if args.policyapplied:
137-
query = query.policy_applied(args.policyapplied)
137+
query = query.set_policy_applied(args.policyapplied)
138138
if args.reason:
139-
query = query.reason_code(args.reason)
139+
query = query.set_reason_code(args.reason)
140140
if args.runstate:
141-
query = query.run_states(args.runstate)
141+
query = query.set_run_states(args.runstate)
142142
if args.sensoraction:
143-
query = query.sensor_actions(args.sensoraction)
143+
query = query.set_sensor_actions(args.sensoraction)
144144
if args.vector:
145-
query = query.threat_cause_vectors(args.vector)
145+
query = query.set_threat_cause_vectors(args.vector)
146146

147147

148148
def load_vmware_criteria(query, args):
149149
load_basic_criteria(query, args)
150150
if args.groupid:
151-
query = query.group_ids(args.groupid)
151+
query = query.set_group_ids(args.groupid)
152152

153153

154154
def load_watchlist_criteria(query, args):
155155
load_basic_criteria(query, args)
156156
if args.watchlistid:
157-
query = query.watchlist_ids(args.watchlistid)
157+
query = query.set_watchlist_ids(args.watchlistid)
158158
if args.watchlistname:
159-
query = query.watchlist_names(args.watchlistname)
159+
query = query.set_watchlist_names(args.watchlistname)

examples/psc/list_alert_facets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
from cbapi.example_helpers import build_cli_parser, get_cb_psc_object
55
from cbapi.psc.models import BaseAlert
6-
from alertsv6common import setup_parser_with_basic_criteria, load_basic_criteria
6+
from helpers.alertsv6 import setup_parser_with_basic_criteria, load_basic_criteria
77

88

99
def main():

examples/psc/list_alerts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
from cbapi.example_helpers import build_cli_parser, get_cb_psc_object
55
from cbapi.psc.models import BaseAlert
6-
from alertsv6common import setup_parser_with_basic_criteria, load_basic_criteria
6+
from helpers.alertsv6 import setup_parser_with_basic_criteria, load_basic_criteria
77

88

99
def main():

examples/psc/list_cbanalytics_alert_facets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
from cbapi.example_helpers import build_cli_parser, get_cb_psc_object
55
from cbapi.psc.models import CBAnalyticsAlert
6-
from alertsv6common import setup_parser_with_cbanalytics_criteria, load_cbanalytics_criteria
6+
from helpers.alertsv6 import setup_parser_with_cbanalytics_criteria, load_cbanalytics_criteria
77

88

99
def main():

0 commit comments

Comments
 (0)