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.
Files changed (55) hide show
  1. zrb/__init__.py +2 -0
  2. zrb/builtin/generator/docker_compose_task/template/src/kebab-zrb-task-name/image/Dockerfile +1 -0
  3. zrb/builtin/generator/docker_compose_task/template/src/kebab-zrb-task-name/image/pyproject.toml +1 -1
  4. zrb/builtin/generator/fastapp/add.py +17 -5
  5. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/loadtest/pyproject.toml +1 -1
  6. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/Dockerfile +1 -0
  7. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/config.py +3 -1
  8. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/auth/entity/group/api.py +67 -52
  9. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/auth/entity/permission/api.py +67 -54
  10. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/auth/entity/user/api.py +85 -67
  11. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/log/entity/activity/api.py +30 -23
  12. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/module/log/entity/activity/event.py +1 -3
  13. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/pyproject.toml +1 -1
  14. zrb/builtin/generator/fastapp/template/src/kebab-zrb-app-name/src/start.sh +20 -15
  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
  16. 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
  17. zrb/builtin/generator/fastapp_field/helper.py +1 -1
  18. zrb/builtin/generator/pip_package/template/_automate/snake_zrb_package_name/cmd/publish.sh +1 -1
  19. zrb/builtin/generator/pip_package/template/_automate/snake_zrb_package_name/local.py +1 -9
  20. zrb/builtin/generator/pip_package/template/src/kebab-zrb-package-name/pyproject.toml +1 -1
  21. zrb/builtin/generator/plugin/template/_cmd/publish.sh +1 -1
  22. zrb/builtin/generator/plugin/template/pyproject.toml +1 -1
  23. zrb/builtin/generator/plugin/template/zrb_init.py +1 -9
  24. zrb/builtin/generator/project/template/pyproject.toml +1 -1
  25. zrb/builtin/generator/simple_python_app/template/src/kebab-zrb-app-name/src/Dockerfile +1 -0
  26. zrb/builtin/generator/simple_python_app/template/src/kebab-zrb-app-name/src/pyproject.toml +1 -1
  27. zrb/config/config.py +10 -7
  28. zrb/helper/accessories/name.py +60 -116
  29. zrb/helper/codemod/add_property_to_class.py +18 -1
  30. zrb/shell-scripts/ensure-podman-is-installed.sh +55 -0
  31. zrb/task/any_task.py +83 -0
  32. zrb/task/base_remote_cmd_task.py +2 -0
  33. zrb/task/base_task/base_task.py +53 -15
  34. zrb/task/base_task/component/base_task_model.py +2 -0
  35. zrb/task/base_task/component/common_task_model.py +26 -0
  36. zrb/task/checker.py +2 -0
  37. zrb/task/cmd_task.py +2 -0
  38. zrb/task/docker_compose_task.py +27 -21
  39. zrb/task/flow_task.py +2 -0
  40. zrb/task/http_checker.py +2 -0
  41. zrb/task/notifier.py +2 -0
  42. zrb/task/path_checker.py +2 -0
  43. zrb/task/path_watcher.py +2 -0
  44. zrb/task/port_checker.py +2 -0
  45. zrb/task/recurring_task.py +2 -0
  46. zrb/task/remote_cmd_task.py +2 -0
  47. zrb/task/resource_maker.py +2 -0
  48. zrb/task/rsync_task.py +2 -0
  49. zrb/task/time_watcher.py +2 -0
  50. zrb/task/wiki_task.py +119 -0
  51. {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/METADATA +1 -1
  52. {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/RECORD +55 -53
  53. {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/LICENSE +0 -0
  54. {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/WHEEL +0 -0
  55. {zrb-0.9.2.dist-info → zrb-0.10.0.dist-info}/entry_points.txt +0 -0
zrb/__init__.py CHANGED
@@ -28,6 +28,7 @@ from zrb.task.resource_maker import Replacement, ReplacementMutator, ResourceMak
28
28
  from zrb.task.rsync_task import RsyncTask
29
29
  from zrb.task.task import Task
30
30
  from zrb.task.time_watcher import TimeWatcher
31
+ from zrb.task.wiki_task import create_wiki_tasks
31
32
  from zrb.task_env.env import Env
32
33
  from zrb.task_env.env_file import EnvFile
33
34
  from zrb.task_group.group import Group
@@ -40,6 +41,7 @@ from zrb.task_input.password_input import PasswordInput
40
41
  from zrb.task_input.str_input import StrInput
41
42
  from zrb.task_input.task_input import Input
42
43
 
44
+ assert create_wiki_tasks
43
45
  assert runner
44
46
  assert AnyTask
45
47
  assert OnTriggered
@@ -1,6 +1,7 @@
1
1
  FROM python:3.10-slim
2
2
  ENV APP_MESSAGE "Hello, world!"
3
3
  ENV APP_PORT 8080
4
+ ENV POETRY_VIRTUAL_ENVS_CREATE=false
4
5
  WORKDIR /home
5
6
  COPY ./pyproject.toml ./pyproject.toml
6
7
  RUN pip install "poetry==1.7.1"
@@ -13,7 +13,7 @@ uvicorn = "==0.20.0"
13
13
 
14
14
  [tool.poetry.dev-dependencies]
15
15
  flake8 = "~7.0.0"
16
- black = "~24.2.0"
16
+ black = "~24.3.0"
17
17
  isort = "~5.13.2"
18
18
  pytest = "~7.4.0"
19
19
  pytest-cov = "~4.1.0"
@@ -85,11 +85,23 @@ copy_resource = ResourceMaker(
85
85
  excludes=[
86
86
  "*/__pycache__",
87
87
  "*/deployment/venv",
88
- "*/src/kebab-app-name/.venv",
89
- "*/src/kebab-app-name/src/frontend/node_modules",
90
- "*/src/kebab-app-name/src/frontend/build",
91
- "*/src/kebab-app-name/src/frontend/.svelte-kit",
92
- "*/src/kebab-app-name/monitoring/clickhouse",
88
+ "*/src/kebab-zrb-app-name/.venv",
89
+ "*/src/kebab-zrb-app-name/src/frontend/node_modules",
90
+ "*/src/kebab-zrb-app-name/src/frontend/build",
91
+ "*/src/kebab-zrb-app-name/src/frontend/.svelte-kit",
92
+ ],
93
+ skip_parsing=[
94
+ "*.mp3",
95
+ "*.pdf",
96
+ "*.exe",
97
+ "*.dll",
98
+ "*.bin",
99
+ "*.iso",
100
+ "*.png",
101
+ "*.jpg",
102
+ "*.gif",
103
+ "*.ico",
104
+ "*/monitoring/clickhouse/user_scripts/histogramQuantile",
93
105
  ],
94
106
  )
95
107
 
@@ -13,7 +13,7 @@ locust = "==2.16.1"
13
13
 
14
14
  [tool.poetry.dev-dependencies]
15
15
  flake8 = "~6.0.0"
16
- black = "~23.12.1"
16
+ black = "~24.3.0"
17
17
  isort = "~5.13.2"
18
18
 
19
19
  [build-system]
@@ -8,6 +8,7 @@ RUN npm install --save-dev && npm run build
8
8
  FROM python:3.10-slim
9
9
  ENV APP_HOST 0.0.0.0
10
10
  ENV APP_PORT 8080
11
+ ENV POETRY_VIRTUAL_ENVS_CREATE=false
11
12
  WORKDIR /home
12
13
  RUN apt update && apt install curl psmisc -y
13
14
  RUN pip install -U pip
@@ -14,7 +14,9 @@ app_reload = str_to_boolean(os.getenv("APP_RELOAD", "true"))
14
14
  app_max_not_ready = int(os.getenv("APP_MAX_NOT_READY", "10"))
15
15
 
16
16
  app_enable_otel = str_to_boolean(os.getenv("APP_ENABLE_OTEL", "false"))
17
- app_otel_exporter_otlp_endpoint = os.getenv("APP_OTEL_EXPORTER_OTLP_ENDPOINT", "false")
17
+ app_otel_exporter_otlp_endpoint = os.getenv(
18
+ "APP_OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4317"
19
+ )
18
20
 
19
21
  app_auth_access_token_cookie_key = os.getenv(
20
22
  "PUBLIC_AUTH_ACCESS_TOKEN_COOKIE_KEY", "access_token"
@@ -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.group import Group, GroupData, GroupResult
10
10
  from module.auth.schema.token import AccessTokenData
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
- if not await authorizer.is_having_permission(
30
- user_token_data.user_id, "auth:permission:get"
31
- ):
32
- raise HTTPAPIException(403, "Unauthorized")
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, "auth:permission:get"
35
+ ):
36
+ raise HTTPAPIException(403, "Unauthorized")
33
37
  try:
34
- result_dict = await rpc_caller.call(
35
- "auth_get_group",
36
- keyword=keyword,
37
- criterion={},
38
- limit=limit,
39
- offset=offset,
40
- user_token_data=user_token_data.model_dump(),
41
- )
42
- return GroupResult(**result_dict)
38
+ with tracer.start_as_current_span("auth.rpc.auth_get_group"):
39
+ result_dict = await rpc_caller.call(
40
+ "auth_get_group",
41
+ keyword=keyword,
42
+ criterion={},
43
+ limit=limit,
44
+ offset=offset,
45
+ user_token_data=user_token_data.model_dump(),
46
+ )
47
+ return GroupResult(**result_dict)
43
48
  except Exception as e:
44
49
  raise HTTPAPIException(error=e)
45
50
 
@@ -47,17 +52,19 @@ def register_api(
47
52
  async def get_group_by_id(
48
53
  id: str, user_token_data: AccessTokenData = Depends(access_token_scheme)
49
54
  ):
50
- if not await authorizer.is_having_permission(
51
- user_token_data.user_id, "auth:group:get_by_id"
52
- ):
53
- raise HTTPAPIException(403, "Unauthorized")
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, "auth:group:get_by_id"
58
+ ):
59
+ raise HTTPAPIException(403, "Unauthorized")
54
60
  try:
55
- result_dict = await rpc_caller.call(
56
- "auth_get_group_by_id",
57
- id=id,
58
- user_token_data=user_token_data.model_dump(),
59
- )
60
- return Group(**result_dict)
61
+ with tracer.start_as_current_span("auth.rpc.auth_get_group_by_id"):
62
+ result_dict = await rpc_caller.call(
63
+ "auth_get_group_by_id",
64
+ id=id,
65
+ user_token_data=user_token_data.model_dump(),
66
+ )
67
+ return Group(**result_dict)
61
68
  except Exception as e:
62
69
  raise HTTPAPIException(error=e)
63
70
 
@@ -65,17 +72,19 @@ def register_api(
65
72
  async def insert_group(
66
73
  data: GroupData, user_token_data: AccessTokenData = Depends(access_token_scheme)
67
74
  ):
68
- if not await authorizer.is_having_permission(
69
- user_token_data.user_id, "auth:group:insert"
70
- ):
71
- raise HTTPAPIException(403, "Unauthorized")
75
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
76
+ if not await authorizer.is_having_permission(
77
+ user_token_data.user_id, "auth:group:insert"
78
+ ):
79
+ raise HTTPAPIException(403, "Unauthorized")
72
80
  try:
73
- result_dict = await rpc_caller.call(
74
- "auth_insert_group",
75
- data=data.model_dump(),
76
- user_token_data=user_token_data.model_dump(),
77
- )
78
- return Group(**result_dict)
81
+ with tracer.start_as_current_span("auth.rpc.auth_insert_group"):
82
+ result_dict = await rpc_caller.call(
83
+ "auth_insert_group",
84
+ data=data.model_dump(),
85
+ user_token_data=user_token_data.model_dump(),
86
+ )
87
+ return Group(**result_dict)
79
88
  except Exception as e:
80
89
  raise HTTPAPIException(error=e)
81
90
 
@@ -85,18 +94,20 @@ def register_api(
85
94
  data: GroupData,
86
95
  user_token_data: AccessTokenData = Depends(access_token_scheme),
87
96
  ):
88
- if not await authorizer.is_having_permission(
89
- user_token_data.user_id, "auth:group:update"
90
- ):
91
- raise HTTPAPIException(403, "Unauthorized")
97
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
98
+ if not await authorizer.is_having_permission(
99
+ user_token_data.user_id, "auth:group:update"
100
+ ):
101
+ raise HTTPAPIException(403, "Unauthorized")
92
102
  try:
93
- result_dict = await rpc_caller.call(
94
- "auth_update_group",
95
- id=id,
96
- data=data.model_dump(),
97
- user_token_data=user_token_data.model_dump(),
98
- )
99
- return Group(**result_dict)
103
+ with tracer.start_as_current_span("auth.rpc.auth_update_group"):
104
+ result_dict = await rpc_caller.call(
105
+ "auth_update_group",
106
+ id=id,
107
+ data=data.model_dump(),
108
+ user_token_data=user_token_data.model_dump(),
109
+ )
110
+ return Group(**result_dict)
100
111
  except Exception as e:
101
112
  raise HTTPAPIException(error=e)
102
113
 
@@ -104,14 +115,18 @@ def register_api(
104
115
  async def delete_group(
105
116
  id: str, user_token_data: AccessTokenData = Depends(access_token_scheme)
106
117
  ):
107
- if not await authorizer.is_having_permission(
108
- user_token_data.user_id, "auth:group:delete"
109
- ):
110
- raise HTTPAPIException(403, "Unauthorized")
118
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
119
+ if not await authorizer.is_having_permission(
120
+ user_token_data.user_id, "auth:group:delete"
121
+ ):
122
+ raise HTTPAPIException(403, "Unauthorized")
111
123
  try:
112
- result_dict = await rpc_caller.call(
113
- "auth_delete_group", id=id, user_token_data=user_token_data.model_dump()
114
- )
115
- return Group(**result_dict)
124
+ with tracer.start_as_current_span("auth.rpc.auth_delete_group"):
125
+ result_dict = await rpc_caller.call(
126
+ "auth_delete_group",
127
+ id=id,
128
+ user_token_data=user_token_data.model_dump(),
129
+ )
130
+ return Group(**result_dict)
116
131
  except Exception as e:
117
132
  raise HTTPAPIException(error=e)
@@ -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.permission import Permission, PermissionData, PermissionResult
10
10
  from module.auth.schema.token import AccessTokenData
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
- if not await authorizer.is_having_permission(
30
- user_token_data.user_id, "auth:permission:get"
31
- ):
32
- raise HTTPAPIException(403, "Unauthorized")
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, "auth:permission:get"
35
+ ):
36
+ raise HTTPAPIException(403, "Unauthorized")
33
37
  try:
34
- result_dict = await rpc_caller.call(
35
- "auth_get_permission",
36
- keyword=keyword,
37
- criterion={},
38
- limit=limit,
39
- offset=offset,
40
- user_token_data=user_token_data.model_dump(),
41
- )
42
- return PermissionResult(**result_dict)
38
+ with tracer.start_as_current_span("auth.rpc.auth_get_permission"):
39
+ result_dict = await rpc_caller.call(
40
+ "auth_get_permission",
41
+ keyword=keyword,
42
+ criterion={},
43
+ limit=limit,
44
+ offset=offset,
45
+ user_token_data=user_token_data.model_dump(),
46
+ )
47
+ return PermissionResult(**result_dict)
43
48
  except Exception as e:
44
49
  raise HTTPAPIException(error=e)
45
50
 
@@ -47,17 +52,19 @@ def register_api(
47
52
  async def get_permission_by_id(
48
53
  id: str, user_token_data: AccessTokenData = Depends(access_token_scheme)
49
54
  ):
50
- if not await authorizer.is_having_permission(
51
- user_token_data.user_id, "auth:permission:get_by_id"
52
- ):
53
- raise HTTPAPIException(403, "Unauthorized")
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, "auth:permission:get_by_id"
58
+ ):
59
+ raise HTTPAPIException(403, "Unauthorized")
54
60
  try:
55
- result_dict = await rpc_caller.call(
56
- "auth_get_permission_by_id",
57
- id=id,
58
- user_token_data=user_token_data.model_dump(),
59
- )
60
- return Permission(**result_dict)
61
+ with tracer.start_as_current_span("auth.rpc.auth_get_permission_by_id"):
62
+ result_dict = await rpc_caller.call(
63
+ "auth_get_permission_by_id",
64
+ id=id,
65
+ user_token_data=user_token_data.model_dump(),
66
+ )
67
+ return Permission(**result_dict)
61
68
  except Exception as e:
62
69
  raise HTTPAPIException(error=e)
63
70
 
@@ -66,17 +73,19 @@ def register_api(
66
73
  data: PermissionData,
67
74
  user_token_data: AccessTokenData = Depends(access_token_scheme),
68
75
  ):
69
- if not await authorizer.is_having_permission(
70
- user_token_data.user_id, "auth:permission:insert"
71
- ):
72
- raise HTTPAPIException(403, "Unauthorized")
76
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
77
+ if not await authorizer.is_having_permission(
78
+ user_token_data.user_id, "auth:permission:insert"
79
+ ):
80
+ raise HTTPAPIException(403, "Unauthorized")
73
81
  try:
74
- result_dict = await rpc_caller.call(
75
- "auth_insert_permission",
76
- data=data.model_dump(),
77
- user_token_data=user_token_data.model_dump(),
78
- )
79
- return Permission(**result_dict)
82
+ with tracer.start_as_current_span("auth.rpc.auth_insert_permission"):
83
+ result_dict = await rpc_caller.call(
84
+ "auth_insert_permission",
85
+ data=data.model_dump(),
86
+ user_token_data=user_token_data.model_dump(),
87
+ )
88
+ return Permission(**result_dict)
80
89
  except Exception as e:
81
90
  raise HTTPAPIException(error=e)
82
91
 
@@ -86,18 +95,20 @@ def register_api(
86
95
  data: PermissionData,
87
96
  user_token_data: AccessTokenData = Depends(access_token_scheme),
88
97
  ):
89
- if not await authorizer.is_having_permission(
90
- user_token_data.user_id, "auth:permission:update"
91
- ):
92
- raise HTTPAPIException(403, "Unauthorized")
98
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
99
+ if not await authorizer.is_having_permission(
100
+ user_token_data.user_id, "auth:permission:update"
101
+ ):
102
+ raise HTTPAPIException(403, "Unauthorized")
93
103
  try:
94
- result_dict = await rpc_caller.call(
95
- "auth_update_permission",
96
- id=id,
97
- data=data.model_dump(),
98
- user_token_data=user_token_data.model_dump(),
99
- )
100
- return Permission(**result_dict)
104
+ with tracer.start_as_current_span("auth.rpc.auth_update_permission"):
105
+ result_dict = await rpc_caller.call(
106
+ "auth_update_permission",
107
+ id=id,
108
+ data=data.model_dump(),
109
+ user_token_data=user_token_data.model_dump(),
110
+ )
111
+ return Permission(**result_dict)
101
112
  except Exception as e:
102
113
  raise HTTPAPIException(error=e)
103
114
 
@@ -105,16 +116,18 @@ def register_api(
105
116
  async def delete_permission(
106
117
  id: str, user_token_data: AccessTokenData = Depends(access_token_scheme)
107
118
  ):
108
- if not await authorizer.is_having_permission(
109
- user_token_data.user_id, "auth:permission:delete"
110
- ):
111
- raise HTTPAPIException(403, "Unauthorized")
119
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
120
+ if not await authorizer.is_having_permission(
121
+ user_token_data.user_id, "auth:permission:delete"
122
+ ):
123
+ raise HTTPAPIException(403, "Unauthorized")
112
124
  try:
113
- result_dict = await rpc_caller.call(
114
- "auth_delete_permission",
115
- id=id,
116
- user_token_data=user_token_data.model_dump(),
117
- )
118
- return Permission(**result_dict)
125
+ with tracer.start_as_current_span("auth.rpc.auth_delete_permission"):
126
+ result_dict = await rpc_caller.call(
127
+ "auth_delete_permission",
128
+ id=id,
129
+ user_token_data=user_token_data.model_dump(),
130
+ )
131
+ return Permission(**result_dict)
119
132
  except Exception as e:
120
133
  raise HTTPAPIException(error=e)
@@ -11,6 +11,9 @@ from module.auth.integration import access_token_scheme, bearer_token_scheme
11
11
  from module.auth.schema.request import IsAuthorizedRequest, RefreshTokenRequest
12
12
  from module.auth.schema.token import AccessTokenData, TokenResponse
13
13
  from module.auth.schema.user import User, UserData, UserLogin, UserResult
14
+ from opentelemetry import trace
15
+
16
+ tracer = trace.get_tracer(__name__)
14
17
 
15
18
 
16
19
  def register_auth_api(
@@ -35,10 +38,11 @@ def register_auth_api(
35
38
 
36
39
  async def _create_token(data: UserLogin) -> TokenResponse:
37
40
  try:
38
- token_response_dict = await rpc_caller.call(
39
- "auth_create_token", login_data=data.model_dump()
40
- )
41
- return TokenResponse(**token_response_dict)
41
+ with tracer.start_as_current_span("auth.rpc.auth_create_token"):
42
+ token_response_dict = await rpc_caller.call(
43
+ "auth_create_token", login_data=data.model_dump()
44
+ )
45
+ return TokenResponse(**token_response_dict)
42
46
  except Exception as e:
43
47
  raise HTTPAPIException(error=e)
44
48
 
@@ -47,12 +51,13 @@ def register_auth_api(
47
51
  data: RefreshTokenRequest, refresh_token: str = Depends(bearer_token_scheme)
48
52
  ) -> TokenResponse:
49
53
  try:
50
- token_response_dict = await rpc_caller.call(
51
- "auth_refresh_token",
52
- refresh_token=refresh_token,
53
- access_token=data.access_token,
54
- )
55
- return TokenResponse(**token_response_dict)
54
+ with tracer.start_as_current_span("auth.rpc.auth_refresh_token"):
55
+ token_response_dict = await rpc_caller.call(
56
+ "auth_refresh_token",
57
+ refresh_token=refresh_token,
58
+ access_token=data.access_token,
59
+ )
60
+ return TokenResponse(**token_response_dict)
56
61
  except Exception as e:
57
62
  raise HTTPAPIException(error=e)
58
63
 
@@ -63,11 +68,12 @@ def register_auth_api(
63
68
  ) -> Mapping[str, str]:
64
69
  try:
65
70
  user_id = user_token_data.user_id
66
- return await rpc_caller.call(
67
- "auth_is_user_authorized",
68
- id=user_id,
69
- permission_name=data.permission_names,
70
- )
71
+ with tracer.start_as_current_span("auth.rpc.auth_is_user_authorized"):
72
+ return await rpc_caller.call(
73
+ "auth_is_user_authorized",
74
+ id=user_id,
75
+ permission_name=data.permission_names,
76
+ )
71
77
  except Exception as e:
72
78
  raise HTTPAPIException(error=e)
73
79
 
@@ -88,20 +94,22 @@ def register_api(
88
94
  offset: int = 0,
89
95
  user_token_data: AccessTokenData = Depends(access_token_scheme),
90
96
  ):
91
- if not await authorizer.is_having_permission(
92
- user_token_data.user_id, "auth:user:get"
93
- ):
94
- raise HTTPAPIException(403, "Unauthorized")
97
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
98
+ if not await authorizer.is_having_permission(
99
+ user_token_data.user_id, "auth:user:get"
100
+ ):
101
+ raise HTTPAPIException(403, "Unauthorized")
95
102
  try:
96
- result_dict = await rpc_caller.call(
97
- "auth_get_user",
98
- keyword=keyword,
99
- criterion={},
100
- limit=limit,
101
- offset=offset,
102
- user_token_data=user_token_data.model_dump(),
103
- )
104
- return UserResult(**result_dict)
103
+ with tracer.start_as_current_span("auth.rpc.auth_get_user"):
104
+ result_dict = await rpc_caller.call(
105
+ "auth_get_user",
106
+ keyword=keyword,
107
+ criterion={},
108
+ limit=limit,
109
+ offset=offset,
110
+ user_token_data=user_token_data.model_dump(),
111
+ )
112
+ return UserResult(**result_dict)
105
113
  except Exception as e:
106
114
  raise HTTPAPIException(error=e)
107
115
 
@@ -109,17 +117,19 @@ def register_api(
109
117
  async def get_user_by_id(
110
118
  id: str, user_token_data: AccessTokenData = Depends(access_token_scheme)
111
119
  ):
112
- if not await authorizer.is_having_permission(
113
- user_token_data.user_id, "auth:user:get_by_id"
114
- ):
115
- raise HTTPAPIException(403, "Unauthorized")
120
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
121
+ if not await authorizer.is_having_permission(
122
+ user_token_data.user_id, "auth:user:get_by_id"
123
+ ):
124
+ raise HTTPAPIException(403, "Unauthorized")
116
125
  try:
117
- result_dict = await rpc_caller.call(
118
- "auth_get_user_by_id",
119
- id=id,
120
- user_token_data=user_token_data.model_dump(),
121
- )
122
- return User(**result_dict)
126
+ with tracer.start_as_current_span("auth.rpc.auth_get_user_by_id"):
127
+ result_dict = await rpc_caller.call(
128
+ "auth_get_user_by_id",
129
+ id=id,
130
+ user_token_data=user_token_data.model_dump(),
131
+ )
132
+ return User(**result_dict)
123
133
  except Exception as e:
124
134
  raise HTTPAPIException(error=e)
125
135
 
@@ -127,17 +137,19 @@ def register_api(
127
137
  async def insert_user(
128
138
  data: UserData, user_token_data: AccessTokenData = Depends(access_token_scheme)
129
139
  ):
130
- if not await authorizer.is_having_permission(
131
- user_token_data.user_id, "auth:user:insert"
132
- ):
133
- raise HTTPAPIException(403, "Unauthorized")
140
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
141
+ if not await authorizer.is_having_permission(
142
+ user_token_data.user_id, "auth:user:insert"
143
+ ):
144
+ raise HTTPAPIException(403, "Unauthorized")
134
145
  try:
135
- result_dict = await rpc_caller.call(
136
- "auth_insert_user",
137
- data=data.model_dump(),
138
- user_token_data=user_token_data.model_dump(),
139
- )
140
- return User(**result_dict)
146
+ with tracer.start_as_current_span("auth.rpc.auth_insert_user"):
147
+ result_dict = await rpc_caller.call(
148
+ "auth_insert_user",
149
+ data=data.model_dump(),
150
+ user_token_data=user_token_data.model_dump(),
151
+ )
152
+ return User(**result_dict)
141
153
  except Exception as e:
142
154
  raise HTTPAPIException(error=e)
143
155
 
@@ -147,18 +159,20 @@ def register_api(
147
159
  data: UserData,
148
160
  user_token_data: AccessTokenData = Depends(access_token_scheme),
149
161
  ):
150
- if not await authorizer.is_having_permission(
151
- user_token_data.user_id, "auth:user:update"
152
- ):
153
- raise HTTPAPIException(403, "Unauthorized")
162
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
163
+ if not await authorizer.is_having_permission(
164
+ user_token_data.user_id, "auth:user:update"
165
+ ):
166
+ raise HTTPAPIException(403, "Unauthorized")
154
167
  try:
155
- result_dict = await rpc_caller.call(
156
- "auth_update_user",
157
- id=id,
158
- data=data.model_dump(),
159
- user_token_data=user_token_data.model_dump(),
160
- )
161
- return User(**result_dict)
168
+ with tracer.start_as_current_span("auth.rpc.auth_update_user"):
169
+ result_dict = await rpc_caller.call(
170
+ "auth_update_user",
171
+ id=id,
172
+ data=data.model_dump(),
173
+ user_token_data=user_token_data.model_dump(),
174
+ )
175
+ return User(**result_dict)
162
176
  except Exception as e:
163
177
  raise HTTPAPIException(error=e)
164
178
 
@@ -166,14 +180,18 @@ def register_api(
166
180
  async def delete_user(
167
181
  id: str, user_token_data: AccessTokenData = Depends(access_token_scheme)
168
182
  ):
169
- if not await authorizer.is_having_permission(
170
- user_token_data.user_id, "auth:user:delete"
171
- ):
172
- raise HTTPAPIException(403, "Unauthorized")
183
+ with tracer.start_as_current_span("authorizer.is_having_permission"):
184
+ if not await authorizer.is_having_permission(
185
+ user_token_data.user_id, "auth:user:delete"
186
+ ):
187
+ raise HTTPAPIException(403, "Unauthorized")
173
188
  try:
174
- result_dict = await rpc_caller.call(
175
- "auth_delete_user", id=id, user_token_data=user_token_data.model_dump()
176
- )
177
- return User(**result_dict)
189
+ with tracer.start_as_current_span("auth.rpc.auth_delete_user"):
190
+ result_dict = await rpc_caller.call(
191
+ "auth_delete_user",
192
+ id=id,
193
+ user_token_data=user_token_data.model_dump(),
194
+ )
195
+ return User(**result_dict)
178
196
  except Exception as e:
179
197
  raise HTTPAPIException(error=e)