Terarea  2
The automation project
Loading...
Searching...
No Matches
api_querier.py
Go to the documentation of this file.
1"""
2 File in charge of querying the data from the API
3"""
4
5from typing import Dict, Any, List, Union
6
7import json
8import urllib.parse
9from requests import Response
10from display_tty import Disp, TOML_CONF, FILE_DESCRIPTOR, SAVE_TO_FILE, FILE_NAME
11
12from .secrets import Secrets
13from .variables import Variables
14from .logger import ActionLogger
15from . import constants as ACONST
16from .query_boilerplate import QueryEndpoint
17
18from ..components import constants as CONST
19from ..components.runtime_data import RuntimeData
20
21
23 """_summary_
24 """
25
26 def __init__(self, service: Dict[str, Any], variable: Variables, scope: str, runtime_data: RuntimeData, logger: ActionLogger, action_id: int, error: int = 84, success: int = 0, debug: bool = False) -> None:
27 """_summary_
28 Class in charge of querying the data from the API
29
30 Args:
31 service (Dict[str, Any]): _description_
32 variable (Variables): _description_: The class variable in charge of tracking the variables for the runtime.
33 scope (str): _description_: The scope of the trigger.
34 runtime_data (RuntimeData): _description_
35 logger (ActionLogger): _description_: The class logger in charge of logging the actions.
36 action_id (int): _description_: The action ID to log.
37 error (int, optional): _description_. Defaults to 84.
38 success (int, optional): _description_. Defaults to 0.
39 debug (bool, optional): _description_. Defaults to False.
40 """
41 title = "APIQuerier"
42 self.error: int = error
43 self.scope: str = scope
44 self.debug: bool = debug
45 self.success: int = success
46 self.action_id: str = str(action_id)
47 self.logger: ActionLogger = logger
48 self.variable: Variables = variable
49 self.service: Dict[str, Any] = service
50 self.runtime_data: RuntimeData = runtime_data
51 # ---------------------- The visual logger class ----------------------
52 self.disp: Disp = Disp(
53 TOML_CONF,
54 SAVE_TO_FILE,
55 FILE_NAME,
56 FILE_DESCRIPTOR,
57 debug=self.debug,
58 logger=self.__class__.__name__
59 )
60 self.disp.log_debug(f"service: {self.service}", title)
61 # ------------------ The class containing the secrets ------------------
62 self.secrets: Secrets = Secrets(
63 success=self.success,
64 error=self.error,
65 debug=self.debug
66 )
67 # ------------------------- Info about the api -------------------------
68 self.api_info: Dict[str, Any] = self.get_api_info(
69 self.service.get("ignore:id")
70 )
71 self.update_secrets(self.api_info)
72 # ------------------------- The gathered data ---------------------------
73 self.disp.log_debug(f"API info: {self.api_info}", title)
74
75 def _log_fatal(self, title: str, msg, action_id: int, raise_item: bool = False, raise_func: object = ValueError) -> int:
76 """_summary_
77 A function that will log a provided fatal error.
78
79 Args:
80 title (str): _description_: the title of the function
81 msg (str): _description_: The message to log
82 raise_item (bool, optional): _description_. Inform if the logger should raise or just return an error. Defaults to False.
83 raise_func (object, optional): _description_. The function to raise if required. Defaults to ValueError.
84
85 Raises:
86 ValueError: _description_: One of the possible errors to raise.
87
88 Returns:
89 int: _description_: Will return self.error if raise_item is False
90 """
91 self.disp.log_error(msg, title)
92 self.logger.log_fatal(
93 ACONST.TYPE_SERVICE_TRIGGER,
94 action_id=action_id,
95 message=msg,
96 resolved=False
97 )
98 if raise_item is True:
99 raise_func(msg)
100 else:
101 return self.error
102
103 def strip_descriptor(self, node: str) -> str:
104 """_summary_
105 A function that will strip the descriptor of the given node.
106
107 Args:
108 descriptor (str): _description_: The descriptor to strip.
109
110 Returns:
111 str: _description_: The stripped descriptor.
112 """
113 title = "strip_descriptor"
114 self.disp.log_debug(f"Node: {node}", title)
115 node = node.split(':')[1]
116 self.disp.log_debug(f"Node (stripped): {node}", title)
117 return node
118
119 def get_api_info(self, api_id: int) -> Dict[str, Any]:
120 """_summary_
121 Get the API information
122
123 Args:
124 api_id (int): _description_
125
126 Returns:
127 Dict[str, Any]: _description_
128 """
129 title = "get_api_info"
130 if api_id is None:
131 self._log_fatal(
132 title=title,
133 msg="The API ID is None",
134 action_id=self.action_id,
135 raise_item=True,
136 raise_func=ValueError
137 )
138 data = self.runtime_data.database_link.get_data_from_table(
139 table=CONST.TAB_SERVICES,
140 column="*",
141 where=f"id='{api_id}'",
142 beautify=True
143 )
144 if isinstance(data, int) is True or len(data) == 0:
145 msg = "Failed to get the API information for"
146 msg += f" the API ID: {api_id}"
147 self._log_fatal(
148 title=title,
149 msg=msg,
150 action_id=self.action_id,
151 raise_item=True,
152 raise_func=ValueError
153 )
154 self.disp.log_debug(f"Gathered API info: {data[0]}", title)
155 return data[0]
156
157 def update_secrets(self, api_info: Dict[str, Any]) -> None:
158 """_summary_
159 Update the secrets
160
161 Args:
162 api_info (Dict[str, Any]): _description_
163 """
164 title = "update_secrets"
165 if api_info is None:
166 self._log_fatal(
167 title=title,
168 msg="The API info is None",
169 action_id=self.action_id,
170 raise_item=True,
171 raise_func=ValueError
172 )
173 node = None
174 oauth = api_info.get("oauth")
175 if str(oauth) == "0":
176 node = api_info.get("api_key")
177 elif str(oauth) == "1":
178 usr_id = self.variable.get_variable("user_id", self.scope)
179 service_id = api_info.get("id")
180 if service_id is None or usr_id is None:
181 self._log_fatal(
182 title=title,
183 msg="The service ID or user ID is None",
184 action_id=self.action_id,
185 raise_item=True,
186 raise_func=ValueError
187 )
188 data: Dict[str, Any] = self.runtime_data.database_link.get_data_from_table(
189 table=CONST.TAB_ACTIVE_OAUTHS,
190 column="*",
191 where=[
192 f"user_id='{usr_id}'",
193 f"service_id='{service_id}'"
194 ],
195 beautify=True
196 )
197 node = data.get("token")
198 else:
199 self._log_fatal(
200 title=title,
201 msg="The oauth token is not valid",
202 action_id=self.action_id,
203 raise_item=True,
204 raise_func=ValueError
205 )
206 if node is None:
207 self._log_fatal(
208 title=title,
209 msg="The token is None",
210 action_id=self.action_id,
211 raise_item=True,
212 raise_func=ValueError
213 )
214 self.secrets.set_token(node)
215
216 def sanitize_parameter_value(self, url_param: str) -> str:
217 """_summary_
218 Sanitize the parameter value
219
220 Args:
221 url_param (str): _description_
222
223 Returns:
224 str: _description_
225 """
226 title = "sanitize_parameter_value"
227 self.disp.log_debug(f"url_param: {url_param}", title)
228 if url_param is None:
229 return ""
230 url_param = urllib.parse.quote(url_param)
231 self.disp.log_debug(f"url_param (sanitised): {url_param}", title)
232 return url_param
233
234 def get_variable_name(self, var: str) -> str:
235 """_summary_
236 Get the variable name
237
238 Args:
239 var (str): _description_
240
241 Returns:
242 str: _description_
243 """
244 title = "get_variable_name"
245 self.disp.log_debug(f"var: {var}", title)
246 result = ""
247 for i in var:
248 if i == "{":
249 continue
250 if i == "}":
251 break
252 result += i
253 self.disp.log_debug(f"result: {result}", title)
254 return result
255
256 def get_special_content(self, var_name: str) -> str:
257 """_summary_
258 Get the content of a special variable
259
260 Args:
261 var_name (str): _description_
262
263 Returns:
264 str: _description_
265 """
266 title = "get_special_content"
267 self.disp.log_debug(f"var_name: {var_name}", title)
268 node = ""
269 lvar_name = var_name.lower()
270 if lvar_name in ("secrets.token", "secret.token", "token"):
271 node = self.secrets.get_token()
272 if lvar_name in ("secrets.bearer", "secret.bearer", "bearer"):
273 node = self.secrets.get_bearer()
274 if lvar_name in ACONST.SECRETS_EQUIVALENCE:
275 msg = f"lvar_name: {lvar_name} found in "
276 msg += "ACONST.SECRETS_EQUIVALENCE"
277 self.disp.log_debug(msg, title)
278 node = ACONST.SECRETS_EQUIVALENCE[lvar_name]()
279 self.disp.log_debug(f"node: {node}", title)
280 return node
281
282 def get_normal_content(self, var_name: str) -> str:
283 """_summary_
284 Get the content of a normal variable
285
286 Args:
287 var_name (str): _description_
288
289 Returns:
290 str: _description_
291 """
292 title = "get_normal_content"
293 self.disp.log_debug(f"var_name: {var_name}", title)
294 if self.variable.has_variable(var_name, self.scope) is False:
295 self.disp.log_debug(f"Variable {var_name} not found", title)
296 return ""
297 data = self.variable.get_variable(var_name, self.scope)
298 self.disp.log_debug(f"{var_name}: {data}", title)
299 return data
300
301 def check_special_vars(self, var: str) -> str:
302 """_summary_
303 Check the variables
304
305 Args:
306 var (str): _description_
307
308 Returns:
309 str: _description_
310 """
311 title = "check_special_vars"
312 if var is None or var == "":
313 self.disp.log_debug("var is None or empty", title)
314 return var
315 var_list = var.split("$ref")
316 self.disp.log_debug(f"var_list: {var_list}", title)
317 for index, item in enumerate(var_list):
318 if item == "":
319 continue
320 if item[0] == "{":
321 var_name = self.get_variable_name(item[1:])
322 var_content = self.get_special_content(var_name)
323 item_new = f"{var_content}{item[len(var_name) + 2:]}"
324 self.disp.log_debug(f"item_new: {item_new}", title)
325 var_list[index] = item_new
326 data = "".join(var_list)
327 self.disp.log_debug(f"data: {data}", title)
328 return data
329
330 def check_normal_vars(self, var: str) -> str:
331 """_summary_
332 Check the normal variables
333
334 Args:
335 var (str): _description_
336
337 Returns:
338 str: _description_
339 """
340 title = "check_normal_vars"
341 if var is None or var == "":
342 self.disp.log_debug("var is None or empty", title)
343 return var
344 var_list = var.split("${")
345 self.disp.log_debug(f"var_list: {var_list}", title)
346 for index, item in enumerate(var_list):
347 if item == "":
348 continue
349 if item[0] == "{":
350 var_name = self.get_variable_name(item[1:])
351 var_content = self.get_normal_content(var_name)
352 item_new = f"{var_content}{item[len(var_name) + 3:]}"
353 self.disp.log_debug(f"item_new: {item_new}", title)
354 var_list[index] = item_new
355 data = "".join(var_list)
356 self.disp.log_debug(f"data: {data}", title)
357 return data
358
359 def compile_url_parameters(self, url_params: Dict[str, Any]) -> str:
360 """_summary_
361 Compile the URL parameters
362
363 Args:
364 url_params (Dict[str, Any]): _description_
365
366 Returns:
367 str: _description_
368 """
369 title = "compile_url_parameters"
370 url = ""
371 index = 0
372 value = None
373 key_stripped = None
374 self.disp.log_debug(f"url_params: {url_params}", title)
375 for key, value in url_params.items():
376 if key in ("input:additional_params", "ignore:additional_params"):
377 if value == "":
378 index += 1
379 continue
380 if isinstance(value, Dict):
381 for key2, value2 in value.items():
382 key_stripped = self.strip_descriptor(key2)
383 value = self.check_special_vars(value2)
384 value = self.check_normal_vars(value2)
385 elif isinstance(value, List):
386 key_stripped = self.strip_descriptor(key)
387 default = None
388 selected = None
389 for i in value:
390 if i.startswith("selected:"):
391 selected = self.strip_descriptor(i)
392 value = self.check_special_vars(selected)
393 value = self.check_normal_vars(selected)
394 break
395 if i.startswith("default:"):
396 default = self.strip_descriptor(i)
397 value = self.check_special_vars(default)
398 value = self.check_normal_vars(default)
399 else:
400 key_stripped = self.strip_descriptor(key)
401 value = self.check_special_vars(value)
402 value = self.check_normal_vars(value)
403 if index != 0:
404 url += "&"
405 self.disp.log_debug(f"url: {url}", title)
406 url += f"{key_stripped}={self.sanitize_parameter_value(value)}"
407 index += 1
408 self.disp.log_debug(f"url: {url}", title)
409 return url
410
411 def process_extra_headers(self, header: str) -> Dict[str, Any]:
412 """_summary_
413 Process the extra headers
414
415 Args:
416 header (Dict[str, Any]): _description_
417
418 Returns:
419 Dict[str, Any]: _description_
420 """
421 title = "process_extra_headers"
422 if header is None or header == "":
423 return {}
424 self.disp.log_debug(f"header: {header}", title)
425 try:
426 header: Dict[str, Any] = json.loads(header)
427 except json.JSONDecodeError as e:
428 self.disp.log_error(f"Error processing header: {e}", title)
429 return {}
430 self.disp.log_debug(f"header: {header}", title)
431 result = {}
432 for key, value in header.items():
433 value = self.check_special_vars(value)
434 value = self.check_normal_vars(value)
435 key_stripped = self.strip_descriptor(key)
436 self.disp.log_debug(f"key: {key_stripped}, value: {value}", title)
437 result[key_stripped] = value
438 self.disp.log_debug(f"header: {result}", title)
439 return result
440
441 def process_headers(self, header: Dict[str, Any]) -> Dict[str, Any]:
442 """_summary_
443 Process the header
444
445 Args:
446 header (Dict[str, Any]): _description_
447
448 Returns:
449 Dict[str, Any]: _description_
450 """
451 title = "process_headers"
452 if header is None:
453 self.disp.log_debug("header: None", title)
454 return {}
455 self.disp.log_debug(f"header: {header}", title)
456 result = {}
457 key_stripped = None
458 value = None
459 for key, value in header.items():
460 if key in ("input:additional_header", "ignore:additional_header"):
461 result.update(self.process_extra_headers(value))
462 continue
463 if isinstance(value, Dict):
464 for key2, value2 in value.items():
465 key_stripped = self.strip_descriptor(key2)
466 value = self.check_special_vars(value2)
467 value = self.check_normal_vars(value2)
468 elif isinstance(value, List):
469 key_stripped = self.strip_descriptor(key)
470 default = None
471 selected = None
472 for i in value:
473 if i.startswith("selected:"):
474 selected = self.strip_descriptor(i)
475 break
476 if i.startswith("default:"):
477 default = self.strip_descriptor(i)
478 if default is not None:
479 value = default
480 if selected is not None:
481 value = selected
482 else:
483 key_stripped = self.strip_descriptor(key)
484 value = self.check_special_vars(value)
485 value = self.check_normal_vars(value)
486 self.disp.log_debug(f"key: {key_stripped}, value: {value}", title)
487 result[key_stripped] = value
488 self.disp.log_debug(f"header: {result}", title)
489 return result
490
491 def process_extra_body(self, body: str) -> Dict[str, Any]:
492 """_summary_
493 Process the extra body
494
495 Args:
496 body (str): _description_
497
498 Returns:
499 Dict[str, Any]: _description_
500 """
501 title = "process_extra_body"
502 if body is None or body == "":
503 return {}
504 self.disp.log_debug(f"body: {body}", title)
505 try:
506 body: Dict[str, Any] = json.loads(body)
507 except json.JSONDecodeError as e:
508 self.disp.log_error(f"Error processing body: {e}", title)
509 return {}
510 self.disp.log_debug(f"body: {body}", title)
511 result = {}
512 for key, value in body.items():
513 value = self.check_special_vars(value)
514 value = self.check_normal_vars(value)
515 key_stripped = self.strip_descriptor(key)
516 self.disp.log_debug(f"key: {key_stripped}, value: {value}", title)
517 result[key_stripped] = value
518 self.disp.log_debug(f"body: {result}", title)
519 return result
520
521 def process_body(self, body: Dict[str, Any]) -> Dict[str, Any]:
522 """_summary_
523 Process the body
524
525 Args:
526 body (Dict[str, Any]): _description_
527
528 Returns:
529 Dict[str, Any]: _description_
530 """
531 title = "process_body"
532 if body is None:
533 self.disp.log_debug("body: None", title)
534 return {}
535 result = {}
536 key_stripped = None
537 value = None
538 for key, value in body.items():
539 if key in ("input:additional_body", "ignore:additional_body"):
540 result.update(self.process_extra_body(value))
541 continue
542 if isinstance(value, Dict):
543 for key2, value2 in value.items():
544 key_stripped = self.strip_descriptor(key2)
545 value = self.check_special_vars(value2)
546 value = self.check_normal_vars(value2)
547 elif isinstance(value, List):
548 key_stripped = self.strip_descriptor(key)
549 default = None
550 selected = None
551 for i in value:
552 if i.startswith("selected:"):
553 selected = self.strip_descriptor(i)
554 break
555 if i.startswith("default:"):
556 default = self.strip_descriptor(i)
557 if default is not None:
558 value = default
559 if selected is not None:
560 value = selected
561 else:
562 key_stripped = self.strip_descriptor(key)
563 value = self.check_special_vars(value)
564 value = self.check_normal_vars(value)
565 self.disp.log_debug(f"key: {key_stripped}, value: {value}", title)
566 result[key_stripped] = value
567 self.disp.log_debug(f"body: {result}", title)
568 return result
569
570 def get_method(self, method: List[str]) -> str:
571 """_summary_
572 Get the method
573
574 Args:
575 method (str): _description_
576
577 Returns:
578 str: _description_
579 """
580 if method is None:
581 return "GET"
582 selected = None
583 default = None
584 for i in method:
585 if i.startswith("selected:"):
586 selected = self.strip_descriptor(i)
587 break
588 if i.startswith("default:"):
589 default = self.strip_descriptor(i)
590 if selected is not None:
591 return selected
592 if default is not None:
593 return default
594 return "GET"
595
596 def extract_response_code(self, code: Dict[str, Any]) -> int:
597 """_summary_
598 Extract the code code
599
600 Args:
601 code (Dict[str, Any]): _description_
602
603 Returns:
604 int: _description_
605 """
606 title = "extract_response_code"
607 default_response: int = 200
608 node: str = code.get("int:code")
609 if node is None:
610 self.disp.log_debug(f"code: {code}", title)
611 return default_response
612 if isinstance(node, int) is True:
613 self.disp.log_debug(f"code: {node}", title)
614 return node
615 if isinstance(node, str) is True:
616 if node.startswith("default:"):
617 self.disp.log_debug(f"code: {node}", title)
618 return int(self.strip_descriptor(node))
619 if node.startswith("selected:"):
620 self.disp.log_debug(f"code: {node}", title)
621 return int(self.strip_descriptor(node))
622 try:
623 node = int(node)
624 self.disp.log_debug(f"code: {node}", title)
625 return node
626 except ValueError as e:
627 self.disp.log_error(f"code: {node}, err: {e}", title)
628 return default_response
629 if isinstance(node, List) is False:
630 self.disp.log_error(f"code: {node}", title)
631 node1 = None
632 node2 = None
633 for i in node:
634 if i.startswith("default:"):
635 node1 = int(self.strip_descriptor(i))
636 if i.startswith("selected:"):
637 node2 = int(self.strip_descriptor(i))
638 if node2 is not None:
639 self.disp.log_debug(f"code: {node2}", title)
640 return node2
641 if node1 is not None:
642 self.disp.log_debug(f"code: {node1}", title)
643 return node1
644 return default_response
645
646 def check_response_code(self, response: Response, expected_response: int) -> None:
647 """_summary_
648 Check the response code
649
650 Args:
651 response (Response): _description_
652 expected_response (int): _description_
653 """
654 title = "check_response_code"
655 if response is None:
656 self._log_fatal(
657 title=title,
658 msg="Response is None",
659 action_id=self.action_id,
660 raise_item=True,
661 raise_func=ValueError
662 )
663 if response.status_code != expected_response:
664 msg = f"Expected response code: {expected_response},"
665 msg += f" got: {response.status_code}"
666 self._log_fatal(
667 title=title,
668 msg=msg,
669 action_id=self.action_id,
670 raise_item=True,
671 raise_func=ValueError
672 )
673
674 def compile_url(self, url_extra: str, url_params: Dict[str, Any]) -> str:
675 """_summary_
676 Compile the URL
677
678 Args:
679 url_extra (str): _description_
680 url_params (Dict[str, Any]): _description_
681
682 Returns:
683 str: _description_
684 """
685 url = ""
686 if url_extra is not None and len(url_extra) > 0:
687 if url_extra[0] == "/":
688 url_extra = url_extra[1:]
689 url += url_extra
690 if url_params is not None and len(url_params) > 0:
691 data = self.compile_url_parameters(url_params)
692 if data != "":
693 url += "?" + data
694 return url
695
696 def replace_url_body_params(self, url_extra: str, url_body_params: Union[Dict[str, Any], None]) -> str:
697 """
698 Replaces placeholders in the URL with values from the given dictionary.
699
700 Args:
701 url_extra: The URL containing placeholders in the format {param}.
702 url_body_params: A dictionary containing the parameters and their values.
703
704 Returns:
705 The URL with the placeholders replaced by their corresponding values.
706
707 If url_body_params is None, the function returns url_extra unchanged.
708 """
709 if url_body_params is None:
710 return url_extra
711
712 for key, value in url_body_params.items():
713 real_key = self.strip_descriptor(key)
714 placeholder = f"{{{real_key}}}"
715 url_extra = url_extra.replace(placeholder, str(value))
716 return url_extra
717
718 def query(self) -> Response:
719 """_summary_
720 Query the API
721
722 Returns:
723 Response: _description_
724 """
725 title = "query"
726 self.disp.log_debug("In query", title)
727 self.disp.log_debug(f"API info: {self.api_info}", title)
728 self.disp.log_debug(f"Service info: {self.service}", title)
729 self.disp.log_debug("Processing url", title)
730
731 # Get informations to send to the API
732 url_extra = (self.service.get("input:url_extra") or self.service.get("ignore:url_extra"))
733 url_body_params = (self.service.get("url_body_params") or self.service.get("ignore:url_body_params"))
734 url_query_params = (self.service.get("url_params") or self.service.get("ignore:url_params"))
735 self.disp.log_debug(
736 f"url_extra: {url_extra}, url_body_params: {url_body_params}, url_query_params: {url_query_params}", title
737 )
738
739 self.disp.log_debug("Processing body", title)
740 body = (self.service.get("body") or self.service.get("ignore:body"))
741 if body is not None:
742 body = self.process_body(body)
743
744 self.disp.log_debug("Processing method", title)
745 method = (self.service.get("drop:method") or self.service.get("ignore:method"))
746 if isinstance(method, List):
747 method = self.get_method(method)
748
749 self.disp.log_debug("Processing headers", title)
750 headers = (self.service.get("header") or self.service.get("ignore:header"))
751 if headers is not None:
752 headers = self.process_headers(headers)
753 self.disp.log_debug("Compiling url", title)
754 url = self.compile_url(self.replace_url_body_params(url_extra, url_body_params), url_query_params)
755 url_base = self.api_info.get("url")
756 if url_base[-1] != "/":
757 url_base += "/"
758 msg = "Processed data: '"
759 msg += f"url_extra: {url_extra}, url_query_params: {url_query_params},"
760 msg += f" body: {body}, method: {method}, headers: {headers},"
761 msg += f" url: {url}, url_base: {url_base}'"
762 self.disp.log_debug(msg, title)
763
764 # Get the expected response
765 expected_response: Union[Dict[str, Any], None] = (self.service.get("response") or self.service.get("ignore:response"))
766 if expected_response is not None:
767 expected_response = self.extract_response_code(expected_response)
768 else:
769 self._log_fatal(
770 title=title,
771 msg="Response section not found in service.",
772 action_id=self.action_id,
773 raise_item=True,
774 raise_func=ValueError
775 )
776 msg = f"Expected response: {expected_response},"
777 msg += f" type: {type(expected_response)}"
778 self.disp.log_debug(msg, title)
779 qei = QueryEndpoint(
780 host=url_base,
781 port=None,
782 delay=CONST.API_REQUEST_DELAY,
783 debug=self.debug
784 )
785 self.disp.log_debug(f"qei = {qei}", title)
786 if not body:
787 body = None
788 if not headers:
789 headers = None
790 self.disp.log_debug(
791 f"final_body = {body}, final_headers = {headers}", title
792 )
793 response = None
794 if method == "GET":
795 response = qei.get_endpoint(url, content=body, header=headers)
796 elif method == "POST":
797 response = qei.post_endpoint(url, content=body, header=headers)
798 elif method == "PUT":
799 response = qei.put_endpoint(url, content=body, header=headers)
800 elif method == "PATCH":
801 response = qei.patch_endpoint(url, content=body, header=headers)
802 elif method == "DELETE":
803 response = qei.delete_endpoint(url, content=body, header=headers)
804 elif method == "HEAD":
805 response = qei.head_endpoint(url, content=body, header=headers)
806 elif method == "OPTIONS":
807 response = qei.options_endpoint(url, content=body, header=headers)
808 else:
809 msg = f"Method {method} is not supported"
810 self._log_fatal(
811 title=title,
812 msg=msg,
813 action_id=self.action_id,
814 raise_item=True,
815 raise_func=ValueError
816 )
817 self.disp.log_debug(f"Response: {response}", title)
818 self.disp.log_debug(
819 f"Response status_code: {response.status_code}", title
820 )
821 self.disp.log_debug(f"Expected response: {expected_response}", title)
822 self.check_response_code(response, expected_response)
823 return response
str compile_url_parameters(self, Dict[str, Any] url_params)
Dict[str, Any] process_headers(self, Dict[str, Any] header)
str get_special_content(self, str var_name)
str replace_url_body_params(self, str url_extra, Union[Dict[str, Any], None] url_body_params)
None check_response_code(self, Response response, int expected_response)
str compile_url(self, str url_extra, Dict[str, Any] url_params)
Dict[str, Any] process_extra_headers(self, str header)
str get_normal_content(self, str var_name)
int extract_response_code(self, Dict[str, Any] code)
None update_secrets(self, Dict[str, Any] api_info)
Dict[str, Any] get_api_info(self, int api_id)
int _log_fatal(self, str title, msg, int action_id, bool raise_item=False, object raise_func=ValueError)
str sanitize_parameter_value(self, str url_param)
str get_method(self, List[str] method)
Dict[str, Any] process_body(self, Dict[str, Any] body)
Dict[str, Any] process_extra_body(self, str body)
None __init__(self, Dict[str, Any] service, Variables variable, str scope, RuntimeData runtime_data, ActionLogger logger, int action_id, int error=84, int success=0, bool debug=False)