tinybird 0.0.1.dev0__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.

Potentially problematic release.


This version of tinybird might be problematic. Click here for more details.

Files changed (45) hide show
  1. tinybird/__cli__.py +8 -0
  2. tinybird/ch_utils/constants.py +244 -0
  3. tinybird/ch_utils/engine.py +855 -0
  4. tinybird/check_pypi.py +25 -0
  5. tinybird/client.py +1281 -0
  6. tinybird/config.py +117 -0
  7. tinybird/connectors.py +428 -0
  8. tinybird/context.py +23 -0
  9. tinybird/datafile.py +5589 -0
  10. tinybird/datatypes.py +434 -0
  11. tinybird/feedback_manager.py +1022 -0
  12. tinybird/git_settings.py +145 -0
  13. tinybird/sql.py +865 -0
  14. tinybird/sql_template.py +2343 -0
  15. tinybird/sql_template_fmt.py +281 -0
  16. tinybird/sql_toolset.py +350 -0
  17. tinybird/syncasync.py +682 -0
  18. tinybird/tb_cli.py +25 -0
  19. tinybird/tb_cli_modules/auth.py +252 -0
  20. tinybird/tb_cli_modules/branch.py +1043 -0
  21. tinybird/tb_cli_modules/cicd.py +434 -0
  22. tinybird/tb_cli_modules/cli.py +1571 -0
  23. tinybird/tb_cli_modules/common.py +2082 -0
  24. tinybird/tb_cli_modules/config.py +344 -0
  25. tinybird/tb_cli_modules/connection.py +803 -0
  26. tinybird/tb_cli_modules/datasource.py +900 -0
  27. tinybird/tb_cli_modules/exceptions.py +91 -0
  28. tinybird/tb_cli_modules/fmt.py +91 -0
  29. tinybird/tb_cli_modules/job.py +85 -0
  30. tinybird/tb_cli_modules/pipe.py +858 -0
  31. tinybird/tb_cli_modules/regions.py +9 -0
  32. tinybird/tb_cli_modules/tag.py +100 -0
  33. tinybird/tb_cli_modules/telemetry.py +310 -0
  34. tinybird/tb_cli_modules/test.py +107 -0
  35. tinybird/tb_cli_modules/tinyunit/tinyunit.py +340 -0
  36. tinybird/tb_cli_modules/tinyunit/tinyunit_lib.py +71 -0
  37. tinybird/tb_cli_modules/token.py +349 -0
  38. tinybird/tb_cli_modules/workspace.py +269 -0
  39. tinybird/tb_cli_modules/workspace_members.py +212 -0
  40. tinybird/tornado_template.py +1194 -0
  41. tinybird-0.0.1.dev0.dist-info/METADATA +2815 -0
  42. tinybird-0.0.1.dev0.dist-info/RECORD +45 -0
  43. tinybird-0.0.1.dev0.dist-info/WHEEL +5 -0
  44. tinybird-0.0.1.dev0.dist-info/entry_points.txt +2 -0
  45. tinybird-0.0.1.dev0.dist-info/top_level.txt +4 -0
