zrb 1.0.0a16__py3-none-any.whl → 1.0.0a20__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 +5 -0
- zrb/__main__.py +3 -0
- zrb/builtin/__init__.py +2 -2
- zrb/builtin/git.py +10 -2
- zrb/builtin/git_subtree.py +4 -0
- zrb/builtin/llm/tool/rag.py +2 -2
- zrb/builtin/project/add/fastapp/fastapp_input.py +16 -0
- zrb/builtin/project/add/fastapp/fastapp_task.py +78 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/.flake8 +3 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/column/create_column_task.py +14 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_task.py +128 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/add_entity_util.py +213 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/any_client_method.py +27 -0
- zrb/builtin/project/add/{fastapp_template/_zrb/entity/module_template → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/my_entity_usecase.py +9 -10
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module/service/my_entity/repository/factory.py +13 -0
- zrb/builtin/project/add/{fastapp_template/_zrb/entity/module_template → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_db_repository.py +14 -9
- zrb/builtin/project/add/{fastapp_template/_zrb/entity/module_template → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/module/my_module}/service/my_entity/repository/my_entity_repository.py +6 -7
- zrb/builtin/project/add/{fastapp_template/_zrb/entity/schema.template.py → fastapp/fastapp_template/my_app_name/_zrb/entity/template/app_template/schema/my_entity.py} +8 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/format_task.py +17 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/input.py +1 -4
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_task.py +85 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/add_module_util.py +154 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/any_client.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 +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/direct_client.py +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/client/factory.py +9 -0
- zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/env.py +2 -4
- zrb/builtin/project/add/{fastapp_template/module/auth → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/script.py.mako +1 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module/route.py +33 -0
- zrb/builtin/project/add/{fastapp_template/_zrb/main.py → fastapp/fastapp_template/my_app_name/_zrb/task.py} +12 -14
- zrb/builtin/project/add/{fastapp_template/_zrb/helper.py → fastapp/fastapp_template/my_app_name/_zrb/util.py} +1 -1
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/venv_task.py +1 -1
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/app.py +2 -2
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/base_db_repository.py +1 -1
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/base_usecase.py +19 -6
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/db_engine.py +1 -1
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/config.py +1 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/main.py +7 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/migrate.py +3 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/client/any_client.py +10 -4
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/api_client.py +7 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/direct_client.py +6 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/client/factory.py +9 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/migration/env.py +2 -4
- zrb/builtin/project/add/{fastapp_template/module/gateway → fastapp/fastapp_template/my_app_name/module/auth}/migration/script.py.mako +1 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/migration_metadata.py +1 -1
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/route.py +37 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/repository/user_db_repository.py +13 -7
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_repository.py +42 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/repository/user_repository_factory.py +13 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/user_usecase.py +13 -12
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/auth/service/user/user_usecase_factory.py +6 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/migration/env.py +2 -4
- zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/module/gateway}/migration/script.py.mako +1 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/route.py +37 -0
- zrb/builtin/project/add/fastapp/fastapp_template/my_app_name/module/gateway/subroute/auth.py +44 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/requirements.txt +1 -1
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/permission.py +8 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/role.py +8 -0
- zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/user.py +8 -0
- zrb/builtin/project/add/fastapp/fastapp_util.py +46 -0
- zrb/builtin/project/create/{create.py → project_task.py} +1 -1
- zrb/builtin/python.py +4 -1
- zrb/builtin/setup/asdf/asdf_helper.py +4 -8
- zrb/builtin/setup/tmux/tmux.py +7 -12
- zrb/builtin/todo.py +42 -26
- zrb/callback/callback.py +0 -1
- zrb/cmd/cmd_val.py +2 -2
- zrb/config.py +18 -0
- zrb/content_transformer/content_transformer.py +8 -7
- zrb/context/any_context.py +6 -6
- zrb/group/group.py +0 -1
- zrb/input/any_input.py +4 -0
- zrb/input/base_input.py +17 -5
- zrb/input/bool_input.py +1 -1
- zrb/input/float_input.py +2 -2
- zrb/input/int_input.py +1 -1
- zrb/input/option_input.py +2 -2
- zrb/input/password_input.py +2 -2
- zrb/input/text_input.py +6 -6
- zrb/runner/cli.py +9 -35
- zrb/runner/common_util.py +31 -0
- zrb/runner/web_app.py +169 -46
- zrb/runner/web_config.py +288 -0
- zrb/runner/web_controller/error_page/controller.py +27 -0
- zrb/runner/web_controller/error_page/view.html +33 -0
- zrb/runner/web_controller/group_info_page/controller.py +40 -0
- zrb/runner/web_controller/group_info_page/view.html +36 -0
- zrb/runner/web_controller/home_page/controller.py +14 -57
- zrb/runner/web_controller/home_page/view.html +29 -20
- zrb/runner/web_controller/login_page/controller.py +25 -0
- zrb/runner/web_controller/login_page/view.html +50 -0
- zrb/runner/web_controller/logout_page/controller.py +26 -0
- zrb/runner/web_controller/logout_page/view.html +40 -0
- zrb/runner/web_controller/{task_ui → session_page}/controller.py +36 -34
- zrb/runner/web_controller/{task_ui → session_page}/partial/input.html +1 -1
- zrb/runner/web_controller/session_page/view.html +91 -0
- zrb/runner/web_controller/static/common.css +11 -0
- zrb/runner/web_controller/static/login/event.js +33 -0
- zrb/runner/web_controller/static/logout/event.js +20 -0
- zrb/runner/web_controller/static/pico.min.css +1 -1
- zrb/runner/web_controller/static/session/common-util.js +63 -0
- zrb/runner/web_controller/static/session/current-session.js +164 -0
- zrb/runner/web_controller/static/session/event.js +120 -0
- zrb/runner/web_controller/static/session/past-session.js +138 -0
- zrb/runner/web_util.py +53 -0
- zrb/session_state_logger/any_session_state_logger.py +0 -1
- zrb/session_state_logger/file_session_state_logger.py +4 -8
- zrb/task/base_trigger.py +0 -1
- zrb/task/cmd_task.py +1 -1
- zrb/task/llm_task.py +3 -6
- zrb/task/make_task.py +0 -1
- zrb/task/scaffolder.py +18 -4
- zrb/task/scheduler.py +0 -1
- zrb/util/cmd/command.py +0 -1
- zrb/util/codemod/{add_code_to_class.py → append_code_to_class.py} +4 -4
- zrb/util/codemod/{add_code_to_function.py → append_code_to_function.py} +5 -3
- zrb/util/codemod/{add_code_to_method.py → append_code_to_method.py} +3 -3
- zrb/util/codemod/{add_key_to_dict.py → append_key_to_dict.py} +1 -1
- zrb/util/codemod/{add_param_to_function_call.py → append_param_to_function_call.py} +1 -1
- zrb/util/codemod/{add_code_to_module.py → prepend_code_to_module.py} +2 -2
- zrb/util/codemod/{add_parent_to_class.py → prepend_parent_to_class.py} +1 -1
- zrb/util/codemod/{add_property_to_class.py → prepend_property_to_class.py} +1 -1
- zrb/util/file.py +18 -0
- zrb/util/git_subtree.py +3 -4
- zrb/util/todo.py +105 -24
- zrb/xcom/xcom.py +0 -1
- {zrb-1.0.0a16.dist-info → zrb-1.0.0a20.dist-info}/METADATA +3 -2
- zrb-1.0.0a20.dist-info/RECORD +243 -0
- zrb/builtin/project/add/fastapp.py +0 -87
- zrb/builtin/project/add/fastapp_template/_zrb/column/create_column_task.py +0 -11
- zrb/builtin/project/add/fastapp_template/_zrb/entity/create_entity_task.py +0 -196
- zrb/builtin/project/add/fastapp_template/_zrb/entity/module_template/service/my_entity/repository/factory.py +0 -13
- zrb/builtin/project/add/fastapp_template/_zrb/module/create_module_task.py +0 -136
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/any_client.py +0 -27
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/api_client.py +0 -6
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/direct_client.py +0 -6
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/client/factory.py +0 -9
- zrb/builtin/project/add/fastapp_template/_zrb/module/module_template/route.py +0 -19
- zrb/builtin/project/add/fastapp_template/main.py +0 -7
- zrb/builtin/project/add/fastapp_template/migrate.py +0 -3
- zrb/builtin/project/add/fastapp_template/module/auth/client/api_client.py +0 -7
- zrb/builtin/project/add/fastapp_template/module/auth/client/direct_client.py +0 -6
- zrb/builtin/project/add/fastapp_template/module/auth/client/factory.py +0 -9
- zrb/builtin/project/add/fastapp_template/module/auth/migration/versions/3093c7336477_add_user_table.py +0 -37
- zrb/builtin/project/add/fastapp_template/module/auth/route.py +0 -22
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/factory.py +0 -13
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/user_repository.py +0 -34
- zrb/builtin/project/add/fastapp_template/module/gateway/route.py +0 -27
- zrb/runner/web_controller/group_info_ui/controller.py +0 -91
- zrb/runner/web_controller/group_info_ui/partial/group_info.html +0 -2
- zrb/runner/web_controller/group_info_ui/partial/group_li.html +0 -1
- zrb/runner/web_controller/group_info_ui/partial/task_info.html +0 -2
- zrb/runner/web_controller/group_info_ui/partial/task_li.html +0 -1
- zrb/runner/web_controller/group_info_ui/view.html +0 -31
- zrb/runner/web_controller/home_page/partial/group_info.html +0 -2
- zrb/runner/web_controller/home_page/partial/group_li.html +0 -1
- zrb/runner/web_controller/home_page/partial/task_info.html +0 -2
- zrb/runner/web_controller/home_page/partial/task_li.html +0 -1
- zrb/runner/web_controller/task_ui/partial/common-util.js +0 -37
- zrb/runner/web_controller/task_ui/partial/main.js +0 -195
- zrb/runner/web_controller/task_ui/partial/show-existing-session.js +0 -97
- zrb/runner/web_controller/task_ui/partial/visualize-history.js +0 -104
- zrb/runner/web_controller/task_ui/view.html +0 -87
- zrb-1.0.0a16.dist-info/RECORD +0 -231
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/.gitignore +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/README.md +0 -0
- /zrb/builtin/project/add/{__init__.py → fastapp/fastapp_template/my_app_name/__init__.py} +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/config.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/_zrb/group.py +0 -0
- /zrb/builtin/project/add/{fastapp_template/__init__.py → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/gateway/subroute/my_module.py} +0 -0
- /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/alembic.ini +0 -0
- /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/README +0 -0
- /zrb/builtin/project/add/{fastapp_template/module/gateway → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration/versions/.gitkeep +0 -0
- /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/migration_metadata.py +0 -0
- /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/_zrb/module/template/app_template/module/my_module}/service/__init__.py +0 -0
- /zrb/builtin/project/add/{fastapp_template/_zrb/module/run_module.template.py → fastapp/fastapp_template/my_app_name/_zrb/module/template/module_task_definition.py} +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/__init__.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/error.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/common/schema.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/__init__.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/alembic.ini +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/migration/README +0 -0
- /zrb/builtin/project/add/{fastapp_template/_zrb/module/module_template → fastapp/fastapp_template/my_app_name/module/auth}/migration/versions/3093c7336477_add_user_table.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/__init__.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/auth/service/user/__init__.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/alembic.ini +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/migration/README +0 -0
- /zrb/builtin/project/add/{fastapp_template/module/auth/service/user/repository/__init__.py → fastapp/fastapp_template/my_app_name/module/gateway/migration/versions/.gitkeep} +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/module/gateway/migration_metadata.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/__init__.py +0 -0
- /zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/template.env +0 -0
- /zrb/runner/web_controller/{group_info_ui → group_info_page}/__init__.py +0 -0
- /zrb/runner/web_controller/{task_ui → session_page}/__init__.py +0 -0
- {zrb-1.0.0a16.dist-info → zrb-1.0.0a20.dist-info}/WHEEL +0 -0
- {zrb-1.0.0a16.dist-info → zrb-1.0.0a20.dist-info}/entry_points.txt +0 -0
@@ -1,9 +1,13 @@
|
|
1
1
|
from abc import ABC, abstractmethod
|
2
2
|
|
3
|
-
from
|
3
|
+
from my_app_name.schema.user import (
|
4
|
+
UserCreateWithAudit,
|
5
|
+
UserResponse,
|
6
|
+
UserUpdateWithAudit,
|
7
|
+
)
|
4
8
|
|
5
9
|
|
6
|
-
class
|
10
|
+
class AnyClient(ABC):
|
7
11
|
@abstractmethod
|
8
12
|
async def get_user_by_id(self, user_id: str) -> UserResponse:
|
9
13
|
pass
|
@@ -14,12 +18,14 @@ class BaseClient(ABC):
|
|
14
18
|
|
15
19
|
@abstractmethod
|
16
20
|
async def create_user(
|
17
|
-
self, data:
|
21
|
+
self, data: UserCreateWithAudit | list[UserCreateWithAudit]
|
18
22
|
) -> UserResponse | list[UserResponse]:
|
19
23
|
pass
|
20
24
|
|
21
25
|
@abstractmethod
|
22
|
-
async def update_user(
|
26
|
+
async def update_user(
|
27
|
+
self, user_id: str, data: UserUpdateWithAudit
|
28
|
+
) -> UserResponse:
|
23
29
|
pass
|
24
30
|
|
25
31
|
@abstractmethod
|
@@ -0,0 +1,7 @@
|
|
1
|
+
from my_app_name.config import APP_AUTH_BASE_URL
|
2
|
+
from my_app_name.module.auth.client.any_client import AnyClient
|
3
|
+
from my_app_name.module.auth.service.user.user_usecase_factory import user_usecase
|
4
|
+
|
5
|
+
|
6
|
+
class APIClient(user_usecase.as_api_client(base_url=APP_AUTH_BASE_URL), AnyClient):
|
7
|
+
pass
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from my_app_name.config import APP_COMMUNICATION
|
2
|
+
from my_app_name.module.auth.client.any_client import AnyClient
|
3
|
+
from my_app_name.module.auth.client.api_client import APIClient
|
4
|
+
from my_app_name.module.auth.client.direct_client import DirectClient
|
5
|
+
|
6
|
+
if APP_COMMUNICATION == "direct":
|
7
|
+
client: AnyClient = DirectClient()
|
8
|
+
elif APP_COMMUNICATION == "api":
|
9
|
+
client: AnyClient = APIClient()
|
@@ -1,8 +1,8 @@
|
|
1
1
|
from logging.config import fileConfig
|
2
2
|
|
3
3
|
from alembic import context
|
4
|
-
from
|
5
|
-
from
|
4
|
+
from my_app_name.config import APP_DB_URL
|
5
|
+
from my_app_name.module.auth.migration_metadata import metadata
|
6
6
|
from sqlalchemy import engine_from_config, pool
|
7
7
|
|
8
8
|
# this is the Alembic Config object, which provides
|
@@ -68,7 +68,6 @@ def run_migrations_offline() -> None:
|
|
68
68
|
target_metadata=target_metadata,
|
69
69
|
literal_binds=True,
|
70
70
|
dialect_opts={"paramstyle": "named"},
|
71
|
-
imports=["import sqlmodel"], # 🔥 FastApp Modification
|
72
71
|
version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
|
73
72
|
include_object=include_object, # 🔥 FastApp Modification
|
74
73
|
)
|
@@ -94,7 +93,6 @@ def run_migrations_online() -> None:
|
|
94
93
|
context.configure(
|
95
94
|
connection=connection,
|
96
95
|
target_metadata=target_metadata,
|
97
|
-
imports=["import sqlmodel"], # 🔥 FastApp Modification
|
98
96
|
version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
|
99
97
|
include_object=include_object, # 🔥 FastApp Modification
|
100
98
|
)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
from fastapi import FastAPI
|
2
|
+
from my_app_name.common.app import app
|
3
|
+
from my_app_name.common.schema import BasicResponse
|
4
|
+
from my_app_name.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
|
5
|
+
from my_app_name.module.auth.service.user.user_usecase_factory import user_usecase
|
6
|
+
|
7
|
+
|
8
|
+
def serve_health_check(app: FastAPI):
|
9
|
+
@app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
|
10
|
+
async def health():
|
11
|
+
"""
|
12
|
+
Microservice's health check
|
13
|
+
"""
|
14
|
+
return BasicResponse(message="ok")
|
15
|
+
|
16
|
+
|
17
|
+
def serve_readiness_check(app: FastAPI):
|
18
|
+
@app.api_route("/readiness", methods=["GET", "HEAD"], response_model=BasicResponse)
|
19
|
+
async def readiness():
|
20
|
+
"""
|
21
|
+
Microservice's readiness check
|
22
|
+
"""
|
23
|
+
return BasicResponse(message="ok")
|
24
|
+
|
25
|
+
|
26
|
+
def serve_route(app: FastAPI):
|
27
|
+
if APP_MODE != "microservices" or "auth" not in APP_MODULES:
|
28
|
+
return
|
29
|
+
if APP_MAIN_MODULE == "auth":
|
30
|
+
serve_health_check(app)
|
31
|
+
serve_readiness_check(app)
|
32
|
+
|
33
|
+
# Serve user endpoints for APIClient
|
34
|
+
user_usecase.serve_route(app)
|
35
|
+
|
36
|
+
|
37
|
+
serve_route(app)
|
@@ -1,9 +1,14 @@
|
|
1
|
-
from
|
2
|
-
from
|
3
|
-
from
|
1
|
+
from my_app_name.common.base_db_repository import BaseDBRepository
|
2
|
+
from my_app_name.common.error import NotFoundError
|
3
|
+
from my_app_name.module.auth.service.user.repository.user_repository import (
|
4
4
|
UserRepository,
|
5
5
|
)
|
6
|
-
from
|
6
|
+
from my_app_name.schema.user import (
|
7
|
+
User,
|
8
|
+
UserCreateWithAudit,
|
9
|
+
UserResponse,
|
10
|
+
UserUpdateWithAudit,
|
11
|
+
)
|
7
12
|
from passlib.context import CryptContext
|
8
13
|
from sqlalchemy.ext.asyncio import AsyncSession
|
9
14
|
from sqlmodel import Session, select
|
@@ -17,12 +22,13 @@ def hash_password(password: str) -> str:
|
|
17
22
|
|
18
23
|
|
19
24
|
class UserDBRepository(
|
20
|
-
BaseDBRepository[User, UserResponse,
|
25
|
+
BaseDBRepository[User, UserResponse, UserCreateWithAudit, UserUpdateWithAudit],
|
26
|
+
UserRepository,
|
21
27
|
):
|
22
28
|
db_model = User
|
23
29
|
response_model = UserResponse
|
24
|
-
create_model =
|
25
|
-
update_model =
|
30
|
+
create_model = UserCreateWithAudit
|
31
|
+
update_model = UserUpdateWithAudit
|
26
32
|
entity_name = "user"
|
27
33
|
column_preprocessors = {"password": hash_password}
|
28
34
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
|
3
|
+
from my_app_name.schema.user import (
|
4
|
+
User,
|
5
|
+
UserCreateWithAudit,
|
6
|
+
UserResponse,
|
7
|
+
UserUpdateWithAudit,
|
8
|
+
)
|
9
|
+
|
10
|
+
|
11
|
+
class UserRepository(ABC):
|
12
|
+
@abstractmethod
|
13
|
+
async def create(self, user_data: UserCreateWithAudit) -> UserResponse:
|
14
|
+
pass
|
15
|
+
|
16
|
+
@abstractmethod
|
17
|
+
async def get_by_id(self, user_id: str) -> UserResponse:
|
18
|
+
pass
|
19
|
+
|
20
|
+
@abstractmethod
|
21
|
+
async def get_all(self) -> list[User]:
|
22
|
+
pass
|
23
|
+
|
24
|
+
@abstractmethod
|
25
|
+
async def update(
|
26
|
+
self, user_id: str, user_data: UserUpdateWithAudit
|
27
|
+
) -> UserResponse:
|
28
|
+
pass
|
29
|
+
|
30
|
+
@abstractmethod
|
31
|
+
async def delete(self, user_id: str) -> UserResponse:
|
32
|
+
pass
|
33
|
+
|
34
|
+
@abstractmethod
|
35
|
+
async def create_bulk(
|
36
|
+
self, user_data_list: list[UserCreateWithAudit]
|
37
|
+
) -> list[UserResponse]:
|
38
|
+
pass
|
39
|
+
|
40
|
+
@abstractmethod
|
41
|
+
async def get_by_credentials(self, username: str, password: str) -> UserResponse:
|
42
|
+
pass
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from my_app_name.common.db_engine import engine
|
2
|
+
from my_app_name.config import APP_REPOSITORY_TYPE
|
3
|
+
from my_app_name.module.auth.service.user.repository.user_db_repository import (
|
4
|
+
UserDBRepository,
|
5
|
+
)
|
6
|
+
from my_app_name.module.auth.service.user.repository.user_repository import (
|
7
|
+
UserRepository,
|
8
|
+
)
|
9
|
+
|
10
|
+
if APP_REPOSITORY_TYPE == "db":
|
11
|
+
user_repository: UserRepository = UserDBRepository(engine)
|
12
|
+
else:
|
13
|
+
user_repository: UserRepository = None
|
@@ -1,13 +1,15 @@
|
|
1
|
-
from
|
2
|
-
from
|
3
|
-
from fastapp_template.module.auth.service.user.repository.user_repository import (
|
1
|
+
from my_app_name.common.base_usecase import BaseUsecase
|
2
|
+
from my_app_name.module.auth.service.user.repository.user_repository import (
|
4
3
|
UserRepository,
|
5
4
|
)
|
6
|
-
from
|
5
|
+
from my_app_name.schema.user import (
|
6
|
+
UserCreateWithAudit,
|
7
|
+
UserResponse,
|
8
|
+
UserUpdateWithAudit,
|
9
|
+
)
|
7
10
|
|
8
11
|
|
9
12
|
class UserUsecase(BaseUsecase):
|
10
|
-
|
11
13
|
def __init__(self, user_repository: UserRepository):
|
12
14
|
super().__init__()
|
13
15
|
self.user_repository = user_repository
|
@@ -30,23 +32,22 @@ class UserUsecase(BaseUsecase):
|
|
30
32
|
response_model=UserResponse | list[UserResponse],
|
31
33
|
)
|
32
34
|
async def create_user(
|
33
|
-
self, data:
|
35
|
+
self, data: UserCreateWithAudit | list[UserCreateWithAudit]
|
34
36
|
) -> UserResponse | list[UserResponse]:
|
35
|
-
if isinstance(data,
|
37
|
+
if isinstance(data, UserCreateWithAudit):
|
36
38
|
return await self.user_repository.create(data)
|
37
39
|
return await self.user_repository.create_bulk(data)
|
38
40
|
|
39
41
|
@BaseUsecase.route(
|
40
42
|
"/api/v1/users/{user_id}", methods=["put"], response_model=UserResponse
|
41
43
|
)
|
42
|
-
async def update_user(
|
44
|
+
async def update_user(
|
45
|
+
self, user_id: str, data: UserUpdateWithAudit
|
46
|
+
) -> UserResponse:
|
43
47
|
return await self.user_repository.update(user_id, data)
|
44
48
|
|
45
49
|
@BaseUsecase.route(
|
46
50
|
"/api/v1/users/{user_id}", methods=["delete"], response_model=UserResponse
|
47
51
|
)
|
48
|
-
async def delete_user(self, user_id: str) -> UserResponse:
|
52
|
+
async def delete_user(self, user_id: str, deleted_by: str) -> UserResponse:
|
49
53
|
return await self.user_repository.delete(user_id)
|
50
|
-
|
51
|
-
|
52
|
-
user_usecase = UserUsecase(user_repository=user_repository)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
from logging.config import fileConfig
|
2
2
|
|
3
3
|
from alembic import context
|
4
|
-
from
|
5
|
-
from
|
4
|
+
from my_app_name.config import APP_DB_URL
|
5
|
+
from my_app_name.module.gateway.migration_metadata import metadata
|
6
6
|
from sqlalchemy import engine_from_config, pool
|
7
7
|
|
8
8
|
# this is the Alembic Config object, which provides
|
@@ -68,7 +68,6 @@ def run_migrations_offline() -> None:
|
|
68
68
|
target_metadata=target_metadata,
|
69
69
|
literal_binds=True,
|
70
70
|
dialect_opts={"paramstyle": "named"},
|
71
|
-
imports=["import sqlmodel"], # 🔥 FastApp Modification
|
72
71
|
version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
|
73
72
|
include_object=include_object, # 🔥 FastApp Modification
|
74
73
|
)
|
@@ -94,7 +93,6 @@ def run_migrations_online() -> None:
|
|
94
93
|
context.configure(
|
95
94
|
connection=connection,
|
96
95
|
target_metadata=target_metadata,
|
97
|
-
imports=["import sqlmodel"], # 🔥 FastApp Modification
|
98
96
|
version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
|
99
97
|
include_object=include_object, # 🔥 FastApp Modification
|
100
98
|
)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
from fastapi import FastAPI
|
2
|
+
from my_app_name.common.app import app
|
3
|
+
from my_app_name.common.schema import BasicResponse
|
4
|
+
from my_app_name.config import APP_MAIN_MODULE, APP_MODE, APP_MODULES
|
5
|
+
from my_app_name.module.gateway.subroute.auth import serve_auth_route
|
6
|
+
|
7
|
+
|
8
|
+
def serve_health_check(app: FastAPI):
|
9
|
+
@app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
|
10
|
+
async def health():
|
11
|
+
"""
|
12
|
+
My App Name's health check
|
13
|
+
"""
|
14
|
+
return BasicResponse(message="ok")
|
15
|
+
|
16
|
+
|
17
|
+
def serve_readiness_check(app: FastAPI):
|
18
|
+
@app.api_route("/readiness", methods=["GET", "HEAD"], response_model=BasicResponse)
|
19
|
+
async def readiness():
|
20
|
+
"""
|
21
|
+
My App Name's readiness check
|
22
|
+
"""
|
23
|
+
return BasicResponse(message="ok")
|
24
|
+
|
25
|
+
|
26
|
+
def serve_route(app: FastAPI):
|
27
|
+
if APP_MODE != "monolith" and "gateway" not in APP_MODULES:
|
28
|
+
return
|
29
|
+
if APP_MODE == "monolith" or APP_MAIN_MODULE == "gateway":
|
30
|
+
serve_health_check(app)
|
31
|
+
serve_readiness_check(app)
|
32
|
+
|
33
|
+
# Serve Auth Route
|
34
|
+
serve_auth_route(app)
|
35
|
+
|
36
|
+
|
37
|
+
serve_route(app)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
from fastapi import FastAPI
|
2
|
+
from my_app_name.module.auth.client.factory import client as auth_client
|
3
|
+
from my_app_name.schema.user import (
|
4
|
+
UserCreate,
|
5
|
+
UserCreateWithAudit,
|
6
|
+
UserResponse,
|
7
|
+
UserUpdate,
|
8
|
+
UserUpdateWithAudit,
|
9
|
+
)
|
10
|
+
|
11
|
+
|
12
|
+
def serve_auth_route(app: FastAPI):
|
13
|
+
|
14
|
+
@app.get("/api/v1/users", response_model=list[UserResponse])
|
15
|
+
async def get_all_users() -> UserResponse:
|
16
|
+
return await auth_client.get_all_users()
|
17
|
+
|
18
|
+
@app.get("/api/v1/users/{user_id}", response_model=UserResponse)
|
19
|
+
async def get_user_by_id(user_id: str) -> UserResponse:
|
20
|
+
return await auth_client.get_user_by_id(user_id)
|
21
|
+
|
22
|
+
@app.post("/api/v1/users", response_model=UserResponse | list[UserResponse])
|
23
|
+
async def create_user(data: UserCreate | list[UserCreate]):
|
24
|
+
if isinstance(data, UserCreate):
|
25
|
+
data_dict = data.model_dump(exclude_unset=True)
|
26
|
+
audited_data = UserCreateWithAudit(**data_dict, created_by="system")
|
27
|
+
return await auth_client.create_user(audited_data)
|
28
|
+
audited_data = [
|
29
|
+
UserCreateWithAudit(
|
30
|
+
**row.model_dump(exclude_unset=True), created_by="system"
|
31
|
+
)
|
32
|
+
for row in data
|
33
|
+
]
|
34
|
+
return await auth_client.create_user(audited_data)
|
35
|
+
|
36
|
+
@app.put("/api/v1/users/{user_id}", response_model=UserResponse)
|
37
|
+
async def update_user(user_id: str, data: UserUpdate) -> UserResponse:
|
38
|
+
data_dict = data.model_dump(exclude_unset=True)
|
39
|
+
audited_data = UserUpdateWithAudit(**data_dict, updated_by="system")
|
40
|
+
return await auth_client.update_user(user_id, audited_data)
|
41
|
+
|
42
|
+
@app.delete("/api/v1/users/{user_id}", response_model=UserResponse)
|
43
|
+
async def delete_user(user_id: str) -> UserResponse:
|
44
|
+
return await auth_client.delete_user(user_id, deleted_by="system")
|
@@ -12,11 +12,19 @@ class PermissionCreate(PermissionBase):
|
|
12
12
|
description: str
|
13
13
|
|
14
14
|
|
15
|
+
class PermissionCreateWithAudit(PermissionCreate):
|
16
|
+
created_by: str
|
17
|
+
|
18
|
+
|
15
19
|
class PermissionUpdate(SQLModel):
|
16
20
|
name: str | None = None
|
17
21
|
description: str | None = None
|
18
22
|
|
19
23
|
|
24
|
+
class PermissionUpdateWithAudit(PermissionUpdate):
|
25
|
+
updated_by: str
|
26
|
+
|
27
|
+
|
20
28
|
class PermissionResponse(PermissionBase):
|
21
29
|
id: str
|
22
30
|
|
zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/role.py
RENAMED
@@ -12,11 +12,19 @@ class RoleCreate(RoleBase):
|
|
12
12
|
description: str
|
13
13
|
|
14
14
|
|
15
|
+
class RoleCreateWithAudit(RoleCreate):
|
16
|
+
created_by: str
|
17
|
+
|
18
|
+
|
15
19
|
class RoleUpdate(SQLModel):
|
16
20
|
name: str | None = None
|
17
21
|
description: str | None = None
|
18
22
|
|
19
23
|
|
24
|
+
class RoleUpdateWithAudit(RoleUpdate):
|
25
|
+
updated_by: str
|
26
|
+
|
27
|
+
|
20
28
|
class RoleResponse(RoleBase):
|
21
29
|
id: str
|
22
30
|
|
zrb/builtin/project/add/{fastapp_template → fastapp/fastapp_template/my_app_name}/schema/user.py
RENAMED
@@ -12,11 +12,19 @@ class UserCreate(UserBase):
|
|
12
12
|
password: str
|
13
13
|
|
14
14
|
|
15
|
+
class UserCreateWithAudit(UserCreate):
|
16
|
+
created_by: str
|
17
|
+
|
18
|
+
|
15
19
|
class UserUpdate(SQLModel):
|
16
20
|
username: str | None = None
|
17
21
|
password: str | None = None
|
18
22
|
|
19
23
|
|
24
|
+
class UserUpdateWithAudit(UserUpdate):
|
25
|
+
updated_by: str
|
26
|
+
|
27
|
+
|
20
28
|
class UserResponse(UserBase):
|
21
29
|
id: str
|
22
30
|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
from zrb.context.any_context import AnyContext
|
4
|
+
from zrb.util.file import read_file, write_file
|
5
|
+
from zrb.util.string.conversion import double_quote, to_snake_case
|
6
|
+
|
7
|
+
|
8
|
+
def is_in_project_app_dir(ctx: AnyContext, file_path: str) -> bool:
|
9
|
+
return file_path.startswith(
|
10
|
+
os.path.join(ctx.input.project_dir, to_snake_case(ctx.input.app))
|
11
|
+
)
|
12
|
+
|
13
|
+
|
14
|
+
def is_project_zrb_init_file(ctx: AnyContext, file_path: str) -> bool:
|
15
|
+
return file_path == os.path.join(ctx.input.project_dir, "zrb_init.py")
|
16
|
+
|
17
|
+
|
18
|
+
def update_project_zrb_init_file(ctx: AnyContext, zrb_init_path: str):
|
19
|
+
existing_zrb_init_code = read_file(zrb_init_path)
|
20
|
+
write_file(
|
21
|
+
file_path=zrb_init_path,
|
22
|
+
content=[
|
23
|
+
_get_import_load_file_code(existing_zrb_init_code),
|
24
|
+
existing_zrb_init_code.strip(),
|
25
|
+
_get_load_app_name_task_code(ctx.input.app),
|
26
|
+
],
|
27
|
+
)
|
28
|
+
|
29
|
+
|
30
|
+
def _get_import_load_file_code(existing_code: str) -> str | None:
|
31
|
+
code = "from zrb import load_file"
|
32
|
+
return code if code not in existing_code else None
|
33
|
+
|
34
|
+
|
35
|
+
def _get_load_app_name_task_code(app: str) -> str:
|
36
|
+
snake_app_name = to_snake_case(app)
|
37
|
+
load_file_param = ", ".join(
|
38
|
+
[double_quote(part) for part in [snake_app_name, "_zrb", "task.py"]]
|
39
|
+
)
|
40
|
+
return "\n".join(
|
41
|
+
[
|
42
|
+
f"# Load {app} automation",
|
43
|
+
f"{snake_app_name} = load_file(os.path.join(_DIR, {load_file_param}))",
|
44
|
+
f"assert {snake_app_name}",
|
45
|
+
]
|
46
|
+
)
|
@@ -21,7 +21,7 @@ scaffold_project = Scaffolder(
|
|
21
21
|
name="project",
|
22
22
|
description="Project name",
|
23
23
|
prompt="Project name",
|
24
|
-
default_str=lambda ctx: os.path.basename(ctx.input
|
24
|
+
default_str=lambda ctx: os.path.basename(ctx.input.project_dir),
|
25
25
|
),
|
26
26
|
],
|
27
27
|
source_path=os.path.join(_DIR, "project-template"),
|
zrb/builtin/python.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import os
|
2
2
|
|
3
3
|
from zrb.context.any_context import AnyContext
|
4
|
+
from zrb.util.file import read_file, write_file
|
4
5
|
|
5
6
|
|
6
7
|
def get_install_prerequisites_cmd(ctx: AnyContext) -> str:
|
@@ -31,14 +32,9 @@ def setup_asdf_ps_config(file_path: str):
|
|
31
32
|
|
32
33
|
|
33
34
|
def _setup_asdf_config(file_path: str, asdf_config: str):
|
34
|
-
dir_path = os.path.dirname(file_path)
|
35
|
-
os.makedirs(dir_path, exist_ok=True)
|
36
35
|
if not os.path.isfile(file_path):
|
37
|
-
|
38
|
-
|
39
|
-
with open(file_path, "r") as f:
|
40
|
-
content = f.read()
|
36
|
+
write_file(file_path, "")
|
37
|
+
content = read_file(file_path)
|
41
38
|
if asdf_config in content:
|
42
39
|
return
|
43
|
-
|
44
|
-
f.write(f"\n{asdf_config}\n")
|
40
|
+
write_file(file_path, [content, asdf_config, ""])
|
zrb/builtin/setup/tmux/tmux.py
CHANGED
@@ -7,6 +7,7 @@ from zrb.context.any_context import AnyContext
|
|
7
7
|
from zrb.input.str_input import StrInput
|
8
8
|
from zrb.task.cmd_task import CmdTask
|
9
9
|
from zrb.task.make_task import make_task
|
10
|
+
from zrb.util.file import read_file, write_file
|
10
11
|
|
11
12
|
install_tmux = CmdTask(
|
12
13
|
name="install-tmux",
|
@@ -28,22 +29,16 @@ install_tmux = CmdTask(
|
|
28
29
|
alias="tmux",
|
29
30
|
)
|
30
31
|
def setup_tmux(ctx: AnyContext):
|
31
|
-
|
32
|
-
tmux_config_template = f.read()
|
32
|
+
tmux_config = read_file(os.path.join(os.path.dirname(__file__), "tmux_config.sh"))
|
33
33
|
tmux_config_file = os.path.expanduser(ctx.input["tmux-config"])
|
34
|
-
tmux_config_dir = os.path.dirname(tmux_config_file)
|
35
34
|
# Make sure config file exists
|
36
|
-
os.makedirs(tmux_config_dir, exist_ok=True)
|
37
35
|
if not os.path.isfile(tmux_config_file):
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
if tmux_config_template in f.read():
|
43
|
-
return
|
36
|
+
write_file(tmux_config_file, "")
|
37
|
+
content = read_file(tmux_config_file)
|
38
|
+
if tmux_config in content:
|
39
|
+
return
|
44
40
|
# Write config
|
45
|
-
|
46
|
-
f.write(f"\n{tmux_config_template}\n")
|
41
|
+
write_file(tmux_config_file, [content, tmux_config, ""])
|
47
42
|
ctx.print("Setup complete, restart your terminal to continue")
|
48
43
|
|
49
44
|
|