tinybird 0.0.1.dev304__py3-none-any.whl → 0.0.1.dev305__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.

tinybird/sql_template.py CHANGED
@@ -2385,6 +2385,14 @@ def render_sql_template(
2385
2385
  documentation="/cli/advanced-templates.html",
2386
2386
  )
2387
2387
  raise SQLTemplateException(str(e), documentation="/cli/advanced-templates.html")
2388
+ except IndexError as e:
2389
+ # This happens when trying to access string indices on empty strings
2390
+ if "string index out of range" in str(e):
2391
+ raise SQLTemplateException(
2392
+ "String index out of range. Check that string parameters have values before accessing specific characters (e.g., param[0]). Provide default values or add length checks in your template.",
2393
+ documentation="/cli/advanced-templates.html",
2394
+ )
2395
+ raise SQLTemplateException(str(e), documentation="/cli/advanced-templates.html")
2388
2396
  except Exception as e:
2389
2397
  # errors might vary here, we need to support as much as possible
2390
2398
  # https://gitlab.com/tinybird/analytics/-/issues/943
tinybird/tb/__cli__.py CHANGED
@@ -4,5 +4,5 @@ __description__ = 'Tinybird Command Line Tool'
4
4
  __url__ = 'https://www.tinybird.co/docs/forward/commands'
5
5
  __author__ = 'Tinybird'
6
6
  __author_email__ = 'support@tinybird.co'
7
- __version__ = '0.0.1.dev304'
8
- __revision__ = '9a414a1'
7
+ __version__ = '0.0.1.dev305'
8
+ __revision__ = 'cc453b3'
@@ -1,11 +1,15 @@
1
+ import json
2
+ import uuid
1
3
  from pathlib import Path
4
+ from typing import Any
2
5
 
3
6
  import click
7
+ import jwt
4
8
  import requests
5
9
  from docker.client import DockerClient
6
10
 
7
11
  from tinybird.tb.modules.cli import cli
8
- from tinybird.tb.modules.common import update_cli
12
+ from tinybird.tb.modules.common import echo_json, update_cli
9
13
  from tinybird.tb.modules.feedback_manager import FeedbackManager
10
14
  from tinybird.tb.modules.local_common import (
11
15
  TB_CONTAINER_NAME,
@@ -125,7 +129,21 @@ def remove() -> None:
125
129
  is_flag=True,
126
130
  help="Skip pulling the latest Tinybird Local image. Use directly your current local image.",
127
131
  )
128
- def start(use_aws_creds: bool, volumes_path: str, skip_new_version: bool) -> None:
132
+ @click.option(
133
+ "--user-token",
134
+ default=None,
135
+ envvar="TB_LOCAL_USER_TOKEN",
136
+ help="User token to use for the Tinybird Local container.",
137
+ )
138
+ @click.option(
139
+ "--workspace-token",
140
+ default=None,
141
+ envvar="TB_LOCAL_WORKSPACE_TOKEN",
142
+ help="Workspace token to use for the Tinybird Local container.",
143
+ )
144
+ def start(
145
+ use_aws_creds: bool, volumes_path: str, skip_new_version: bool, user_token: str, workspace_token: str
146
+ ) -> None:
129
147
  """Start Tinybird Local"""
130
148
  if volumes_path is not None:
131
149
  absolute_path = Path(volumes_path).absolute()
@@ -134,7 +152,7 @@ def start(use_aws_creds: bool, volumes_path: str, skip_new_version: bool) -> Non
134
152
 
135
153
  click.echo(FeedbackManager.highlight(message="» Starting Tinybird Local..."))
136
154
  docker_client = get_docker_client()
137
- start_tinybird_local(docker_client, use_aws_creds, volumes_path, skip_new_version)
155
+ start_tinybird_local(docker_client, use_aws_creds, volumes_path, skip_new_version, user_token, workspace_token)
138
156
  click.echo(FeedbackManager.success(message="✓ Tinybird Local is ready!"))
139
157
 
140
158
 
@@ -183,3 +201,35 @@ def version() -> None:
183
201
  """Show Tinybird Local version"""
184
202
  response = requests.get(f"{TB_LOCAL_ADDRESS}/version")
185
203
  click.echo(FeedbackManager.success(message=f"✓ Tinybird Local version: {response.text}"))
