|
23 | 23 | from .utils import SKIP_IN_PATH, _quote, _rewrite_parameters
|
24 | 24 |
|
25 | 25 |
|
26 |
| -class QueryRulesetClient(NamespacedClient): |
| 26 | +class QueryRulesClient(NamespacedClient): |
27 | 27 |
|
28 | 28 | @_rewrite_parameters()
|
29 |
| - async def delete( |
| 29 | + async def delete_rule( |
| 30 | + self, |
| 31 | + *, |
| 32 | + ruleset_id: str, |
| 33 | + rule_id: str, |
| 34 | + error_trace: t.Optional[bool] = None, |
| 35 | + filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None, |
| 36 | + human: t.Optional[bool] = None, |
| 37 | + pretty: t.Optional[bool] = None, |
| 38 | + ) -> ObjectApiResponse[t.Any]: |
| 39 | + """ |
| 40 | + Deletes a query rule within a query ruleset. |
| 41 | +
|
| 42 | + `<https://www.elastic.co/guide/en/elasticsearch/reference/master/delete-query-rule.html>`_ |
| 43 | +
|
| 44 | + :param ruleset_id: The unique identifier of the query ruleset containing the |
| 45 | + rule to delete |
| 46 | + :param rule_id: The unique identifier of the query rule within the specified |
| 47 | + ruleset to delete |
| 48 | + """ |
| 49 | + if ruleset_id in SKIP_IN_PATH: |
| 50 | + raise ValueError("Empty value passed for parameter 'ruleset_id'") |
| 51 | + if rule_id in SKIP_IN_PATH: |
| 52 | + raise ValueError("Empty value passed for parameter 'rule_id'") |
| 53 | + __path_parts: t.Dict[str, str] = { |
| 54 | + "ruleset_id": _quote(ruleset_id), |
| 55 | + "rule_id": _quote(rule_id), |
| 56 | + } |
| 57 | + __path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}' |
| 58 | + __query: t.Dict[str, t.Any] = {} |
| 59 | + if error_trace is not None: |
| 60 | + __query["error_trace"] = error_trace |
| 61 | + if filter_path is not None: |
| 62 | + __query["filter_path"] = filter_path |
| 63 | + if human is not None: |
| 64 | + __query["human"] = human |
| 65 | + if pretty is not None: |
| 66 | + __query["pretty"] = pretty |
| 67 | + __headers = {"accept": "application/json"} |
| 68 | + return await self.perform_request( # type: ignore[return-value] |
| 69 | + "DELETE", |
| 70 | + __path, |
| 71 | + params=__query, |
| 72 | + headers=__headers, |
| 73 | + endpoint_id="query_rules.delete_rule", |
| 74 | + path_parts=__path_parts, |
| 75 | + ) |
| 76 | + |
| 77 | + @_rewrite_parameters() |
| 78 | + async def delete_ruleset( |
30 | 79 | self,
|
31 | 80 | *,
|
32 | 81 | ruleset_id: str,
|
@@ -61,12 +110,61 @@ async def delete(
|
61 | 110 | __path,
|
62 | 111 | params=__query,
|
63 | 112 | headers=__headers,
|
64 |
| - endpoint_id="query_ruleset.delete", |
| 113 | + endpoint_id="query_rules.delete_ruleset", |
| 114 | + path_parts=__path_parts, |
| 115 | + ) |
| 116 | + |
| 117 | + @_rewrite_parameters() |
| 118 | + async def get_rule( |
| 119 | + self, |
| 120 | + *, |
| 121 | + ruleset_id: str, |
| 122 | + rule_id: str, |
| 123 | + error_trace: t.Optional[bool] = None, |
| 124 | + filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None, |
| 125 | + human: t.Optional[bool] = None, |
| 126 | + pretty: t.Optional[bool] = None, |
| 127 | + ) -> ObjectApiResponse[t.Any]: |
| 128 | + """ |
| 129 | + Returns the details about a query rule within a query ruleset |
| 130 | +
|
| 131 | + `<https://www.elastic.co/guide/en/elasticsearch/reference/master/get-query-rule.html>`_ |
| 132 | +
|
| 133 | + :param ruleset_id: The unique identifier of the query ruleset containing the |
| 134 | + rule to retrieve |
| 135 | + :param rule_id: The unique identifier of the query rule within the specified |
| 136 | + ruleset to retrieve |
| 137 | + """ |
| 138 | + if ruleset_id in SKIP_IN_PATH: |
| 139 | + raise ValueError("Empty value passed for parameter 'ruleset_id'") |
| 140 | + if rule_id in SKIP_IN_PATH: |
| 141 | + raise ValueError("Empty value passed for parameter 'rule_id'") |
| 142 | + __path_parts: t.Dict[str, str] = { |
| 143 | + "ruleset_id": _quote(ruleset_id), |
| 144 | + "rule_id": _quote(rule_id), |
| 145 | + } |
| 146 | + __path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}' |
| 147 | + __query: t.Dict[str, t.Any] = {} |
| 148 | + if error_trace is not None: |
| 149 | + __query["error_trace"] = error_trace |
| 150 | + if filter_path is not None: |
| 151 | + __query["filter_path"] = filter_path |
| 152 | + if human is not None: |
| 153 | + __query["human"] = human |
| 154 | + if pretty is not None: |
| 155 | + __query["pretty"] = pretty |
| 156 | + __headers = {"accept": "application/json"} |
| 157 | + return await self.perform_request( # type: ignore[return-value] |
| 158 | + "GET", |
| 159 | + __path, |
| 160 | + params=__query, |
| 161 | + headers=__headers, |
| 162 | + endpoint_id="query_rules.get_rule", |
65 | 163 | path_parts=__path_parts,
|
66 | 164 | )
|
67 | 165 |
|
68 | 166 | @_rewrite_parameters()
|
69 |
| - async def get( |
| 167 | + async def get_ruleset( |
70 | 168 | self,
|
71 | 169 | *,
|
72 | 170 | ruleset_id: str,
|
@@ -101,14 +199,14 @@ async def get(
|
101 | 199 | __path,
|
102 | 200 | params=__query,
|
103 | 201 | headers=__headers,
|
104 |
| - endpoint_id="query_ruleset.get", |
| 202 | + endpoint_id="query_rules.get_ruleset", |
105 | 203 | path_parts=__path_parts,
|
106 | 204 | )
|
107 | 205 |
|
108 | 206 | @_rewrite_parameters(
|
109 | 207 | parameter_aliases={"from": "from_"},
|
110 | 208 | )
|
111 |
| - async def list( |
| 209 | + async def list_rulesets( |
112 | 210 | self,
|
113 | 211 | *,
|
114 | 212 | error_trace: t.Optional[bool] = None,
|
@@ -147,14 +245,87 @@ async def list(
|
147 | 245 | __path,
|
148 | 246 | params=__query,
|
149 | 247 | headers=__headers,
|
150 |
| - endpoint_id="query_ruleset.list", |
| 248 | + endpoint_id="query_rules.list_rulesets", |
| 249 | + path_parts=__path_parts, |
| 250 | + ) |
| 251 | + |
| 252 | + @_rewrite_parameters( |
| 253 | + body_fields=("actions", "criteria", "type"), |
| 254 | + ) |
| 255 | + async def put_rule( |
| 256 | + self, |
| 257 | + *, |
| 258 | + ruleset_id: str, |
| 259 | + rule_id: str, |
| 260 | + actions: t.Optional[t.Mapping[str, t.Any]] = None, |
| 261 | + criteria: t.Optional[t.Sequence[t.Mapping[str, t.Any]]] = None, |
| 262 | + type: t.Optional[t.Union["t.Literal['pinned']", str]] = None, |
| 263 | + error_trace: t.Optional[bool] = None, |
| 264 | + filter_path: t.Optional[t.Union[str, t.Sequence[str]]] = None, |
| 265 | + human: t.Optional[bool] = None, |
| 266 | + pretty: t.Optional[bool] = None, |
| 267 | + body: t.Optional[t.Dict[str, t.Any]] = None, |
| 268 | + ) -> ObjectApiResponse[t.Any]: |
| 269 | + """ |
| 270 | + Creates or updates a query rule within a query ruleset. |
| 271 | +
|
| 272 | + `<https://www.elastic.co/guide/en/elasticsearch/reference/master/put-query-rule.html>`_ |
| 273 | +
|
| 274 | + :param ruleset_id: The unique identifier of the query ruleset containing the |
| 275 | + rule to be created or updated |
| 276 | + :param rule_id: The unique identifier of the query rule within the specified |
| 277 | + ruleset to be created or updated |
| 278 | + :param actions: |
| 279 | + :param criteria: |
| 280 | + :param type: |
| 281 | + """ |
| 282 | + if ruleset_id in SKIP_IN_PATH: |
| 283 | + raise ValueError("Empty value passed for parameter 'ruleset_id'") |
| 284 | + if rule_id in SKIP_IN_PATH: |
| 285 | + raise ValueError("Empty value passed for parameter 'rule_id'") |
| 286 | + if actions is None and body is None: |
| 287 | + raise ValueError("Empty value passed for parameter 'actions'") |
| 288 | + if criteria is None and body is None: |
| 289 | + raise ValueError("Empty value passed for parameter 'criteria'") |
| 290 | + if type is None and body is None: |
| 291 | + raise ValueError("Empty value passed for parameter 'type'") |
| 292 | + __path_parts: t.Dict[str, str] = { |
| 293 | + "ruleset_id": _quote(ruleset_id), |
| 294 | + "rule_id": _quote(rule_id), |
| 295 | + } |
| 296 | + __path = f'/_query_rules/{__path_parts["ruleset_id"]}/_rule/{__path_parts["rule_id"]}' |
| 297 | + __query: t.Dict[str, t.Any] = {} |
| 298 | + __body: t.Dict[str, t.Any] = body if body is not None else {} |
| 299 | + if error_trace is not None: |
| 300 | + __query["error_trace"] = error_trace |
| 301 | + if filter_path is not None: |
| 302 | + __query["filter_path"] = filter_path |
| 303 | + if human is not None: |
| 304 | + __query["human"] = human |
| 305 | + if pretty is not None: |
| 306 | + __query["pretty"] = pretty |
| 307 | + if not __body: |
| 308 | + if actions is not None: |
| 309 | + __body["actions"] = actions |
| 310 | + if criteria is not None: |
| 311 | + __body["criteria"] = criteria |
| 312 | + if type is not None: |
| 313 | + __body["type"] = type |
| 314 | + __headers = {"accept": "application/json", "content-type": "application/json"} |
| 315 | + return await self.perform_request( # type: ignore[return-value] |
| 316 | + "PUT", |
| 317 | + __path, |
| 318 | + params=__query, |
| 319 | + headers=__headers, |
| 320 | + body=__body, |
| 321 | + endpoint_id="query_rules.put_rule", |
151 | 322 | path_parts=__path_parts,
|
152 | 323 | )
|
153 | 324 |
|
154 | 325 | @_rewrite_parameters(
|
155 | 326 | body_fields=("rules",),
|
156 | 327 | )
|
157 |
| - async def put( |
| 328 | + async def put_ruleset( |
158 | 329 | self,
|
159 | 330 | *,
|
160 | 331 | ruleset_id: str,
|
@@ -200,6 +371,6 @@ async def put(
|
200 | 371 | params=__query,
|
201 | 372 | headers=__headers,
|
202 | 373 | body=__body,
|
203 |
| - endpoint_id="query_ruleset.put", |
| 374 | + endpoint_id="query_rules.put_ruleset", |
204 | 375 | path_parts=__path_parts,
|
205 | 376 | )
|
0 commit comments