Skip to content

Commit c54c656

Browse files
author
Juliya Smith
authored
Bugfix/too many py42s (#271)
1 parent 6790edf commit c54c656

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ how a consumer would use the library (e.g. adding unit tests, updating documenta
1717
- Issue where outputting or sending an alert or file-event with a timestamp without
1818
decimals would error.
1919

20+
- A performance issue with the `code42 departing-employee bulk add` command.
21+
2022
### Changed
2123

2224
- `code42 alert-rules list` now outputs via a pager when results contain more than 10 rules.

src/code42cli/cmds/departing_employee.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ def _list(state, format, filter):
6666
@sdk_options()
6767
def add(state, username, cloud_alias, departure_date, notes):
6868
"""Add a user to the Departing Employees detection list."""
69-
if departure_date:
70-
departure_date = departure_date.strftime(DATE_FORMAT)
7169
_add_departing_employee(state.sdk, username, cloud_alias, departure_date, notes)
7270

7371

@@ -102,26 +100,21 @@ def bulk(state):
102100
)
103101
@read_csv_arg(headers=DEPARTING_EMPLOYEE_CSV_HEADERS)
104102
@sdk_options()
105-
@click.pass_context
106-
def bulk_add(ctx, state, csv_rows):
103+
def bulk_add(state, csv_rows):
104+
sdk = state.sdk # Force initialization of py42 to only happen once.
105+
107106
def handle_row(username, cloud_alias, departure_date, notes):
108107
if departure_date:
109108
try:
110109
departure_date = click.DateTime(formats=[DATE_FORMAT]).convert(
111110
departure_date, None, None
112111
)
113112
except click.exceptions.BadParameter:
114-
message = "Invalid date {}, valid date format {}".format(
115-
departure_date, DATE_FORMAT
113+
message = (
114+
f"Invalid date {departure_date}, valid date format {DATE_FORMAT}."
116115
)
117116
raise Code42CLIError(message)
118-
ctx.invoke(
119-
add,
120-
username=username,
121-
cloud_alias=cloud_alias,
122-
departure_date=departure_date,
123-
notes=notes,
124-
)
117+
_add_departing_employee(sdk, username, cloud_alias, departure_date, notes)
125118

126119
run_bulk_process(
127120
handle_row,
@@ -155,6 +148,8 @@ def _get_departing_employees(sdk, filter):
155148

156149

157150
def _add_departing_employee(sdk, username, cloud_alias, departure_date, notes):
151+
if departure_date:
152+
departure_date = departure_date.strftime(DATE_FORMAT)
158153
user_id = get_user_id(sdk, username)
159154
sdk.detectionlists.departing_employee.add(user_id, departure_date)
160155
update_user(sdk, username, cloud_alias=cloud_alias, notes=notes)

0 commit comments

Comments
 (0)