zrb 0.9.2__py3-none-any.whl → 0.10.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/generator/docker_compose_task/template/src/kebab-zrb-task-name/image/Dockerfile +1 -0
- zrb/builtin/generator/docker_compose_task/template/src/kebab-zrb-task-name/image/pyproject.toml +1 -1
- zrb/builtin/generator/fastapp/add.py +17 -5
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/loadtest/pyproject.toml +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/Dockerfile +1 -0
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/config.py +3 -1
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/auth/entity/group/api.py +67 -52
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/auth/entity/permission/api.py +67 -54
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/auth/entity/user/api.py +85 -67
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/log/entity/activity/api.py +30 -23
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/log/entity/activity/event.py +1 -3
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/pyproject.toml +1 -1
- zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/start.sh +20 -15
- zrb/builtin/generator/fastapp_crud/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/entity/snake_zrb_entity_name/api.py +82 -58
- zrb/builtin/generator/fastapp_crud/template/src/kebab-zrb-app-name/src/module/snake_zrb_module_name/schema/snake_zrb_entity_name.py +1 -1
- zrb/builtin/generator/fastapp_field/helper.py +1 -1
- zrb/builtin/generator/pip_package/template/_automate/snake_zrb_package_name/cmd/publish.sh +1 -1
- zrb/builtin/generator/pip_package/template/_automate/snake_zrb_package_name/local.py +1 -9
- zrb/builtin/generator/pip_package/template/src/kebab-zrb-package-name/pyproject.toml +1 -1
- zrb/builtin/generator/plugin/template/_cmd/publish.sh +1 -1
- zrb/builtin/generator/plugin/template/pyproject.toml +1 -1
- zrb/builtin/generator/plugin/template/zrb_init.py +1 -9
- zrb/builtin/generator/project/template/pyproject.toml +1 -1
- zrb/builtin/generator/simple_python_app/template/src/kebab-zrb-app-name/src/Dockerfile +1 -0
- zrb/builtin/generator/simple_python_app/template/src/kebab-zrb-app-name/src/pyproject.toml +1 -1
- zrb/config/config.py +10 -7
- zrb/helper/accessories/name.py +60 -116
- zrb/helper/codemod/add_property_to_class.py +18 -1
- zrb/shell-scripts/ensure-podman-is-installed.sh +55 -0
- zrb/task/any_task.py +83 -0
- zrb/task/base_remote_cmd_task.py +2 -0
- zrb/task/base_task/base_task.py +53 -15
- zrb/task/base_task/component/base_task_model.py +2 -0
- zrb/task/base_task/component/common_task_model.py +26 -0
- zrb/task/checker.py +2 -0
- zrb/task/cmd_task.py +2 -0
- zrb/task/docker_compose_task.py +27 -21
- zrb/task/flow_task.py +2 -0
- zrb/task/http_checker.py +2 -0
- zrb/task/notifier.py +2 -0
- zrb/task/path_checker.py +2 -0
- zrb/task/path_watcher.py +2 -0
- zrb/task/port_checker.py +2 -0
- zrb/task/recurring_task.py +2 -0
- zrb/task/remote_cmd_task.py +2 -0
- zrb/task/resource_maker.py +2 -0
- zrb/task/rsync_task.py +2 -0
- zrb/task/time_watcher.py +2 -0
- zrb/task/wiki_task.py +119 -0
- {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/METADATA +1 -1
- {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/RECORD +55 -53
- {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/LICENSE +0 -0
- {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/WHEEL +0 -0
- {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/entry_points.txt +0 -0
zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/log/entity/activity/api.py
CHANGED
@@ -8,6 +8,9 @@ from module.auth.component import Authorizer
|
|
8
8
|
from module.auth.integration import access_token_scheme
|
9
9
|
from module.auth.schema.token import AccessTokenData
|
10
10
|
from module.log.schema.activity import Activity, ActivityResult
|
11
|
+
from opentelemetry import trace
|
12
|
+
|
13
|
+
tracer = trace.get_tracer(__name__)
|
11
14
|
|
12
15
|
|
13
16
|
def register_api(
|
@@ -26,20 +29,22 @@ def register_api(
|
|
26
29
|
offset: int = 0,
|
27
30
|
user_token_data: AccessTokenData = Depends(access_token_scheme),
|
28
31
|
):
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
with tracer.start_as_current_span("authorizer.is_having_permission"):
|
33
|
+
if not await authorizer.is_having_permission(
|
34
|
+
user_token_data.user_id, "log:activity:get"
|
35
|
+
):
|
36
|
+
raise HTTPAPIException(403, "Unauthorized")
|
33
37
|
try:
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
with tracer.start_as_current_span("log.rpc.log_get_activity"):
|
39
|
+
result_dict = await rpc_caller.call(
|
40
|
+
"log_get_activity",
|
41
|
+
keyword=keyword,
|
42
|
+
criterion={},
|
43
|
+
limit=limit,
|
44
|
+
offset=offset,
|
45
|
+
user_token_data=user_token_data.model_dump(),
|
46
|
+
)
|
47
|
+
return ActivityResult(**result_dict)
|
43
48
|
except Exception as e:
|
44
49
|
raise HTTPAPIException(error=e)
|
45
50
|
|
@@ -47,16 +52,18 @@ def register_api(
|
|
47
52
|
async def get_activity_by_id(
|
48
53
|
id: str, user_token_data: AccessTokenData = Depends(access_token_scheme)
|
49
54
|
):
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
55
|
+
with tracer.start_as_current_span("authorizer.is_having_permission"):
|
56
|
+
if not await authorizer.is_having_permission(
|
57
|
+
user_token_data.user_id, "log:activity:get_by_id"
|
58
|
+
):
|
59
|
+
raise HTTPAPIException(403, "Unauthorized")
|
54
60
|
try:
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
+
with tracer.start_as_current_span("log.rpc.log_get_activity_by_id"):
|
62
|
+
result_dict = await rpc_caller.call(
|
63
|
+
"log_get_activity_by_id",
|
64
|
+
id=id,
|
65
|
+
user_token_data=user_token_data.model_dump(),
|
66
|
+
)
|
67
|
+
return Activity(**result_dict)
|
61
68
|
except Exception as e:
|
62
69
|
raise HTTPAPIException(error=e)
|
@@ -13,7 +13,5 @@ def register_event(
|
|
13
13
|
logger.info('🥪 Register event handlers for "log.activity"')
|
14
14
|
|
15
15
|
@consumer.register("log_new_activity")
|
16
|
-
async def insert(
|
17
|
-
data: Mapping[str, Any],
|
18
|
-
):
|
16
|
+
async def insert(data: Mapping[str, Any]):
|
19
17
|
await activity_model.insert(data=ActivityData(**data))
|
@@ -39,20 +39,25 @@ fi
|
|
39
39
|
# Start kebab-zrb-app-name
|
40
40
|
##############################################################################
|
41
41
|
|
42
|
+
# Reload option can only be used when APP_ENABLE_OTEL is false
|
43
|
+
_RELOAD=""
|
44
|
+
if [ $(_to_boolean "$APP_ENABLE_OTEL") = "false" ] && [ $(_to_boolean "$APP_RELOAD") = "true" ]
|
45
|
+
then
|
46
|
+
_RELOAD="--reload"
|
47
|
+
fi
|
48
|
+
|
49
|
+
# Constructing otel command
|
50
|
+
# See: https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/fastapi/fastapi.html#installation
|
51
|
+
_OTEL_COMMAND=""
|
42
52
|
if [ $(_to_boolean "$APP_ENABLE_OTEL") = "true" ]
|
43
53
|
then
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
fi
|
55
|
-
# Run uvicorn
|
56
|
-
echo "Start uvicorn"
|
57
|
-
poetry run uvicorn main:app --host "$APP_HOST" --port "$APP_PORT" $_RELOAD
|
58
|
-
fi
|
54
|
+
export OTEL_RESOURCE_ATTRIBUTES="service.name=${APP_NAME}"
|
55
|
+
export OTEL_EXPORTER_OTLP_ENDPOINT="$APP_OTEL_EXPORTER_OTLP_ENDPOINT"
|
56
|
+
export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST=".*"
|
57
|
+
export OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE=".*"
|
58
|
+
_OTEL_COMMAND="opentelemetry-instrument"
|
59
|
+
fi
|
60
|
+
|
61
|
+
# Run uvicorn
|
62
|
+
echo "Start uvicorn"
|
63
|
+
poetry run $_OTEL_COMMAND uvicorn main:app --host "$APP_HOST" --port "$APP_PORT" $_RELOAD
|
@@ -12,6 +12,9 @@ from module.snake_zrb_module_name.schema.snake_zrb_entity_name import (
|
|
12
12
|
PascalZrbEntityNameData,
|
13
13
|
PascalZrbEntityNameResult,
|
14
14
|
)
|
15
|
+
from opentelemetry import trace
|
16
|
+
|
17
|
+
tracer = trace.get_tracer(__name__)
|
15
18
|
|
16
19
|
|
17
20
|
def register_api(
|
@@ -33,20 +36,25 @@ def register_api(
|
|
33
36
|
offset: int = 0,
|
34
37
|
user_token_data: AccessTokenData = Depends(access_token_scheme),
|
35
38
|
):
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
with tracer.start_as_current_span("authorizer.is_having_permission"):
|
40
|
+
if not await authorizer.is_having_permission(
|
41
|
+
user_token_data.user_id,
|
42
|
+
"snake_zrb_module_name:snake_zrb_entity_name:get",
|
43
|
+
):
|
44
|
+
raise HTTPAPIException(403, "Unauthorized")
|
40
45
|
try:
|
41
|
-
|
42
|
-
"snake_zrb_module_name_get_snake_zrb_entity_name"
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
with tracer.start_as_current_span(
|
47
|
+
"snake_zrb_module_name.rpc.snake_zrb_module_name_get_snake_zrb_entity_name" # noqa
|
48
|
+
):
|
49
|
+
result_dict = await rpc_caller.call(
|
50
|
+
"snake_zrb_module_name_get_snake_zrb_entity_name",
|
51
|
+
keyword=keyword,
|
52
|
+
criterion={},
|
53
|
+
limit=limit,
|
54
|
+
offset=offset,
|
55
|
+
user_token_data=user_token_data.model_dump(),
|
56
|
+
)
|
57
|
+
return PascalZrbEntityNameResult(**result_dict)
|
50
58
|
except Exception as e:
|
51
59
|
raise HTTPAPIException(error=e)
|
52
60
|
|
@@ -57,18 +65,22 @@ def register_api(
|
|
57
65
|
async def get_snake_zrb_entity_name_by_id(
|
58
66
|
id: str, user_token_data: AccessTokenData = Depends(access_token_scheme)
|
59
67
|
):
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
68
|
+
with tracer.start_as_current_span("authorizer.is_having_permission"):
|
69
|
+
if not await authorizer.is_having_permission(
|
70
|
+
user_token_data.user_id,
|
71
|
+
"snake_zrb_module_name:snake_zrb_entity_name:get_by_id",
|
72
|
+
):
|
73
|
+
raise HTTPAPIException(403, "Unauthorized")
|
65
74
|
try:
|
66
|
-
|
67
|
-
"snake_zrb_module_name_get_snake_zrb_entity_name_by_id"
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
75
|
+
with tracer.start_as_current_span(
|
76
|
+
"snake_zrb_module_name.rpc.snake_zrb_module_name_get_snake_zrb_entity_name_by_id" # noqa
|
77
|
+
):
|
78
|
+
result_dict = await rpc_caller.call(
|
79
|
+
"snake_zrb_module_name_get_snake_zrb_entity_name_by_id",
|
80
|
+
id=id,
|
81
|
+
user_token_data=user_token_data.model_dump(),
|
82
|
+
)
|
83
|
+
return PascalZrbEntityName(**result_dict)
|
72
84
|
except Exception as e:
|
73
85
|
raise HTTPAPIException(error=e)
|
74
86
|
|
@@ -80,18 +92,22 @@ def register_api(
|
|
80
92
|
data: PascalZrbEntityNameData,
|
81
93
|
user_token_data: AccessTokenData = Depends(access_token_scheme),
|
82
94
|
):
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
95
|
+
with tracer.start_as_current_span("authorizer.is_having_permission"):
|
96
|
+
if not await authorizer.is_having_permission(
|
97
|
+
user_token_data.user_id,
|
98
|
+
"snake_zrb_module_name:snake_zrb_entity_name:insert",
|
99
|
+
):
|
100
|
+
raise HTTPAPIException(403, "Unauthorized")
|
88
101
|
try:
|
89
|
-
|
90
|
-
"snake_zrb_module_name_insert_snake_zrb_entity_name"
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
102
|
+
with tracer.start_as_current_span(
|
103
|
+
"snake_zrb_module_name.rpc.snake_zrb_module_name_insert_snake_zrb_entity_name" # noqa
|
104
|
+
):
|
105
|
+
result_dict = await rpc_caller.call(
|
106
|
+
"snake_zrb_module_name_insert_snake_zrb_entity_name",
|
107
|
+
data=data.model_dump(),
|
108
|
+
user_token_data=user_token_data.model_dump(),
|
109
|
+
)
|
110
|
+
return PascalZrbEntityName(**result_dict)
|
95
111
|
except Exception as e:
|
96
112
|
raise HTTPAPIException(error=e)
|
97
113
|
|
@@ -104,19 +120,23 @@ def register_api(
|
|
104
120
|
data: PascalZrbEntityNameData,
|
105
121
|
user_token_data: AccessTokenData = Depends(access_token_scheme),
|
106
122
|
):
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
123
|
+
with tracer.start_as_current_span("authorizer.is_having_permission"):
|
124
|
+
if not await authorizer.is_having_permission(
|
125
|
+
user_token_data.user_id,
|
126
|
+
"snake_zrb_module_name:snake_zrb_entity_name:update",
|
127
|
+
):
|
128
|
+
raise HTTPAPIException(403, "Unauthorized")
|
112
129
|
try:
|
113
|
-
|
114
|
-
"snake_zrb_module_name_update_snake_zrb_entity_name"
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
130
|
+
with tracer.start_as_current_span(
|
131
|
+
"snake_zrb_module_name.rpc.snake_zrb_module_name_update_snake_zrb_entity_name" # noqa
|
132
|
+
):
|
133
|
+
result_dict = await rpc_caller.call(
|
134
|
+
"snake_zrb_module_name_update_snake_zrb_entity_name",
|
135
|
+
id=id,
|
136
|
+
data=data.model_dump(),
|
137
|
+
user_token_data=user_token_data.model_dump(),
|
138
|
+
)
|
139
|
+
return PascalZrbEntityName(**result_dict)
|
120
140
|
except Exception as e:
|
121
141
|
raise HTTPAPIException(error=e)
|
122
142
|
|
@@ -127,17 +147,21 @@ def register_api(
|
|
127
147
|
async def delete_snake_zrb_entity_name(
|
128
148
|
id: str, user_token_data: AccessTokenData = Depends(access_token_scheme)
|
129
149
|
):
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
150
|
+
with tracer.start_as_current_span("authorizer.is_having_permission"):
|
151
|
+
if not await authorizer.is_having_permission(
|
152
|
+
user_token_data.user_id,
|
153
|
+
"snake_zrb_module_name:snake_zrb_entity_name:delete",
|
154
|
+
):
|
155
|
+
raise HTTPAPIException(403, "Unauthorized")
|
135
156
|
try:
|
136
|
-
|
137
|
-
"snake_zrb_module_name_delete_snake_zrb_entity_name"
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
157
|
+
with tracer.start_as_current_span(
|
158
|
+
"snake_zrb_module_name.rpc.snake_zrb_module_name_delete_snake_zrb_entity_name" # noqa
|
159
|
+
):
|
160
|
+
result_dict = await rpc_caller.call(
|
161
|
+
"snake_zrb_module_name_delete_snake_zrb_entity_name",
|
162
|
+
id=id,
|
163
|
+
user_token_data=user_token_data.model_dump(),
|
164
|
+
)
|
165
|
+
return PascalZrbEntityName(**result_dict)
|
142
166
|
except Exception as e:
|
143
167
|
raise HTTPAPIException(error=e)
|
@@ -300,7 +300,7 @@ async def add_column_to_schema(
|
|
300
300
|
code=code,
|
301
301
|
class_name=f"{pascal_entity_name}Data",
|
302
302
|
property_name=snake_column_name,
|
303
|
-
property_type="str",
|
303
|
+
property_type="Optional[str]",
|
304
304
|
)
|
305
305
|
task.print_out(f"Write modified code to: {schema_file_path}")
|
306
306
|
await write_text_file_async(schema_file_path, code)
|
@@ -1,2 +1,2 @@
|
|
1
1
|
echo "Publish"
|
2
|
-
poetry publish
|
2
|
+
poetry publish
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import os
|
2
2
|
|
3
|
-
from zrb import CmdTask,
|
3
|
+
from zrb import CmdTask, runner
|
4
4
|
from zrb.builtin.group import project_group
|
5
5
|
|
6
6
|
CURRENT_DIR = os.path.dirname(__file__)
|
@@ -49,14 +49,6 @@ publish_snake_zrb_package_name = CmdTask(
|
|
49
49
|
name="publish-kebab-zrb-package-name",
|
50
50
|
description="Publish human readable zrb package name",
|
51
51
|
group=project_group,
|
52
|
-
inputs=[
|
53
|
-
StrInput(
|
54
|
-
name="kebab-zrb-package-name-repo",
|
55
|
-
prompt="Pypi repository for human readable zrb package name",
|
56
|
-
description="Pypi repository for human readalbe zrb package name",
|
57
|
-
default="pypi",
|
58
|
-
)
|
59
|
-
],
|
60
52
|
upstreams=[build_snake_zrb_package_name],
|
61
53
|
cwd=RESOURCE_DIR,
|
62
54
|
cmd_path=[
|
@@ -1,2 +1,2 @@
|
|
1
1
|
echo "Publish"
|
2
|
-
poetry publish
|
2
|
+
poetry publish
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import os
|
2
2
|
|
3
|
-
from zrb import CmdTask,
|
3
|
+
from zrb import CmdTask, runner
|
4
4
|
from zrb.builtin.group import plugin_group
|
5
5
|
|
6
6
|
PROJECT_DIR = os.path.dirname(__file__)
|
@@ -46,14 +46,6 @@ publish_plugin = CmdTask(
|
|
46
46
|
name="publish",
|
47
47
|
group=plugin_group,
|
48
48
|
description="Publish plugin",
|
49
|
-
inputs=[
|
50
|
-
StrInput(
|
51
|
-
name="plugin-repo",
|
52
|
-
prompt="Pypi repository for plugin",
|
53
|
-
description="Pypi repository for human readalbe zrb package name",
|
54
|
-
default="pypi",
|
55
|
-
)
|
56
|
-
],
|
57
49
|
upstreams=[build_plugin],
|
58
50
|
cwd=PROJECT_DIR,
|
59
51
|
cmd_path=[
|
zrb/config/config.py
CHANGED
@@ -7,13 +7,7 @@ from zrb.helper.typecheck import typechecked
|
|
7
7
|
|
8
8
|
@typechecked
|
9
9
|
def get_version() -> str:
|
10
|
-
|
11
|
-
return metadata.version("zrb")
|
12
|
-
except metadata.PackageNotFoundError:
|
13
|
-
import flit
|
14
|
-
|
15
|
-
meta = flit.read_module_metadata("zrb")
|
16
|
-
return str(meta["module"]["version"])
|
10
|
+
return metadata.version("zrb")
|
17
11
|
|
18
12
|
|
19
13
|
@typechecked
|
@@ -24,6 +18,12 @@ def get_current_shell() -> str:
|
|
24
18
|
return "bash"
|
25
19
|
|
26
20
|
|
21
|
+
def _get_valid_container_backend(container_backend: str) -> str:
|
22
|
+
if container_backend.lower().strip() == "podman":
|
23
|
+
return "podman"
|
24
|
+
return "docker"
|
25
|
+
|
26
|
+
|
27
27
|
default_shell = os.getenv("ZRB_SHELL", get_current_shell())
|
28
28
|
init_script_str = os.getenv("ZRB_INIT_SCRIPTS", "")
|
29
29
|
init_scripts = init_script_str.split(":") if init_script_str != "" else []
|
@@ -34,3 +34,6 @@ show_advertisement = to_boolean(os.getenv("ZRB_SHOW_ADVERTISEMENT", "1"))
|
|
34
34
|
show_prompt = to_boolean(os.getenv("ZRB_SHOW_PROMPT", "1"))
|
35
35
|
show_time = to_boolean(os.getenv("ZRB_SHOW_TIME", "1"))
|
36
36
|
version = get_version()
|
37
|
+
container_backend = _get_valid_container_backend(
|
38
|
+
os.getenv("ZRB_CONTAINER_BACKEND", "docker")
|
39
|
+
)
|