def test_generate_template_cmd_factory_returns_expected_command(): add_headers = ["foo", "bar"] remove_headers = ["test"] help_message = "HELP!" template = generate_template_cmd_factory( group_name="cmd-group", commands_dict={ "add": add_headers, "remove": remove_headers }, help_message=help_message, ) assert template.help == help_message assert template.name == "generate-template" assert len(template.params) == 2 assert template.params[0].name == "cmd" assert template.params[0].type.choices == ["add", "remove"] assert template.params[1].name == "path"
def test_generate_template_cmd_factory_when_using_defaults_returns_expected_command( ): add_headers = ["foo", "bar"] remove_headers = ["test"] template = generate_template_cmd_factory( group_name="cmd-group", commands_dict={ "add": add_headers, "remove": remove_headers }, ) assert (template.help == "Generate the CSV template needed for bulk adding/removing users.") assert template.name == "generate-template" assert len(template.params) == 2 assert template.params[0].name == "cmd" assert template.params[0].type.choices == ["add", "remove"] assert template.params[1].name == "path"
@devices.group(cls=OrderedGroup) @sdk_options(hidden=True) def bulk(state): """Tools for managing devices in bulk.""" pass _bulk_device_activation_headers = ["guid"] devices_generate_template = generate_template_cmd_factory( group_name="devices", commands_dict={ "reactivate": _bulk_device_activation_headers, "deactivate": _bulk_device_activation_headers, }, help_message="Generate the CSV template needed for bulk device commands.", ) bulk.add_command(devices_generate_template) @bulk.command(name="deactivate") @read_csv_arg(headers=_bulk_device_activation_headers) @change_device_name_option( "Prepend 'deactivated_<current_date>' to the name of any successfully deactivated devices." ) @purge_date_option @format_option @sdk_options() def bulk_deactivate(state, csv_rows, change_device_name, purge_date, format):
@file_events.group(cls=OrderedGroup) @sdk_options(hidden=True) def bulk(state): """Tools for executing bulk case file-event actions.""" pass FILE_EVENTS_HEADERS = [ "number", "event_id", ] case_file_events_generate_template = generate_template_cmd_factory( group_name="file_events", commands_dict={ "add": FILE_EVENTS_HEADERS, "remove": FILE_EVENTS_HEADERS }, ) bulk.add_command(case_file_events_generate_template) @bulk.command( name="add", help="Bulk associate file events to cases using a CSV file with " f"format: {','.join(FILE_EVENTS_HEADERS)}.", ) @read_csv_arg(headers=FILE_EVENTS_HEADERS) @sdk_options() def bulk_add(state, csv_rows): sdk = state.sdk
@departing_employee.group(cls=OrderedGroup) @sdk_options(hidden=True) def bulk(state): """Tools for executing bulk departing employee actions.""" pass DEPARTING_EMPLOYEE_CSV_HEADERS = ["username", "cloud_alias", "departure_date", "notes"] REMOVE_EMPLOYEE_HEADERS = ["username"] departing_employee_generate_template = generate_template_cmd_factory( group_name="departing_employee", commands_dict={ "add": DEPARTING_EMPLOYEE_CSV_HEADERS, "remove": REMOVE_EMPLOYEE_HEADERS, }, ) bulk.add_command(departing_employee_generate_template) @bulk.command( name="add", help="Bulk add users to the departing employees detection list using a CSV file with " f"format: {','.join(DEPARTING_EMPLOYEE_CSV_HEADERS)}.", ) @read_csv_arg(headers=DEPARTING_EMPLOYEE_CSV_HEADERS) @sdk_options() def bulk_add(state, csv_rows): sdk = state.sdk # Force initialization of py42 to only happen once.
echo(format_json(rule_detail.text)) @alert_rules.group(cls=OrderedGroup) @sdk_options(hidden=True) def bulk(state): """Tools for executing bulk alert rule actions.""" pass ALERT_RULES_CSV_HEADERS = ["rule_id", "username"] alert_rules_generate_template = generate_template_cmd_factory( group_name="alert_rules", commands_dict={ "add": ALERT_RULES_CSV_HEADERS, "remove": ALERT_RULES_CSV_HEADERS }, ) bulk.add_command(alert_rules_generate_template) @bulk.command( help="Bulk add users to alert rules from a csv file. CSV file format: {}". format(",".join(ALERT_RULES_CSV_HEADERS))) @read_csv_arg(headers=ALERT_RULES_CSV_HEADERS) @sdk_options() def add(state, csv_rows): sdk = state.sdk def handle_row(rule_id, username):
else: click.echo("No results found.") @legal_hold.group(cls=OrderedGroup) @sdk_options(hidden=True) def bulk(state): """Tools for executing bulk legal hold actions.""" pass LEGAL_HOLD_CSV_HEADERS = ["matter_id", "username"] legal_hold_generate_template = generate_template_cmd_factory( group_name="legal_hold", commands_dict={"add": LEGAL_HOLD_CSV_HEADERS, "remove": LEGAL_HOLD_CSV_HEADERS}, ) bulk.add_command(legal_hold_generate_template) @bulk.command( name="add", help="Bulk add custodians to legal hold matters using a CSV file. CSV file format: {}".format( ",".join(LEGAL_HOLD_CSV_HEADERS) ), ) @read_csv_arg(headers=LEGAL_HOLD_CSV_HEADERS) @sdk_options() def bulk_add(state, csv_rows): sdk = state.sdk
@sdk_options(hidden=True) def bulk(state): """Tools for executing high risk employee actions in bulk.""" pass HIGH_RISK_EMPLOYEE_CSV_HEADERS = [ "username", "cloud_alias", "risk_tag", "notes" ] RISK_TAG_CSV_HEADERS = ["username", "tag"] high_risk_employee_generate_template = generate_template_cmd_factory( group_name="high_risk_employee", commands_dict={ "add": HIGH_RISK_EMPLOYEE_CSV_HEADERS, "remove": "username", "add-risk-tags": RISK_TAG_CSV_HEADERS, "remove-risk-tags": RISK_TAG_CSV_HEADERS, }, ) bulk.add_command(high_risk_employee_generate_template) @bulk.command( name="add", help= "Bulk add users to the high risk employees detection list using a CSV file with " f"format: {','.join(HIGH_RISK_EMPLOYEE_CSV_HEADERS)}.", ) @read_csv_arg(headers=HIGH_RISK_EMPLOYEE_CSV_HEADERS) @sdk_options()
"description", ] TRUST_UPDATE_HEADERS = [ "resource_id", "value", "description", ] TRUST_REMOVE_HEADERS = [ "resource_id", ] trusted_activities_generate_template = generate_template_cmd_factory( group_name="trusted_activities", commands_dict={ "create": TRUST_CREATE_HEADERS, "update": TRUST_UPDATE_HEADERS, "remove": TRUST_REMOVE_HEADERS, }, help_message= "Generate the CSV template needed for bulk trusted-activities commands", ) bulk.add_command(trusted_activities_generate_template) @bulk.command( name="create", help="Bulk create trusted activities using a CSV file with " f"format: {','.join(TRUST_CREATE_HEADERS)}.\b\n\n" f"Available `type` values are: {'|'.join(TrustedActivityType.choices())}", ) @read_csv_arg(headers=TRUST_CREATE_HEADERS) @sdk_options()
def update(cli_state, alert_id, state, note): """Update alert information.""" _update_alert(cli_state.sdk, alert_id, state, note) @alerts.group(cls=OrderedGroup) @opt.sdk_options(hidden=True) def bulk(state): """Tools for executing bulk alert actions.""" pass UPDATE_ALERT_CSV_HEADERS = ["id", "state", "note"] update_alerts_generate_template = generate_template_cmd_factory( group_name=ALERTS_KEYWORD, commands_dict={"update": UPDATE_ALERT_CSV_HEADERS}, help_message="Generate the CSV template needed for bulk alert commands.", ) bulk.add_command(update_alerts_generate_template) @bulk.command( name="update", help= f"Bulk update alerts using a CSV file with format: {','.join(UPDATE_ALERT_CSV_HEADERS)}", ) @opt.sdk_options() @read_csv_arg(headers=UPDATE_ALERT_CSV_HEADERS) def bulk_update(cli_state, csv_rows): """Bulk update alerts.""" sdk = cli_state.sdk
except Py42NotFoundError: raise Code42CLIError(f"Invalid org UID {org_uid}.") @users.group(cls=OrderedGroup) @sdk_options(hidden=True) def bulk(state): """Tools for managing users in bulk.""" pass users_generate_template = generate_template_cmd_factory( group_name="users", commands_dict={ "update": _bulk_user_update_headers, "move": _bulk_user_move_headers, "add-alias": _bulk_user_alias_headers, "remove-alias": _bulk_user_alias_headers, }, help_message="Generate the CSV template needed for bulk user commands.", ) bulk.add_command(users_generate_template) @bulk.command( name="update", help="Update a list of users from the provided CSV in format: " f"{','.join(_bulk_user_update_headers)}", ) @read_csv_arg(headers=_bulk_user_update_headers) @format_option @sdk_options()