fusio-worker-runtime 0.1.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Apioo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.1
2
+ Name: fusio-worker-runtime
3
+ Version: 0.1.1
4
+ Summary: Fusio worker Python runtime
5
+ Author-email: Christoph Kappestein <christoph.kappestein@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/apioo/fusio-worker-python-runtime
8
+ Project-URL: Issues, https://github.com/apioo/fusio-worker-python-runtime/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Software Development :: Code Generators
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: httpx>=0.27
17
+ Requires-Dist: pydantic>=2.7.0
18
+ Requires-Dist: PyMySQL>=1.0
19
+ Requires-Dist: psycopg2>=2.9
20
+ Requires-Dist: pymongo>=3.12
21
+ Requires-Dist: elasticsearch>=7.15
22
+
23
+
24
+ # Fusio-Worker-Python-Runtime
25
+
26
+ This library provides the Fusio worker Python runtime.
@@ -0,0 +1,4 @@
1
+
2
+ # Fusio-Worker-Python-Runtime
3
+
4
+ This library provides the Fusio worker Python runtime.
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "fusio-worker-runtime"
3
+ version = "0.1.1"
4
+ authors = [
5
+ { name="Christoph Kappestein", email="christoph.kappestein@gmail.com" },
6
+ ]
7
+ description = "Fusio worker Python runtime"
8
+ readme = "README.md"
9
+ requires-python = ">=3.8"
10
+ license = {text = "MIT"}
11
+ classifiers = [
12
+ "Programming Language :: Python :: 3",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Operating System :: OS Independent",
15
+ "Topic :: Software Development :: Code Generators",
16
+ ]
17
+ dependencies = [
18
+ "httpx >= 0.27",
19
+ "pydantic >= 2.7.0",
20
+ "PyMySQL >= 1.0",
21
+ "psycopg2 >= 2.9",
22
+ "pymongo >= 3.12",
23
+ "elasticsearch >= 7.15"
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/apioo/fusio-worker-python-runtime"
28
+ Issues = "https://github.com/apioo/fusio-worker-python-runtime/issues"
29
+
30
+ [build-system]
31
+ requires = ["setuptools>=61.0"]
32
+ build-backend = "setuptools.build_meta"
33
+
34
+ [tool.setuptools]
35
+ packages = ["runtime"]
36
+ package-dir = {"" = "src"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from setuptools import setup
2
+
3
+ setup()
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.1
2
+ Name: fusio-worker-runtime
3
+ Version: 0.1.1
4
+ Summary: Fusio worker Python runtime
5
+ Author-email: Christoph Kappestein <christoph.kappestein@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/apioo/fusio-worker-python-runtime
8
+ Project-URL: Issues, https://github.com/apioo/fusio-worker-python-runtime/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Topic :: Software Development :: Code Generators
13
+ Requires-Python: >=3.8
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: httpx>=0.27
17
+ Requires-Dist: pydantic>=2.7.0
18
+ Requires-Dist: PyMySQL>=1.0
19
+ Requires-Dist: psycopg2>=2.9
20
+ Requires-Dist: pymongo>=3.12
21
+ Requires-Dist: elasticsearch>=7.15
22
+
23
+
24
+ # Fusio-Worker-Python-Runtime
25
+
26
+ This library provides the Fusio worker Python runtime.
@@ -0,0 +1,10 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ src/fusio_worker_runtime.egg-info/PKG-INFO
6
+ src/fusio_worker_runtime.egg-info/SOURCES.txt
7
+ src/fusio_worker_runtime.egg-info/dependency_links.txt
8
+ src/fusio_worker_runtime.egg-info/requires.txt
9
+ src/fusio_worker_runtime.egg-info/top_level.txt
10
+ src/runtime/runtime.py
@@ -0,0 +1,6 @@
1
+ httpx>=0.27
2
+ pydantic>=2.7.0
3
+ PyMySQL>=1.0
4
+ psycopg2>=2.9
5
+ pymongo>=3.12
6
+ elasticsearch>=7.15
@@ -0,0 +1,182 @@
1
+ import base64
2
+ import importlib
3
+ import json
4
+ from typing import Dict
5
+
6
+ import httpx
7
+ import psycopg2
8
+ import pymysql.cursors
9
+ from elasticsearch import Elasticsearch
10
+ from pymongo import MongoClient
11
+
12
+ from generated.about import About
13
+ from generated.execute import Execute
14
+ from generated.execute_connection import ExecuteConnection
15
+ from generated.response import Response
16
+ from generated.response_event import ResponseEvent
17
+ from generated.response_http import ResponseHTTP
18
+ from generated.response_log import ResponseLog
19
+
20
+
21
+ class Runtime:
22
+ def get(self):
23
+ about = About()
24
+ about.api_version = "1.0.0"
25
+ about.language = "python"
26
+ return about
27
+
28
+ def run(self, action: str, execute: Execute):
29
+ connector = Connector(execute.connections)
30
+ dispatcher = Dispatcher()
31
+ logger = Logger()
32
+ response_builder = ResponseBuilder()
33
+
34
+ module = importlib.import_module(action, package=__name__)
35
+
36
+ module.handle(execute.request, execute.context, connector, response_builder, dispatcher, logger)
37
+
38
+ response = response_builder.get_response()
39
+ if not response:
40
+ response = ResponseHTTP()
41
+ response.status_code = 204
42
+
43
+ result = Response()
44
+ result.response = response
45
+ result.events = dispatcher.get_events()
46
+ result.logs = logger.get_logs()
47
+ return result
48
+
49
+
50
+ class Connector:
51
+ def __init__(self, configs: Dict[str, ExecuteConnection]):
52
+ self.configs = configs
53
+ self.connections = {}
54
+
55
+ def get_connection(self, name):
56
+ if name in self.connections.keys():
57
+ return self.connections[name]
58
+
59
+ if name not in self.configs.keys():
60
+ raise Exception("Provided connection is not configured")
61
+
62
+ connection = self.configs[name]
63
+ config = json.loads(base64.b64decode(connection.config))
64
+
65
+ if connection.type == "Fusio.Adapter.Sql.Connection.Sql":
66
+ if config['type'] == "pdo_mysql":
67
+ con = pymysql.connect(
68
+ host=config['host'],
69
+ user=config['username'],
70
+ password=config['password'],
71
+ database=config['database']
72
+ )
73
+ elif config['type'] == "pdo_pgsql":
74
+ con = psycopg2.connect(
75
+ host=config['host'],
76
+ database=config['database'],
77
+ user=config['username'],
78
+ password=config['password']
79
+ )
80
+ else:
81
+ raise Exception("SQL type is not supported")
82
+
83
+ self.connections[name] = con
84
+
85
+ return con
86
+ elif connection.type == "Fusio.Adapter.Sql.Connection.SqlAdvanced":
87
+ # TODO
88
+
89
+ return None
90
+ elif connection.type == "Fusio.Adapter.Http.Connection.Http":
91
+ client = httpx.Client(base_url=config['url'])
92
+
93
+ # @TODO configure proxy for http client
94
+ # config['username']
95
+ # config['password']
96
+ # config['proxy']
97
+
98
+ self.connections[name] = client
99
+
100
+ return client
101
+ elif connection.type == "Fusio.Adapter.Mongodb.Connection.MongoDB":
102
+ client = MongoClient(config['url'])
103
+ database = client[config['database']]
104
+
105
+ self.connections[name] = database
106
+
107
+ return database
108
+ elif connection.type == "Fusio.Adapter.Elasticsearch.Connection.Elasticsearch":
109
+ host = config['host']
110
+ client = Elasticsearch(host.split(','))
111
+
112
+ self.connections[name] = client
113
+
114
+ return client
115
+ else:
116
+ raise Exception("Provided a not supported connection type")
117
+
118
+
119
+ class Dispatcher:
120
+ def __init__(self):
121
+ self.events = []
122
+
123
+ def dispatch(self, event_name, data):
124
+ event = ResponseEvent()
125
+ event.event_name = event_name
126
+ event.data = data
127
+ self.events.append(event)
128
+
129
+ def get_events(self):
130
+ return self.events
131
+
132
+
133
+ class Logger:
134
+ def __init__(self):
135
+ self.logs = []
136
+
137
+ def emergency(self, message):
138
+ self.log("EMERGENCY", message)
139
+
140
+ def alert(self, message):
141
+ self.log("ALERT", message)
142
+
143
+ def critical(self, message):
144
+ self.log("CRITICAL", message)
145
+
146
+ def error(self, message):
147
+ self.log("ERROR", message)
148
+
149
+ def warning(self, message):
150
+ self.log("WARNING", message)
151
+
152
+ def notice(self, message):
153
+ self.log("NOTICE", message)
154
+
155
+ def info(self, message):
156
+ self.log("INFO", message)
157
+
158
+ def debug(self, message):
159
+ self.log("DEBUG", message)
160
+
161
+ def log(self, level, message):
162
+ log = ResponseLog()
163
+ log.level = level
164
+ log.message = message
165
+ self.logs.append(log)
166
+
167
+ def get_logs(self):
168
+ return self.logs
169
+
170
+
171
+ class ResponseBuilder:
172
+ def __init__(self):
173
+ self.response = None
174
+
175
+ def build(self, status_code, headers, body):
176
+ self.response = ResponseHTTP()
177
+ self.response.status_code = status_code
178
+ self.response.headers = headers
179
+ self.response.body = body
180
+
181
+ def get_response(self):
182
+ return self.response