-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathbatch_function_template.jinja2
More file actions
56 lines (49 loc) · 2.18 KB
/
Copy pathbatch_function_template.jinja2
File metadata and controls
56 lines (49 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def {{ operation }}(self{% if function_definition|length > 0 %}{{ function_definition }}{% endif %}):
"""
**{{ description }}**
{{ doc_url }}
{% for d in descriptions %}
- {{ d }}
{% endfor %}
"""
{% if kwarg_line|length > 0 %}
{{ kwarg_line }}
{% for safe_name, original_name in (renamed_params | default({})).items() %}
if "{{ safe_name }}" in kwargs:
kwargs["{{ original_name }}"] = kwargs.pop("{{ safe_name }}")
{% endfor %}
{% endif %}
{% if assert_blocks|length > 0 %}
{% for param, values, nullable in assert_blocks %}
if "{{ param }}" in kwargs{% if nullable %} and kwargs["{{ param }}"] is not None{% endif %}:
options = {{ values }}
assert kwargs["{{ param }}"] in options, f'''"{{ param }}" cannot be "{kwargs['{{ param }}']}", & must be set to one of: {options}'''
{% endfor %}
{% endif %}
{% for param in path_params %}
{{ param }} = urllib.parse.quote({{ param }}, safe="")
{% endfor %}
resource = f"{{ resource }}"
{% if query_params|length > 0 %}
query_params = [{% for param in query_params %}"{{ param }}", {% endfor %}]
params = {k.strip(): v for k, v in kwargs.items() if k.strip() in query_params}
{% endif %}
{% if array_params|length > 0 %}
array_params = [{% for param in array_params %}"{{ param }}", {% endfor %}]
for k, v in kwargs.items():
if k.strip() in array_params:
params[f"{k.strip()}[]"] = kwargs[f"{k}"]
params.pop(k.strip())
{% endif %}
{% if body_params|length > 0 and batch_operation != 'destroy' %}
body_params = [{% for param in body_params %}"{{ param }}", {% endfor %}]
payload = {k.strip(): v for k, v in kwargs.items() if k.strip() in body_params}
{% endif %}
action = {
"resource": resource,
"operation": "{{ batch_operation }}",
{% if body_params|length > 0 and batch_operation != 'destroy'%}
"body": payload,
{% endif %}
}
{{ call_line }}