polyapi-python 0.2.0.dev8__tar.gz → 0.2.1__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.2.0.dev8 → polyapi-python-0.2.1}/PKG-INFO +1 -1
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/auth.py +26 -5
- polyapi-python-0.2.1/polyapi/webhook.py +92 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi_python.egg-info/PKG-INFO +1 -1
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/pyproject.toml +1 -1
- polyapi-python-0.2.0.dev8/polyapi/webhook.py +0 -85
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/LICENSE +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/README.md +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/__init__.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/__main__.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/api.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/cli.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/config.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/constants.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/exceptions.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/execute.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/function_cli.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/generate.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/py.typed +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/schema.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/server.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/typedefs.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/utils.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi/variables.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi_python.egg-info/SOURCES.txt +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi_python.egg-info/dependency_links.txt +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi_python.egg-info/requires.txt +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/polyapi_python.egg-info/top_level.txt +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/setup.cfg +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/tests/test_api.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/tests/test_auth.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/tests/test_function_cli.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/tests/test_server.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/tests/test_utils.py +0 -0
- {polyapi-python-0.2.0.dev8 → polyapi-python-0.2.1}/tests/test_variables.py +0 -0
|
@@ -15,6 +15,12 @@ GET_TOKEN_TEMPLATE = """
|
|
|
15
15
|
import asyncio
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
class AuthFunctionResponse(TypedDict):
|
|
19
|
+
status: int
|
|
20
|
+
data: Any
|
|
21
|
+
headers: Dict[str, str]
|
|
22
|
+
|
|
23
|
+
|
|
18
24
|
async def getToken(clientId: str, clientSecret: str, scopes: List[str], callback, options: Optional[Dict[str, Any]] = None):
|
|
19
25
|
\"""{description}
|
|
20
26
|
|
|
@@ -102,27 +108,40 @@ async def getToken(clientId: str, clientSecret: str, scopes: List[str], callback
|
|
|
102
108
|
return {{"close": closeEventHandler}}
|
|
103
109
|
"""
|
|
104
110
|
|
|
111
|
+
INTROSPECT_TOKEN_TEMPLATE = """
|
|
112
|
+
def introspectToken(token: str) -> AuthFunctionResponse:
|
|
113
|
+
\"""{description}
|
|
114
|
+
|
|
115
|
+
Function ID: {function_id}
|
|
116
|
+
\"""
|
|
117
|
+
url = "/auth-providers/{function_id}/introspect"
|
|
118
|
+
resp = execute_post(url, {{"token": token}})
|
|
119
|
+
return resp.json()
|
|
120
|
+
"""
|
|
121
|
+
|
|
105
122
|
REFRESH_TOKEN_TEMPLATE = """
|
|
106
|
-
def refreshToken(token: str) ->
|
|
123
|
+
def refreshToken(token: str) -> AuthFunctionResponse:
|
|
107
124
|
\"""{description}
|
|
108
125
|
|
|
109
126
|
Function ID: {function_id}
|
|
110
127
|
\"""
|
|
111
128
|
url = "/auth-providers/{function_id}/refresh"
|
|
112
129
|
resp = execute_post(url, {{"token": token}})
|
|
113
|
-
|
|
114
|
-
return resp.text
|
|
130
|
+
return resp.json()
|
|
115
131
|
"""
|
|
116
132
|
|
|
117
133
|
REVOKE_TOKEN_TEMPLATE = """
|
|
118
|
-
def revokeToken(token: str) ->
|
|
134
|
+
def revokeToken(token: str) -> Optional[AuthFunctionResponse]:
|
|
119
135
|
\"""{description}
|
|
120
136
|
|
|
121
137
|
Function ID: {function_id}
|
|
122
138
|
\"""
|
|
123
139
|
url = "/auth-providers/{function_id}/revoke"
|
|
124
140
|
resp = execute_post(url, {{"token": token}})
|
|
125
|
-
|
|
141
|
+
try:
|
|
142
|
+
return resp.json()
|
|
143
|
+
except:
|
|
144
|
+
return None
|
|
126
145
|
"""
|
|
127
146
|
|
|
128
147
|
|
|
@@ -147,6 +166,8 @@ def render_auth_function(
|
|
|
147
166
|
|
|
148
167
|
if function_name == "getToken":
|
|
149
168
|
func_str = GET_TOKEN_TEMPLATE.format(function_id=function_id, description=function_description, client_id=uuid.uuid4().hex)
|
|
169
|
+
elif function_name == "introspectToken":
|
|
170
|
+
func_str = INTROSPECT_TOKEN_TEMPLATE.format(function_id=function_id, description=function_description)
|
|
150
171
|
elif function_name == "refreshToken":
|
|
151
172
|
func_str = REFRESH_TOKEN_TEMPLATE.format(function_id=function_id, description=function_description)
|
|
152
173
|
elif function_name == "revokeToken":
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import uuid
|
|
2
|
+
from typing import Any, Dict, List, Tuple
|
|
3
|
+
|
|
4
|
+
from polyapi.typedefs import PropertySpecification
|
|
5
|
+
|
|
6
|
+
WEBHOOK_TEMPLATE = """
|
|
7
|
+
import asyncio
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def {function_name}(callback, options=None):
|
|
11
|
+
\"""{description}
|
|
12
|
+
|
|
13
|
+
Function ID: {function_id}
|
|
14
|
+
\"""
|
|
15
|
+
options = options or {{}}
|
|
16
|
+
eventsClientId = "{client_id}"
|
|
17
|
+
function_id = "{function_id}"
|
|
18
|
+
|
|
19
|
+
api_key, base_url = get_api_key_and_url()
|
|
20
|
+
|
|
21
|
+
async def _inner():
|
|
22
|
+
socket = socketio.AsyncClient()
|
|
23
|
+
await socket.connect(base_url, transports=['websocket'], namespaces=['/events'])
|
|
24
|
+
|
|
25
|
+
def registerCallback(registered: bool):
|
|
26
|
+
nonlocal socket
|
|
27
|
+
if registered:
|
|
28
|
+
socket.on('handleWebhookEvent:{function_id}', handleEvent, namespace="/events")
|
|
29
|
+
else:
|
|
30
|
+
print("Could not set register webhook event handler for {function_id}")
|
|
31
|
+
|
|
32
|
+
async def handleEvent(data):
|
|
33
|
+
nonlocal api_key
|
|
34
|
+
nonlocal options
|
|
35
|
+
polyCustom = {{}}
|
|
36
|
+
resp = await callback(data.get("body"), data.get("headers"), data.get("params"), polyCustom)
|
|
37
|
+
if options.get("waitForResponse"):
|
|
38
|
+
await socket.emit('setWebhookListenerResponse', {{
|
|
39
|
+
"webhookHandleID": function_id,
|
|
40
|
+
"apiKey": api_key,
|
|
41
|
+
"clientID": eventsClientId,
|
|
42
|
+
"executionId": data.get("executionId"),
|
|
43
|
+
"response": {{
|
|
44
|
+
"data": resp,
|
|
45
|
+
"statusCode": polyCustom.get("responseStatusCode", 200),
|
|
46
|
+
"contentType": polyCustom.get("responseContentType", None),
|
|
47
|
+
}},
|
|
48
|
+
}}, namespace="/events")
|
|
49
|
+
|
|
50
|
+
data = {{
|
|
51
|
+
"clientID": eventsClientId,
|
|
52
|
+
"webhookHandleID": function_id,
|
|
53
|
+
"apiKey": api_key,
|
|
54
|
+
"waitForResponse": options.get("waitForResponse"),
|
|
55
|
+
}}
|
|
56
|
+
await socket.emit('registerWebhookEventHandler', data, namespace="/events", callback=registerCallback)
|
|
57
|
+
|
|
58
|
+
async def closeEventHandler():
|
|
59
|
+
nonlocal socket
|
|
60
|
+
if not socket:
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
await socket.emit('unregisterWebhookEventHandler', {{
|
|
64
|
+
"clientID": eventsClientId,
|
|
65
|
+
"webhookHandleID": function_id,
|
|
66
|
+
"apiKey": api_key
|
|
67
|
+
}}, namespace="/events")
|
|
68
|
+
|
|
69
|
+
await socket.wait()
|
|
70
|
+
|
|
71
|
+
return closeEventHandler
|
|
72
|
+
|
|
73
|
+
return asyncio.run(_inner())
|
|
74
|
+
"""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def render_webhook_handle(
|
|
78
|
+
function_type: str,
|
|
79
|
+
function_name: str,
|
|
80
|
+
function_id: str,
|
|
81
|
+
function_description: str,
|
|
82
|
+
arguments: List[PropertySpecification],
|
|
83
|
+
return_type: Dict[str, Any],
|
|
84
|
+
) -> Tuple[str, str]:
|
|
85
|
+
func_str = WEBHOOK_TEMPLATE.format(
|
|
86
|
+
description=function_description,
|
|
87
|
+
client_id=uuid.uuid4().hex,
|
|
88
|
+
function_id=function_id,
|
|
89
|
+
function_name=function_name,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
return func_str, ""
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import uuid
|
|
2
|
-
from typing import Any, Dict, List, Tuple
|
|
3
|
-
|
|
4
|
-
from polyapi.typedefs import PropertySpecification
|
|
5
|
-
|
|
6
|
-
WEBHOOK_TEMPLATE = """
|
|
7
|
-
async def {function_name}(callback, options=None):
|
|
8
|
-
\"""{description}
|
|
9
|
-
|
|
10
|
-
Function ID: {function_id}
|
|
11
|
-
\"""
|
|
12
|
-
options = options or {{}}
|
|
13
|
-
eventsClientId = "{client_id}"
|
|
14
|
-
function_id = "{function_id}"
|
|
15
|
-
|
|
16
|
-
api_key, base_url = get_api_key_and_url()
|
|
17
|
-
socket = socketio.AsyncClient()
|
|
18
|
-
await socket.connect(base_url, transports=['websocket'], namespaces=['/events'])
|
|
19
|
-
|
|
20
|
-
def registerCallback(registered: bool):
|
|
21
|
-
nonlocal socket
|
|
22
|
-
if registered:
|
|
23
|
-
socket.on('handleWebhookEvent:{function_id}', handleEvent, namespace="/events")
|
|
24
|
-
else:
|
|
25
|
-
print("Could not set register webhook event handler for {function_id}")
|
|
26
|
-
|
|
27
|
-
async def handleEvent(data):
|
|
28
|
-
nonlocal api_key
|
|
29
|
-
nonlocal options
|
|
30
|
-
polyCustom = {{}}
|
|
31
|
-
resp = await callback(data.get("body"), data.get("headers"), data.get("params"), polyCustom)
|
|
32
|
-
if resp and options.get("waitForResponse"):
|
|
33
|
-
await socket.emit('setWebhookListenerResponse', {{
|
|
34
|
-
"webhookHandleID": function_id,
|
|
35
|
-
"apiKey": api_key,
|
|
36
|
-
"clientID": eventsClientId,
|
|
37
|
-
"executionId": data.get("executionId"),
|
|
38
|
-
"response": {{
|
|
39
|
-
"data": resp,
|
|
40
|
-
"statusCode": polyCustom.get("responseStatusCode", 200),
|
|
41
|
-
"contentType": polyCustom.get("responseContentType", None),
|
|
42
|
-
}},
|
|
43
|
-
}}, namespace="/events")
|
|
44
|
-
|
|
45
|
-
data = {{
|
|
46
|
-
"clientID": eventsClientId,
|
|
47
|
-
"webhookHandleID": function_id,
|
|
48
|
-
"apiKey": api_key,
|
|
49
|
-
"waitForResponse": options.get("waitForResponse"),
|
|
50
|
-
}}
|
|
51
|
-
await socket.emit('registerWebhookEventHandler', data, namespace="/events", callback=registerCallback)
|
|
52
|
-
|
|
53
|
-
async def closeEventHandler():
|
|
54
|
-
nonlocal socket
|
|
55
|
-
if not socket:
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
await socket.emit('unregisterWebhookEventHandler', {{
|
|
59
|
-
"clientID": eventsClientId,
|
|
60
|
-
"webhookHandleID": function_id,
|
|
61
|
-
"apiKey": api_key
|
|
62
|
-
}}, namespace="/events")
|
|
63
|
-
|
|
64
|
-
await socket.wait()
|
|
65
|
-
|
|
66
|
-
return closeEventHandler
|
|
67
|
-
"""
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def render_webhook_handle(
|
|
71
|
-
function_type: str,
|
|
72
|
-
function_name: str,
|
|
73
|
-
function_id: str,
|
|
74
|
-
function_description: str,
|
|
75
|
-
arguments: List[PropertySpecification],
|
|
76
|
-
return_type: Dict[str, Any],
|
|
77
|
-
) -> Tuple[str, str]:
|
|
78
|
-
func_str = WEBHOOK_TEMPLATE.format(
|
|
79
|
-
description=function_description,
|
|
80
|
-
client_id=uuid.uuid4().hex,
|
|
81
|
-
function_id=function_id,
|
|
82
|
-
function_name=function_name,
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
return func_str, ""
|
|
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.2.0.dev8 → polyapi-python-0.2.1}/polyapi_python.egg-info/dependency_links.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
|