zrb 0.23.0__py3-none-any.whl → 0.24.0__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 -0
- zrb/builtin/devtool/install/_input.py +2 -2
- zrb/builtin/project/add/app/generator/template/src/kebab-zrb-package-name/src/snake_zrb_package_name/snake_zrb_generator_name/template/_automate/snake_zrb_app_name/container/start.py +5 -6
- zrb/builtin/project/add/app/python/template/_automate/snake_zrb_app_name/container/start.py +5 -6
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/_helper.py +1 -52
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/microservices/start.py +5 -6
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/monolith/start.py +5 -6
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/support/start.py +4 -6
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/README.md +84 -8
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/loadtest/locustfile.py +1 -3
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/loadtest/template.env +1 -1
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/config.py +59 -61
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/frontend/src/routes/+layout.svelte +1 -1
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/frontend/vite.config.ts +7 -1
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/app/__init__.py +0 -0
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/{app.py → app/app.py} +30 -29
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/{app_lifespan.py → app/app_lifespan.py} +16 -16
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/{app_state.py → app/app_state.py} +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/db_connection.py +14 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/frontend_index.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/log.py +6 -6
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/messagebus.py +33 -33
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/rpc.py +9 -9
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/main.py +1 -3
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/access_token_scheme.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/access_token_util.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/model/user_model.py +6 -6
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/refresh_token_util.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/integration/user.py +18 -18
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/migrate.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/register_module.py +9 -9
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/log/migrate.py +2 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/log/register_module.py +9 -9
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/template.env +5 -2
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_group_crud.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_permission_crud.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_user_crud.py +7 -7
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/auth/test_user_login.py +14 -14
- zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/test/test_liveness_and_readiness.py +3 -3
- zrb/builtin/project/add/fastapp/crud/_helper/__init__.py +7 -0
- zrb/builtin/project/add/fastapp/crud/_helper/_common.py +8 -0
- zrb/builtin/project/add/fastapp/crud/_helper/register_api.py +45 -0
- zrb/builtin/project/add/fastapp/crud/_helper/register_permission.py +40 -0
- zrb/builtin/project/add/fastapp/crud/_helper/register_rpc.py +45 -0
- zrb/builtin/project/add/fastapp/crud/crud.py +3 -12
- zrb/builtin/project/add/fastapp/crud/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/entity/snake_zrb_entity_name/repo.py +12 -1
- zrb/builtin/project/add/fastapp/crud/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/schema/snake_zrb_entity_name.py +1 -0
- zrb/builtin/project/add/fastapp/crud/template/src/kebab-zrb-app-name/test/snake_zrb_module_name/test_snake_zrb_entity_name.py +8 -7
- zrb/builtin/project/add/fastapp/field/_helper/__init__.py +17 -0
- zrb/builtin/project/add/fastapp/field/_helper/_common.py +102 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_delete_page.py +49 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_detail_page.py +49 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_insert_page.py +62 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_list_page.py +47 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_repo.py +47 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_schema.py +45 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_test.py +49 -0
- zrb/builtin/project/add/fastapp/field/_helper/inject_update_page.py +50 -0
- zrb/builtin/project/add/fastapp/field/_input.py +14 -2
- zrb/builtin/project/add/fastapp/field/field.py +70 -90
- zrb/builtin/project/add/fastapp/module/_helper/__init__.py +17 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_all_disabled_env.py +22 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_all_enabled_env.py +22 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_deployment_template_env.py +25 -0
- zrb/builtin/project/add/fastapp/module/_helper/append_src_template_env.py +25 -0
- zrb/builtin/project/add/fastapp/module/_helper/create_app_config.py +29 -0
- zrb/builtin/project/add/fastapp/module/_helper/create_microservice_config.py +158 -0
- zrb/builtin/project/add/fastapp/module/_helper/register_migration.py +35 -0
- zrb/builtin/project/add/fastapp/module/_helper/register_module.py +33 -0
- zrb/builtin/project/add/fastapp/module/module.py +8 -37
- zrb/builtin/project/add/fastapp/module/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/migrate.py +2 -2
- zrb/builtin/project/add/fastapp/module/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/register_module.py +9 -9
- zrb/builtin/project/add/plugin/plugin.py +2 -2
- zrb/builtin/project/create/create.py +2 -2
- zrb/builtin/version.py +3 -3
- zrb/config/config.py +14 -14
- zrb/helper/callable.py +3 -1
- zrb/helper/cli.py +4 -4
- zrb/helper/file/copy_tree.py +26 -10
- zrb/helper/log.py +3 -3
- zrb/helper/string/parse_replacement.py +1 -1
- zrb/helper/typecheck.py +2 -2
- zrb/helper/typing.py +2 -2
- zrb/helper/util.py +12 -0
- zrb/runner.py +2 -2
- zrb/task/base_remote_cmd_task.py +5 -1
- zrb/task/base_task/base_task.py +3 -3
- zrb/task/base_task/component/base_task_model.py +9 -9
- zrb/task/cmd_task.py +15 -7
- zrb/task/docker_compose_start_task.py +151 -0
- zrb/task/docker_compose_task.py +35 -16
- zrb/task_input/base_input.py +2 -2
- zrb/task_input/multiline_input.py +2 -2
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/METADATA +3 -3
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/RECORD +98 -80
- zrb/builtin/project/add/app/generator/template/src/kebab-zrb-package-name/src/snake_zrb_package_name/snake_zrb_generator_name/template/_automate/snake_zrb_app_name/container/init.py +0 -34
- zrb/builtin/project/add/app/python/template/_automate/snake_zrb_app_name/container/init.py +0 -34
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/microservices/init.py +0 -36
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/monolith/init.py +0 -36
- zrb/builtin/project/add/fastapp/app/template/_automate/snake_zrb_app_name/container/support/init.py +0 -26
- zrb/builtin/project/add/fastapp/crud/_helper.py +0 -118
- zrb/builtin/project/add/fastapp/field/_helper.py +0 -342
- zrb/builtin/project/add/fastapp/module/_helper.py +0 -313
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/LICENSE +0 -0
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/WHEEL +0 -0
- {zrb-0.23.0.dist-info → zrb-0.24.0.dist-info}/entry_points.txt +0 -0
@@ -1,28 +1,29 @@
|
|
1
1
|
from config import (
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
2
|
+
APP_AUTH_ACCESS_TOKEN_COOKIE_KEY,
|
3
|
+
APP_AUTH_REFRESH_TOKEN_COOKIE_KEY,
|
4
|
+
APP_BRAND,
|
5
|
+
APP_CORS_ALLOW_CREDENTIALS,
|
6
|
+
APP_CORS_ALLOW_HEADERS,
|
7
|
+
APP_CORS_ALLOW_METHODS,
|
8
|
+
APP_CORS_ALLOW_ORIGIN_REGEX,
|
9
|
+
APP_CORS_ALLOW_ORIGINS,
|
10
|
+
APP_CORS_EXPOSE_HEADERS,
|
11
|
+
APP_CORS_MAX_AGE,
|
12
|
+
APP_ENABLE_FRONTEND,
|
13
|
+
APP_NAME,
|
14
|
+
APP_TITLE,
|
15
15
|
)
|
16
16
|
from fastapi import FastAPI, status
|
17
17
|
from fastapi.middleware.cors import CORSMiddleware
|
18
18
|
from fastapi.responses import JSONResponse
|
19
|
-
from integration.app_lifespan import app_lifespan
|
19
|
+
from integration.app.app_lifespan import app_lifespan
|
20
|
+
from integration.app.app_state import app_state
|
20
21
|
from integration.frontend_index import frontend_index_response
|
21
22
|
from schema.frontend_config import FrontendConfig
|
22
23
|
|
23
|
-
app = FastAPI(title=
|
24
|
+
app = FastAPI(title=APP_NAME, lifespan=app_lifespan)
|
24
25
|
|
25
|
-
if
|
26
|
+
if APP_ENABLE_FRONTEND:
|
26
27
|
|
27
28
|
@app.middleware("http")
|
28
29
|
async def catch_all(request, call_next):
|
@@ -37,13 +38,13 @@ if app_enable_frontend:
|
|
37
38
|
|
38
39
|
app.add_middleware(
|
39
40
|
CORSMiddleware,
|
40
|
-
allow_origins=
|
41
|
-
allow_origin_regex=
|
42
|
-
allow_methods=
|
43
|
-
allow_headers=
|
44
|
-
allow_credentials=
|
45
|
-
expose_headers=
|
46
|
-
max_age=
|
41
|
+
allow_origins=APP_CORS_ALLOW_ORIGINS,
|
42
|
+
allow_origin_regex=APP_CORS_ALLOW_ORIGIN_REGEX,
|
43
|
+
allow_methods=APP_CORS_ALLOW_METHODS,
|
44
|
+
allow_headers=APP_CORS_ALLOW_HEADERS,
|
45
|
+
allow_credentials=APP_CORS_ALLOW_CREDENTIALS,
|
46
|
+
expose_headers=APP_CORS_EXPOSE_HEADERS,
|
47
|
+
max_age=APP_CORS_MAX_AGE,
|
47
48
|
)
|
48
49
|
|
49
50
|
|
@@ -59,7 +60,7 @@ def get_application_liveness_status():
|
|
59
60
|
"""
|
60
61
|
if app_state.get_liveness():
|
61
62
|
return JSONResponse(
|
62
|
-
content={"app":
|
63
|
+
content={"app": APP_NAME, "alive": True}, status_code=status.HTTP_200_OK
|
63
64
|
)
|
64
65
|
return JSONResponse(
|
65
66
|
content={"message": "Service is not alive"},
|
@@ -80,7 +81,7 @@ def get_application_readiness_status():
|
|
80
81
|
"""
|
81
82
|
if app_state.get_readiness():
|
82
83
|
return JSONResponse(
|
83
|
-
content={"app":
|
84
|
+
content={"app": APP_NAME, "ready": True}, status_code=status.HTTP_200_OK
|
84
85
|
)
|
85
86
|
return JSONResponse(
|
86
87
|
content={"message": "Service is not ready"},
|
@@ -92,8 +93,8 @@ def get_application_readiness_status():
|
|
92
93
|
@app.get("/api/v1/frontend/configs", response_model=FrontendConfig)
|
93
94
|
def get_configs() -> FrontendConfig:
|
94
95
|
return FrontendConfig(
|
95
|
-
brand=
|
96
|
-
title=
|
97
|
-
access_token_cookie_key=
|
98
|
-
refresh_token_cookie_key=
|
96
|
+
brand=APP_BRAND,
|
97
|
+
title=APP_TITLE,
|
98
|
+
access_token_cookie_key=APP_AUTH_ACCESS_TOKEN_COOKIE_KEY,
|
99
|
+
refresh_token_cookie_key=APP_AUTH_REFRESH_TOKEN_COOKIE_KEY,
|
99
100
|
)
|
@@ -2,17 +2,17 @@ import os
|
|
2
2
|
from contextlib import asynccontextmanager
|
3
3
|
|
4
4
|
from config import (
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
APP_DB_AUTO_MIGRATE,
|
6
|
+
APP_ENABLE_EVENT_HANDLER,
|
7
|
+
APP_ENABLE_FRONTEND,
|
8
|
+
APP_ENABLE_RPC_SERVER,
|
9
|
+
APP_NAME,
|
10
|
+
APP_SRC_DIR,
|
11
11
|
)
|
12
12
|
from fastapi import FastAPI
|
13
13
|
from fastapi.staticfiles import StaticFiles
|
14
14
|
from helper.async_task import create_task
|
15
|
-
from integration.app_state import app_state, set_not_ready_on_error
|
15
|
+
from integration.app.app_state import app_state, set_not_ready_on_error
|
16
16
|
from integration.log import logger
|
17
17
|
from integration.messagebus import consumer
|
18
18
|
from integration.rpc import rpc_server
|
@@ -21,24 +21,24 @@ from migrate import migrate
|
|
21
21
|
|
22
22
|
@asynccontextmanager
|
23
23
|
async def app_lifespan(app: FastAPI):
|
24
|
-
logger.info(f"{
|
25
|
-
if
|
24
|
+
logger.info(f"{APP_NAME} started")
|
25
|
+
if APP_DB_AUTO_MIGRATE:
|
26
26
|
await migrate()
|
27
27
|
app_state.set_liveness(True)
|
28
|
-
if
|
28
|
+
if APP_ENABLE_EVENT_HANDLER:
|
29
29
|
create_task(consumer.start(), on_error=set_not_ready_on_error)
|
30
|
-
if
|
30
|
+
if APP_ENABLE_RPC_SERVER:
|
31
31
|
create_task(rpc_server.start(), on_error=set_not_ready_on_error)
|
32
|
-
if
|
33
|
-
build_path = os.path.join(
|
32
|
+
if APP_ENABLE_FRONTEND:
|
33
|
+
build_path = os.path.join(APP_SRC_DIR, "frontend", "build")
|
34
34
|
app.mount(
|
35
35
|
path="",
|
36
36
|
app=StaticFiles(directory=build_path, html=True),
|
37
37
|
name="frontend-static-resources",
|
38
38
|
)
|
39
39
|
app_state.set_readiness(True)
|
40
|
-
logger.info(f"{
|
40
|
+
logger.info(f"{APP_NAME} started")
|
41
41
|
yield
|
42
|
-
if
|
42
|
+
if APP_ENABLE_EVENT_HANDLER:
|
43
43
|
await consumer.stop()
|
44
|
-
logger.info(f"{
|
44
|
+
logger.info(f"{APP_NAME} closed")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import asyncio
|
2
2
|
|
3
|
-
from config import
|
3
|
+
from config import APP_MAX_NOT_READY
|
4
4
|
from integration.log import logger
|
5
5
|
|
6
6
|
|
@@ -35,5 +35,5 @@ app_state = AppState()
|
|
35
35
|
async def set_not_ready_on_error(exception: Exception):
|
36
36
|
logger.critical(exception)
|
37
37
|
app_state.set_readiness(False)
|
38
|
-
await asyncio.sleep(
|
38
|
+
await asyncio.sleep(APP_MAX_NOT_READY)
|
39
39
|
app_state.set_liveness(False)
|
zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/db_connection.py
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
import time
|
2
2
|
|
3
|
-
from config import
|
3
|
+
from config import (
|
4
|
+
APP_DB_CONNECTION,
|
5
|
+
APP_DB_ENGINE_SHOW_LOG,
|
6
|
+
APP_DB_POOL_MAX_OVERFLOW,
|
7
|
+
APP_DB_POOL_PRE_PING,
|
8
|
+
APP_DB_POOL_SIZE,
|
9
|
+
)
|
4
10
|
from integration.log import logger
|
5
11
|
from sqlalchemy import Engine, create_engine, event
|
6
12
|
|
@@ -27,4 +33,10 @@ def after_cursor_execute(conn, cursor, statement, parameters, context, executema
|
|
27
33
|
)
|
28
34
|
|
29
35
|
|
30
|
-
engine: Engine = create_engine(
|
36
|
+
engine: Engine = create_engine(
|
37
|
+
APP_DB_CONNECTION,
|
38
|
+
echo=APP_DB_ENGINE_SHOW_LOG,
|
39
|
+
pool_pre_ping=APP_DB_POOL_PRE_PING,
|
40
|
+
pool_size=APP_DB_POOL_SIZE,
|
41
|
+
max_identifier_length=APP_DB_POOL_MAX_OVERFLOW,
|
42
|
+
)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import os
|
2
2
|
|
3
|
-
from config import
|
3
|
+
from config import APP_SRC_DIR
|
4
4
|
from fastapi.responses import HTMLResponse
|
5
5
|
|
6
|
-
index_html_path = os.path.join(
|
6
|
+
index_html_path = os.path.join(APP_SRC_DIR, "frontend", "build", "index.html")
|
7
7
|
with open(index_html_path, "r") as f:
|
8
8
|
index_html_content = f.read()
|
9
9
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import logging
|
2
2
|
|
3
|
-
from config import
|
3
|
+
from config import APP_ENABLE_OTEL, APP_LOGGING_LEVEL, APP_OTEL_EXPORTER_OTLP_ENDPOINT
|
4
4
|
from opentelemetry._logs import set_logger_provider
|
5
5
|
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import OTLPLogExporter
|
6
6
|
from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler
|
@@ -10,14 +10,14 @@ from opentelemetry.sdk._logs.export import BatchLogRecordProcessor
|
|
10
10
|
# Create logger
|
11
11
|
##############################################################################
|
12
12
|
logger = logging.getLogger("src")
|
13
|
-
logger.setLevel(
|
13
|
+
logger.setLevel(APP_LOGGING_LEVEL)
|
14
14
|
|
15
15
|
##############################################################################
|
16
16
|
# Formatter log handler
|
17
17
|
##############################################################################
|
18
18
|
|
19
19
|
stream_handler = logging.StreamHandler()
|
20
|
-
stream_handler.setLevel(
|
20
|
+
stream_handler.setLevel(APP_LOGGING_LEVEL)
|
21
21
|
# create formatter
|
22
22
|
formatter = logging.Formatter("%(levelname)s:\t%(message)s")
|
23
23
|
# set stream handler's formatter
|
@@ -29,17 +29,17 @@ logger.addHandler(stream_handler)
|
|
29
29
|
# Open telemetry log handler
|
30
30
|
##############################################################################
|
31
31
|
|
32
|
-
if
|
32
|
+
if APP_ENABLE_OTEL:
|
33
33
|
# create logger providers
|
34
34
|
otlp_logger_provider = LoggerProvider()
|
35
35
|
# set the providers
|
36
36
|
set_logger_provider(otlp_logger_provider)
|
37
|
-
otlp_log_exporter = OTLPLogExporter(endpoint=
|
37
|
+
otlp_log_exporter = OTLPLogExporter(endpoint=APP_OTEL_EXPORTER_OTLP_ENDPOINT)
|
38
38
|
# add the batch processors to the trace provider
|
39
39
|
otlp_logger_provider.add_log_record_processor(
|
40
40
|
BatchLogRecordProcessor(otlp_log_exporter)
|
41
41
|
)
|
42
42
|
otlp_log_handler = LoggingHandler(
|
43
|
-
level=
|
43
|
+
level=APP_LOGGING_LEVEL, logger_provider=otlp_logger_provider
|
44
44
|
)
|
45
45
|
logger.addHandler(otlp_log_handler)
|
zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/integration/messagebus.py
CHANGED
@@ -14,31 +14,31 @@ from component.messagebus import (
|
|
14
14
|
RMQPublisher,
|
15
15
|
)
|
16
16
|
from config import (
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
APP_BROKER_TYPE,
|
18
|
+
APP_KAFKA_BOOTSTRAP_SERVERS,
|
19
|
+
APP_KAFKA_SASL_MECHANISM,
|
20
|
+
APP_KAFKA_SASL_PASS,
|
21
|
+
APP_KAFKA_SASL_USER,
|
22
|
+
APP_KAFKA_SECURITY_PROTOCOL,
|
23
|
+
APP_NAME,
|
24
|
+
APP_RMQ_CONNECTION_STRING,
|
25
25
|
)
|
26
26
|
from integration.log import logger
|
27
27
|
|
28
28
|
|
29
29
|
def init_admin(default_admin: Admin) -> Admin:
|
30
|
-
if
|
30
|
+
if APP_BROKER_TYPE == "rabbitmq":
|
31
31
|
return RMQAdmin(
|
32
|
-
logger=logger, connection_string=
|
32
|
+
logger=logger, connection_string=APP_RMQ_CONNECTION_STRING, configs={}
|
33
33
|
)
|
34
|
-
if
|
34
|
+
if APP_BROKER_TYPE == "kafka":
|
35
35
|
return KafkaAdmin(
|
36
36
|
logger=logger,
|
37
|
-
bootstrap_servers=
|
38
|
-
security_protocol=
|
39
|
-
sasl_mechanism=
|
40
|
-
sasl_plain_username=
|
41
|
-
sasl_plain_password=
|
37
|
+
bootstrap_servers=APP_KAFKA_BOOTSTRAP_SERVERS,
|
38
|
+
security_protocol=APP_KAFKA_SECURITY_PROTOCOL,
|
39
|
+
sasl_mechanism=APP_KAFKA_SASL_MECHANISM,
|
40
|
+
sasl_plain_username=APP_KAFKA_SASL_USER,
|
41
|
+
sasl_plain_password=APP_KAFKA_SASL_PASS,
|
42
42
|
configs={},
|
43
43
|
)
|
44
44
|
return default_admin
|
@@ -47,21 +47,21 @@ def init_admin(default_admin: Admin) -> Admin:
|
|
47
47
|
def init_publisher(
|
48
48
|
serializer: MessageSerializer, admin: Admin, default_publisher: Publisher
|
49
49
|
) -> Publisher:
|
50
|
-
if
|
50
|
+
if APP_BROKER_TYPE == "rabbitmq":
|
51
51
|
return RMQPublisher(
|
52
52
|
logger=logger,
|
53
|
-
connection_string=
|
53
|
+
connection_string=APP_RMQ_CONNECTION_STRING,
|
54
54
|
serializer=serializer,
|
55
55
|
rmq_admin=admin,
|
56
56
|
)
|
57
|
-
if
|
57
|
+
if APP_BROKER_TYPE == "kafka":
|
58
58
|
return KafkaPublisher(
|
59
59
|
logger=logger,
|
60
|
-
bootstrap_servers=
|
61
|
-
security_protocol=
|
62
|
-
sasl_mechanism=
|
63
|
-
sasl_plain_username=
|
64
|
-
sasl_plain_password=
|
60
|
+
bootstrap_servers=APP_KAFKA_BOOTSTRAP_SERVERS,
|
61
|
+
security_protocol=APP_KAFKA_SECURITY_PROTOCOL,
|
62
|
+
sasl_mechanism=APP_KAFKA_SASL_MECHANISM,
|
63
|
+
sasl_plain_username=APP_KAFKA_SASL_USER,
|
64
|
+
sasl_plain_password=APP_KAFKA_SASL_PASS,
|
65
65
|
serializer=serializer,
|
66
66
|
kafka_admin=admin,
|
67
67
|
)
|
@@ -71,22 +71,22 @@ def init_publisher(
|
|
71
71
|
def init_consumer(
|
72
72
|
serializer: MessageSerializer, admin: Admin, default_consumer: Consumer
|
73
73
|
) -> Consumer:
|
74
|
-
if
|
74
|
+
if APP_BROKER_TYPE == "rabbitmq":
|
75
75
|
return RMQConsumer(
|
76
76
|
logger=logger,
|
77
|
-
connection_string=
|
77
|
+
connection_string=APP_RMQ_CONNECTION_STRING,
|
78
78
|
serializer=serializer,
|
79
79
|
rmq_admin=admin,
|
80
80
|
)
|
81
|
-
if
|
81
|
+
if APP_BROKER_TYPE == "kafka":
|
82
82
|
return KafkaConsumer(
|
83
83
|
logger=logger,
|
84
|
-
bootstrap_servers=
|
85
|
-
security_protocol=
|
86
|
-
sasl_mechanism=
|
87
|
-
sasl_plain_username=
|
88
|
-
sasl_plain_password=
|
89
|
-
group_id=
|
84
|
+
bootstrap_servers=APP_KAFKA_BOOTSTRAP_SERVERS,
|
85
|
+
security_protocol=APP_KAFKA_SECURITY_PROTOCOL,
|
86
|
+
sasl_mechanism=APP_KAFKA_SASL_MECHANISM,
|
87
|
+
sasl_plain_username=APP_KAFKA_SASL_USER,
|
88
|
+
sasl_plain_password=APP_KAFKA_SASL_PASS,
|
89
|
+
group_id=APP_NAME,
|
90
90
|
serializer=serializer,
|
91
91
|
kafka_admin=admin,
|
92
92
|
)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
from component.messagebus import KafkaConsumer, RMQConsumer
|
2
2
|
from component.rpc import Caller, MessagebusCaller, MessagebusServer, Server
|
3
3
|
from config import (
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
APP_BROKER_TYPE,
|
5
|
+
APP_KAFKA_BOOTSTRAP_SERVERS,
|
6
|
+
APP_NAME,
|
7
|
+
APP_RMQ_CONNECTION_STRING,
|
8
8
|
)
|
9
9
|
from integration.log import logger
|
10
10
|
from integration.messagebus import (
|
@@ -18,20 +18,20 @@ from ulid import ULID
|
|
18
18
|
|
19
19
|
|
20
20
|
def create_consumer():
|
21
|
-
if
|
21
|
+
if APP_BROKER_TYPE == "rabbitmq":
|
22
22
|
return RMQConsumer(
|
23
23
|
logger=logger,
|
24
|
-
connection_string=
|
24
|
+
connection_string=APP_RMQ_CONNECTION_STRING,
|
25
25
|
serializer=message_serializer,
|
26
26
|
rmq_admin=admin,
|
27
27
|
identifier="rmq-rpc-reply-consumer",
|
28
28
|
)
|
29
|
-
if
|
29
|
+
if APP_BROKER_TYPE == "kafka":
|
30
30
|
random_uuid = str(ULID())
|
31
|
-
group_id = f"{
|
31
|
+
group_id = f"{APP_NAME}-reply-{random_uuid}"
|
32
32
|
return KafkaConsumer(
|
33
33
|
logger=logger,
|
34
|
-
bootstrap_servers=
|
34
|
+
bootstrap_servers=APP_KAFKA_BOOTSTRAP_SERVERS,
|
35
35
|
group_id=group_id,
|
36
36
|
serializer=message_serializer,
|
37
37
|
kafka_admin=admin,
|
@@ -1,9 +1,7 @@
|
|
1
|
-
from integration.app import app
|
1
|
+
from integration.app.app import app
|
2
2
|
from module.auth.register_module import register_auth
|
3
3
|
from module.log.register_module import register_log
|
4
4
|
|
5
|
-
# Make sure app is loaded.
|
6
|
-
# Uvicorn or adny ASGII server you use will pick it up and run the app.
|
7
5
|
assert app
|
8
6
|
register_auth()
|
9
7
|
register_log()
|
@@ -1,4 +1,4 @@
|
|
1
|
-
from config import
|
1
|
+
from config import APP_AUTH_ACCESS_TOKEN_COOKIE_KEY
|
2
2
|
from module.auth.component import (
|
3
3
|
AccessTokenScheme,
|
4
4
|
create_oauth2_bearer_access_token_scheme,
|
@@ -11,6 +11,6 @@ access_token_scheme: AccessTokenScheme = (
|
|
11
11
|
guest_user=guest_user,
|
12
12
|
access_token_util=access_token_util,
|
13
13
|
token_url="/api/v1/auth/login-oauth",
|
14
|
-
token_cookie_key=
|
14
|
+
token_cookie_key=APP_AUTH_ACCESS_TOKEN_COOKIE_KEY,
|
15
15
|
)
|
16
16
|
)
|
@@ -1,18 +1,18 @@
|
|
1
1
|
from config import (
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
APP_AUTH_ACCESS_TOKEN_TYPE,
|
3
|
+
APP_AUTH_JWT_TOKEN_ALGORITHM,
|
4
|
+
APP_AUTH_JWT_TOKEN_SECRET_KEY,
|
5
5
|
)
|
6
6
|
from module.auth.component import AccessTokenUtil, JWTAccessTokenUtil
|
7
7
|
|
8
8
|
|
9
9
|
def init_token_util() -> AccessTokenUtil:
|
10
|
-
if
|
10
|
+
if APP_AUTH_ACCESS_TOKEN_TYPE.lower() == "jwt":
|
11
11
|
return JWTAccessTokenUtil(
|
12
|
-
secret_key=
|
13
|
-
algorithm=
|
12
|
+
secret_key=APP_AUTH_JWT_TOKEN_SECRET_KEY,
|
13
|
+
algorithm=APP_AUTH_JWT_TOKEN_ALGORITHM,
|
14
14
|
)
|
15
|
-
raise ValueError(f"Invalid auth token type: {
|
15
|
+
raise ValueError(f"Invalid auth token type: {APP_AUTH_ACCESS_TOKEN_TYPE}")
|
16
16
|
|
17
17
|
|
18
18
|
access_token_util = init_token_util()
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from config import (
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
APP_AUTH_ACCESS_TOKEN_EXPIRE_SECONDS,
|
3
|
+
APP_AUTH_ADMIN_ACTIVE,
|
4
|
+
APP_AUTH_REFRESH_TOKEN_EXPIRE_SECONDS,
|
5
5
|
)
|
6
6
|
from integration.messagebus import publisher
|
7
7
|
from module.auth.entity.user.model import UserModel
|
@@ -15,10 +15,10 @@ user_model: UserModel = UserModel(
|
|
15
15
|
publisher=publisher,
|
16
16
|
permission_model=permission_model,
|
17
17
|
access_token_util=access_token_util,
|
18
|
-
access_token_expire_seconds=
|
18
|
+
access_token_expire_seconds=APP_AUTH_ACCESS_TOKEN_EXPIRE_SECONDS,
|
19
19
|
refresh_token_util=refresh_token_util,
|
20
|
-
refresh_token_expire_seconds=
|
20
|
+
refresh_token_expire_seconds=APP_AUTH_REFRESH_TOKEN_EXPIRE_SECONDS,
|
21
21
|
guest_user=guest_user,
|
22
|
-
admin_user=admin_user if
|
22
|
+
admin_user=admin_user if APP_AUTH_ADMIN_ACTIVE else None,
|
23
23
|
admin_user_password=admin_user_password,
|
24
24
|
)
|
@@ -1,18 +1,18 @@
|
|
1
1
|
from config import (
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
APP_AUTH_JWT_TOKEN_ALGORITHM,
|
3
|
+
APP_AUTH_JWT_TOKEN_SECRET_KEY,
|
4
|
+
APP_AUTH_REFRESH_TOKEN_TYPE,
|
5
5
|
)
|
6
6
|
from module.auth.component import JWTRefreshTokenUtil, RefreshTokenUtil
|
7
7
|
|
8
8
|
|
9
9
|
def init_token_util() -> RefreshTokenUtil:
|
10
|
-
if
|
10
|
+
if APP_AUTH_REFRESH_TOKEN_TYPE.lower() == "jwt":
|
11
11
|
return JWTRefreshTokenUtil(
|
12
|
-
secret_key=
|
13
|
-
algorithm=
|
12
|
+
secret_key=APP_AUTH_JWT_TOKEN_SECRET_KEY,
|
13
|
+
algorithm=APP_AUTH_JWT_TOKEN_ALGORITHM,
|
14
14
|
)
|
15
|
-
raise ValueError(f"Invalid auth token type: {
|
15
|
+
raise ValueError(f"Invalid auth token type: {APP_AUTH_REFRESH_TOKEN_TYPE}")
|
16
16
|
|
17
17
|
|
18
18
|
refresh_token_util = init_token_util()
|
@@ -1,33 +1,33 @@
|
|
1
1
|
from config import (
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
APP_AUTH_ADMIN_EMAIL,
|
3
|
+
APP_AUTH_ADMIN_PASSWORD,
|
4
|
+
APP_AUTH_ADMIN_PHONE,
|
5
|
+
APP_AUTH_ADMIN_USER_ID,
|
6
|
+
APP_AUTH_ADMIN_USERNAME,
|
7
|
+
APP_AUTH_GUEST_EMAIL,
|
8
|
+
APP_AUTH_GUEST_PHONE,
|
9
|
+
APP_AUTH_GUEST_USER_ID,
|
10
|
+
APP_AUTH_GUEST_USERNAME,
|
11
11
|
)
|
12
12
|
from module.auth.schema.user import User
|
13
13
|
|
14
|
-
admin_user_password =
|
14
|
+
admin_user_password = APP_AUTH_ADMIN_PASSWORD
|
15
15
|
|
16
16
|
admin_user = User(
|
17
|
-
id=
|
18
|
-
username=
|
19
|
-
email=
|
20
|
-
phone=
|
17
|
+
id=APP_AUTH_ADMIN_USER_ID,
|
18
|
+
username=APP_AUTH_ADMIN_USERNAME,
|
19
|
+
email=APP_AUTH_ADMIN_EMAIL,
|
20
|
+
phone=APP_AUTH_ADMIN_PHONE,
|
21
21
|
groups=[],
|
22
22
|
permissions=[],
|
23
23
|
description="System administrator",
|
24
24
|
)
|
25
25
|
|
26
26
|
guest_user = User(
|
27
|
-
id=
|
28
|
-
username=
|
29
|
-
email=
|
30
|
-
phone=
|
27
|
+
id=APP_AUTH_GUEST_USER_ID,
|
28
|
+
username=APP_AUTH_GUEST_USERNAME,
|
29
|
+
email=APP_AUTH_GUEST_EMAIL,
|
30
|
+
phone=APP_AUTH_GUEST_PHONE,
|
31
31
|
groups=[],
|
32
32
|
permissions=[],
|
33
33
|
description="Visitor",
|
zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/auth/migrate.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from config import
|
1
|
+
from config import APP_ENABLE_AUTH_MODULE
|
2
2
|
from helper.migration import migrate
|
3
3
|
from integration.db_connection import engine
|
4
4
|
from integration.log import logger
|
@@ -7,7 +7,7 @@ from module.auth.register_permission import register_permission
|
|
7
7
|
|
8
8
|
|
9
9
|
async def migrate_auth():
|
10
|
-
if not
|
10
|
+
if not APP_ENABLE_AUTH_MODULE:
|
11
11
|
logger.info('🥪 Skip DB migration for "auth"')
|
12
12
|
return
|
13
13
|
logger.info('🥪 Perform DB migration for "auth"')
|
@@ -1,10 +1,10 @@
|
|
1
1
|
from config import (
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
APP_ENABLE_API,
|
3
|
+
APP_ENABLE_AUTH_MODULE,
|
4
|
+
APP_ENABLE_EVENT_HANDLER,
|
5
|
+
APP_ENABLE_RPC_SERVER,
|
6
6
|
)
|
7
|
-
from integration.app import app
|
7
|
+
from integration.app.app import app
|
8
8
|
from integration.log import logger
|
9
9
|
from integration.messagebus import consumer, publisher
|
10
10
|
from integration.rpc import rpc_caller, rpc_server
|
@@ -15,10 +15,10 @@ from module.auth.rpc import register_rpc
|
|
15
15
|
|
16
16
|
|
17
17
|
def register_auth():
|
18
|
-
if not
|
18
|
+
if not APP_ENABLE_AUTH_MODULE:
|
19
19
|
logger.info('🥪 Skip registering "auth"')
|
20
20
|
return
|
21
|
-
if
|
21
|
+
if APP_ENABLE_API:
|
22
22
|
register_api(
|
23
23
|
logger=logger,
|
24
24
|
app=app,
|
@@ -26,11 +26,11 @@ def register_auth():
|
|
26
26
|
rpc_caller=rpc_caller,
|
27
27
|
publisher=publisher,
|
28
28
|
)
|
29
|
-
if
|
29
|
+
if APP_ENABLE_EVENT_HANDLER:
|
30
30
|
register_event(
|
31
31
|
logger=logger, consumer=consumer, rpc_caller=rpc_caller, publisher=publisher
|
32
32
|
)
|
33
|
-
if
|
33
|
+
if APP_ENABLE_RPC_SERVER:
|
34
34
|
register_rpc(
|
35
35
|
logger=logger,
|
36
36
|
rpc_server=rpc_server,
|
zrb/builtin/project/add/fastapp/app/template/src/kebab-zrb-app-name/src/module/log/migrate.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from config import
|
1
|
+
from config import APP_ENABLE_LOG_MODULE
|
2
2
|
from helper.migration import migrate
|
3
3
|
from integration.db_connection import engine
|
4
4
|
from integration.log import logger
|
@@ -6,7 +6,7 @@ from module.log.integration import Base
|
|
6
6
|
|
7
7
|
|
8
8
|
async def migrate_log():
|
9
|
-
if not
|
9
|
+
if not APP_ENABLE_LOG_MODULE:
|
10
10
|
logger.info('🥪 Skip DB migration for "log"')
|
11
11
|
return
|
12
12
|
logger.info('🥪 Perform DB migration for "log"')
|