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