fire-rpc 0.0.1.dev0__tar.gz → 0.1.0__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.
- {fire_rpc-0.0.1.dev0 → fire_rpc-0.1.0}/PKG-INFO +4 -4
- fire_rpc-0.1.0/fire_rpc/__init__.py +35 -0
- fire_rpc-0.1.0/fire_rpc/__main__.py +6 -0
- {fire_rpc-0.0.1.dev0 → fire_rpc-0.1.0}/pyproject.toml +4 -3
- fire_rpc-0.0.1.dev0/fire_rpc/__init__.py +0 -0
- {fire_rpc-0.0.1.dev0 → fire_rpc-0.1.0}/LICENSE +0 -0
- {fire_rpc-0.0.1.dev0 → fire_rpc-0.1.0}/README.md +0 -0
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: fire-rpc
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: turn fire command line to a rpc server
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: weihong.xu
|
|
7
7
|
Author-email: xuweihong.cn@gmail.com
|
|
8
|
-
Requires-Python: >=3.
|
|
8
|
+
Requires-Python: >=3.9,<4.0
|
|
9
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
10
|
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
12
11
|
Classifier: Programming Language :: Python :: 3.9
|
|
13
12
|
Classifier: Programming Language :: Python :: 3.10
|
|
14
13
|
Classifier: Programming Language :: Python :: 3.11
|
|
15
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Dist: aiohttp (>=3.11.12,<4.0.0)
|
|
16
16
|
Requires-Dist: fire (>=0.5.0,<0.6.0)
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from aiohttp import web
|
|
2
|
+
import asyncio
|
|
3
|
+
import fire
|
|
4
|
+
import json
|
|
5
|
+
|
|
6
|
+
def make_rpc_server(base_url: str, cmd_entry, secret = None,
|
|
7
|
+
auth_header='X-Auth-Token', json_dumps=json.dumps):
|
|
8
|
+
async def handler(request: web.Request) -> web.Response:
|
|
9
|
+
try:
|
|
10
|
+
if secret is not None:
|
|
11
|
+
auth_token = request.headers.get(auth_header)
|
|
12
|
+
if auth_token != secret:
|
|
13
|
+
return web.json_response({'error': 'unauthorized'}, status=401)
|
|
14
|
+
data = await request.json()
|
|
15
|
+
args = data.get('args')
|
|
16
|
+
if args is None:
|
|
17
|
+
return web.json_response({'error': 'args not found'}, status=400)
|
|
18
|
+
if not isinstance(args, list):
|
|
19
|
+
return web.json_response({'error': 'args must be a list'}, status=400)
|
|
20
|
+
ret = fire.Fire(cmd_entry, args)
|
|
21
|
+
res = {'result': ret}
|
|
22
|
+
return web.json_response(res, dumps=json_dumps)
|
|
23
|
+
|
|
24
|
+
except (Exception, SystemExit) as e:
|
|
25
|
+
return web.json_response({'error': str(e)}, status=400)
|
|
26
|
+
|
|
27
|
+
app = web.Application()
|
|
28
|
+
app.add_routes([web.post(base_url, handler)])
|
|
29
|
+
return app
|
|
30
|
+
|
|
31
|
+
def start_rpc_server(base_url: str, cmd_entry, secret=None, json_dumps=json.dumps,
|
|
32
|
+
host='localhost', port=8000, auth_header='X-Auth-Token'):
|
|
33
|
+
loop = asyncio.new_event_loop()
|
|
34
|
+
app = make_rpc_server(base_url, cmd_entry, secret=secret, auth_header=auth_header, json_dumps=json_dumps)
|
|
35
|
+
web.run_app(app, loop=loop, host=host, port=port)
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "fire-rpc"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = ""
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "turn fire command line to a rpc server"
|
|
5
5
|
authors = ["weihong.xu <xuweihong.cn@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
7
7
|
readme = "README.md"
|
|
8
8
|
|
|
9
9
|
[tool.poetry.dependencies]
|
|
10
|
-
python = "^3.
|
|
10
|
+
python = "^3.9"
|
|
11
11
|
fire = "^0.5.0"
|
|
12
|
+
aiohttp = "^3.11.12"
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
[build-system]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|