204
+
205
+
206
+ @local.command()
207
+ @click.pass_context
208
+ def generate_tokens(ctx: click.Context) -> None:
209
+ """Generate static tokens for initializing Tinybird Local"""
210
+ output = ctx.ensure_object(dict).get("output")
211
+ user_id = str(uuid.uuid4())
212
+ workspace_id = str(uuid.uuid4())
213
+ user_token_id = str(uuid.uuid4())
214
+ workspace_token_id = str(uuid.uuid4())
215
+ payload = {"u": user_id, "id": user_token_id, "host": None}
216
+ user_token = generate_token(payload)
217
+ payload = {"u": workspace_id, "id": workspace_token_id, "host": None}
218
+ workspace_token = generate_token(payload)
219
+
220
+ if output == "json":
221
+ echo_json({"workspace_token": workspace_token, "user_token": user_token})
222
+ else:
223
+ click.echo(FeedbackManager.gray(message="Workspace token: ") + FeedbackManager.info(message=workspace_token))
224
+ click.echo(FeedbackManager.gray(message="User token: ") + FeedbackManager.info(message=user_token))
225
+ click.echo(FeedbackManager.success(message="✓ Tinybird Local tokens generated!"))
226
+
227
+
228
+ def generate_token(payload: dict[str, Any]) -> str:
229
+ algo = jwt.algorithms.get_default_algorithms()["HS256"]
230
+ msg = json.dumps(payload)
231
+ msg_base64 = jwt.utils.base64url_encode(msg.encode())
232
+ sign_key = algo.prepare_key("abcd")
233
+ signature = algo.sign(msg_base64, sign_key)
234
+ token = msg_base64 + b"." + jwt.utils.base64url_encode(signature)
235
+ return "p." + token.decode()
@@ -234,7 +234,9 @@ def start_tinybird_local(
234
234
  docker_client: DockerClient,
235
235
  use_aws_creds: bool,
236
236
  volumes_path: Optional[str] = None,
237
- skip_new_version: bool = False,
237
+ skip_new_version: bool = True,
238
+ user_token: Optional[str] = None,
239
+ workspace_token: Optional[str] = None,
238
240
  ) -> None:
239
241
  """Start the Tinybird container."""
240
242
  pull_show_prompt = False
