tinybird 0.0.1.dev189__tar.gz → 0.0.1.dev191__tar.gz
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-0.0.1.dev189 → tinybird-0.0.1.dev191}/PKG-INFO +1 -1
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/prompts.py +19 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/__cli__.py +2 -2
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/client.py +1 -5
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/cli.py +12 -17
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/common.py +23 -7
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/connection.py +20 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/create.py +23 -5
- tinybird-0.0.1.dev191/tinybird/tb/modules/datasource.py +945 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/feedback_manager.py +3 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/info.py +8 -3
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/project.py +33 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird.egg-info/PKG-INFO +1 -1
- tinybird-0.0.1.dev189/tinybird/tb/modules/datasource.py +0 -475
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/setup.cfg +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/__cli__.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/ch_utils/constants.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/ch_utils/engine.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/check_pypi.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/client.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/config.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/connectors.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/context.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/datafile.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/datatypes.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/feedback_manager.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/git_settings.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/sql.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/sql_template.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/sql_template_fmt.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/sql_toolset.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/syncasync.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/check_pypi.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/cli.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/config.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/build.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/cicd.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/config.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/copy.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/build.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/build_common.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/build_datasource.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/build_pipe.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/common.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/diff.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/exceptions.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/fixture.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/format_common.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/format_datasource.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/format_pipe.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/parse_datasource.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/parse_pipe.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/pipe_checker.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/playground.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/datafile/pull.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/deployment.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/deprecations.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/dev_server.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/endpoint.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/exceptions.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/infra.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/job.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/llm.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/llm_utils.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/local.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/local_common.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/login.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/logout.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/materialization.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/mock.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/open.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/pipe.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/regions.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/secret.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/shell.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/table.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/telemetry.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/test.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/tinyunit/tinyunit.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/tinyunit/tinyunit_lib.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/token.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/watch.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/workspace.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb/modules/workspace_members.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/auth.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/branch.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/cicd.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/cli.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/common.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/config.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/connection.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/datasource.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/exceptions.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/fmt.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/job.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/pipe.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/regions.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/tag.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/telemetry.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/test.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/tinyunit/tinyunit.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/tinyunit/tinyunit_lib.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/workspace.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tb_cli_modules/workspace_members.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird/tornado_template.py +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird.egg-info/SOURCES.txt +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird.egg-info/dependency_links.txt +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird.egg-info/entry_points.txt +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird.egg-info/requires.txt +0 -0
- {tinybird-0.0.1.dev189 → tinybird-0.0.1.dev191}/tinybird.egg-info/top_level.txt +0 -0
|
@@ -1010,3 +1010,22 @@ Current README.md file:
|
|
|
1010
1010
|
<readme>[readme content here]</readme>
|
|
1011
1011
|
</readme_instructions>
|
|
1012
1012
|
"""
|
|
1013
|
+
|
|
1014
|
+
|
|
1015
|
+
def quarantine_prompt(datasource_definition: str) -> str:
|
|
1016
|
+
return f"""
|
|
1017
|
+
- You are an expert in Tinybird.
|
|
1018
|
+
- You are given a list of rows that went to quarantine during ingestion because of data quality issues.
|
|
1019
|
+
- Return the errors in a human readable format so the user can understand what is the problem and fix it.
|
|
1020
|
+
- Be concise and to the point.
|
|
1021
|
+
- Do not mention clickhouse tables. Refer to data sources instead.
|
|
1022
|
+
- The possible fixes recommended fixes are:
|
|
1023
|
+
- Changing a column type in the datasource definition: tell the user what to change in the datasource file, then build again before appending the data.
|
|
1024
|
+
- Changing the data because of the wrong data type: tell the user what to change in the data file, then append the data again.
|
|
1025
|
+
- The format of the response always inside the tag <quarantine_errors>[response]</quarantine_errors>
|
|
1026
|
+
- Do not use markdown format in the response, because it is a CLI output.
|
|
1027
|
+
- The datasource definition is the following:
|
|
1028
|
+
<datasource_definition>
|
|
1029
|
+
{datasource_definition}
|
|
1030
|
+
</datasource_definition>
|
|
1031
|
+
"""
|
|
@@ -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.
|
|
8
|
-
__revision__ = '
|
|
7
|
+
__version__ = '0.0.1.dev191'
|
|
8
|
+
__revision__ = 'c8535c7'
|
|
@@ -1024,11 +1024,7 @@ class TinyB:
|
|
|
1024
1024
|
)
|
|
1025
1025
|
|
|
1026
1026
|
async def kafka_list_topics(self, connection_id: str, timeout=5):
|
|
1027
|
-
resp = await self._req(
|
|
1028
|
-
f"/v0/connectors/{connection_id}/preview?preview_activity=false",
|
|
1029
|
-
connect_timeout=timeout,
|
|
1030
|
-
request_timeout=timeout,
|
|
1031
|
-
)
|
|
1027
|
+
resp = await self._req(f"/v0/connectors/{connection_id}/preview?preview_activity=false", timeout=timeout)
|
|
1032
1028
|
return [x["topic"] for x in resp["preview"]]
|
|
1033
1029
|
|
|
1034
1030
|
async def get_gcp_service_account_details(self) -> Dict[str, Any]:
|
|
@@ -28,7 +28,9 @@ from tinybird.tb.modules.common import (
|
|
|
28
28
|
CLIException,
|
|
29
29
|
_get_tb_client,
|
|
30
30
|
coro,
|
|
31
|
+
echo_json,
|
|
31
32
|
echo_safe_format_table,
|
|
33
|
+
force_echo,
|
|
32
34
|
getenv_bool,
|
|
33
35
|
try_update_config_with_remote,
|
|
34
36
|
)
|
|
@@ -72,7 +74,7 @@ VERSION = f"{__cli__.__version__} (rev {__cli__.__revision__})"
|
|
|
72
74
|
@click.option("--cloud/--local", is_flag=True, default=False, help="Run against cloud or local.")
|
|
73
75
|
@click.option("--staging", is_flag=True, default=False, help="Run against a staging deployment.")
|
|
74
76
|
@click.option(
|
|
75
|
-
"--output", type=click.Choice(["json", "
|
|
77
|
+
"--output", type=click.Choice(["human", "json", "csv"], case_sensitive=False), default="human", help="Output format"
|
|
76
78
|
)
|
|
77
79
|
@click.option("--max-depth", type=int, default=3, help="Maximum depth of the project files.")
|
|
78
80
|
@click.version_option(version=VERSION)
|
|
@@ -95,7 +97,7 @@ async def cli(
|
|
|
95
97
|
Use `OBFUSCATE_REGEX_PATTERN` and `OBFUSCATE_PATTERN_SEPARATOR` environment variables to define a regex pattern and a separator (in case of a single string with multiple regex) to obfuscate secrets in the CLI output.
|
|
96
98
|
"""
|
|
97
99
|
# We need to unpatch for our tests not to break
|
|
98
|
-
if output
|
|
100
|
+
if output != "human":
|
|
99
101
|
__hide_click_output()
|
|
100
102
|
else:
|
|
101
103
|
if show_tokens or not cloud or ctx.invoked_subcommand == "build":
|
|
@@ -195,17 +197,10 @@ async def pull(ctx: Context, force: bool, fmt: bool) -> None:
|
|
|
195
197
|
|
|
196
198
|
@cli.command()
|
|
197
199
|
@click.argument("query", required=False)
|
|
198
|
-
@click.option("--
|
|
200
|
+
@click.option("--rows-limit", default=100, help="Max number of rows retrieved")
|
|
199
201
|
@click.option("--pipeline", default=None, help="The name of the pipe to run the SQL Query")
|
|
200
202
|
@click.option("--pipe", default=None, help="The path to the .pipe file to run the SQL Query of a specific NODE")
|
|
201
203
|
@click.option("--node", default=None, help="The NODE name")
|
|
202
|
-
@click.option(
|
|
203
|
-
"--format",
|
|
204
|
-
"format_",
|
|
205
|
-
type=click.Choice(["json", "csv", "human"], case_sensitive=False),
|
|
206
|
-
default="human",
|
|
207
|
-
help="Output format",
|
|
208
|
-
)
|
|
209
204
|
@click.option("--stats/--no-stats", default=False, help="Show query stats")
|
|
210
205
|
@click.pass_context
|
|
211
206
|
@coro
|
|
@@ -216,13 +211,13 @@ async def sql(
|
|
|
216
211
|
pipeline: Optional[str],
|
|
217
212
|
pipe: Optional[str],
|
|
218
213
|
node: Optional[str],
|
|
219
|
-
format_: str,
|
|
220
214
|
stats: bool,
|
|
221
215
|
) -> None:
|
|
222
216
|
"""Run SQL query over data sources and pipes."""
|
|
223
|
-
|
|
224
217
|
client = ctx.ensure_object(dict)["client"]
|
|
225
|
-
|
|
218
|
+
output = ctx.ensure_object(dict)["output"]
|
|
219
|
+
|
|
220
|
+
req_format = "CSVWithNames" if output == "csv" else "JSON"
|
|
226
221
|
res = None
|
|
227
222
|
try:
|
|
228
223
|
if query:
|
|
@@ -275,11 +270,11 @@ async def sql(
|
|
|
275
270
|
bytes_read = humanfriendly.format_size(stats_dict["bytes_read"])
|
|
276
271
|
click.echo(FeedbackManager.info_query_stats(seconds=seconds, rows=rows_read, bytes=bytes_read))
|
|
277
272
|
|
|
278
|
-
if
|
|
279
|
-
|
|
273
|
+
if output == "csv":
|
|
274
|
+
force_echo(str(res))
|
|
280
275
|
elif isinstance(res, dict) and "data" in res and res["data"]:
|
|
281
|
-
if
|
|
282
|
-
|
|
276
|
+
if output == "json":
|
|
277
|
+
echo_json(res, indent=8)
|
|
283
278
|
else:
|
|
284
279
|
dd = []
|
|
285
280
|
for d in res["data"]:
|
|
@@ -424,6 +424,14 @@ async def _analyze(filename: str, client: TinyB, format: str, connector: Optiona
|
|
|
424
424
|
return meta, data
|
|
425
425
|
|
|
426
426
|
|
|
427
|
+
async def analyze_file(filename: str, client: TinyB, format: str):
|
|
428
|
+
meta, data = await _analyze(filename, client, format)
|
|
429
|
+
schema = meta["analysis"]["schema"]
|
|
430
|
+
schema = schema.replace(", ", ",\n ")
|
|
431
|
+
content = f"""DESCRIPTION >\n Generated from {filename}\n\nSCHEMA >\n {schema}"""
|
|
432
|
+
return content
|
|
433
|
+
|
|
434
|
+
|
|
427
435
|
async def _generate_datafile(
|
|
428
436
|
filename: str,
|
|
429
437
|
client: TinyB,
|
|
@@ -971,7 +979,7 @@ async def push_data(
|
|
|
971
979
|
cb.prev_done = 0 # type: ignore[attr-defined]
|
|
972
980
|
|
|
973
981
|
if not silent:
|
|
974
|
-
click.echo(FeedbackManager.
|
|
982
|
+
click.echo(FeedbackManager.highlight(message=f"\n» Appending data to {datasource_name}..."))
|
|
975
983
|
|
|
976
984
|
if isinstance(url, list):
|
|
977
985
|
urls = url
|
|
@@ -1882,15 +1890,19 @@ def get_gcs_connection_name(project_folder) -> str:
|
|
|
1882
1890
|
return get_connection_name(project_folder=project_folder, connection_type="GCS")
|
|
1883
1891
|
|
|
1884
1892
|
|
|
1885
|
-
def
|
|
1886
|
-
|
|
1893
|
+
def get_kafka_connection_name(project_folder: str, connection_name: Optional[str] = None) -> str:
|
|
1894
|
+
return get_connection_name(project_folder=project_folder, connection_type="KAFKA", connection_name=connection_name)
|
|
1895
|
+
|
|
1896
|
+
|
|
1897
|
+
def get_connection_name(project_folder: str, connection_type: str, connection_name: Optional[str] = None) -> str:
|
|
1887
1898
|
valid_pattern = r"^[a-zA-Z][a-zA-Z0-9_]*$"
|
|
1888
1899
|
|
|
1889
1900
|
while not connection_name:
|
|
1901
|
+
short_id = str(uuid.uuid4())[:4]
|
|
1890
1902
|
connection_name = click.prompt(
|
|
1891
|
-
|
|
1892
|
-
prompt_suffix="\n> ",
|
|
1903
|
+
"Enter a name (only alphanumeric characters and underscores)",
|
|
1893
1904
|
show_default=True,
|
|
1905
|
+
default=f"{connection_type.lower()}_{short_id}",
|
|
1894
1906
|
)
|
|
1895
1907
|
assert isinstance(connection_name, str)
|
|
1896
1908
|
|
|
@@ -2238,5 +2250,9 @@ def get_error_event(error: str) -> Tuple[str, str]:
|
|
|
2238
2250
|
return error_event, silent_error_msg
|
|
2239
2251
|
|
|
2240
2252
|
|
|
2241
|
-
def
|
|
2242
|
-
click.echo(
|
|
2253
|
+
def force_echo(string: str) -> None:
|
|
2254
|
+
click.echo(string, force_output=True) # type: ignore
|
|
2255
|
+
|
|
2256
|
+
|
|
2257
|
+
def echo_json(data: Dict[str, Any], indent: Union[None, int, str] = None) -> None:
|
|
2258
|
+
force_echo(json.dumps(data, indent=indent))
|
|
@@ -18,6 +18,7 @@ from tinybird.tb.modules.common import (
|
|
|
18
18
|
echo_safe_humanfriendly_tables_format_smart_table,
|
|
19
19
|
get_gcs_connection_name,
|
|
20
20
|
get_gcs_svc_account_creds,
|
|
21
|
+
get_kafka_connection_name,
|
|
21
22
|
get_s3_connection_name,
|
|
22
23
|
production_aws_iamrole_only,
|
|
23
24
|
run_aws_iamrole_connection_flow,
|
|
@@ -26,6 +27,7 @@ from tinybird.tb.modules.common import (
|
|
|
26
27
|
from tinybird.tb.modules.create import (
|
|
27
28
|
generate_aws_iamrole_connection_file_with_secret,
|
|
28
29
|
generate_gcs_connection_file_with_secrets,
|
|
30
|
+
generate_kafka_connection_with_secrets,
|
|
29
31
|
)
|
|
30
32
|
from tinybird.tb.modules.feedback_manager import FeedbackManager
|
|
31
33
|
from tinybird.tb.modules.project import Project
|
|
@@ -275,3 +277,21 @@ async def connection_create_gcs(ctx: Context) -> None:
|
|
|
275
277
|
connection_path=connection_path,
|
|
276
278
|
)
|
|
277
279
|
)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@connection_create.command(name="kafka", short_help="Creates a Kafka connection.")
|
|
283
|
+
@click.option("--name", help="The name of the connection")
|
|
284
|
+
@click.pass_context
|
|
285
|
+
@coro
|
|
286
|
+
async def connection_create_kafka(ctx: Context, name: Optional[str] = None) -> None:
|
|
287
|
+
"""
|
|
288
|
+
Creates a Kafka connection.
|
|
289
|
+
|
|
290
|
+
\b
|
|
291
|
+
$ tb connection create kafka
|
|
292
|
+
"""
|
|
293
|
+
click.echo(FeedbackManager.highlight(message="» Creating Kafka connection..."))
|
|
294
|
+
project: Project = ctx.ensure_object(dict)["project"]
|
|
295
|
+
name = get_kafka_connection_name(project.folder, name)
|
|
296
|
+
await generate_kafka_connection_with_secrets(name=name, folder=project.folder)
|
|
297
|
+
click.echo(FeedbackManager.success(message="✓ Done!"))
|
|
@@ -409,10 +409,14 @@ def generate_connection_file(name: str, content: str, folder: str, skip_feedback
|
|
|
409
409
|
|
|
410
410
|
|
|
411
411
|
async def generate_aws_iamrole_connection_file_with_secret(
|
|
412
|
-
name: str, service: str, role_arn_secret_name: str, region: str, folder: str
|
|
412
|
+
name: str, service: str, role_arn_secret_name: str, region: str, folder: str, with_default_secret: bool = False
|
|
413
413
|
) -> Path:
|
|
414
|
+
if with_default_secret:
|
|
415
|
+
default_secret = ', "arn:aws:iam::123456789012:role/my-role"'
|
|
416
|
+
else:
|
|
417
|
+
default_secret = ""
|
|
414
418
|
content = f"""TYPE {service}
|
|
415
|
-
S3_ARN {{{{ tb_secret("{role_arn_secret_name}") }}}}
|
|
419
|
+
S3_ARN {{{{ tb_secret("{role_arn_secret_name}"{default_secret}) }}}}
|
|
416
420
|
S3_REGION {region}
|
|
417
421
|
"""
|
|
418
422
|
file_path = generate_connection_file(name, content, folder, skip_feedback=True)
|
|
@@ -483,6 +487,7 @@ async def create_resources_from_data(
|
|
|
483
487
|
data: str,
|
|
484
488
|
project: Project,
|
|
485
489
|
config: Dict[str, Any],
|
|
490
|
+
skip_pipes: bool = False,
|
|
486
491
|
) -> List[Path]:
|
|
487
492
|
local_client = await get_tinybird_local_client(config)
|
|
488
493
|
folder_path = project.path
|
|
@@ -495,7 +500,7 @@ async def create_resources_from_data(
|
|
|
495
500
|
result.append(ds_file)
|
|
496
501
|
name = ds_file.stem
|
|
497
502
|
no_pipes = len(project.get_pipe_files()) == 0
|
|
498
|
-
if no_pipes:
|
|
503
|
+
if not skip_pipes and no_pipes:
|
|
499
504
|
pipe_file = generate_pipe_file(
|
|
500
505
|
f"{name}_endpoint",
|
|
501
506
|
f"""
|
|
@@ -510,7 +515,9 @@ TYPE ENDPOINT
|
|
|
510
515
|
return result
|
|
511
516
|
|
|
512
517
|
|
|
513
|
-
async def create_resources_from_url(
|
|
518
|
+
async def create_resources_from_url(
|
|
519
|
+
url: str, project: Project, config: Dict[str, Any], skip_pipes: bool = False
|
|
520
|
+
) -> List[Path]:
|
|
514
521
|
result: List[Path] = []
|
|
515
522
|
local_client = await get_tinybird_local_client(config)
|
|
516
523
|
format = url.split(".")[-1]
|
|
@@ -518,7 +525,7 @@ async def create_resources_from_url(url: str, project: Project, config: Dict[str
|
|
|
518
525
|
result.append(ds_file)
|
|
519
526
|
name = ds_file.stem
|
|
520
527
|
no_pipes = len(project.get_pipe_files()) == 0
|
|
521
|
-
if no_pipes:
|
|
528
|
+
if not skip_pipes and no_pipes:
|
|
522
529
|
pipe_file = generate_pipe_file(
|
|
523
530
|
f"{name}_endpoint",
|
|
524
531
|
f"""
|
|
@@ -531,3 +538,14 @@ TYPE ENDPOINT
|
|
|
531
538
|
)
|
|
532
539
|
result.append(pipe_file)
|
|
533
540
|
return result
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
async def generate_kafka_connection_with_secrets(name: str, folder: str) -> Path:
|
|
544
|
+
content = """TYPE kafka
|
|
545
|
+
KAFKA_BOOTSTRAP_SERVERS {{ tb_secret("KAFKA_SERVERS", "localhost:9092") }}
|
|
546
|
+
KAFKA_SECURITY_PROTOCOL SASL_SSL
|
|
547
|
+
KAFKA_SASL_MECHANISM PLAIN
|
|
548
|
+
KAFKA_KEY {{ tb_secret("KAFKA_USERNAME", "") }}
|
|
549
|
+
KAFKA_SECRET {{ tb_secret("KAFKA_PASSWORD", "") }}
|
|
550
|
+
"""
|
|
551
|
+
return generate_connection_file(name, content, folder, skip_feedback=True)
|