22 DetectionList ,
33 DetectionListHandlers ,
44 load_user_descriptions ,
5+ load_username_description ,
56 get_user_id ,
67 update_user ,
78)
89from code42cli .cmds .detectionlists .enums import DetectionListUserKeys
10+ from code42cli .commands import Command
911
1012
1113def load_subcommands ():
14+
1215 handlers = _create_handlers ()
1316 detection_list = DetectionList .create_high_risk_employee_list (handlers )
14- return detection_list .load_subcommands ()
17+ cmd_list = detection_list .load_subcommands ()
18+ cmd_list .extend (
19+ [
20+ Command (
21+ u"add-risk-tags" ,
22+ u"Associates risk tags with a user." ,
23+ handler = add_risk_tags ,
24+ arg_customizer = _load_risk_tag_mgmt_descriptions ,
25+ ),
26+ Command (
27+ u"remove-risk-tags" ,
28+ u"Disassociates risk tags from a user." ,
29+ handler = remove_risk_tags ,
30+ arg_customizer = _load_risk_tag_mgmt_descriptions ,
31+ ),
32+ ]
33+ )
34+ return cmd_list
1535
1636
1737def _create_handlers ():
@@ -20,6 +40,17 @@ def _create_handlers():
2040 )
2141
2242
43+ def add_risk_tags (sdk , profile , username , risk_tag ):
44+ risk_tag = _handle_list_args (risk_tag )
45+ user_id = get_user_id (sdk , username )
46+ sdk .detectionlists .add_user_risk_tags (user_id , risk_tag )
47+
48+ def remove_risk_tags (sdk , profile , username , risk_tag ):
49+ risk_tag = _handle_list_args (risk_tag )
50+ user_id = get_user_id (sdk , username )
51+ sdk .detectionlists .remove_user_risk_tags (user_id , risk_tag )
52+
53+
2354def add_high_risk_employee (sdk , profile , username , cloud_alias = None , risk_tag = None , notes = None ):
2455 """Adds an employee to the high risk employee detection list.
2556
@@ -31,9 +62,7 @@ def add_high_risk_employee(sdk, profile, username, cloud_alias=None, risk_tag=No
3162 risk_tag (iter[str]): Risk tags associated with the employee.
3263 notes: (str): Notes about the employee.
3364 """
34- if risk_tag and type (risk_tag ) != list :
35- risk_tag = risk_tag .split ()
36-
65+ risk_tag = _handle_list_args (risk_tag )
3766 user_id = get_user_id (sdk , username )
3867 update_user (sdk , user_id , cloud_alias , risk_tag , notes )
3968 sdk .detectionlists .high_risk_employee .add (user_id )
@@ -51,8 +80,7 @@ def remove_high_risk_employee(sdk, profile, username):
5180 sdk .detectionlists .high_risk_employee .remove (user_id )
5281
5382
54- def _load_add_description (argument_collection ):
55- load_user_descriptions (argument_collection )
83+ def _load_risk_tag_description (argument_collection ):
5684 risk_tag = argument_collection .arg_configs [DetectionListUserKeys .RISK_TAG ]
5785 risk_tag .as_multi_val_param ()
5886 risk_tag .set_help (
@@ -66,3 +94,21 @@ def _load_add_description(argument_collection):
6694 u"POOR_SECURITY_PRACTICES, "
6795 u"CONTRACT_EMPLOYEE]"
6896 )
97+
98+
99+ def _load_add_description (argument_collection ):
100+ load_user_descriptions (argument_collection )
101+ _load_risk_tag_description (argument_collection )
102+
103+
104+ def _load_risk_tag_mgmt_descriptions (argument_collection ):
105+ load_username_description (argument_collection )
106+ _load_risk_tag_description (argument_collection )
107+
108+
109+ def _handle_list_args (list_arg ):
110+ """Converts str args to a list. Useful for `bulk` commands which don't use `argparse` but
111+ instead pass in values from files, such as in the form "item1 item2"."""
112+ if list_arg and type (list_arg ) != list :
113+ return list_arg .split ()
114+ return list_arg
0 commit comments