polyapi-python 0.3.7.dev0__tar.gz → 0.3.7.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {polyapi_python-0.3.7.dev0/polyapi_python.egg-info → polyapi_python-0.3.7.dev1}/PKG-INFO +1 -1
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/api.py +10 -2
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/config.py +30 -1
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/execute.py +51 -5
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/generate.py +5 -1
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/utils.py +1 -1
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1/polyapi_python.egg-info}/PKG-INFO +1 -1
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/pyproject.toml +1 -1
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/LICENSE +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/README.md +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/__init__.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/__main__.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/auth.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/cli.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/client.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/constants.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/deployables.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/error_handler.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/exceptions.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/function_cli.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/parser.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/poly_schemas.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/prepare.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/py.typed +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/rendered_spec.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/schema.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/server.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/sync.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/typedefs.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/variables.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi/webhook.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi_python.egg-info/SOURCES.txt +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi_python.egg-info/dependency_links.txt +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi_python.egg-info/requires.txt +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi_python.egg-info/top_level.txt +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/setup.cfg +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_api.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_auth.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_deployables.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_generate.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_parser.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_rendered_spec.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_schema.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_server.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_utils.py +0 -0
- {polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/tests/test_variables.py +0 -0
|
@@ -23,8 +23,16 @@ def {function_name}(
|
|
|
23
23
|
|
|
24
24
|
Function ID: {function_id}
|
|
25
25
|
\"""
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
if get_direct_execute_config():
|
|
27
|
+
resp = direct_execute("{function_type}", "{function_id}", {data})
|
|
28
|
+
return {api_response_type}({{
|
|
29
|
+
"status": resp.status_code,
|
|
30
|
+
"headers": dict(resp.headers),
|
|
31
|
+
"data": resp.json()
|
|
32
|
+
}}) # type: ignore
|
|
33
|
+
else:
|
|
34
|
+
resp = execute("{function_type}", "{function_id}", {data})
|
|
35
|
+
return {api_response_type}(resp.json()) # type: ignore
|
|
28
36
|
|
|
29
37
|
|
|
30
38
|
"""
|
|
@@ -8,6 +8,10 @@ from polyapi.utils import is_valid_polyapi_url, print_green, print_yellow
|
|
|
8
8
|
# cached values
|
|
9
9
|
API_KEY = None
|
|
10
10
|
API_URL = None
|
|
11
|
+
API_FUNCTION_DIRECT_EXECUTE = None
|
|
12
|
+
MTLS_CERT_PATH = None
|
|
13
|
+
MTLS_KEY_PATH = None
|
|
14
|
+
MTLS_CA_PATH = None
|
|
11
15
|
|
|
12
16
|
|
|
13
17
|
def get_config_file_path() -> str:
|
|
@@ -45,6 +49,13 @@ def get_api_key_and_url() -> Tuple[str | None, str | None]:
|
|
|
45
49
|
API_KEY = key
|
|
46
50
|
API_URL = url
|
|
47
51
|
|
|
52
|
+
# Read and cache MTLS and direct execute settings
|
|
53
|
+
global API_FUNCTION_DIRECT_EXECUTE, MTLS_CERT_PATH, MTLS_KEY_PATH, MTLS_CA_PATH
|
|
54
|
+
API_FUNCTION_DIRECT_EXECUTE = config.get("polyapi", "api_function_direct_execute", fallback="false").lower() == "true"
|
|
55
|
+
MTLS_CERT_PATH = config.get("polyapi", "mtls_cert_path", fallback=None)
|
|
56
|
+
MTLS_KEY_PATH = config.get("polyapi", "mtls_key_path", fallback=None)
|
|
57
|
+
MTLS_CA_PATH = config.get("polyapi", "mtls_ca_path", fallback=None)
|
|
58
|
+
|
|
48
59
|
return key, url
|
|
49
60
|
|
|
50
61
|
|
|
@@ -104,4 +115,22 @@ def clear_config():
|
|
|
104
115
|
|
|
105
116
|
path = get_config_file_path()
|
|
106
117
|
if os.path.exists(path):
|
|
107
|
-
os.remove(path)
|
|
118
|
+
os.remove(path)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def get_mtls_config() -> Tuple[bool, str | None, str | None, str | None]:
|
|
122
|
+
"""Return MTLS configuration settings"""
|
|
123
|
+
global MTLS_CERT_PATH, MTLS_KEY_PATH, MTLS_CA_PATH
|
|
124
|
+
if MTLS_CERT_PATH is None or MTLS_KEY_PATH is None or MTLS_CA_PATH is None:
|
|
125
|
+
# Force a config read if values aren't cached
|
|
126
|
+
get_api_key_and_url()
|
|
127
|
+
return bool(MTLS_CERT_PATH and MTLS_KEY_PATH and MTLS_CA_PATH), MTLS_CERT_PATH, MTLS_KEY_PATH, MTLS_CA_PATH
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def get_direct_execute_config() -> bool:
|
|
131
|
+
"""Return whether direct execute is enabled"""
|
|
132
|
+
global API_FUNCTION_DIRECT_EXECUTE
|
|
133
|
+
if API_FUNCTION_DIRECT_EXECUTE is None:
|
|
134
|
+
# Force a config read if value isn't cached
|
|
135
|
+
get_api_key_and_url()
|
|
136
|
+
return bool(API_FUNCTION_DIRECT_EXECUTE)
|
|
@@ -1,22 +1,68 @@
|
|
|
1
|
-
from typing import Dict
|
|
1
|
+
from typing import Dict, Optional
|
|
2
2
|
import requests
|
|
3
3
|
from requests import Response
|
|
4
|
-
from polyapi.config import get_api_key_and_url
|
|
4
|
+
from polyapi.config import get_api_key_and_url, get_mtls_config
|
|
5
5
|
from polyapi.exceptions import PolyApiException
|
|
6
6
|
|
|
7
|
+
def direct_execute(function_type, function_id, data) -> Response:
|
|
8
|
+
""" execute a specific function id/type
|
|
9
|
+
"""
|
|
10
|
+
api_key, api_url = get_api_key_and_url()
|
|
11
|
+
headers = {"Authorization": f"Bearer {api_key}"}
|
|
12
|
+
url = f"{api_url}/functions/{function_type}/{function_id}/direct-execute"
|
|
13
|
+
|
|
14
|
+
endpoint_info = requests.post(url, json=data, headers=headers)
|
|
15
|
+
if endpoint_info.status_code < 200 or endpoint_info.status_code >= 300:
|
|
16
|
+
raise PolyApiException(f"{endpoint_info.status_code}: {endpoint_info.content.decode('utf-8', errors='ignore')}")
|
|
17
|
+
|
|
18
|
+
endpoint_info_data = endpoint_info.json()
|
|
19
|
+
request_params = endpoint_info_data.copy()
|
|
20
|
+
request_params.pop("url", None)
|
|
21
|
+
|
|
22
|
+
if "maxRedirects" in request_params:
|
|
23
|
+
request_params["allow_redirects"] = request_params.pop("maxRedirects") > 0
|
|
24
|
+
|
|
25
|
+
has_mtls, cert_path, key_path, ca_path = get_mtls_config()
|
|
26
|
+
|
|
27
|
+
if has_mtls:
|
|
28
|
+
resp = requests.request(
|
|
29
|
+
url=endpoint_info_data["url"],
|
|
30
|
+
cert=(cert_path, key_path),
|
|
31
|
+
verify=ca_path,
|
|
32
|
+
**request_params
|
|
33
|
+
)
|
|
34
|
+
else:
|
|
35
|
+
resp = requests.request(
|
|
36
|
+
url=endpoint_info_data["url"],
|
|
37
|
+
verify=False,
|
|
38
|
+
**request_params
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
if resp.status_code < 200 or resp.status_code >= 300:
|
|
42
|
+
error_content = resp.content.decode("utf-8", errors="ignore")
|
|
43
|
+
raise PolyApiException(f"{resp.status_code}: {error_content}")
|
|
44
|
+
|
|
45
|
+
return resp
|
|
7
46
|
|
|
8
47
|
def execute(function_type, function_id, data) -> Response:
|
|
9
48
|
""" execute a specific function id/type
|
|
10
49
|
"""
|
|
11
50
|
api_key, api_url = get_api_key_and_url()
|
|
12
51
|
headers = {"Authorization": f"Bearer {api_key}"}
|
|
52
|
+
|
|
13
53
|
url = f"{api_url}/functions/{function_type}/{function_id}/execute"
|
|
14
|
-
|
|
15
|
-
#
|
|
16
|
-
|
|
54
|
+
|
|
55
|
+
# Make the request
|
|
56
|
+
resp = requests.post(
|
|
57
|
+
url,
|
|
58
|
+
json=data,
|
|
59
|
+
headers=headers,
|
|
60
|
+
)
|
|
61
|
+
|
|
17
62
|
if resp.status_code < 200 or resp.status_code >= 300:
|
|
18
63
|
error_content = resp.content.decode("utf-8", errors="ignore")
|
|
19
64
|
raise PolyApiException(f"{resp.status_code}: {error_content}")
|
|
65
|
+
|
|
20
66
|
return resp
|
|
21
67
|
|
|
22
68
|
|
|
@@ -14,7 +14,7 @@ from .api import render_api_function
|
|
|
14
14
|
from .server import render_server_function
|
|
15
15
|
from .utils import add_import_to_init, get_auth_headers, init_the_init, print_green, to_func_namespace
|
|
16
16
|
from .variables import generate_variables
|
|
17
|
-
from .config import get_api_key_and_url
|
|
17
|
+
from .config import get_api_key_and_url, get_direct_execute_config
|
|
18
18
|
|
|
19
19
|
SUPPORTED_FUNCTION_TYPES = {
|
|
20
20
|
"apiFunction",
|
|
@@ -46,6 +46,10 @@ def get_specs(contexts=Optional[List[str]], no_types: bool = False) -> List:
|
|
|
46
46
|
if contexts:
|
|
47
47
|
params["contexts"] = contexts
|
|
48
48
|
|
|
49
|
+
# Add apiFunctionDirectExecute parameter if direct execute is enabled
|
|
50
|
+
if get_direct_execute_config():
|
|
51
|
+
params["apiFunctionDirectExecute"] = "true"
|
|
52
|
+
|
|
49
53
|
resp = requests.get(url, headers=headers, params=params)
|
|
50
54
|
if resp.status_code == 200:
|
|
51
55
|
return resp.json()
|
|
@@ -16,7 +16,7 @@ from polyapi.schema import (
|
|
|
16
16
|
|
|
17
17
|
# this string should be in every __init__ file.
|
|
18
18
|
# it contains all the imports needed for the function or variable code to run
|
|
19
|
-
CODE_IMPORTS = "from typing import List, Dict, Any, Optional, Callable\nfrom typing_extensions import TypedDict, NotRequired\nimport logging\nimport requests\nimport socketio # type: ignore\nfrom polyapi.config import get_api_key_and_url\nfrom polyapi.execute import execute, execute_post, variable_get, variable_update\n\n"
|
|
19
|
+
CODE_IMPORTS = "from typing import List, Dict, Any, Optional, Callable\nfrom typing_extensions import TypedDict, NotRequired\nimport logging\nimport requests\nimport socketio # type: ignore\nfrom polyapi.config import get_api_key_and_url, get_direct_execute_config\nfrom polyapi.execute import execute, execute_post, variable_get, variable_update, direct_execute\n\n"
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def init_the_init(full_path: str, code_imports="") -> None:
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.2", "wheel"]
|
|
|
3
3
|
|
|
4
4
|
[project]
|
|
5
5
|
name = "polyapi-python"
|
|
6
|
-
version = "0.3.7.
|
|
6
|
+
version = "0.3.7.dev1"
|
|
7
7
|
description = "The Python Client for PolyAPI, the IPaaS by Developers for Developers"
|
|
8
8
|
authors = [{ name = "Dan Fellin", email = "dan@polyapi.io" }]
|
|
9
9
|
dependencies = [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi_python.egg-info/requires.txt
RENAMED
|
File without changes
|
{polyapi_python-0.3.7.dev0 → polyapi_python-0.3.7.dev1}/polyapi_python.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|