Skip to content

Commit c7a7f61

Browse files
author
Juliya Smith
authored
Chore/cleanups (#114)
* Remove inaccurate unneeded doc * Dont override existing var * Conform prefix like other existing var * Missing period * Unneeded u's * missing space * Remove unused var * Appease possible None * Flake8 no defining lambdas * Rm unused vars * use defs instead of lambdas when defining * Remove unused vars * Imply negation is test name / rm dup test name * Remove unused var * Spelling * More flakey fixes * Remove unused stuff * Fix doc str var * other cleanups
1 parent 1a1133f commit c7a7f61

23 files changed

Lines changed: 146 additions & 151 deletions

src/code42cli/cmds/alert_rules.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ def bulk(state):
113113
@sdk_options
114114
def add(state, csv_rows):
115115
sdk = state.sdk
116-
row_handler = lambda rule_id, username: _add_user(sdk, rule_id, username)
117-
run_bulk_process(row_handler, csv_rows, progress_label="Adding users to alert-rules:")
116+
def handle_row(rule_id, username):
117+
_add_user(sdk, rule_id, username)
118+
run_bulk_process(handle_row, csv_rows, progress_label="Adding users to alert-rules:")
118119

119120

120121
@bulk.command(
@@ -126,8 +127,9 @@ def add(state, csv_rows):
126127
@sdk_options
127128
def remove(state, csv_rows):
128129
sdk = state.sdk
129-
row_handler = lambda rule_id, username: _remove_user(sdk, rule_id, username)
130-
run_bulk_process(row_handler, csv_rows, progress_label="Removing users from alert-rules:")
130+
def handle_row(rule_id, username):
131+
_remove_user(sdk, rule_id, username)
132+
run_bulk_process(handle_row, csv_rows, progress_label="Removing users from alert-rules:")
131133

132134

133135
def _add_user(sdk, rule_id, username):
@@ -136,7 +138,7 @@ def _add_user(sdk, rule_id, username):
136138
try:
137139
if rules:
138140
sdk.alerts.rules.add_user(rule_id, user_id)
139-
except Py42InternalServerError as e:
141+
except Py42InternalServerError:
140142
_check_if_system_rule(rules)
141143
raise
142144

@@ -147,7 +149,7 @@ def _remove_user(sdk, rule_id, username):
147149
try:
148150
if rules:
149151
sdk.alerts.rules.remove_user(rule_id, user_id)
150-
except Py42InternalServerError as e:
152+
except Py42InternalServerError:
151153
_check_if_system_rule(rules)
152154
raise
153155

src/code42cli/cmds/departing_employee.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ def bulk(state):
6363
@sdk_options
6464
def add(state, csv_rows):
6565
sdk = state.sdk
66-
row_handler = lambda username, cloud_alias, departure_date, notes: _add_departing_employee(
67-
sdk, username, cloud_alias, departure_date, notes
68-
)
66+
def handle_row(username, cloud_alias, departure_date, notes):
67+
_add_departing_employee(
68+
sdk, username, cloud_alias, departure_date, notes
69+
)
6970
run_bulk_process(
70-
row_handler, csv_rows, progress_label="Adding users to departing employee detection list:"
71+
handle_row, csv_rows, progress_label="Adding users to departing employee detection list:"
7172
)
7273

7374

@@ -79,9 +80,10 @@ def add(state, csv_rows):
7980
@sdk_options
8081
def remove(state, file_rows):
8182
sdk = state.sdk
82-
row_handler = lambda username: _remove_departing_employee(sdk, username)
83+
def handle_row(username):
84+
_remove_departing_employee(sdk, username)
8385
run_bulk_process(
84-
row_handler,
86+
handle_row,
8587
file_rows,
8688
progress_label="Removing users from departing employee detection list:",
8789
)

src/code42cli/cmds/detectionlists/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ def update_user(sdk, username, cloud_alias=None, risk_tag=None, notes=None):
77
88
Args:
99
sdk (py42.sdk.SDKClient): py42 sdk.
10-
user_id (str or unicode): The ID of the user to update. This is their `userUid` found from
11-
`sdk.users.get_by_username()`.
10+
username (str or unicode): The username of the user to update.
1211
cloud_alias (str or unicode): A cloud alias to add to the user.
1312
risk_tag (iter[str or unicode]): A list of risk tags associated with user.
1413
notes (str or unicode): Notes about the user.

src/code42cli/cmds/high_risk_employee.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,12 @@ def bulk(state):
102102
@sdk_options
103103
def add(state, csv_rows):
104104
sdk = state.sdk
105-
row_handler = lambda username, cloud_alias, risk_tag, notes: _add_high_risk_employee(
106-
sdk, username, cloud_alias, risk_tag, notes
107-
)
105+
def handle_row(username, cloud_alias, risk_tag, notes):
106+
_add_high_risk_employee(
107+
sdk, username, cloud_alias, risk_tag, notes
108+
)
108109
run_bulk_process(
109-
row_handler, csv_rows, progress_label="Adding users to high risk employee detection list:"
110+
handle_row, csv_rows, progress_label="Adding users to high risk employee detection list:"
110111
)
111112

112113

@@ -118,9 +119,10 @@ def add(state, csv_rows):
118119
@sdk_options
119120
def remove(state, file_rows):
120121
sdk = state.sdk
121-
row_handler = lambda username: _remove_high_risk_employee(sdk, username)
122+
def handle_row(username):
123+
_remove_high_risk_employee(sdk, username)
122124
run_bulk_process(
123-
row_handler,
125+
handle_row,
124126
file_rows,
125127
progress_label="Removing users from high risk employee detection list:",
126128
)
@@ -135,9 +137,10 @@ def remove(state, file_rows):
135137
@sdk_options
136138
def add_risk_tags(state, csv_rows):
137139
sdk = state.sdk
138-
row_handler = lambda username, tag: _add_risk_tags(sdk, username, tag)
140+
def handle_row(username, tag):
141+
_add_risk_tags(sdk, username, tag)
139142
run_bulk_process(
140-
row_handler, csv_rows, progress_label="Adding risk tags to users:",
143+
handle_row, csv_rows, progress_label="Adding risk tags to users:",
141144
)
142145

143146

@@ -150,9 +153,10 @@ def add_risk_tags(state, csv_rows):
150153
@sdk_options
151154
def remove_risk_tags(state, csv_rows):
152155
sdk = state.sdk
153-
row_handler = lambda username, tag: _remove_risk_tags(sdk, username, tag)
156+
def handle_row(username, tag):
157+
_remove_risk_tags(sdk, username, tag)
154158
run_bulk_process(
155-
row_handler, csv_rows, progress_label="Removing risk tags from users:",
159+
handle_row, csv_rows, progress_label="Removing risk tags from users:",
156160
)
157161

158162

@@ -169,12 +173,5 @@ def _add_high_risk_employee(sdk, username, cloud_alias, risk_tag, notes):
169173

170174

171175
def _remove_high_risk_employee(sdk, username):
172-
"""Removes an employee from the high risk employee detection list.
173-
174-
Args:
175-
sdk (py42.sdk.SDKClient): py42.
176-
profile (C42Profile): Your code42 profile.
177-
username (str): The username of the employee to remove.
178-
"""
179176
user_id = get_user_id(sdk, username)
180177
sdk.detectionlists.high_risk_employee.remove(user_id)

src/code42cli/cmds/legal_hold.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@ def bulk(state):
140140
@sdk_options
141141
def add(state, csv_rows):
142142
sdk = state.sdk
143-
row_handler = lambda matter_id, username: _add_user_to_legal_hold(sdk, matter_id, username)
144-
run_bulk_process(row_handler, csv_rows, progress_label="Adding users to legal hold:")
143+
def handle_row(matter_id, username):
144+
_add_user_to_legal_hold(sdk, matter_id, username)
145+
run_bulk_process(handle_row, csv_rows, progress_label="Adding users to legal hold:")
145146

146147

147148
@bulk.command(
@@ -153,8 +154,9 @@ def add(state, csv_rows):
153154
@sdk_options
154155
def remove(state, csv_rows):
155156
sdk = state.sdk
156-
row_handler = lambda matter_id, username: _remove_user_from_legal_hold(sdk, matter_id, username)
157-
run_bulk_process(row_handler, csv_rows, progress_label="Removing users from legal hold:")
157+
def handle_row(matter_id, username):
158+
_remove_user_from_legal_hold(sdk, matter_id, username)
159+
run_bulk_process(handle_row, csv_rows, progress_label="Removing users from legal hold:")
158160

159161

160162
def _add_user_to_legal_hold(sdk, matter_id, username):

src/code42cli/cmds/profile.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ def create(name, server, username, disable_ssl_errors=False):
7373
@disable_ssl_option
7474
def update(name=None, server=None, username=None, disable_ssl_errors=None):
7575
"""Update an existing profile."""
76-
profile = cliprofile.get_profile(name)
77-
cliprofile.update_profile(profile.name, server, username, disable_ssl_errors)
78-
_prompt_for_allow_password_set(profile.name)
79-
echo("Profile '{}' has been updated.".format(profile.name))
76+
c42profile = cliprofile.get_profile(name)
77+
cliprofile.update_profile(c42profile.name, server, username, disable_ssl_errors)
78+
_prompt_for_allow_password_set(c42profile.name)
79+
echo("Profile '{}' has been updated.".format(c42profile.name))
8080

8181

8282
@profile.command()
@@ -92,8 +92,8 @@ def _list():
9292
profiles = cliprofile.get_all_profiles()
9393
if not profiles:
9494
raise Code42CLIError("No existing profile.", help=CREATE_PROFILE_HELP)
95-
for profile in profiles:
96-
echo(str(profile))
95+
for c42profile in profiles:
96+
echo(str(c42profile))
9797

9898

9999
@profile.command()
@@ -125,11 +125,11 @@ def delete_all():
125125
message = (
126126
"\nAre you sure you want to delete the following profiles?\n\t{}"
127127
"\n\nThis will also delete any stored passwords and checkpoints. (y/n): "
128-
).format("\n\t".join([profile.name for profile in existing_profiles]))
128+
).format("\n\t".join([c42profile.name for c42profile in existing_profiles]))
129129
if does_user_agree(message):
130-
for profile in existing_profiles:
131-
cliprofile.delete_profile(profile.name)
132-
echo("Profile '{}' has been deleted.".format(profile.name))
130+
for profile_obj in existing_profiles:
131+
cliprofile.delete_profile(profile_obj.name)
132+
echo("Profile '{}' has been deleted.".format(profile_obj.name))
133133
else:
134134
echo("\nNo profiles exist. Nothing to delete.")
135135

src/code42cli/cmds/search/cursor_store.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def clean(self):
5555
self.delete(cursor.name)
5656

5757
def get_all_cursors(self):
58-
"""Returns a list of all cursors stored in this directory (which istypically scoped to a profile)."""
58+
"""Returns a list of all cursors stored in this directory (which is typically scoped to a profile)."""
5959
dir_contents = os.listdir(self._dir_path)
6060
return [Cursor(f) for f in dir_contents if self._is_file(f)]
6161

@@ -65,13 +65,13 @@ def _is_file(self, node_name):
6565

6666
class FileEventCursorStore(BaseCursorStore):
6767
def __init__(self, profile_name):
68-
dir_path = get_user_project_path(u"file_event_checkpoints", profile_name)
68+
dir_path = get_user_project_path("file_event_checkpoints", profile_name)
6969
super(FileEventCursorStore, self).__init__(dir_path)
7070

7171

7272
class AlertCursorStore(BaseCursorStore):
7373
def __init__(self, profile_name):
74-
dir_path = get_user_project_path(u"alert_checkpoints", profile_name)
74+
dir_path = get_user_project_path("alert_checkpoints", profile_name)
7575
super(AlertCursorStore, self).__init__(dir_path)
7676

7777

src/code42cli/cmds/search/extraction.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ def handle_response(response):
6060
except Exception as ex:
6161
handlers.handle_error(ex)
6262
handlers.TOTAL_EVENTS += len(events)
63+
event = None
6364
for event in events:
6465
output_logger.info(event)
65-
last_event_timestamp = extractor._get_timestamp_from_item(event)
66-
handlers.record_cursor_position(last_event_timestamp)
66+
if event:
67+
last_event_timestamp = extractor._get_timestamp_from_item(event)
68+
handlers.record_cursor_position(last_event_timestamp)
6769

6870
handlers.handle_response = handle_response
6971
return handlers
@@ -75,6 +77,8 @@ def create_time_range_filter(filter_cls, begin_date=None, end_date=None):
7577
`None` if both begin_date and end_date args are `None`.
7678
7779
Args:
80+
filter_cls: The class of filter to create. (must be a subclass of
81+
:class:`py42.sdk.queries.query_filter.QueryFilterTimestampField`)
7882
begin_date: The begin date for the range.
7983
end_date: The end date for the range.
8084
"""

src/code42cli/cmds/search/options.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import click
55

6-
from code42cli.cmds.search.enums import ServerProtocol
76
from code42cli.date_helper import parse_min_timestamp, parse_max_timestamp
87
from code42cli.logger import get_main_cli_logger
98
from code42cli.options import incompatible_with

src/code42cli/cmds/securitydata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def _get_saved_search_query(ctx, param, arg):
129129

130130
saved_search_option = click.option(
131131
"--saved-search",
132-
help="Get events from a saved search filter with the given ID",
132+
help="Get events from a saved search filter with the given ID.",
133133
callback=_get_saved_search_query,
134134
cls=incompatible_with("advanced_query"),
135135
)

0 commit comments

Comments
 (0)