@@ -0,0 +1,212 @@
1
+ # This is a command file for our CLI. Please keep it clean.
2
+ #
3
+ # - If it makes sense and only when strictly necessary, you can create utility functions in this file.
4
+ # - But please, **do not** interleave utility functions and command definitions.
5
+
6
+ from copy import deepcopy
7
+ from dataclasses import dataclass
8
+ from typing import Any, Dict, Optional, Tuple
9
+
10
+ import click
11
+ from click import Context
12
+
13
+ from tinybird.client import TinyB
14
+ from tinybird.config import get_display_host
15
+ from tinybird.feedback_manager import FeedbackManager
16
+ from tinybird.tb_cli_modules.common import (
17
+ ask_for_user_token,
18
+ check_user_token,
19
+ coro,
20
+ echo_safe_humanfriendly_tables_format_smart_table,
21
+ get_current_workspace,
22
+ )
23
+ from tinybird.tb_cli_modules.config import CLIConfig
24
+ from tinybird.tb_cli_modules.exceptions import CLIWorkspaceMembersException
25
+ from tinybird.tb_cli_modules.workspace import workspace
26
+
27
+ ROLES = ["viewer", "guest", "admin"]
28
+
29
+
30
+ @dataclass
31
+ class WorkspaceMemberCommandContext:
32
+ client: TinyB
33
+ config: CLIConfig
34
+ host: str
35
+ ui_host: str
36
+ workspace: Dict[str, Any]
37
+
38
+
39
+ async def get_command_context(ctx: click.Context) -> WorkspaceMemberCommandContext:
40
+ config = CLIConfig.get_project_config()
41
+ client = config.get_client()
42
+ host = config.get_host() or CLIConfig.DEFAULTS["host"]
43
+ ui_host = get_display_host(host)
44
+
45
+ workspace = await get_current_workspace(config)
46
+
47
+ if not workspace:
48
+ raise CLIWorkspaceMembersException(FeedbackManager.error_unknown_resource(resource=config["d"]))
49
+
50
+ return WorkspaceMemberCommandContext(client, config, host, ui_host, workspace)
51
+
52
+
53
+ def get_workspace_users(cmd_ctx: WorkspaceMemberCommandContext) -> Tuple[Any, ...]:
54
+ return tuple(u["email"] for u in cmd_ctx.workspace["members"])
55
+
56
+
57
+ @workspace.group()
58
+ @click.pass_context
59
+ def members(ctx: Context) -> None:
60
+ """Workspace members management commands."""
61
+
62
+
63
+ @members.command(name="add", short_help="Adds members to the current Workspace")
64
+ @click.argument("members_emails")
65
+ @click.option("--role", is_flag=False, default=None, help="Role for the members being added", type=click.Choice(ROLES))
66
+ @click.option("--user_token", is_flag=False, default=None, help="When passed, we won't prompt asking for it")
67
+ @click.pass_context
68
+ @coro
69
+ async def add_members_to_workspace(
70
+ ctx: Context, members_emails: str, user_token: Optional[str], role: Optional[str]
71
+ ) -> None:
72
+ """Adds members to the current Workspace."""
73
+
74
+ cmd_ctx = await get_command_context(ctx)
75
+
76
+ requested_users = [u.strip() for u in members_emails.split(",")]
77
+ users_to_add = [u for u in requested_users if u not in get_workspace_users(cmd_ctx)]
78
+
79
+ if len(users_to_add) == 0:
80
+ msg = (
81
+ FeedbackManager.info_user_already_exists(user=requested_users[0], workspace_name=cmd_ctx.workspace["name"])
82
+ if len(requested_users) == 1
83
+ else FeedbackManager.info_users_already_exists(workspace_name=cmd_ctx.workspace["name"])
84
+ )
85
+ click.echo(msg)
86
+ else:
87
+ if not user_token:
88
+ user_token = ask_for_user_token(f"add users to {cmd_ctx.workspace['name']}", cmd_ctx.ui_host)
89
+ await check_user_token(ctx, user_token)
90
+
91
+ user_client: TinyB = deepcopy(cmd_ctx.client)
92
+ user_client.token = user_token
93
+ await user_client.add_users_to_workspace(cmd_ctx.workspace, users_to_add, role)
94
+ msg = (
95
+ FeedbackManager.success_workspace_user_added(user=users_to_add[0], workspace_name=cmd_ctx.workspace["name"])
96
+ if len(users_to_add) == 1
97
+ else FeedbackManager.success_workspace_users_added(workspace_name=cmd_ctx.workspace["name"])
98
+ )
99
+ click.echo(msg)
100
+
101
+
102
+ @members.command(name="ls", short_help="List members in the current Workspace")
103
+ @click.pass_context
104
+ @coro
105
+ async def list_members_in_workspace(ctx: Context) -> None:
106
+ """List members in the current Workspace."""
107
+
108
+ cmd_ctx = await get_command_context(ctx)
109
+ users = tuple([u] for u in get_workspace_users(cmd_ctx))
110
+
111
+ echo_safe_humanfriendly_tables_format_smart_table(users, column_names=["email"])
112
+
113
+
114
+ @members.command(name="rm", short_help="Removes members from the current Workspace")
115
+ @click.argument("members_emails")
116
+ @click.option("--user_token", is_flag=False, default=None, help="When passed, we won't prompt asking for it")
117
+ @click.pass_context
118
+ @coro
119
+ async def remove_members_from_workspace(ctx: Context, members_emails: str, user_token: Optional[str]) -> None:
120
+ """Removes members from the current Workspace."""
121
+
122
+ cmd_ctx = await get_command_context(ctx)
123
+
124
+ requested_users = [u.strip() for u in members_emails.split(",")]
125
+ workspace_users = get_workspace_users(cmd_ctx)
126
+ users_to_remove = [u for u in requested_users if u in workspace_users]
127
+ non_valid_users = [u for u in requested_users if u not in workspace_users]
128
+
129
+ if len(users_to_remove) == 0:
130
+ msg = (
131
+ FeedbackManager.info_user_not_exists(user=requested_users[0], workspace_name=cmd_ctx.workspace["name"])
132
+ if len(requested_users) == 1
133
+ else FeedbackManager.info_users_not_exists(workspace_name=cmd_ctx.workspace["name"])
134
+ )
135
+ click.echo(msg)
136
+ else:
137
+ if not user_token:
138
+ user_token = ask_for_user_token(f"remove users from {cmd_ctx.workspace['name']}", cmd_ctx.ui_host)
139
+ await check_user_token(ctx, user_token)
140
+
141
+ if len(non_valid_users) > 0:
142
+ click.echo(
143
+ FeedbackManager.warning_user_doesnt_exist(user=non_valid_users[0], workspace=cmd_ctx.workspace["name"])
144
+ if len(non_valid_users) == 1
145
+ else FeedbackManager.warning_users_dont_exist(
146
+ users=", ".join(non_valid_users), workspace=cmd_ctx.workspace["name"]
147
+ )
148
+ )
149
+
150
+ user_client: TinyB = deepcopy(cmd_ctx.client)
151
+ user_client.token = user_token
152
+ await user_client.remove_users_from_workspace(cmd_ctx.workspace, users_to_remove)
153
+ msg = (
154
+ FeedbackManager.success_workspace_user_removed(
155
+ user=users_to_remove[0], workspace_name=cmd_ctx.workspace["name"]
156
+ )
157
+ if len(users_to_remove) == 1
158
+ else FeedbackManager.success_workspace_users_removed(workspace_name=cmd_ctx.workspace["name"])
159
+ )
160
+ click.echo(msg)
161
+
162
+
163
+ @members.command(name="set-role", short_help="Sets the role for existing workspace members")
164
+ @click.argument("role", required=True, type=click.Choice(ROLES))
165
+ @click.argument("members_emails", required=True, type=str)
166
+ @click.option("--user_token", is_flag=False, default=None, help="When passed, we won't prompt asking for it")
167
+ @click.pass_context
168
+ @coro
169
+ async def set_workspace_member_role(ctx: Context, role: str, members_emails: str, user_token: Optional[str]) -> None:
170
+ """Sets the role for existing workspace members."""
171
+
172
+ cmd_ctx = await get_command_context(ctx)
173
+
174
+ requested_users = [u.strip() for u in members_emails.split(",")]
175
+ workspace_users = get_workspace_users(cmd_ctx)
176
+ users_to_change = [u for u in requested_users if u in workspace_users]
177
+ non_valid_users = [u for u in requested_users if u not in workspace_users]
178
+
179
+ if len(users_to_change) == 0:
180
+ msg = (
181
+ FeedbackManager.info_user_not_exists(user=requested_users[0], workspace_name=cmd_ctx.workspace["name"])
182
+ if len(requested_users) == 1
183
+ else FeedbackManager.info_users_not_exists(workspace_name=cmd_ctx.workspace["name"])
184
+ )
185
+ click.echo(msg)
186
+ else:
187
+ if not user_token:
188
+ user_token = ask_for_user_token(f"change user roles in {cmd_ctx.workspace['name']}", cmd_ctx.ui_host)
189
+ await check_user_token(ctx, user_token)
190
+
191
+ if len(non_valid_users) > 0:
192
+ click.echo(
193
+ FeedbackManager.warning_user_doesnt_exist(user=non_valid_users[0], workspace=cmd_ctx.workspace["name"])
194
+ if len(non_valid_users) == 1
195
+ else FeedbackManager.warning_users_dont_exist(
196
+ users=", ".join(non_valid_users), workspace=cmd_ctx.workspace["name"]
197
+ )
198
+ )
199
+
200
+ user_client: TinyB = deepcopy(cmd_ctx.client)
201
+ user_client.token = user_token
202
+ await user_client.set_role_for_users_in_workspace(cmd_ctx.workspace, users_to_change, role=role)
203
+ msg = (
204
+ FeedbackManager.success_workspace_user_changed_role(
205
+ user=users_to_change[0], role=role, workspace_name=cmd_ctx.workspace["name"]
206
+ )
207
+ if len(users_to_change) == 1
208
+ else FeedbackManager.success_workspace_users_changed_role(
209
+ role=role, workspace_name=cmd_ctx.workspace["name"]
210
+ )
211
+ )
212
+ click.echo(msg)