reyserver 1.1.59__py3-none-any.whl → 1.1.60__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.
Potentially problematic release.
This version of reyserver might be problematic. Click here for more details.
- reyserver/radmin.py +46 -3
- reyserver/rauth.py +6 -5
- reyserver/rclient.py +61 -12
- {reyserver-1.1.59.dist-info → reyserver-1.1.60.dist-info}/METADATA +1 -1
- reyserver-1.1.60.dist-info/RECORD +12 -0
- reyserver-1.1.59.dist-info/RECORD +0 -12
- {reyserver-1.1.59.dist-info → reyserver-1.1.60.dist-info}/WHEEL +0 -0
- {reyserver-1.1.59.dist-info → reyserver-1.1.60.dist-info}/licenses/LICENSE +0 -0
reyserver/radmin.py
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
12
12
|
from typing import Any, Type
|
|
13
13
|
from collections.abc import Sequence
|
|
14
14
|
from sqlalchemy.ext.asyncio import async_sessionmaker
|
|
15
|
+
from fastapi import Request
|
|
15
16
|
from sqladmin import Admin, ModelView
|
|
17
|
+
from sqladmin.authentication import AuthenticationBackend
|
|
16
18
|
from reydb import DatabaseEngineAsync, rorm
|
|
17
19
|
from reykit.rbase import Singleton
|
|
18
20
|
|
|
@@ -23,11 +25,12 @@ from . import rserver
|
|
|
23
25
|
__all__ = (
|
|
24
26
|
'ServerAdminModel',
|
|
25
27
|
'ServerAdminModelView',
|
|
26
|
-
'ServerAdminModelViewStats'
|
|
28
|
+
'ServerAdminModelViewStats',
|
|
29
|
+
'ServerAdmin'
|
|
27
30
|
)
|
|
28
31
|
|
|
29
32
|
|
|
30
|
-
class ServerAdminModel(ModelView):
|
|
33
|
+
class ServerAdminModel(ServerBase, ModelView):
|
|
31
34
|
"""
|
|
32
35
|
Server admin model type.
|
|
33
36
|
"""
|
|
@@ -50,6 +53,40 @@ class ServerAdminModelViewStats(ServerAdminModelView):
|
|
|
50
53
|
column_list = ['item', 'value', 'comment']
|
|
51
54
|
|
|
52
55
|
|
|
56
|
+
# class ServerAdminAuthentication(ServerAdmin, AuthenticationBackend):
|
|
57
|
+
# """
|
|
58
|
+
# Server admin authentication type.
|
|
59
|
+
# """
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# async def authenticate(self, request: Request) -> bool:
|
|
63
|
+
# """
|
|
64
|
+
# Authenticate request.
|
|
65
|
+
|
|
66
|
+
# Parameters
|
|
67
|
+
# ----------
|
|
68
|
+
# request : Request.
|
|
69
|
+
# """
|
|
70
|
+
|
|
71
|
+
# #
|
|
72
|
+
# ...
|
|
73
|
+
# request.session['token']
|
|
74
|
+
# ...
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# async def login(self, request: Request) -> bool:
|
|
78
|
+
# form = await request.form()
|
|
79
|
+
# form['username']
|
|
80
|
+
# form['password']
|
|
81
|
+
# ...
|
|
82
|
+
# request.session['token'] = ...
|
|
83
|
+
# ...
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# async def logout(self, request: Request) -> None:
|
|
87
|
+
# request.session.clear()
|
|
88
|
+
|
|
89
|
+
|
|
53
90
|
class ServerAdmin(ServerBase, Singleton):
|
|
54
91
|
"""
|
|
55
92
|
Server admin type, singleton mode.
|
|
@@ -73,7 +110,13 @@ class ServerAdmin(ServerBase, Singleton):
|
|
|
73
110
|
'Admin API model bind database engine dictionary.'
|
|
74
111
|
Session = async_sessionmaker()
|
|
75
112
|
Session.configure(binds=self.api_admin_binds)
|
|
76
|
-
|
|
113
|
+
auth = self.__create_auth()
|
|
114
|
+
self.admin = Admin(
|
|
115
|
+
self.server.app,
|
|
116
|
+
session_maker=Session,
|
|
117
|
+
authentication_backend=auth
|
|
118
|
+
)
|
|
119
|
+
|
|
77
120
|
|
|
78
121
|
|
|
79
122
|
def add_model(
|
reyserver/rauth.py
CHANGED
|
@@ -415,6 +415,7 @@ async def depend_auth(
|
|
|
415
415
|
"""
|
|
416
416
|
|
|
417
417
|
# Check.
|
|
418
|
+
print(11111111111111111)
|
|
418
419
|
api_path = f'{request.method} {request.url.path}'
|
|
419
420
|
if (
|
|
420
421
|
not server.is_started_auth
|
|
@@ -429,14 +430,14 @@ async def depend_auth(
|
|
|
429
430
|
token = auth.credentials
|
|
430
431
|
|
|
431
432
|
# Decode.
|
|
432
|
-
|
|
433
|
-
if
|
|
433
|
+
json = decode_jwt(token, key)
|
|
434
|
+
if json is None:
|
|
434
435
|
exit_api(401)
|
|
435
|
-
|
|
436
|
-
request.state.
|
|
436
|
+
json: Token
|
|
437
|
+
request.state.user = json['user']
|
|
437
438
|
|
|
438
439
|
# Check.
|
|
439
|
-
perm_apis =
|
|
440
|
+
perm_apis = json['user']['perm_apis']
|
|
440
441
|
perm_apis = [
|
|
441
442
|
f'^{pattern}$'
|
|
442
443
|
for pattern in perm_apis
|
reyserver/rclient.py
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
from typing import TypedDict
|
|
12
|
+
from typing import TypedDict
|
|
13
13
|
from datetime import datetime as Datetime
|
|
14
|
+
from requests import Response
|
|
15
|
+
from reykit.rbase import copy_type_hints
|
|
14
16
|
from reykit.ros import File, Folder, overload
|
|
15
17
|
from reykit.rnet import join_url, request, get_response_file_name
|
|
16
18
|
|
|
@@ -31,31 +33,40 @@ class ServerClient(ServerBase):
|
|
|
31
33
|
"""
|
|
32
34
|
|
|
33
35
|
|
|
34
|
-
def __init__(
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
username: str,
|
|
39
|
+
password: str,
|
|
40
|
+
url: str = 'http://127.0.0.1:8000',
|
|
41
|
+
) -> None:
|
|
35
42
|
"""
|
|
36
43
|
Build instance attributes.
|
|
37
44
|
|
|
38
45
|
Parameters
|
|
39
46
|
----------
|
|
47
|
+
username: User name.
|
|
48
|
+
password: User password.
|
|
40
49
|
url : Server url.
|
|
41
50
|
"""
|
|
42
51
|
|
|
43
52
|
# Build.
|
|
53
|
+
self.username = username
|
|
54
|
+
self.password = password
|
|
44
55
|
self.url = url
|
|
56
|
+
self.token = self.create_session(username, password)
|
|
45
57
|
|
|
46
58
|
|
|
47
59
|
def create_session(
|
|
48
60
|
self,
|
|
49
|
-
|
|
50
|
-
password: str
|
|
51
|
-
account_type: Literal['name', 'email', 'phone'] = 'name'
|
|
61
|
+
username: str,
|
|
62
|
+
password: str
|
|
52
63
|
) -> str:
|
|
53
64
|
"""
|
|
54
65
|
Create session.
|
|
55
66
|
|
|
56
67
|
Parameters
|
|
57
68
|
----------
|
|
58
|
-
account : User
|
|
69
|
+
account : User name.
|
|
59
70
|
password : User password.
|
|
60
71
|
account_type : User account type.
|
|
61
72
|
|
|
@@ -67,9 +78,8 @@ class ServerClient(ServerBase):
|
|
|
67
78
|
# Parameter.
|
|
68
79
|
url = join_url(self.url, 'sessions')
|
|
69
80
|
json = {
|
|
70
|
-
'account':
|
|
71
|
-
'password': password
|
|
72
|
-
'account_type': account_type
|
|
81
|
+
'account': username,
|
|
82
|
+
'password': password
|
|
73
83
|
}
|
|
74
84
|
|
|
75
85
|
# Request.
|
|
@@ -80,6 +90,45 @@ class ServerClient(ServerBase):
|
|
|
80
90
|
return token
|
|
81
91
|
|
|
82
92
|
|
|
93
|
+
def _request(self, *args, **kwargs) -> Response:
|
|
94
|
+
"""
|
|
95
|
+
Send request.
|
|
96
|
+
|
|
97
|
+
Parameters
|
|
98
|
+
----------
|
|
99
|
+
args : Position arguments.
|
|
100
|
+
kwargs : Keyword arguments.
|
|
101
|
+
|
|
102
|
+
Returns
|
|
103
|
+
-------
|
|
104
|
+
Response.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
# Parameter.
|
|
108
|
+
headers = kwargs.setdefault('headers', {})
|
|
109
|
+
headers['Authorization'] = f'Bearer {self.token}'
|
|
110
|
+
kwargs['check'] = list(range(200, 400))
|
|
111
|
+
kwargs['check'].append(401)
|
|
112
|
+
|
|
113
|
+
# Request.
|
|
114
|
+
response = request(*args, **kwargs)
|
|
115
|
+
|
|
116
|
+
# Check.
|
|
117
|
+
if response.status_code != 401:
|
|
118
|
+
return response
|
|
119
|
+
|
|
120
|
+
# Try request.
|
|
121
|
+
self.token = self.create_session(self.username, self.password)
|
|
122
|
+
headers['Authorization'] = f'Bearer {self.token}'
|
|
123
|
+
kwargs['check'] = True
|
|
124
|
+
response = request(*args, **kwargs)
|
|
125
|
+
|
|
126
|
+
return response
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
request = copy_type_hints(_request, request)
|
|
130
|
+
|
|
131
|
+
|
|
83
132
|
def upload_file(
|
|
84
133
|
self,
|
|
85
134
|
source: str | bytes,
|
|
@@ -128,7 +177,7 @@ class ServerClient(ServerBase):
|
|
|
128
177
|
# Request.
|
|
129
178
|
data = {'name': file_name, 'note': note}
|
|
130
179
|
files = {'file': file_bytes}
|
|
131
|
-
response = request(url, data=data, files=files, check=True)
|
|
180
|
+
response = self.request(url, data=data, files=files, check=True)
|
|
132
181
|
|
|
133
182
|
## Extract.
|
|
134
183
|
response_json = response.json()
|
|
@@ -177,7 +226,7 @@ class ServerClient(ServerBase):
|
|
|
177
226
|
url = join_url(self.url, 'files', file_id, 'download')
|
|
178
227
|
|
|
179
228
|
# Request.
|
|
180
|
-
response = request(url, check=True)
|
|
229
|
+
response = self.request(url, check=True)
|
|
181
230
|
file_bytes = response.content
|
|
182
231
|
|
|
183
232
|
# Not save.
|
|
@@ -215,7 +264,7 @@ class ServerClient(ServerBase):
|
|
|
215
264
|
url = join_url(self.url, 'files', file_id)
|
|
216
265
|
|
|
217
266
|
# Request.
|
|
218
|
-
response = request(url, check=True)
|
|
267
|
+
response = self.request(url, check=True)
|
|
219
268
|
response_dict = response.json()
|
|
220
269
|
|
|
221
270
|
return response_dict
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
reyserver/__init__.py,sha256=Oq-lOcQInzhgKt1_4OB2jNx0OO2d9qZg9iZqUx6YRr8,398
|
|
2
|
+
reyserver/radmin.py,sha256=0nOEBd1vFDn0annjiGXi3TN9C6Vofpb8W_UfXj5TuhM,4257
|
|
3
|
+
reyserver/rall.py,sha256=MI1NnqUpq22CK9w3XPPBS0K8lNuf0BnbI0pn4MGMx38,293
|
|
4
|
+
reyserver/rauth.py,sha256=KgHWuRmqmxMoeNFCvCpdxb0S5uv7VH75M0vuMrZTOt8,15111
|
|
5
|
+
reyserver/rbase.py,sha256=kzSbo6yoPlWquR6XiseTKi5hEbllaG3qVmmwnnKKac0,6898
|
|
6
|
+
reyserver/rclient.py,sha256=VDUqQMVUTGzmZ8kjiMet2_zEt0_Siw0gyQkqHRIZ594,6281
|
|
7
|
+
reyserver/rfile.py,sha256=0wS-ohsAOGcSCg07U66wpqJlxnCLWN6gkEQJK4qavWQ,8877
|
|
8
|
+
reyserver/rserver.py,sha256=mjc-SeE2RZZwB5Z1nUSMo_VMign3VcftIK1Kv7XIne8,11484
|
|
9
|
+
reyserver-1.1.60.dist-info/METADATA,sha256=JuZnt-TPamZk_dtV07w4aEm6cT5fZa3Js146QUa6wNI,1666
|
|
10
|
+
reyserver-1.1.60.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
11
|
+
reyserver-1.1.60.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
|
12
|
+
reyserver-1.1.60.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
reyserver/__init__.py,sha256=Oq-lOcQInzhgKt1_4OB2jNx0OO2d9qZg9iZqUx6YRr8,398
|
|
2
|
-
reyserver/radmin.py,sha256=Hwy8QsiQOyK2YP7abcS22IbRKB7sgcDGPHQ2-mHtf-8,3269
|
|
3
|
-
reyserver/rall.py,sha256=MI1NnqUpq22CK9w3XPPBS0K8lNuf0BnbI0pn4MGMx38,293
|
|
4
|
-
reyserver/rauth.py,sha256=irnwf1_OSOjB9fB7VBWY5RvpetPX2ydivMt_teXmDVs,15079
|
|
5
|
-
reyserver/rbase.py,sha256=kzSbo6yoPlWquR6XiseTKi5hEbllaG3qVmmwnnKKac0,6898
|
|
6
|
-
reyserver/rclient.py,sha256=Ffm66YuWupzEtQ6RqEm2KCc6jSF8JeMB7Xq6pzRFZ6M,5073
|
|
7
|
-
reyserver/rfile.py,sha256=0wS-ohsAOGcSCg07U66wpqJlxnCLWN6gkEQJK4qavWQ,8877
|
|
8
|
-
reyserver/rserver.py,sha256=mjc-SeE2RZZwB5Z1nUSMo_VMign3VcftIK1Kv7XIne8,11484
|
|
9
|
-
reyserver-1.1.59.dist-info/METADATA,sha256=oJNACNqqErBtx9jcDkkGRQoTyDaFT-T5tnfbEkVm-6E,1666
|
|
10
|
-
reyserver-1.1.59.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
11
|
-
reyserver-1.1.59.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
|
12
|
-
reyserver-1.1.59.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|