polyapi-python 0.2.0.dev8__py3-none-any.whl → 0.2.1.dev0__py3-none-any.whl
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/auth.py +26 -5
- polyapi/webhook.py +48 -44
- {polyapi_python-0.2.0.dev8.dist-info → polyapi_python-0.2.1.dev0.dist-info}/METADATA +1 -1
- {polyapi_python-0.2.0.dev8.dist-info → polyapi_python-0.2.1.dev0.dist-info}/RECORD +7 -7
- {polyapi_python-0.2.0.dev8.dist-info → polyapi_python-0.2.1.dev0.dist-info}/LICENSE +0 -0
- {polyapi_python-0.2.0.dev8.dist-info → polyapi_python-0.2.1.dev0.dist-info}/WHEEL +0 -0
- {polyapi_python-0.2.0.dev8.dist-info → polyapi_python-0.2.1.dev0.dist-info}/top_level.txt +0 -0
polyapi/auth.py
CHANGED
|
@@ -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":
|
polyapi/webhook.py
CHANGED
|
@@ -4,7 +4,7 @@ from typing import Any, Dict, List, Tuple
|
|
|
4
4
|
from polyapi.typedefs import PropertySpecification
|
|
5
5
|
|
|
6
6
|
WEBHOOK_TEMPLATE = """
|
|
7
|
-
|
|
7
|
+
def {function_name}(callback, options=None):
|
|
8
8
|
\"""{description}
|
|
9
9
|
|
|
10
10
|
Function ID: {function_id}
|
|
@@ -14,56 +14,60 @@ async def {function_name}(callback, options=None):
|
|
|
14
14
|
function_id = "{function_id}"
|
|
15
15
|
|
|
16
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
17
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"apiKey": api_key,
|
|
49
|
-
"waitForResponse": options.get("waitForResponse"),
|
|
50
|
-
}}
|
|
51
|
-
await socket.emit('registerWebhookEventHandler', data, namespace="/events", callback=registerCallback)
|
|
18
|
+
async def _inner():
|
|
19
|
+
socket = socketio.AsyncClient()
|
|
20
|
+
await socket.connect(base_url, transports=['websocket'], namespaces=['/events'])
|
|
52
21
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
22
|
+
def registerCallback(registered: bool):
|
|
23
|
+
nonlocal socket
|
|
24
|
+
if registered:
|
|
25
|
+
socket.on('handleWebhookEvent:{function_id}', handleEvent, namespace="/events")
|
|
26
|
+
else:
|
|
27
|
+
print("Could not set register webhook event handler for {function_id}")
|
|
57
28
|
|
|
58
|
-
|
|
29
|
+
async def handleEvent(data):
|
|
30
|
+
nonlocal api_key
|
|
31
|
+
nonlocal options
|
|
32
|
+
polyCustom = {{}}
|
|
33
|
+
resp = await callback(data.get("body"), data.get("headers"), data.get("params"), polyCustom)
|
|
34
|
+
if resp and options.get("waitForResponse"):
|
|
35
|
+
await socket.emit('setWebhookListenerResponse', {{
|
|
36
|
+
"webhookHandleID": function_id,
|
|
37
|
+
"apiKey": api_key,
|
|
38
|
+
"clientID": eventsClientId,
|
|
39
|
+
"executionId": data.get("executionId"),
|
|
40
|
+
"response": {{
|
|
41
|
+
"data": resp,
|
|
42
|
+
"statusCode": polyCustom.get("responseStatusCode", 200),
|
|
43
|
+
"contentType": polyCustom.get("responseContentType", None),
|
|
44
|
+
}},
|
|
45
|
+
}}, namespace="/events")
|
|
46
|
+
|
|
47
|
+
data = {{
|
|
59
48
|
"clientID": eventsClientId,
|
|
60
49
|
"webhookHandleID": function_id,
|
|
61
|
-
"apiKey": api_key
|
|
62
|
-
|
|
50
|
+
"apiKey": api_key,
|
|
51
|
+
"waitForResponse": options.get("waitForResponse"),
|
|
52
|
+
}}
|
|
53
|
+
await socket.emit('registerWebhookEventHandler', data, namespace="/events", callback=registerCallback)
|
|
54
|
+
|
|
55
|
+
async def closeEventHandler():
|
|
56
|
+
nonlocal socket
|
|
57
|
+
if not socket:
|
|
58
|
+
return
|
|
59
|
+
|
|
60
|
+
await socket.emit('unregisterWebhookEventHandler', {{
|
|
61
|
+
"clientID": eventsClientId,
|
|
62
|
+
"webhookHandleID": function_id,
|
|
63
|
+
"apiKey": api_key
|
|
64
|
+
}}, namespace="/events")
|
|
65
|
+
|
|
66
|
+
await socket.wait()
|
|
63
67
|
|
|
64
|
-
|
|
68
|
+
return closeEventHandler
|
|
65
69
|
|
|
66
|
-
return
|
|
70
|
+
return asyncio.run(inner())
|
|
67
71
|
"""
|
|
68
72
|
|
|
69
73
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
polyapi/__init__.py,sha256=VRAaN5WZPDmj7AnprtJ3szHXWlqWInKXBfEmfpyXTK8,434
|
|
2
2
|
polyapi/__main__.py,sha256=V4zhAh_YGxno5f_KSrlkELxcuDh9bR3WSd0n-2r-qQQ,93
|
|
3
3
|
polyapi/api.py,sha256=Pq_OT8egmtlzMjovN5GGZXWnF5oWMkrgR0rmrzJ6ifM,1861
|
|
4
|
-
polyapi/auth.py,sha256=
|
|
4
|
+
polyapi/auth.py,sha256=p2KSLt6q52t9gnqPmgXTOQ2_lmdFilZkIoGmQrRTPLQ,5330
|
|
5
5
|
polyapi/cli.py,sha256=wMv4RpNDEz2qIQ5NjlRTop-ImfeeqCSkx22ZIrzwA50,2086
|
|
6
6
|
polyapi/config.py,sha256=S8TU10upy5OW1_vX-CqQTJD-ZOB6329aMjiUCmukfUI,2292
|
|
7
7
|
polyapi/constants.py,sha256=NGjso6K5rGnE8TGdrXmdEfvvr-HI3DTVGwOYiWO68LM,511
|
|
@@ -15,9 +15,9 @@ polyapi/server.py,sha256=mcbH8pG16fFMiFL52wdii0217ZLsznQnElAFEvXZ7IA,2211
|
|
|
15
15
|
polyapi/typedefs.py,sha256=RZ3I6sgJm_5MuuORG1QjUE-UJy_z2WRXNdiWjEdLvQg,1371
|
|
16
16
|
polyapi/utils.py,sha256=wZQrwSOst5wyoYYLoMk1DnAEbVsJ0-2YkmmDQ9gI3FY,5399
|
|
17
17
|
polyapi/variables.py,sha256=d36-trnfTL_8m2NkorMiImb4O3UrJbiFV38CHxV5i0A,4200
|
|
18
|
-
polyapi/webhook.py,sha256=
|
|
19
|
-
polyapi_python-0.2.
|
|
20
|
-
polyapi_python-0.2.
|
|
21
|
-
polyapi_python-0.2.
|
|
22
|
-
polyapi_python-0.2.
|
|
23
|
-
polyapi_python-0.2.
|
|
18
|
+
polyapi/webhook.py,sha256=yHfcLjlr-zmlsM39AgBVLX2_MJOH10GRLxTb0JeWjrI,2914
|
|
19
|
+
polyapi_python-0.2.1.dev0.dist-info/LICENSE,sha256=Hi0kDr56Dsy0uYIwNt4r9G7tI8x8miXRTlyvbeplCP8,1068
|
|
20
|
+
polyapi_python-0.2.1.dev0.dist-info/METADATA,sha256=tjRWo5WiDU2UxkBkSdaWyW3fiaFfyGUFgdB2xPY_llI,4823
|
|
21
|
+
polyapi_python-0.2.1.dev0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
22
|
+
polyapi_python-0.2.1.dev0.dist-info/top_level.txt,sha256=CEFllOnzowci_50RYJac-M54KD2IdAptFsayVVF_f04,8
|
|
23
|
+
polyapi_python-0.2.1.dev0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|