zrb 1.0.0a1__py3-none-any.whl → 1.0.0a3__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 +48 -39
- zrb/__main__.py +3 -3
- zrb/attr/type.py +2 -1
- zrb/builtin/__init__.py +40 -2
- zrb/builtin/base64.py +32 -0
- zrb/builtin/git.py +156 -0
- zrb/builtin/git_subtree.py +88 -0
- zrb/builtin/group.py +34 -0
- zrb/builtin/llm.py +31 -0
- zrb/builtin/md5.py +34 -0
- zrb/builtin/project/__init__.py +0 -0
- zrb/builtin/project/add/__init__.py +0 -0
- zrb/builtin/project/add/fastapp.py +72 -0
- zrb/builtin/project/add/fastapp_template/.gitignore +4 -0
- zrb/builtin/project/add/fastapp_template/README.md +7 -0
- zrb/builtin/project/add/fastapp_template/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/_zrb/config.py +17 -0
- zrb/builtin/project/add/fastapp_template/_zrb/group.py +16 -0
- zrb/builtin/project/add/fastapp_template/_zrb/helper.py +97 -0
- zrb/builtin/project/add/fastapp_template/_zrb/main.py +132 -0
- zrb/builtin/project/add/fastapp_template/_zrb/venv_task.py +22 -0
- zrb/builtin/project/add/fastapp_template/common/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/common/app.py +18 -0
- zrb/builtin/project/add/fastapp_template/common/db_engine.py +5 -0
- zrb/builtin/project/add/fastapp_template/common/db_repository.py +134 -0
- zrb/builtin/project/add/fastapp_template/common/error.py +8 -0
- zrb/builtin/project/add/fastapp_template/common/schema.py +5 -0
- zrb/builtin/project/add/fastapp_template/common/usecase.py +232 -0
- zrb/builtin/project/add/fastapp_template/config.py +29 -0
- zrb/builtin/project/add/fastapp_template/main.py +7 -0
- zrb/builtin/project/add/fastapp_template/migrate.py +3 -0
- zrb/builtin/project/add/fastapp_template/module/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/module/auth/alembic.ini +117 -0
- zrb/builtin/project/add/fastapp_template/module/auth/client/api_client.py +7 -0
- zrb/builtin/project/add/fastapp_template/module/auth/client/base_client.py +27 -0
- zrb/builtin/project/add/fastapp_template/module/auth/client/direct_client.py +6 -0
- zrb/builtin/project/add/fastapp_template/module/auth/client/factory.py +9 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration/README +1 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration/env.py +108 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration/script.py.mako +26 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration/versions/3093c7336477_add_user_table.py +37 -0
- zrb/builtin/project/add/fastapp_template/module/auth/migration_metadata.py +6 -0
- zrb/builtin/project/add/fastapp_template/module/auth/route.py +22 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/db_repository.py +39 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/factory.py +13 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/repository/repository.py +34 -0
- zrb/builtin/project/add/fastapp_template/module/auth/service/user/usecase.py +45 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/alembic.ini +117 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration/README +1 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration/env.py +108 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration/script.py.mako +26 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration/versions/.gitkeep +0 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/migration_metadata.py +3 -0
- zrb/builtin/project/add/fastapp_template/module/gateway/route.py +27 -0
- zrb/builtin/project/add/fastapp_template/requirements.txt +6 -0
- zrb/builtin/project/add/fastapp_template/schema/__init__.py +0 -0
- zrb/builtin/project/add/fastapp_template/schema/role.py +31 -0
- zrb/builtin/project/add/fastapp_template/schema/user.py +31 -0
- zrb/builtin/project/add/fastapp_template/template.env +2 -0
- zrb/builtin/project/create/__init__.py +0 -0
- zrb/builtin/project/create/create.py +41 -0
- zrb/builtin/project/create/project-template/README.md +3 -0
- zrb/builtin/project/create/project-template/zrb_init.py +7 -0
- zrb/builtin/python.py +11 -0
- zrb/builtin/shell/__init__.py +0 -5
- zrb/builtin/shell/autocomplete/__init__.py +0 -9
- zrb/builtin/shell/autocomplete/bash.py +5 -6
- zrb/builtin/shell/autocomplete/subcmd.py +7 -8
- zrb/builtin/shell/autocomplete/zsh.py +5 -6
- zrb/builtin/todo.py +186 -0
- zrb/callback/any_callback.py +1 -1
- zrb/callback/callback.py +5 -5
- zrb/cmd/cmd_val.py +2 -2
- zrb/config.py +4 -1
- zrb/content_transformer/any_content_transformer.py +1 -1
- zrb/content_transformer/content_transformer.py +2 -2
- zrb/context/any_context.py +5 -1
- zrb/context/any_shared_context.py +3 -3
- zrb/context/context.py +15 -9
- zrb/context/shared_context.py +9 -8
- zrb/env/__init__.py +0 -3
- zrb/env/any_env.py +2 -2
- zrb/env/env.py +4 -5
- zrb/env/env_file.py +4 -4
- zrb/env/env_map.py +4 -4
- zrb/group/__init__.py +0 -3
- zrb/group/any_group.py +3 -3
- zrb/group/group.py +7 -6
- zrb/input/any_input.py +1 -1
- zrb/input/base_input.py +4 -4
- zrb/input/bool_input.py +5 -5
- zrb/input/float_input.py +3 -3
- zrb/input/int_input.py +3 -3
- zrb/input/option_input.py +51 -0
- zrb/input/password_input.py +2 -2
- zrb/input/str_input.py +1 -1
- zrb/input/text_input.py +12 -10
- zrb/runner/cli.py +79 -44
- zrb/runner/web_app/group_info_ui/controller.py +7 -8
- zrb/runner/web_app/group_info_ui/view.html +2 -2
- zrb/runner/web_app/home_page/controller.py +7 -6
- zrb/runner/web_app/home_page/view.html +2 -2
- zrb/runner/web_app/task_ui/controller.py +13 -13
- zrb/runner/web_app/task_ui/partial/common-util.js +37 -0
- zrb/runner/web_app/task_ui/partial/main.js +9 -2
- zrb/runner/web_app/task_ui/partial/show-existing-session.js +20 -5
- zrb/runner/web_app/task_ui/partial/visualize-history.js +1 -41
- zrb/runner/web_app/task_ui/view.html +4 -2
- zrb/runner/web_server.py +137 -211
- zrb/runner/web_util.py +5 -35
- zrb/session/any_session.py +13 -7
- zrb/session/session.py +80 -41
- zrb/session_state_log/session_state_log.py +7 -5
- zrb/session_state_logger/any_session_state_logger.py +1 -1
- zrb/session_state_logger/default_session_state_logger.py +2 -2
- zrb/session_state_logger/file_session_state_logger.py +19 -27
- zrb/task/any_task.py +8 -3
- zrb/task/base_task.py +47 -33
- zrb/task/base_trigger.py +11 -12
- zrb/task/cmd_task.py +55 -43
- zrb/task/http_check.py +8 -8
- zrb/task/llm_task.py +160 -0
- zrb/task/make_task.py +9 -9
- zrb/task/rsync_task.py +7 -7
- zrb/task/scaffolder.py +14 -11
- zrb/task/scheduler.py +6 -7
- zrb/task/task.py +1 -1
- zrb/task/tcp_check.py +8 -8
- zrb/util/attr.py +19 -3
- zrb/util/cli/style.py +71 -2
- zrb/util/cli/subcommand.py +2 -2
- zrb/util/codemod/__init__.py +0 -0
- zrb/util/codemod/add_code_to_class.py +35 -0
- zrb/util/codemod/add_code_to_function.py +36 -0
- zrb/util/codemod/add_code_to_method.py +55 -0
- zrb/util/codemod/add_key_to_dict.py +51 -0
- zrb/util/codemod/add_param_to_function_call.py +39 -0
- zrb/util/codemod/add_property_to_class.py +55 -0
- zrb/util/git.py +156 -0
- zrb/util/git_subtree.py +94 -0
- zrb/util/group.py +2 -2
- zrb/util/llm/tool.py +63 -0
- zrb/util/string/conversion.py +7 -0
- zrb/util/todo.py +135 -0
- {zrb-1.0.0a1.dist-info → zrb-1.0.0a3.dist-info}/METADATA +11 -7
- zrb-1.0.0a3.dist-info/RECORD +194 -0
- zrb/builtin/shell/_group.py +0 -9
- zrb/builtin/shell/autocomplete/_group.py +0 -6
- zrb/runner/web_app/any_request_handler.py +0 -24
- zrb/runner/web_server.bak.py +0 -208
- zrb-1.0.0a1.dist-info/RECORD +0 -120
- {zrb-1.0.0a1.dist-info → zrb-1.0.0a3.dist-info}/WHEEL +0 -0
- {zrb-1.0.0a1.dist-info → zrb-1.0.0a3.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
from functools import partial, wraps
|
3
|
+
from typing import Any, Callable, Sequence
|
4
|
+
|
5
|
+
import httpx
|
6
|
+
from fastapi import APIRouter, params
|
7
|
+
from fastapi.routing import APIRoute
|
8
|
+
from fastapi.types import IncEx
|
9
|
+
from fastapi.utils import generate_unique_id
|
10
|
+
from starlette.responses import JSONResponse, Response
|
11
|
+
|
12
|
+
|
13
|
+
class RouteParam:
|
14
|
+
def __init__(
|
15
|
+
self,
|
16
|
+
path: str,
|
17
|
+
response_model: Any,
|
18
|
+
status_code: int | None = None,
|
19
|
+
tags: list[str | Enum] | None = None,
|
20
|
+
dependencies: Sequence[params.Depends] | None = None,
|
21
|
+
summary: str | None = None,
|
22
|
+
description: str = "",
|
23
|
+
response_description: str = "",
|
24
|
+
responses: dict[int | str, dict[str, Any]] | None = None,
|
25
|
+
deprecated: bool | None = None,
|
26
|
+
methods: set[str] | list[str] | None = None,
|
27
|
+
operation_id: str | None = None,
|
28
|
+
response_model_include: IncEx | None = None,
|
29
|
+
response_model_exclude: IncEx | None = None,
|
30
|
+
response_model_by_alias: bool = True,
|
31
|
+
response_model_exclude_unset: bool = False,
|
32
|
+
response_model_exclude_defaults: bool = False,
|
33
|
+
response_model_exclude_none: bool = False,
|
34
|
+
include_in_schema: bool = True,
|
35
|
+
response_class: type[Response] = Response,
|
36
|
+
name: str | None = None,
|
37
|
+
openapi_extra: dict[str, Any] | None = None,
|
38
|
+
generate_unique_id_function: Callable[[APIRoute], str] | None = None,
|
39
|
+
func: Callable | None = None,
|
40
|
+
):
|
41
|
+
self.path = path
|
42
|
+
self.response_model = response_model
|
43
|
+
self.status_code = status_code
|
44
|
+
self.tags = tags
|
45
|
+
self.dependencies = dependencies
|
46
|
+
self.summary = summary
|
47
|
+
self.description = description
|
48
|
+
self.response_description = response_description
|
49
|
+
self.responses = responses
|
50
|
+
self.deprecated = deprecated
|
51
|
+
self.methods = methods
|
52
|
+
self.operation_id = operation_id
|
53
|
+
self.response_model_include = response_model_include
|
54
|
+
self.response_model_exclude = response_model_exclude
|
55
|
+
self.response_model_by_alias = response_model_by_alias
|
56
|
+
self.response_model_exclude_unset = response_model_exclude_unset
|
57
|
+
self.response_model_exclude_defaults = response_model_exclude_defaults
|
58
|
+
self.response_model_exclude_none = response_model_exclude_none
|
59
|
+
self.include_in_schema = include_in_schema
|
60
|
+
self.response_class = response_class
|
61
|
+
self.name = name
|
62
|
+
self.openapi_extra = openapi_extra
|
63
|
+
self.generate_unique_id_function = generate_unique_id_function
|
64
|
+
self.func = func
|
65
|
+
|
66
|
+
|
67
|
+
class BaseUsecase:
|
68
|
+
_route_params: dict[str, RouteParam] = {}
|
69
|
+
|
70
|
+
@classmethod
|
71
|
+
def route(
|
72
|
+
cls,
|
73
|
+
path: str,
|
74
|
+
*,
|
75
|
+
response_model: Any = None,
|
76
|
+
status_code: int | None = None,
|
77
|
+
tags: list[str | Enum] | None = None,
|
78
|
+
dependencies: Sequence[params.Depends] | None = None,
|
79
|
+
summary: str | None = None,
|
80
|
+
description: str = None,
|
81
|
+
response_description: str = "Successful Response",
|
82
|
+
responses: dict[int | str, dict[str, Any]] | None = None,
|
83
|
+
deprecated: bool | None = None,
|
84
|
+
methods: set[str] | list[str] | None = None,
|
85
|
+
operation_id: str | None = None,
|
86
|
+
response_model_include: IncEx | None = None,
|
87
|
+
response_model_exclude: IncEx | None = None,
|
88
|
+
response_model_by_alias: bool = True,
|
89
|
+
response_model_exclude_unset: bool = False,
|
90
|
+
response_model_exclude_defaults: bool = False,
|
91
|
+
response_model_exclude_none: bool = False,
|
92
|
+
include_in_schema: bool = True,
|
93
|
+
response_class: type[Response] = JSONResponse,
|
94
|
+
name: str | None = None,
|
95
|
+
openapi_extra: dict[str, Any] | None = None,
|
96
|
+
generate_unique_id_function: Callable[[APIRoute], str] = generate_unique_id,
|
97
|
+
):
|
98
|
+
"""
|
99
|
+
Decorator to register a method with its HTTP details.
|
100
|
+
"""
|
101
|
+
|
102
|
+
def decorator(func: Callable):
|
103
|
+
cls._route_params[func.__name__] = RouteParam(
|
104
|
+
path=path,
|
105
|
+
response_model=response_model,
|
106
|
+
status_code=status_code,
|
107
|
+
tags=tags,
|
108
|
+
dependencies=dependencies,
|
109
|
+
summary=summary,
|
110
|
+
description=description,
|
111
|
+
response_description=response_description,
|
112
|
+
responses=responses,
|
113
|
+
deprecated=deprecated,
|
114
|
+
methods=methods,
|
115
|
+
operation_id=operation_id,
|
116
|
+
response_model_include=response_model_include,
|
117
|
+
response_model_exclude=response_model_exclude,
|
118
|
+
response_model_by_alias=response_model_by_alias,
|
119
|
+
response_model_exclude_unset=response_model_exclude_unset,
|
120
|
+
response_model_exclude_defaults=response_model_exclude_defaults,
|
121
|
+
response_model_exclude_none=response_model_exclude_none,
|
122
|
+
include_in_schema=include_in_schema,
|
123
|
+
response_class=response_class,
|
124
|
+
name=name,
|
125
|
+
openapi_extra=openapi_extra,
|
126
|
+
generate_unique_id_function=generate_unique_id_function,
|
127
|
+
func=func,
|
128
|
+
)
|
129
|
+
|
130
|
+
@wraps(func)
|
131
|
+
async def wrapped(*args, **kwargs):
|
132
|
+
return await func(*args, **kwargs)
|
133
|
+
|
134
|
+
return wrapped
|
135
|
+
|
136
|
+
return decorator
|
137
|
+
|
138
|
+
def as_direct_client(self):
|
139
|
+
"""
|
140
|
+
Dynamically create a direct client class.
|
141
|
+
"""
|
142
|
+
_methods = self._route_params
|
143
|
+
DirectClient = create_client_class("DirectClient")
|
144
|
+
for name, details in _methods.items():
|
145
|
+
func = details.func
|
146
|
+
client_method = create_direct_client_method(func, self)
|
147
|
+
setattr(DirectClient, name, client_method.__get__(DirectClient))
|
148
|
+
return DirectClient
|
149
|
+
|
150
|
+
def as_api_client(self, base_url: str):
|
151
|
+
"""
|
152
|
+
Dynamically create an API client class.
|
153
|
+
"""
|
154
|
+
_methods = self._route_params
|
155
|
+
APIClient = create_client_class("APIClient")
|
156
|
+
# Dynamically generate methods
|
157
|
+
for name, param in _methods.items():
|
158
|
+
client_method = create_api_client_method(param, base_url)
|
159
|
+
setattr(APIClient, name, client_method.__get__(APIClient))
|
160
|
+
return APIClient
|
161
|
+
|
162
|
+
def serve_route(self, app: APIRouter):
|
163
|
+
"""
|
164
|
+
Dynamically add routes to FastAPI.
|
165
|
+
"""
|
166
|
+
for _, route_param in self._route_params.items():
|
167
|
+
bound_func = partial(route_param.func, self)
|
168
|
+
bound_func.__name__ = route_param.func.__name__
|
169
|
+
bound_func.__doc__ = route_param.func.__doc__
|
170
|
+
app.add_api_route(
|
171
|
+
path=route_param.path,
|
172
|
+
endpoint=bound_func,
|
173
|
+
response_model=route_param.response_model,
|
174
|
+
status_code=route_param.status_code,
|
175
|
+
tags=route_param.tags,
|
176
|
+
dependencies=route_param.dependencies,
|
177
|
+
summary=route_param.summary,
|
178
|
+
description=route_param.description,
|
179
|
+
response_description=route_param.response_description,
|
180
|
+
responses=route_param.responses,
|
181
|
+
deprecated=route_param.deprecated,
|
182
|
+
methods=route_param.methods,
|
183
|
+
operation_id=route_param.operation_id,
|
184
|
+
response_model_include=route_param.response_model_include,
|
185
|
+
response_model_exclude=route_param.response_model_exclude,
|
186
|
+
response_model_by_alias=route_param.response_model_by_alias,
|
187
|
+
response_model_exclude_unset=route_param.response_model_exclude_unset,
|
188
|
+
response_model_exclude_defaults=route_param.response_model_exclude_defaults,
|
189
|
+
response_model_exclude_none=route_param.response_model_exclude_none,
|
190
|
+
include_in_schema=route_param.include_in_schema,
|
191
|
+
response_class=route_param.response_class,
|
192
|
+
name=route_param.name,
|
193
|
+
openapi_extra=route_param.openapi_extra,
|
194
|
+
generate_unique_id_function=route_param.generate_unique_id_function,
|
195
|
+
)
|
196
|
+
|
197
|
+
|
198
|
+
def create_client_class(name):
|
199
|
+
class Client:
|
200
|
+
pass
|
201
|
+
|
202
|
+
Client.__name__ = name
|
203
|
+
return Client
|
204
|
+
|
205
|
+
|
206
|
+
def create_direct_client_method(func: Callable, usecase: BaseUsecase):
|
207
|
+
async def client_method(self, *args, **kwargs):
|
208
|
+
return await func(usecase, *args, **kwargs)
|
209
|
+
|
210
|
+
return client_method
|
211
|
+
|
212
|
+
|
213
|
+
def create_api_client_method(param: RouteParam, base_url: str):
|
214
|
+
_url = param.path
|
215
|
+
_methods = [method.lower() for method in param.methods]
|
216
|
+
|
217
|
+
async def client_method(self, *args, **kwargs):
|
218
|
+
async with httpx.AsyncClient() as client:
|
219
|
+
url = base_url + _url.format(**kwargs)
|
220
|
+
if "post" in _methods:
|
221
|
+
response = await client.post(url, json=kwargs)
|
222
|
+
elif "put" in _methods:
|
223
|
+
response = await client.put(url, json=kwargs)
|
224
|
+
elif "delete" in _methods:
|
225
|
+
response = await client.delete(url, json=kwargs)
|
226
|
+
else:
|
227
|
+
response = await client.get(url, params=kwargs)
|
228
|
+
# Add more HTTP methods as needed
|
229
|
+
response.raise_for_status()
|
230
|
+
return response.json()
|
231
|
+
|
232
|
+
return client_method
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import os
|
2
|
+
|
3
|
+
APP_PATH = os.path.dirname(__file__)
|
4
|
+
|
5
|
+
APP_MODE = os.getenv("APP_NAME_MODE", "monolith")
|
6
|
+
APP_MODULES = [
|
7
|
+
module.strip()
|
8
|
+
for module in os.getenv("APP_NAME_MODULES", "").split(",")
|
9
|
+
if module.strip() != ""
|
10
|
+
]
|
11
|
+
APP_PORT = int(os.getenv("APP_NAME_PORT", "3000"))
|
12
|
+
APP_COMMUNICATION = os.getenv(
|
13
|
+
"APP_NAME_COMMUNICATION", "direct" if APP_MODE == "monolith" else "api"
|
14
|
+
)
|
15
|
+
APP_REPOSITORY_TYPE = os.getenv("APP_REPOSITORY_TYPE", "db")
|
16
|
+
APP_DB_URL = os.getenv(
|
17
|
+
"APP_DB_URL",
|
18
|
+
(
|
19
|
+
f"sqlite:///{APP_PATH}/monolith.db"
|
20
|
+
if APP_MODE == "monolith" or len(APP_MODULES) == 0
|
21
|
+
else f"sqlite:///{APP_PATH}/{APP_MODULES[0]}_microservices.db"
|
22
|
+
),
|
23
|
+
)
|
24
|
+
APP_AUTH_SUPER_USER = os.getenv("APP_NAME_AUTH_SUPER_USER", "admin")
|
25
|
+
APP_AUTH_SUPER_USER_PASSWORD = os.getenv(
|
26
|
+
"APP_NAME_AUTH_SUPER_USER_PASSWORD", "secure-password"
|
27
|
+
)
|
28
|
+
|
29
|
+
APP_AUTH_BASE_URL = os.getenv("APP_NAME_AUTH_BASE_URL", "http://localhost:3001")
|
File without changes
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# A generic, single database configuration.
|
2
|
+
|
3
|
+
[alembic]
|
4
|
+
# path to migration scripts
|
5
|
+
# Use forward slashes (/) also on windows to provide an os agnostic path
|
6
|
+
script_location = migration
|
7
|
+
|
8
|
+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
|
9
|
+
# Uncomment the line below if you want the files to be prepended with date and time
|
10
|
+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
|
11
|
+
# for all available tokens
|
12
|
+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
|
13
|
+
|
14
|
+
# sys.path path, will be prepended to sys.path if present.
|
15
|
+
# defaults to the current working directory.
|
16
|
+
prepend_sys_path = ../..
|
17
|
+
|
18
|
+
# timezone to use when rendering the date within the migration file
|
19
|
+
# as well as the filename.
|
20
|
+
# If specified, requires the python>=3.9 or backports.zoneinfo library.
|
21
|
+
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
|
22
|
+
# string value is passed to ZoneInfo()
|
23
|
+
# leave blank for localtime
|
24
|
+
# timezone =
|
25
|
+
|
26
|
+
# max length of characters to apply to the "slug" field
|
27
|
+
# truncate_slug_length = 40
|
28
|
+
|
29
|
+
# set to 'true' to run the environment during
|
30
|
+
# the 'revision' command, regardless of autogenerate
|
31
|
+
# revision_environment = false
|
32
|
+
|
33
|
+
# set to 'true' to allow .pyc and .pyo files without
|
34
|
+
# a source .py file to be detected as revisions in the
|
35
|
+
# versions/ directory
|
36
|
+
# sourceless = false
|
37
|
+
|
38
|
+
# version location specification; This defaults
|
39
|
+
# to migration/versions. When using multiple version
|
40
|
+
# directories, initial revisions must be specified with --version-path.
|
41
|
+
# The path separator used here should be the separator specified by "version_path_separator" below.
|
42
|
+
# version_locations = %(here)s/bar:%(here)s/bat:migration/versions
|
43
|
+
|
44
|
+
# version path separator; As mentioned above, this is the character used to split
|
45
|
+
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
|
46
|
+
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
|
47
|
+
# Valid values for version_path_separator are:
|
48
|
+
#
|
49
|
+
# version_path_separator = :
|
50
|
+
# version_path_separator = ;
|
51
|
+
# version_path_separator = space
|
52
|
+
# version_path_separator = newline
|
53
|
+
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
|
54
|
+
|
55
|
+
# set to 'true' to search source files recursively
|
56
|
+
# in each "version_locations" directory
|
57
|
+
# new in Alembic version 1.10
|
58
|
+
# recursive_version_locations = false
|
59
|
+
|
60
|
+
# the output encoding used when revision files
|
61
|
+
# are written from script.py.mako
|
62
|
+
# output_encoding = utf-8
|
63
|
+
|
64
|
+
sqlalchemy.url = driver://user:pass@localhost/dbname
|
65
|
+
|
66
|
+
|
67
|
+
[post_write_hooks]
|
68
|
+
# post_write_hooks defines scripts or Python functions that are run
|
69
|
+
# on newly generated revision scripts. See the documentation for further
|
70
|
+
# detail and examples
|
71
|
+
|
72
|
+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
|
73
|
+
# hooks = black
|
74
|
+
# black.type = console_scripts
|
75
|
+
# black.entrypoint = black
|
76
|
+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
|
77
|
+
|
78
|
+
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
|
79
|
+
# hooks = ruff
|
80
|
+
# ruff.type = exec
|
81
|
+
# ruff.executable = %(here)s/.venv/bin/ruff
|
82
|
+
# ruff.options = --fix REVISION_SCRIPT_FILENAME
|
83
|
+
|
84
|
+
# Logging configuration
|
85
|
+
[loggers]
|
86
|
+
keys = root,sqlalchemy,alembic
|
87
|
+
|
88
|
+
[handlers]
|
89
|
+
keys = console
|
90
|
+
|
91
|
+
[formatters]
|
92
|
+
keys = generic
|
93
|
+
|
94
|
+
[logger_root]
|
95
|
+
level = WARNING
|
96
|
+
handlers = console
|
97
|
+
qualname =
|
98
|
+
|
99
|
+
[logger_sqlalchemy]
|
100
|
+
level = WARNING
|
101
|
+
handlers =
|
102
|
+
qualname = sqlalchemy.engine
|
103
|
+
|
104
|
+
[logger_alembic]
|
105
|
+
level = INFO
|
106
|
+
handlers =
|
107
|
+
qualname = alembic
|
108
|
+
|
109
|
+
[handler_console]
|
110
|
+
class = StreamHandler
|
111
|
+
args = (sys.stderr,)
|
112
|
+
level = NOTSET
|
113
|
+
formatter = generic
|
114
|
+
|
115
|
+
[formatter_generic]
|
116
|
+
format = %(levelname)-5.5s [%(name)s] %(message)s
|
117
|
+
datefmt = %H:%M:%S
|
@@ -0,0 +1,7 @@
|
|
1
|
+
from fastapp_template.config import APP_AUTH_BASE_URL
|
2
|
+
from fastapp_template.module.auth.client.base_client import BaseClient
|
3
|
+
from fastapp_template.module.auth.service.user.usecase import user_usecase
|
4
|
+
|
5
|
+
|
6
|
+
class APIClient(user_usecase.as_api_client(base_url=APP_AUTH_BASE_URL), BaseClient):
|
7
|
+
pass
|
@@ -0,0 +1,27 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
|
3
|
+
from fastapp_template.schema.user import UserCreate, UserResponse, UserUpdate
|
4
|
+
|
5
|
+
|
6
|
+
class BaseClient(ABC):
|
7
|
+
@abstractmethod
|
8
|
+
async def get_user_by_id(self, user_id: str) -> UserResponse:
|
9
|
+
pass
|
10
|
+
|
11
|
+
@abstractmethod
|
12
|
+
async def get_all_users(self) -> list[UserResponse]:
|
13
|
+
pass
|
14
|
+
|
15
|
+
@abstractmethod
|
16
|
+
async def create_user(
|
17
|
+
self, data: UserCreate | list[UserCreate]
|
18
|
+
) -> UserResponse | list[UserResponse]:
|
19
|
+
pass
|
20
|
+
|
21
|
+
@abstractmethod
|
22
|
+
async def update_user(self, user_id: str, data: UserUpdate) -> UserResponse:
|
23
|
+
pass
|
24
|
+
|
25
|
+
@abstractmethod
|
26
|
+
async def delete_user(self, user_id: str) -> UserResponse:
|
27
|
+
pass
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from fastapp_template.config import APP_COMMUNICATION
|
2
|
+
from fastapp_template.module.auth.client.api_client import APIClient
|
3
|
+
from fastapp_template.module.auth.client.base_client import BaseClient
|
4
|
+
from fastapp_template.module.auth.client.direct_client import DirectClient
|
5
|
+
|
6
|
+
if APP_COMMUNICATION == "direct":
|
7
|
+
client: BaseClient = DirectClient()
|
8
|
+
elif APP_COMMUNICATION == "api":
|
9
|
+
client: BaseClient = APIClient()
|
@@ -0,0 +1 @@
|
|
1
|
+
Generic single-database configuration.
|
@@ -0,0 +1,108 @@
|
|
1
|
+
from logging.config import fileConfig
|
2
|
+
|
3
|
+
from alembic import context
|
4
|
+
from fastapp_template.config import APP_DB_URL
|
5
|
+
from fastapp_template.module.auth.migration_metadata import metadata
|
6
|
+
from sqlalchemy import engine_from_config, pool
|
7
|
+
|
8
|
+
# this is the Alembic Config object, which provides
|
9
|
+
# access to the values within the .ini file in use.
|
10
|
+
config = context.config
|
11
|
+
|
12
|
+
# 🔥 FastApp Modification
|
13
|
+
MIGRATION_TABLE = "_migration_auth"
|
14
|
+
# 🔥 FastApp Modification
|
15
|
+
config.set_section_option(config.config_ini_section, "sqlalchemy.url", APP_DB_URL)
|
16
|
+
|
17
|
+
# Interpret the config file for Python logging.
|
18
|
+
# This line sets up loggers basically.
|
19
|
+
if config.config_file_name is not None:
|
20
|
+
fileConfig(config.config_file_name)
|
21
|
+
|
22
|
+
# add your model's MetaData object here
|
23
|
+
# for 'autogenerate' support
|
24
|
+
# from myapp import mymodel
|
25
|
+
# target_metadata = mymodel.Base.metadata
|
26
|
+
target_metadata = metadata
|
27
|
+
|
28
|
+
# other values from the config, defined by the needs of env.py,
|
29
|
+
# can be acquired:
|
30
|
+
# my_important_option = config.get_main_option("my_important_option")
|
31
|
+
# ... etc.
|
32
|
+
|
33
|
+
|
34
|
+
# 🔥 FastApp Modification
|
35
|
+
def include_object(object, name, type_, reflected, compare_to):
|
36
|
+
"""
|
37
|
+
Filter which objects Alembic should include in migrations.
|
38
|
+
Args:
|
39
|
+
object: The SQLAlchemy object (table, column, etc.)
|
40
|
+
name: The name of the object
|
41
|
+
type_: The type of the object ("table", "column", etc.)
|
42
|
+
reflected: True if the object is reflected from the database
|
43
|
+
compare_to: The object being compared against
|
44
|
+
Returns:
|
45
|
+
bool: True to include, False to exclude
|
46
|
+
"""
|
47
|
+
# Exclude tables not in metadata
|
48
|
+
if type_ == "table" and name not in target_metadata.tables:
|
49
|
+
return False # Skip this table
|
50
|
+
return True
|
51
|
+
|
52
|
+
|
53
|
+
def run_migrations_offline() -> None:
|
54
|
+
"""Run migrations in 'offline' mode.
|
55
|
+
|
56
|
+
This configures the context with just a URL
|
57
|
+
and not an Engine, though an Engine is acceptable
|
58
|
+
here as well. By skipping the Engine creation
|
59
|
+
we don't even need a DBAPI to be available.
|
60
|
+
|
61
|
+
Calls to context.execute() here emit the given string to the
|
62
|
+
script output.
|
63
|
+
|
64
|
+
"""
|
65
|
+
url = config.get_main_option("sqlalchemy.url")
|
66
|
+
context.configure(
|
67
|
+
url=url,
|
68
|
+
target_metadata=target_metadata,
|
69
|
+
literal_binds=True,
|
70
|
+
dialect_opts={"paramstyle": "named"},
|
71
|
+
imports=["import sqlmodel"], # 🔥 FastApp Modification
|
72
|
+
version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
|
73
|
+
include_object=include_object, # 🔥 FastApp Modification
|
74
|
+
)
|
75
|
+
|
76
|
+
with context.begin_transaction():
|
77
|
+
context.run_migrations()
|
78
|
+
|
79
|
+
|
80
|
+
def run_migrations_online() -> None:
|
81
|
+
"""Run migrations in 'online' mode.
|
82
|
+
|
83
|
+
In this scenario we need to create an Engine
|
84
|
+
and associate a connection with the context.
|
85
|
+
|
86
|
+
"""
|
87
|
+
connectable = engine_from_config(
|
88
|
+
config.get_section(config.config_ini_section, {}),
|
89
|
+
prefix="sqlalchemy.",
|
90
|
+
poolclass=pool.NullPool,
|
91
|
+
)
|
92
|
+
|
93
|
+
with connectable.connect() as connection:
|
94
|
+
context.configure(
|
95
|
+
connection=connection,
|
96
|
+
target_metadata=target_metadata,
|
97
|
+
imports=["import sqlmodel"], # 🔥 FastApp Modification
|
98
|
+
version_table=MIGRATION_TABLE, # 🔥 FastApp Modification
|
99
|
+
include_object=include_object, # 🔥 FastApp Modification
|
100
|
+
)
|
101
|
+
with context.begin_transaction():
|
102
|
+
context.run_migrations()
|
103
|
+
|
104
|
+
|
105
|
+
if context.is_offline_mode():
|
106
|
+
run_migrations_offline()
|
107
|
+
else:
|
108
|
+
run_migrations_online()
|
@@ -0,0 +1,26 @@
|
|
1
|
+
"""${message}
|
2
|
+
|
3
|
+
Revision ID: ${up_revision}
|
4
|
+
Revises: ${down_revision | comma,n}
|
5
|
+
Create Date: ${create_date}
|
6
|
+
|
7
|
+
"""
|
8
|
+
from typing import Sequence, Union
|
9
|
+
|
10
|
+
from alembic import op
|
11
|
+
import sqlalchemy as sa
|
12
|
+
${imports if imports else ""}
|
13
|
+
|
14
|
+
# revision identifiers, used by Alembic.
|
15
|
+
revision: str = ${repr(up_revision)}
|
16
|
+
down_revision: Union[str, None] = ${repr(down_revision)}
|
17
|
+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
|
18
|
+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
|
19
|
+
|
20
|
+
|
21
|
+
def upgrade() -> None:
|
22
|
+
${upgrades if upgrades else "pass"}
|
23
|
+
|
24
|
+
|
25
|
+
def downgrade() -> None:
|
26
|
+
${downgrades if downgrades else "pass"}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
"""Add user table
|
2
|
+
|
3
|
+
Revision ID: 3093c7336477
|
4
|
+
Revises:
|
5
|
+
Create Date: 2024-11-20 05:57:01.684118
|
6
|
+
|
7
|
+
"""
|
8
|
+
|
9
|
+
from typing import Sequence, Union
|
10
|
+
|
11
|
+
import sqlalchemy as sa
|
12
|
+
import sqlmodel
|
13
|
+
from alembic import op
|
14
|
+
|
15
|
+
# revision identifiers, used by Alembic.
|
16
|
+
revision: str = "3093c7336477"
|
17
|
+
down_revision: Union[str, None] = None
|
18
|
+
branch_labels: Union[str, Sequence[str], None] = None
|
19
|
+
depends_on: Union[str, Sequence[str], None] = None
|
20
|
+
|
21
|
+
|
22
|
+
def upgrade() -> None:
|
23
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
24
|
+
op.create_table(
|
25
|
+
"user",
|
26
|
+
sa.Column("id", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
27
|
+
sa.Column("username", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
28
|
+
sa.Column("password", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
|
29
|
+
sa.PrimaryKeyConstraint("id"),
|
30
|
+
)
|
31
|
+
# ### end Alembic commands ###
|
32
|
+
|
33
|
+
|
34
|
+
def downgrade() -> None:
|
35
|
+
# ### commands auto generated by Alembic - please adjust! ###
|
36
|
+
op.drop_table("user")
|
37
|
+
# ### end Alembic commands ###
|
@@ -0,0 +1,22 @@
|
|
1
|
+
from fastapp_template.common.app import app
|
2
|
+
from fastapp_template.common.schema import BasicResponse
|
3
|
+
from fastapp_template.config import APP_MODE, APP_MODULES
|
4
|
+
from fastapp_template.module.auth.service.user.usecase import user_usecase
|
5
|
+
|
6
|
+
if APP_MODE == "microservices" and "auth" in APP_MODULES:
|
7
|
+
|
8
|
+
if APP_MODE == "microservices" and (
|
9
|
+
len(APP_MODULES) > 0 and APP_MODULES[0] == "auth"
|
10
|
+
):
|
11
|
+
|
12
|
+
@app.api_route("/health", methods=["GET", "HEAD"], response_model=BasicResponse)
|
13
|
+
async def health():
|
14
|
+
return BasicResponse(message="ok")
|
15
|
+
|
16
|
+
@app.api_route(
|
17
|
+
"/readiness", methods=["GET", "HEAD"], response_model=BasicResponse
|
18
|
+
)
|
19
|
+
async def readiness():
|
20
|
+
return BasicResponse(message="ok")
|
21
|
+
|
22
|
+
user_usecase.serve_route(app)
|
File without changes
|
File without changes
|
File without changes
|