zrb 1.0.0a20__py3-none-any.whl → 1.0.0b1__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.
- zrb/__init__.py +2 -1
- zrb/builtin/llm/llm_chat.py +2 -2
- zrb/builtin/llm/tool/web.py +1 -1
- zrb/builtin/project/add/fastapp/fastapp_task.py +2 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/config.py +4 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +16 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +91 -9
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/{my_entity_usecase.py → my_entity_service.py} +7 -13
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/my_entity_service_factory.py +8 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/gateway_subroute.py +37 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/format_task.py +1 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/input.py +13 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +22 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +42 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/gateway/subroute/my_module.py +7 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/api_client.py +1 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/direct_client.py +1 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/factory.py +3 -3
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/route.py +10 -10
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/task.py +4 -4
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/app.py +42 -5
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/{base_usecase.py → base_service.py} +3 -3
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/common/view.py +37 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/config.py +24 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/api_client.py +2 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/direct_client.py +2 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/route.py +2 -2
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/{user_usecase.py → user_service.py} +7 -7
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_service_factory.py +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/route.py +42 -13
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/util/view.py +74 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/error.html +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/content/homepage.html +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/images/android-chrome-192x192.png +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/images/android-chrome-512x512.png +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/images/favicon-32x32.png +0 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.amber.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.blue.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.cyan.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.fuchsia.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.green.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.grey.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.indigo.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.jade.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.lime.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.orange.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.pink.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.pumpkin.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.purple.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.red.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.sand.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.slate.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.violet.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.yellow.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/static/pico-css/pico.zinc.min.css +4 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/view/template/default.html +34 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/requirements.txt +1 -0
- zrb/builtin/python.py +1 -1
- zrb/config.py +2 -2
- zrb/content_transformer/any_content_transformer.py +7 -0
- zrb/content_transformer/content_transformer.py +6 -0
- zrb/runner/cli.py +4 -6
- zrb/runner/web_app.py +28 -238
- zrb/runner/web_config/config.py +91 -0
- zrb/runner/web_config/config_factory.py +26 -0
- zrb/runner/web_route/docs_route.py +17 -0
- zrb/runner/web_route/error_page/serve_default_404.py +28 -0
- zrb/runner/{web_controller/error_page/controller.py → web_route/error_page/show_error_page.py} +2 -2
- zrb/runner/{web_controller → web_route}/error_page/view.html +6 -0
- zrb/runner/web_route/home_page/home_page_route.py +51 -0
- zrb/runner/{web_controller → web_route}/home_page/view.html +1 -0
- zrb/runner/web_route/login_api_route.py +31 -0
- zrb/runner/web_route/login_page/login_page_route.py +39 -0
- zrb/runner/{web_controller → web_route}/login_page/view.html +1 -0
- zrb/runner/web_route/logout_api_route.py +18 -0
- zrb/runner/web_route/logout_page/logout_page_route.py +40 -0
- zrb/runner/{web_controller → web_route}/logout_page/view.html +1 -0
- zrb/runner/{web_controller/group_info_page/controller.py → web_route/node_page/group/show_group_page.py} +3 -3
- zrb/runner/{web_controller/group_info_page → web_route/node_page/group}/view.html +1 -0
- zrb/runner/web_route/node_page/node_page_route.py +50 -0
- zrb/runner/{web_controller/session_page/controller.py → web_route/node_page/task/show_task_page.py} +5 -5
- zrb/runner/{web_controller/session_page → web_route/node_page/task}/view.html +1 -0
- zrb/runner/web_route/refresh_token_api_route.py +38 -0
- zrb/runner/web_route/static/refresh-token.template.js +22 -0
- zrb/runner/{web_controller/static → web_route/static/resources}/session/current-session.js +1 -1
- zrb/runner/{web_controller/static → web_route/static/resources}/session/event.js +5 -6
- zrb/runner/{web_controller/static → web_route/static/resources}/session/past-session.js +9 -3
- zrb/runner/web_route/static/static_route.py +44 -0
- zrb/runner/web_route/task_input_api_route.py +47 -0
- zrb/runner/web_route/task_session_api_route.py +102 -0
- zrb/runner/web_schema/session.py +5 -0
- zrb/runner/web_schema/token.py +11 -0
- zrb/runner/web_schema/user.py +32 -0
- zrb/runner/web_util/cookie.py +29 -0
- zrb/runner/{web_util.py → web_util/html.py} +1 -18
- zrb/runner/web_util/token.py +68 -0
- zrb/runner/web_util/user.py +63 -0
- zrb/session/session.py +6 -4
- zrb/session_state_logger/{default_session_state_logger.py → session_state_logger_factory.py} +1 -1
- zrb/task/base_task.py +29 -4
- zrb/task/base_trigger.py +2 -0
- zrb/task/cmd_task.py +2 -0
- zrb/task/http_check.py +2 -0
- zrb/task/llm_task.py +2 -0
- zrb/task/make_task.py +2 -0
- zrb/task/rsync_task.py +2 -0
- zrb/task/scaffolder.py +8 -5
- zrb/task/scheduler.py +2 -0
- zrb/task/tcp_check.py +2 -0
- zrb/task_status/task_status.py +4 -3
- {zrb-1.0.0a20.dist-info → zrb-1.0.0b1.dist-info}/METADATA +8 -52
- {zrb-1.0.0a20.dist-info → zrb-1.0.0b1.dist-info}/RECORD +126 -81
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_usecase_factory.py +0 -6
- zrb/runner/web_config.py +0 -288
- zrb/runner/web_controller/home_page/__init__.py +0 -0
- zrb/runner/web_controller/home_page/controller.py +0 -33
- zrb/runner/web_controller/login_page/controller.py +0 -25
- zrb/runner/web_controller/logout_page/controller.py +0 -26
- zrb/runner/web_controller/session_page/__init__.py +0 -0
- /zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/{create_column_task.py → add_column_task.py} +0 -0
- /zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/{factory.py → my_entity_repository_factory.py} +0 -0
- /zrb/runner/{web_controller → web_route}/__init__.py +0 -0
- /zrb/runner/{web_controller/group_info_page → web_route/home_page}/__init__.py +0 -0
- /zrb/runner/{web_controller/session_page → web_route/node_page/task}/partial/input.html +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/common.css +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/favicon-32x32.png +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/login/event.js +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/logout/event.js +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/pico.min.css +0 -0
- /zrb/runner/{web_controller/static → web_route/static/resources}/session/common-util.js +0 -0
- {zrb-1.0.0a20.dist-info → zrb-1.0.0b1.dist-info}/WHEEL +0 -0
- {zrb-1.0.0a20.dist-info → zrb-1.0.0b1.dist-info}/entry_points.txt +0 -0
zrb/runner/web_config.py
DELETED
@@ -1,288 +0,0 @@
|
|
1
|
-
from datetime import datetime, timedelta
|
2
|
-
from typing import TYPE_CHECKING, Callable
|
3
|
-
|
4
|
-
from pydantic import BaseModel, ConfigDict
|
5
|
-
|
6
|
-
from zrb.config import (
|
7
|
-
WEB_ACCESS_TOKEN_COOKIE_NAME,
|
8
|
-
WEB_AUTH_ACCESS_TOKEN_EXPIRE_MINUTES,
|
9
|
-
WEB_AUTH_REFRESH_TOKEN_EXPIRE_MINUTES,
|
10
|
-
WEB_ENABLE_AUTH,
|
11
|
-
WEB_GUEST_USERNAME,
|
12
|
-
WEB_HTTP_PORT,
|
13
|
-
WEB_REFRESH_TOKEN_COOKIE_NAME,
|
14
|
-
WEB_SECRET_KEY,
|
15
|
-
WEB_SUPER_ADMIN_PASSWORD,
|
16
|
-
WEB_SUPER_ADMIN_USERNAME,
|
17
|
-
)
|
18
|
-
from zrb.group.any_group import AnyGroup
|
19
|
-
from zrb.task.any_task import AnyTask
|
20
|
-
from zrb.util.group import get_all_subtasks
|
21
|
-
|
22
|
-
if TYPE_CHECKING:
|
23
|
-
# Import Request only for type checking to reduce runtime dependencies
|
24
|
-
from fastapi import Request
|
25
|
-
|
26
|
-
|
27
|
-
class User(BaseModel):
|
28
|
-
model_config = ConfigDict(arbitrary_types_allowed=True)
|
29
|
-
username: str
|
30
|
-
password: str = ""
|
31
|
-
is_super_admin: bool = False
|
32
|
-
is_guest: bool = False
|
33
|
-
accessible_tasks: list[AnyTask | str] = []
|
34
|
-
|
35
|
-
def is_password_match(self, password: str) -> bool:
|
36
|
-
return self.password == password
|
37
|
-
|
38
|
-
def can_access_group(self, group: AnyGroup) -> bool:
|
39
|
-
if self.is_super_admin:
|
40
|
-
return True
|
41
|
-
all_tasks = get_all_subtasks(group, web_only=True)
|
42
|
-
if any(self.can_access_task(task) for task in all_tasks):
|
43
|
-
return True
|
44
|
-
return False
|
45
|
-
|
46
|
-
def can_access_task(self, task: AnyTask) -> bool:
|
47
|
-
if self.is_super_admin:
|
48
|
-
return True
|
49
|
-
if task.name in self.accessible_tasks or task in self.accessible_tasks:
|
50
|
-
return True
|
51
|
-
return False
|
52
|
-
|
53
|
-
|
54
|
-
class Token(BaseModel):
|
55
|
-
access_token: str
|
56
|
-
refresh_token: str
|
57
|
-
token_type: str
|
58
|
-
|
59
|
-
|
60
|
-
class WebConfig:
|
61
|
-
def __init__(
|
62
|
-
self,
|
63
|
-
port: int,
|
64
|
-
secret_key: str,
|
65
|
-
access_token_expire_minutes: int,
|
66
|
-
refresh_token_expire_minutes: int,
|
67
|
-
access_token_cookie_name: str,
|
68
|
-
refresh_token_cookie_name: str,
|
69
|
-
enable_auth: bool,
|
70
|
-
super_admin_username: str,
|
71
|
-
super_admin_password: str,
|
72
|
-
guest_username: str,
|
73
|
-
guest_accessible_tasks: list[AnyTask | str] = [],
|
74
|
-
find_user_by_username: Callable[[str], User | None] | None = None,
|
75
|
-
):
|
76
|
-
self._secret_key = secret_key
|
77
|
-
self._access_token_expire_minutes = access_token_expire_minutes
|
78
|
-
self._refresh_token_expire_minutes = refresh_token_expire_minutes
|
79
|
-
self._access_token_cookie_name = access_token_cookie_name
|
80
|
-
self._refresh_token_cookie_name = refresh_token_cookie_name
|
81
|
-
self._enable_auth = enable_auth
|
82
|
-
self._port = port
|
83
|
-
self._user_list = []
|
84
|
-
self._super_admin_username = super_admin_username
|
85
|
-
self._super_admin_password = super_admin_password
|
86
|
-
self._guest_username = guest_username
|
87
|
-
self._guest_accessible_tasks = guest_accessible_tasks
|
88
|
-
self._find_user_by_username = find_user_by_username
|
89
|
-
|
90
|
-
@property
|
91
|
-
def port(self) -> int:
|
92
|
-
return self._port
|
93
|
-
|
94
|
-
@property
|
95
|
-
def access_token_cookie_name(self) -> str:
|
96
|
-
return self._access_token_cookie_name
|
97
|
-
|
98
|
-
@property
|
99
|
-
def refresh_token_cookie_name(self) -> str:
|
100
|
-
return self._refresh_token_cookie_name
|
101
|
-
|
102
|
-
@property
|
103
|
-
def access_token_max_age(self) -> int:
|
104
|
-
self._access_token_expire_minutes * 60
|
105
|
-
|
106
|
-
@property
|
107
|
-
def refresh_token_max_age(self) -> int:
|
108
|
-
self._refresh_token_expire_minutes * 60
|
109
|
-
|
110
|
-
@property
|
111
|
-
def default_user(self) -> User:
|
112
|
-
if self._enable_auth:
|
113
|
-
return User(
|
114
|
-
username=self._guest_username,
|
115
|
-
password="",
|
116
|
-
is_guest=True,
|
117
|
-
accessible_tasks=self._guest_accessible_tasks,
|
118
|
-
)
|
119
|
-
return User(
|
120
|
-
username=self._guest_username,
|
121
|
-
password="",
|
122
|
-
is_guest=True,
|
123
|
-
is_super_admin=True,
|
124
|
-
)
|
125
|
-
|
126
|
-
@property
|
127
|
-
def super_admin(self) -> User:
|
128
|
-
return User(
|
129
|
-
username=self._super_admin_username,
|
130
|
-
password=self._super_admin_password,
|
131
|
-
is_super_admin=True,
|
132
|
-
)
|
133
|
-
|
134
|
-
@property
|
135
|
-
def user_list(self) -> list[User]:
|
136
|
-
if not self._enable_auth:
|
137
|
-
return [self.default_user]
|
138
|
-
return self._user_list + [self.super_admin, self.default_user]
|
139
|
-
|
140
|
-
def set_guest_accessible_tasks(self, tasks: list[AnyTask | str]):
|
141
|
-
self._guest_accessible_tasks = tasks
|
142
|
-
|
143
|
-
def set_find_user_by_username(
|
144
|
-
self, find_user_by_username: Callable[[str], User | None]
|
145
|
-
):
|
146
|
-
self._find_user_by_username = find_user_by_username
|
147
|
-
|
148
|
-
def append_user(self, user: User):
|
149
|
-
duplicates = [
|
150
|
-
existing_user
|
151
|
-
for existing_user in self.user_list
|
152
|
-
if existing_user.username == user.username
|
153
|
-
]
|
154
|
-
if len(duplicates) > 0:
|
155
|
-
raise ValueError(f"User already exists {user.username}")
|
156
|
-
self._user_list.append(user)
|
157
|
-
|
158
|
-
def enable_auth(self):
|
159
|
-
self._enable_auth = True
|
160
|
-
|
161
|
-
def disable_auth(self):
|
162
|
-
self._enable_auth = False
|
163
|
-
|
164
|
-
def find_user_by_username(self, username: str) -> User | None:
|
165
|
-
user = None
|
166
|
-
if self._find_user_by_username is not None:
|
167
|
-
user = self._find_user_by_username(username)
|
168
|
-
if user is None:
|
169
|
-
user = next((u for u in self.user_list if u.username == username), None)
|
170
|
-
return user
|
171
|
-
|
172
|
-
async def get_user_by_request(self, request: "Request") -> User | None:
|
173
|
-
from fastapi.security import OAuth2PasswordBearer
|
174
|
-
|
175
|
-
if not self._enable_auth:
|
176
|
-
return self.default_user
|
177
|
-
# Normally we use "Depends"
|
178
|
-
get_bearer_token = OAuth2PasswordBearer(
|
179
|
-
tokenUrl="/api/v1/login", auto_error=False
|
180
|
-
)
|
181
|
-
bearer_token = await get_bearer_token(request)
|
182
|
-
token_user = self._get_user_from_token(bearer_token)
|
183
|
-
if token_user is not None:
|
184
|
-
return token_user
|
185
|
-
cookie_user = self._get_user_from_cookie(request)
|
186
|
-
if cookie_user is not None:
|
187
|
-
return cookie_user
|
188
|
-
return self.default_user
|
189
|
-
|
190
|
-
def _get_user_from_token(self, token: str) -> User | None:
|
191
|
-
try:
|
192
|
-
from jose import jwt
|
193
|
-
|
194
|
-
payload = jwt.decode(
|
195
|
-
token,
|
196
|
-
self._secret_key,
|
197
|
-
options={"require_sub": True, "require_exp": True},
|
198
|
-
)
|
199
|
-
username: str = payload.get("sub")
|
200
|
-
if username is None:
|
201
|
-
return None
|
202
|
-
user = self.find_user_by_username(username)
|
203
|
-
if user is None:
|
204
|
-
return None
|
205
|
-
return user
|
206
|
-
except Exception:
|
207
|
-
return None
|
208
|
-
|
209
|
-
def _get_user_from_cookie(self, request: "Request") -> User | None:
|
210
|
-
token = request.cookies.get(self._access_token_cookie_name)
|
211
|
-
if token:
|
212
|
-
return self._get_user_from_token(token)
|
213
|
-
return None
|
214
|
-
|
215
|
-
def get_user_by_credentials(self, username: str, password: str) -> User:
|
216
|
-
user = self.find_user_by_username(username)
|
217
|
-
if user is None or not user.is_password_match(password):
|
218
|
-
return self.default_user
|
219
|
-
return user
|
220
|
-
|
221
|
-
def generate_tokens(self, username: str, password: str) -> Token:
|
222
|
-
if not self._enable_auth:
|
223
|
-
user = self.default_user
|
224
|
-
else:
|
225
|
-
user = self.get_user_by_credentials(username, password)
|
226
|
-
access_token = self.create_access_token(user.username)
|
227
|
-
refresh_token = self.create_refresh_token(user.username)
|
228
|
-
return Token(
|
229
|
-
access_token=access_token, refresh_token=refresh_token, token_type="bearer"
|
230
|
-
)
|
231
|
-
|
232
|
-
def create_access_token(self, username: str) -> str:
|
233
|
-
from jose import jwt
|
234
|
-
|
235
|
-
expire = datetime.now() + timedelta(minutes=self._access_token_expire_minutes)
|
236
|
-
to_encode = {"sub": username, "exp": expire, "type": "access"}
|
237
|
-
return jwt.encode(to_encode, self._secret_key)
|
238
|
-
|
239
|
-
def create_refresh_token(self, username: str) -> str:
|
240
|
-
from jose import jwt
|
241
|
-
|
242
|
-
expire = datetime.now() + timedelta(minutes=self._refresh_token_expire_minutes)
|
243
|
-
to_encode = {"sub": username, "exp": expire, "type": "refresh"}
|
244
|
-
return jwt.encode(to_encode, self._secret_key)
|
245
|
-
|
246
|
-
def refresh_tokens(self, refresh_token: str) -> Token:
|
247
|
-
from fastapi import HTTPException
|
248
|
-
from jose import jwt
|
249
|
-
|
250
|
-
# Decode and validate token
|
251
|
-
try:
|
252
|
-
payload = jwt.decode(
|
253
|
-
refresh_token,
|
254
|
-
self._secret_key,
|
255
|
-
options={"require_exp": True, "require_sub": True},
|
256
|
-
)
|
257
|
-
except Exception:
|
258
|
-
raise HTTPException(status_code=401, detail="Invalid JWT token")
|
259
|
-
if payload.get("type") != "refresh":
|
260
|
-
raise HTTPException(status_code=401, detail="Invalid token type")
|
261
|
-
username: str = payload.get("sub")
|
262
|
-
if username is None:
|
263
|
-
raise HTTPException(status_code=401, detail="Invalid refresh token")
|
264
|
-
user = self.find_user_by_username(username)
|
265
|
-
if user is None:
|
266
|
-
raise HTTPException(status_code=401, detail="User not found")
|
267
|
-
# Create new token
|
268
|
-
new_access_token = self.create_access_token(username)
|
269
|
-
new_refresh_token = self.create_refresh_token(username)
|
270
|
-
return Token(
|
271
|
-
access_token=new_access_token,
|
272
|
-
refresh_token=new_refresh_token,
|
273
|
-
token_type="bearer",
|
274
|
-
)
|
275
|
-
|
276
|
-
|
277
|
-
web_config = WebConfig(
|
278
|
-
port=WEB_HTTP_PORT,
|
279
|
-
secret_key=WEB_SECRET_KEY,
|
280
|
-
access_token_expire_minutes=WEB_AUTH_ACCESS_TOKEN_EXPIRE_MINUTES,
|
281
|
-
refresh_token_expire_minutes=WEB_AUTH_REFRESH_TOKEN_EXPIRE_MINUTES,
|
282
|
-
access_token_cookie_name=WEB_ACCESS_TOKEN_COOKIE_NAME,
|
283
|
-
refresh_token_cookie_name=WEB_REFRESH_TOKEN_COOKIE_NAME,
|
284
|
-
enable_auth=WEB_ENABLE_AUTH,
|
285
|
-
super_admin_username=WEB_SUPER_ADMIN_USERNAME,
|
286
|
-
super_admin_password=WEB_SUPER_ADMIN_PASSWORD,
|
287
|
-
guest_username=WEB_GUEST_USERNAME,
|
288
|
-
)
|
File without changes
|
@@ -1,33 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
|
3
|
-
from zrb.group.any_group import AnyGroup
|
4
|
-
from zrb.runner.web_config import User
|
5
|
-
from zrb.runner.web_util import (
|
6
|
-
get_html_auth_link,
|
7
|
-
get_html_subgroup_info,
|
8
|
-
get_html_subtask_info,
|
9
|
-
)
|
10
|
-
from zrb.util.file import read_file
|
11
|
-
from zrb.util.string.format import fstring_format
|
12
|
-
|
13
|
-
|
14
|
-
def show_home_page(user: User, root_group: AnyGroup):
|
15
|
-
from fastapi.responses import HTMLResponse
|
16
|
-
|
17
|
-
_DIR = os.path.dirname(__file__)
|
18
|
-
_VIEW_TEMPLATE = read_file(os.path.join(_DIR, "view.html"))
|
19
|
-
group_info = get_html_subgroup_info(user, "/ui/", root_group)
|
20
|
-
task_info = get_html_subtask_info(user, "/ui/", root_group)
|
21
|
-
auth_link = get_html_auth_link(user)
|
22
|
-
return HTMLResponse(
|
23
|
-
fstring_format(
|
24
|
-
_VIEW_TEMPLATE,
|
25
|
-
{
|
26
|
-
"group_info": group_info,
|
27
|
-
"task_info": task_info,
|
28
|
-
"name": root_group.name,
|
29
|
-
"description": root_group.description,
|
30
|
-
"auth_link": auth_link,
|
31
|
-
},
|
32
|
-
)
|
33
|
-
)
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
|
3
|
-
from zrb.group.any_group import AnyGroup
|
4
|
-
from zrb.runner.web_config import User
|
5
|
-
from zrb.runner.web_util import get_html_auth_link
|
6
|
-
from zrb.util.file import read_file
|
7
|
-
from zrb.util.string.format import fstring_format
|
8
|
-
|
9
|
-
|
10
|
-
def show_login_page(user: User, root_group: AnyGroup):
|
11
|
-
from fastapi.responses import HTMLResponse
|
12
|
-
|
13
|
-
_DIR = os.path.dirname(__file__)
|
14
|
-
_VIEW_TEMPLATE = read_file(os.path.join(_DIR, "view.html"))
|
15
|
-
auth_link = get_html_auth_link(user)
|
16
|
-
return HTMLResponse(
|
17
|
-
fstring_format(
|
18
|
-
_VIEW_TEMPLATE,
|
19
|
-
{
|
20
|
-
"name": root_group.name,
|
21
|
-
"description": root_group.description,
|
22
|
-
"auth_link": auth_link,
|
23
|
-
},
|
24
|
-
)
|
25
|
-
)
|
@@ -1,26 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
|
3
|
-
from zrb.group.any_group import AnyGroup
|
4
|
-
from zrb.runner.web_config import User
|
5
|
-
from zrb.runner.web_util import get_html_auth_link
|
6
|
-
from zrb.util.file import read_file
|
7
|
-
from zrb.util.string.format import fstring_format
|
8
|
-
|
9
|
-
|
10
|
-
def show_logout_page(user: User, root_group: AnyGroup):
|
11
|
-
from fastapi.responses import HTMLResponse
|
12
|
-
|
13
|
-
_DIR = os.path.dirname(__file__)
|
14
|
-
_VIEW_TEMPLATE = read_file(os.path.join(_DIR, "view.html"))
|
15
|
-
auth_link = get_html_auth_link(user)
|
16
|
-
return HTMLResponse(
|
17
|
-
fstring_format(
|
18
|
-
_VIEW_TEMPLATE,
|
19
|
-
{
|
20
|
-
"name": root_group.name,
|
21
|
-
"description": root_group.description,
|
22
|
-
"auth_link": auth_link,
|
23
|
-
"user": user,
|
24
|
-
},
|
25
|
-
)
|
26
|
-
)
|
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
|