@@ -261,7 +263,13 @@ def start_tinybird_local(
261
263
  if pull_required:
262
264
  docker_client.images.pull(TB_IMAGE_NAME, platform="linux/amd64")
263
265
 
264
- environment = get_use_aws_creds() if use_aws_creds else {}
266
+ environment = {}
267
+ if use_aws_creds:
268
+ environment.update(get_use_aws_creds())
269
+ if user_token:
270
+ environment["TB_LOCAL_USER_TOKEN"] = user_token
271
+ if workspace_token:
272
+ environment["TB_LOCAL_WORKSPACE_TOKEN"] = workspace_token
265
273
 
266
274
  container = get_existing_container_with_matching_env(docker_client, TB_CONTAINER_NAME, environment)
267
275
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tinybird
3
- Version: 0.0.1.dev304
3
+ Version: 0.0.1.dev305
4
4
  Summary: Tinybird Command Line Tool
5
5
  Home-page: https://www.tinybird.co/docs/forward/commands
6
6
  Author: Tinybird
@@ -39,6 +39,7 @@ Requires-Dist: packaging<24,>=23.1
39
39
  Requires-Dist: llm>=0.19
40
40
  Requires-Dist: thefuzz==0.22.1
41
41
  Requires-Dist: python-dotenv==1.1.0
42
+ Requires-Dist: pyjwt[crypto]==2.9.0
42
43
  Dynamic: author
43
44
  Dynamic: author-email
44
45
  Dynamic: description
@@ -6,7 +6,7 @@ tinybird/git_settings.py,sha256=Sw_8rGmribEFJ4Z_6idrVytxpFYk7ez8ei0qHULzs3E,3934
6
6
  tinybird/prompts.py,sha256=HoDv9TxPiP8v2XoGTWYxP133dK9CEbXVv4XE5IT339c,45483
7
7
  tinybird/service_datasources.py,sha256=y36l2QYLxFEYRBEBuYCKtjkPjGu0P2a8Fz_AjOTTNM4,48914
8
8
  tinybird/sql.py,sha256=7pkwQMUVy0CH5zFgLMZyCx1BeaJSQYC05EmOb9vO3Ls,48694
9
- tinybird/sql_template.py,sha256=vOpIAgHoLu3D3aFwywgYHJgRmYxtrxvro8sRwYHX-tk,102415
9
+ tinybird/sql_template.py,sha256=qz1Q-d8jlGpU8w-jcwn_NM4ApFtJAhEL-3_3-JELrl4,102979
10
10
  tinybird/sql_template_fmt.py,sha256=KUHdj5rYCYm_rKKdXYSJAE9vIyXUQLB0YSZnUXHeBlY,10196
11
11
  tinybird/sql_toolset.py,sha256=Y2_fQrbk5GSNoRncAmRS_snpV61XQbiOy4uYkeF6pr4,19767
12
12
  tinybird/syncasync.py,sha256=IPnOx6lMbf9SNddN1eBtssg8vCLHMt76SuZ6YNYm-Yk,27761
@@ -18,7 +18,7 @@ tinybird/datafile/exceptions.py,sha256=8rw2umdZjtby85QbuRKFO5ETz_eRHwUY5l7eHsy1w
18
18
  tinybird/datafile/parse_connection.py,sha256=tRyn2Rpr1TeWet5BXmMoQgaotbGdYep1qiTak_OqC5E,1825
19
19
  tinybird/datafile/parse_datasource.py,sha256=ssW8QeFSgglVFi3sDZj_HgkJiTJ2069v2JgqnH3CkDE,1825
20
20
  tinybird/datafile/parse_pipe.py,sha256=8e9LMecSQVWHC4AXf8cdxoQ1nxUR4fTObYxTctO_EXQ,3816
21
- tinybird/tb/__cli__.py,sha256=zKFXL0dY2JM1qGDKRazQWAKaCs3Ex5FQRqD_WLnFa5Q,247
21
+ tinybird/tb/__cli__.py,sha256=KoDxX7t1llHSTiafcOR0AIeehU6WnVkQeNq7EuQ6nuw,247
22
22
  tinybird/tb/check_pypi.py,sha256=Gp0HkHHDFMSDL6nxKlOY51z7z1Uv-2LRexNTZSHHGmM,552
23
23
  tinybird/tb/cli.py,sha256=FdDFEIayjmsZEVsVSSvRiVYn_FHOVg_zWQzchnzfWho,1008
24
24
  tinybird/tb/client.py,sha256=Z27O6kXbQ1ZVi_K6qzdUJoS877nt7rqQDRckOycjNmI,53544
@@ -45,8 +45,8 @@ tinybird/tb/modules/infra.py,sha256=J9Noe9aZo5Y9ZKAhqh9jnv8azfivXLLHQ2a9TeMWN9s,
45
45
  tinybird/tb/modules/job.py,sha256=wBsnu8UPTOha2rkLvucgmw4xYv73ubmui3eeSIF68ZM,3107
46
46
  tinybird/tb/modules/llm.py,sha256=fPBBCmM3KlCksLlgJkg4joDn6y3H5QjDzE-Pm4YNf7E,1782
47
47
  tinybird/tb/modules/llm_utils.py,sha256=nS9r4FAElJw8yXtmdYrx-rtI2zXR8qXfi1QqUDCfxvg,3469
48
- tinybird/tb/modules/local.py,sha256=cez8ZV7Gt9F1siz54dpgtynEw-il3Y9mNcQgEtOVvmw,6512
49
- tinybird/tb/modules/local_common.py,sha256=KhALzU0L3AC56vqs3peBe-dqGzw5hWkOg_CfS0skohk,18528
48
+ tinybird/tb/modules/local.py,sha256=aGqBtRyr9Ks0BWUFEveez2g_-4h6YjLO6Rt49b1i-yE,8384
49
+ tinybird/tb/modules/local_common.py,sha256=UUDGS5M3C261NUtZO_LrmfEYfUH1sjn1kjjBMlY32xI,18801
50
50
  tinybird/tb/modules/login.py,sha256=q2fc0dy5brwofQSNQppipS1aDcyrxHvVjZZbzIA3b4g,1916
51
51
  tinybird/tb/modules/login_common.py,sha256=u1Eh1u6L7V3x8qmxVO-LnWDELHWAnXm3bvb7BNjVXF8,11990
52
52
  tinybird/tb/modules/logout.py,sha256=sniI4JNxpTrVeRCp0oGJuQ3yRerG4hH5uz6oBmjv724,1009
@@ -121,8 +121,8 @@ tinybird/tb_cli_modules/config.py,sha256=IsgdtFRnUrkY8-Zo32lmk6O7u3bHie1QCxLwgp4
121
121
  tinybird/tb_cli_modules/exceptions.py,sha256=pmucP4kTF4irIt7dXiG-FcnI-o3mvDusPmch1L8RCWk,3367
122
122
  tinybird/tb_cli_modules/regions.py,sha256=QjsL5H6Kg-qr0aYVLrvb1STeJ5Sx_sjvbOYO0LrEGMk,166
123
123
  tinybird/tb_cli_modules/telemetry.py,sha256=Hh2Io8ZPROSunbOLuMvuIFU4TqwWPmQTqal4WS09K1A,10449
124
- tinybird-0.0.1.dev304.dist-info/METADATA,sha256=lhsEuveQfvJdP9vvlunpZqBKmKtSyhi4V7cy3xfe8nw,1845
125
- tinybird-0.0.1.dev304.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
126
- tinybird-0.0.1.dev304.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
127
- tinybird-0.0.1.dev304.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
128
- tinybird-0.0.1.dev304.dist-info/RECORD,,
124
+ tinybird-0.0.1.dev305.dist-info/METADATA,sha256=kf9UMEPqhBrJvZD_DpAjOJ-demRErf4gMk42ifnZ7cQ,1881
125
+ tinybird-0.0.1.dev305.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
126
+ tinybird-0.0.1.dev305.dist-info/entry_points.txt,sha256=LwdHU6TfKx4Qs7BqqtaczEZbImgU7Abe9Lp920zb_fo,43
127
+ tinybird-0.0.1.dev305.dist-info/top_level.txt,sha256=VqqqEmkAy7UNaD8-V51FCoMMWXjLUlR0IstvK7tJYVY,54
128
+ tinybird-0.0.1.dev305.dist-info/RECORD,,