@@ -60,7 +60,7 @@ def batch_update_curated_rule_set_deployments(
6060 proj_instance : str ,
6161 proj_region : str ,
6262) -> Mapping [str , Any ]:
63- """Batch updates multiple curated rule set deployments.
63+ """Batch updates multiple curated rule set deployments.
6464
6565 Args:
6666 http_session: Authorized session for HTTP requests.
@@ -78,96 +78,95 @@ def batch_update_curated_rule_set_deployments(
7878 Requires the following IAM permission on the parent resource:
7979 chronicle.curatedRuleSetDeployments.update
8080 """
81- base_url_with_region = regions .url_always_prepend_region (
82- CHRONICLE_API_BASE_URL , proj_region )
83- parent = f"projects/{ proj_id } /locations/{ proj_region } /instances/{ proj_instance } "
84-
85- # We use "-" in the URL because we provide category and rule_set IDs
86- # in the request data
87- url = f"{ base_url_with_region } /v1alpha/{ parent } /curatedRuleSetCategories/-/curatedRuleSets/-/curatedRuleSetDeployments:batchUpdate"
88-
89- def make_deployment_name (category : str , rule_set : str ,
90- precision : str ) -> str :
91- """Helper function to create a deployment name."""
92- return f"{ parent } /curatedRuleSetCategories/{ category } /curatedRuleSets/{ rule_set } /curatedRuleSetDeployments/{ precision } "
93-
94- # Example deployment configurations - update these with actual IDs
95- # Deployment A
96- category_a = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
97- rule_set_a = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
98- precision_a = "broad"
99-
100- # Deployment B
101- category_b = "cccccccc-cccc-cccc-cccc-cccccccccccc"
102- rule_set_b = "dddddddd-dddd-dddd-dddd-dddddddddddd"
103- precision_b = "precise"
104-
105- print ("\n NOTE: Using example category/rule_set/precision IDs." )
106- print ("Please update the script with actual IDs before use.\n " )
107-
108- json_data = {
109- "parent" :
110- f"{ parent } /curatedRuleSetCategories/-/curatedRuleSets/-" ,
111- "requests" : [
112- {
113- "curated_rule_set_deployment" : {
114- "name" :
115- make_deployment_name (
116- category_a ,
117- rule_set_a ,
118- precision_a ,
119- ),
120- "enabled" :
121- True ,
122- "alerting" :
123- False ,
124- },
125- "update_mask" : {
126- "paths" : ["alerting" , "enabled" ],
127- },
128- },
129- {
130- "curated_rule_set_deployment" : {
131- "name" :
132- make_deployment_name (
133- category_b ,
134- rule_set_b ,
135- precision_b ,
136- ),
137- "enabled" :
138- True ,
139- "alerting" :
140- True ,
141- },
142- "update_mask" : {
143- "paths" : ["alerting" , "enabled" ],
144- },
145- },
146- ],
147- }
148-
149- response = http_session .request ("POST" , url , json = json_data )
150- if response .status_code >= 400 :
151- print (response .text )
152- response .raise_for_status ()
153-
154- return response .json ()
81+ base_url_with_region = regions .url_always_prepend_region (
82+ CHRONICLE_API_BASE_URL , proj_region )
83+ parent = f"projects/{ proj_id } /locations/{ proj_region } /instances/{ proj_instance } "
84+
85+ # We use "-" in the URL because we provide category and rule_set IDs
86+ # in the request data
87+ url = f"{ base_url_with_region } /v1alpha/{ parent } /curatedRuleSetCategories/-/curatedRuleSets/-/curatedRuleSetDeployments:batchUpdate"
88+
89+ def make_deployment_name (category : str , rule_set : str , precision : str ) -> str :
90+ """Helper function to create a deployment name."""
91+ return f"{ parent } /curatedRuleSetCategories/{ category } /curatedRuleSets/{ rule_set } /curatedRuleSetDeployments/{ precision } "
92+
93+ # Example deployment configurations - update these with actual IDs
94+ # Deployment A
95+ category_a = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
96+ rule_set_a = "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"
97+ precision_a = "broad"
98+
99+ # Deployment B
100+ category_b = "cccccccc-cccc-cccc-cccc-cccccccccccc"
101+ rule_set_b = "dddddddd-dddd-dddd-dddd-dddddddddddd"
102+ precision_b = "precise"
103+
104+ print ("\n NOTE: Using example category/rule_set/precision IDs." )
105+ print ("Please update the script with actual IDs before use.\n " )
106+
107+ json_data = {
108+ "parent" :
109+ f"{ parent } /curatedRuleSetCategories/-/curatedRuleSets/-" ,
110+ "requests" : [
111+ {
112+ "curated_rule_set_deployment" : {
113+ "name" :
114+ make_deployment_name (
115+ category_a ,
116+ rule_set_a ,
117+ precision_a ,
118+ ),
119+ "enabled" :
120+ True ,
121+ "alerting" :
122+ False ,
123+ },
124+ "update_mask" : {
125+ "paths" : ["alerting" , "enabled" ],
126+ },
127+ },
128+ {
129+ "curated_rule_set_deployment" : {
130+ "name" :
131+ make_deployment_name (
132+ category_b ,
133+ rule_set_b ,
134+ precision_b ,
135+ ),
136+ "enabled" :
137+ True ,
138+ "alerting" :
139+ True ,
140+ },
141+ "update_mask" : {
142+ "paths" : ["alerting" , "enabled" ],
143+ },
144+ },
145+ ],
146+ }
147+
148+ response = http_session .request ("POST" , url , json = json_data )
149+ if response .status_code >= 400 :
150+ print (response .text )
151+ response .raise_for_status ()
152+
153+ return response .json ()
155154
156155
157156if __name__ == "__main__" :
158- parser = argparse .ArgumentParser ()
159- # common
160- chronicle_auth .add_argument_credentials_file (parser )
161- project_id .add_argument_project_id (parser )
162- project_instance .add_argument_project_instance (parser )
163- regions .add_argument_region (parser )
164-
165- args = parser .parse_args ()
166-
167- auth_session = chronicle_auth .initialize_http_session (
168- args . credentials_file , SCOPES )
169- result = batch_update_curated_rule_set_deployments (auth_session ,
170- args .project_id ,
171- args .project_instance ,
172- args .region )
173- print (json .dumps (result , indent = 2 ))
157+ parser = argparse .ArgumentParser ()
158+ # common
159+ chronicle_auth .add_argument_credentials_file (parser )
160+ project_id .add_argument_project_id (parser )
161+ project_instance .add_argument_project_instance (parser )
162+ regions .add_argument_region (parser )
163+
164+ args = parser .parse_args ()
165+
166+ auth_session = chronicle_auth .initialize_http_session (args . credentials_file ,
167+ SCOPES )
168+ result = batch_update_curated_rule_set_deployments (auth_session ,
169+ args .project_id ,
170+ args .project_instance ,
171+ args .region )
172+ print (json .dumps (result , indent = 2 ))
0 commit comments