diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index e7007d4047..6b4900fda5 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -6,6 +6,7 @@ * Added support for fully qualified name (`database.schema.name`) in `name` parameter in streamlit project definition * Added support for fully qualified image repository names in `spcs image-repository` commands. * Added `--if-not-exists` option to `create` commands for `service`, and `compute-pool`. Added `--replace` and `--if-not-exists` options for `image-repository create`. +* Added support for python connector diagnostic report. ## Fixes and improvements * Adding `--image-name` option for image name argument in `spcs image-repository list-tags` for consistency with other commands. diff --git a/src/snowflake/cli/api/cli_global_context.py b/src/snowflake/cli/api/cli_global_context.py index 3c6ecd4caa..c91ead2eec 100644 --- a/src/snowflake/cli/api/cli_global_context.py +++ b/src/snowflake/cli/api/cli_global_context.py @@ -24,6 +24,9 @@ def __init__(self): self._private_key_path: Optional[str] = None self._warehouse: Optional[str] = None self._mfa_passcode: Optional[str] = None + self._enable_diag: Optional[bool] = False + self._diag_log_path: Optional[Path] = None + self._diag_allowlist_path: Optional[Path] = None self._temporary_connection: bool = False def __setattr__(self, key, value): @@ -118,6 +121,27 @@ def mfa_passcode(self) -> Optional[str]: def set_mfa_passcode(self, value: Optional[str]): self._mfa_passcode = value + @property + def enable_diag(self) -> Optional[bool]: + return self._enable_diag + + def set_enable_diag(self, value: Optional[bool]): + self._enable_diag = value + + @property + def diag_log_path(self) -> Optional[Path]: + return self._diag_log_path + + def set_diag_log_path(self, value: Optional[Path]): + self._diag_log_path = value + + @property + def diag_allowlist_path(self) -> Optional[Path]: + return self._diag_allowlist_path + + def set_diag_allowlist_path(self, value: Optional[Path]): + self._diag_allowlist_path = value + @property def temporary_connection(self) -> bool: return self._temporary_connection @@ -150,6 +174,9 @@ def _build_connection(self): return connect_to_snowflake( temporary_connection=self.temporary_connection, mfa_passcode=self._mfa_passcode, + enable_diag=self._enable_diag, + diag_log_path=self._diag_log_path, + diag_allowlist_path=self._diag_allowlist_path, connection_name=self.connection_name, **self._collect_not_empty_connection_attributes(), ) diff --git a/src/snowflake/cli/api/commands/decorators.py b/src/snowflake/cli/api/commands/decorators.py index a41353ca25..a1764d18ad 100644 --- a/src/snowflake/cli/api/commands/decorators.py +++ b/src/snowflake/cli/api/commands/decorators.py @@ -12,6 +12,9 @@ ConnectionOption, DatabaseOption, DebugOption, + DiagAllowlistPathOption, + DiagLogPathOption, + EnableDiagOption, MfaPasscodeOption, OutputFormatOption, PasswordOption, @@ -242,6 +245,24 @@ def _evaluate_param_type( annotation=Optional[str], default=MfaPasscodeOption, ), + inspect.Parameter( + "enable_diag", + inspect.Parameter.KEYWORD_ONLY, + annotation=Optional[bool], + default=EnableDiagOption, + ), + inspect.Parameter( + "diag_log_path", + inspect.Parameter.KEYWORD_ONLY, + annotation=Optional[str], + default=DiagLogPathOption, + ), + inspect.Parameter( + "diag_allowlist_path", + inspect.Parameter.KEYWORD_ONLY, + annotation=Optional[str], + default=DiagAllowlistPathOption, + ), ] GLOBAL_OPTIONS = [ diff --git a/src/snowflake/cli/api/commands/flags.py b/src/snowflake/cli/api/commands/flags.py index af61d9103f..e6aa7994f3 100644 --- a/src/snowflake/cli/api/commands/flags.py +++ b/src/snowflake/cli/api/commands/flags.py @@ -1,6 +1,8 @@ from __future__ import annotations +import tempfile from inspect import signature +from pathlib import Path from typing import Any, Callable, List, Optional, Tuple import click @@ -265,6 +267,42 @@ def _password_callback(value: str): rich_help_panel=_CONNECTION_SECTION, ) +EnableDiagOption = typer.Option( + False, + "--enable-diag", + help="Run python connector diagnostic test", + callback=_callback(lambda: cli_context_manager.connection_context.set_enable_diag), + show_default=False, + is_flag=True, + rich_help_panel=_CONNECTION_SECTION, +) + +DiagLogPathOption: Path = typer.Option( + tempfile.gettempdir(), + "--diag-log-path", + help="Diagnostic report path", + callback=_callback( + lambda: cli_context_manager.connection_context.set_diag_log_path + ), + show_default=False, + rich_help_panel=_CONNECTION_SECTION, + exists=True, + writable=True, +) + +DiagAllowlistPathOption: Path = typer.Option( + None, + "--diag-allowlist-path", + help="Diagnostic report path to optional allowlist", + callback=_callback( + lambda: cli_context_manager.connection_context.set_diag_allowlist_path + ), + show_default=False, + rich_help_panel=_CONNECTION_SECTION, + exists=True, + file_okay=True, +) + OutputFormatOption = typer.Option( OutputFormat.TABLE.value, "--format", diff --git a/src/snowflake/cli/app/snow_connector.py b/src/snowflake/cli/app/snow_connector.py index b34178c6ba..54b18908d4 100644 --- a/src/snowflake/cli/app/snow_connector.py +++ b/src/snowflake/cli/app/snow_connector.py @@ -27,6 +27,9 @@ def connect_to_snowflake( temporary_connection: bool = False, mfa_passcode: Optional[str] = None, + enable_diag: Optional[bool] = False, + diag_log_path: Optional[str] = None, + diag_allowlist_path: Optional[str] = None, connection_name: Optional[str] = None, **overrides, ) -> SnowflakeConnection: @@ -65,6 +68,15 @@ def connect_to_snowflake( if mfa_passcode: connection_parameters["passcode"] = mfa_passcode + if enable_diag: + connection_parameters["enable_connection_diag"] = enable_diag + if diag_log_path: + connection_parameters["connection_diag_log_path"] = diag_log_path + if diag_allowlist_path: + connection_parameters[ + "connection_diag_allowlist_path" + ] = diag_allowlist_path + try: # Whatever output is generated when creating connection, # we don't want it in our output. This is particularly important diff --git a/src/snowflake/cli/plugins/connection/commands.py b/src/snowflake/cli/plugins/connection/commands.py index 14bfd54982..573e6e749a 100644 --- a/src/snowflake/cli/plugins/connection/commands.py +++ b/src/snowflake/cli/plugins/connection/commands.py @@ -10,6 +10,9 @@ from snowflake.cli.api.commands.flags import ( PLAIN_PASSWORD_MSG, ConnectionOption, + DiagAllowlistPathOption, + DiagLogPathOption, + EnableDiagOption, MfaPasscodeOption, ) from snowflake.cli.api.commands.snow_typer import SnowTyper @@ -227,7 +230,12 @@ def add( @app.command(requires_connection=False) def test( - connection: str = ConnectionOption, mfa_passcode: str = MfaPasscodeOption, **options + connection: str = ConnectionOption, + mfa_passcode: str = MfaPasscodeOption, + enable_diag: bool = EnableDiagOption, + diag_log_path: str = DiagLogPathOption, + diag_allowlist_path: str = DiagAllowlistPathOption, + **options, ) -> CommandResult: """ Tests the connection to Snowflake. @@ -265,6 +273,11 @@ def test( "Warehouse": f'{conn.warehouse or "not set"}', } + if enable_diag: + result[ + "Diag Report Location" + ] = f"{diag_log_path}/SnowflakeConnectionTestReport.txt" + return ObjectResult(result) diff --git a/tests/__snapshots__/test_help_messages.ambr b/tests/__snapshots__/test_help_messages.ambr index a7b99913d5..475e0532c4 100644 --- a/tests/__snapshots__/test_help_messages.ambr +++ b/tests/__snapshots__/test_help_messages.ambr @@ -163,6 +163,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -266,6 +271,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -334,6 +344,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -424,6 +439,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -503,6 +523,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -565,6 +590,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -749,6 +779,11 @@ │ `default`. │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -839,6 +874,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -909,6 +949,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -989,6 +1034,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1067,6 +1117,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1130,6 +1185,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1195,6 +1255,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1258,6 +1323,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1323,6 +1393,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1488,6 +1563,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1562,6 +1642,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1664,6 +1749,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1736,6 +1826,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1804,6 +1899,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -1971,6 +2071,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2034,6 +2139,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2122,6 +2232,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2186,6 +2301,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2249,6 +2369,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2313,6 +2438,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2385,6 +2515,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2474,6 +2609,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2536,6 +2676,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2605,6 +2750,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2693,6 +2843,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2757,6 +2912,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2826,6 +2986,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2890,6 +3055,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -2977,6 +3147,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3042,6 +3217,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3105,6 +3285,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3251,6 +3436,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3314,6 +3504,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3385,6 +3580,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3448,6 +3648,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3540,6 +3745,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3603,6 +3813,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3666,6 +3881,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3742,6 +3962,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3808,6 +4033,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3923,6 +4153,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -3991,6 +4226,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -4055,6 +4295,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ @@ -4153,6 +4398,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ diff --git a/tests/api/commands/__snapshots__/test_snow_typer.ambr b/tests/api/commands/__snapshots__/test_snow_typer.ambr index 5d79558542..ff72324b9a 100644 --- a/tests/api/commands/__snapshots__/test_snow_typer.ambr +++ b/tests/api/commands/__snapshots__/test_snow_typer.ambr @@ -45,6 +45,11 @@ │ of one defined in config │ │ --mfa-passcode TEXT Token to use for multi-factor │ │ authentication (MFA) │ + │ --enable-diag Run python connector diagnostic │ + │ test │ + │ --diag-log-path TEXT Diagnostic report path │ + │ --diag-allowlist-path TEXT Diagnostic report path to optional │ + │ allowlist │ ╰──────────────────────────────────────────────────────────────────────────────╯ ╭─ Global configuration ───────────────────────────────────────────────────────╮ │ --format [TABLE|JSON] Specifies the output format. │ diff --git a/tests/app/test_telemetry.py b/tests/app/test_telemetry.py index 4a24c3c156..056b83f666 100644 --- a/tests/app/test_telemetry.py +++ b/tests/app/test_telemetry.py @@ -34,7 +34,7 @@ def test_executing_command_sends_telemetry_data( "version_python": "2.3.4", "command": ["connection", "test"], "command_group": "connection", - "command_flags": {"format": "DEFAULT"}, + "command_flags": {"diag_log_path": "DEFAULT", "format": "DEFAULT"}, "command_output_type": "TABLE", "type": "executing_command", }, diff --git a/tests/test_common_decorators.py b/tests/test_common_decorators.py index f1018b7f73..c40467d789 100644 --- a/tests/test_common_decorators.py +++ b/tests/test_common_decorators.py @@ -18,6 +18,9 @@ "warehouse", "temporary_connection", "mfa_passcode", + "enable_diag", + "diag_log_path", + "diag_allowlist_path", "format", "verbose", "debug", diff --git a/tests/test_common_global_context.py b/tests/test_common_global_context.py index 58730317ec..d7017e00f6 100644 --- a/tests/test_common_global_context.py +++ b/tests/test_common_global_context.py @@ -59,6 +59,9 @@ def test_connection_caching(mock_connect): call( temporary_connection=False, mfa_passcode=None, + enable_diag=False, + diag_log_path=None, + diag_allowlist_path=None, connection_name=None, account=None, user=None, @@ -73,6 +76,9 @@ def test_connection_caching(mock_connect): call( temporary_connection=False, mfa_passcode=None, + enable_diag=False, + diag_log_path=None, + diag_allowlist_path=None, connection_name=None, account=None, user="newValue3", diff --git a/tests/test_connection.py b/tests/test_connection.py index 246bc62af5..dbe5d380f9 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -234,7 +234,9 @@ def test_second_connection_not_update_default_connection(runner, snapshot): @mock.patch("snowflake.cli.plugins.connection.commands.ObjectManager") @mock.patch("snowflake.cli.app.snow_connector.connect_to_snowflake") def test_connection_test(mock_connect, mock_om, runner): - result = runner.invoke(["connection", "test", "-c", "full"]) + result = runner.invoke( + ["connection", "test", "-c", "full", "--diag-log-path", "/tmp"] + ) assert result.exit_code == 0, result.output assert "Host" in result.output assert "Password" not in result.output @@ -243,6 +245,9 @@ def test_connection_test(mock_connect, mock_om, runner): mock_connect.assert_called_with( temporary_connection=False, mfa_passcode=None, + enable_diag=False, + diag_log_path="/tmp", + diag_allowlist_path=None, connection_name="full", account=None, user=None, @@ -672,3 +677,32 @@ def _change_connection(config_file, conn_name): config = _change_connection(tmp_file, "conn2") assert config["default_connection_name"] == "conn2" + + +@mock.patch("snowflake.cli.plugins.connection.commands.ObjectManager") +@mock.patch("snowflake.cli.app.snow_connector.connect_to_snowflake") +def test_connection_test_diag_report(mock_connect, mock_om, runner): + result = runner.invoke( + ["connection", "test", "-c", "full", "--enable-diag", "--diag-log-path", "/tmp"] + ) + assert result.exit_code == 0, result.output + print(result.output) + assert "Host" in result.output + assert "Diag Report" in result.output + mock_connect.assert_called_once_with( + temporary_connection=False, + mfa_passcode=None, + enable_diag=True, + diag_log_path="/tmp", + diag_allowlist_path=None, + connection_name="full", + account=None, + user=None, + password=None, + authenticator=None, + private_key_path=None, + database=None, + schema=None, + role=None, + warehouse=None, + ) diff --git a/tests/test_sql.py b/tests/test_sql.py index f433dc8bec..b32074f04a 100644 --- a/tests/test_sql.py +++ b/tests/test_sql.py @@ -95,6 +95,8 @@ def test_sql_overrides_connection_configuration(mock_conn, runner, mock_cursor): "warehouseValue", "--password", "passFromTest", + "--diag-log-path", + "/tmp", ], catch_exceptions=False, ) @@ -103,6 +105,9 @@ def test_sql_overrides_connection_configuration(mock_conn, runner, mock_cursor): mock_conn.assert_called_once_with( temporary_connection=False, mfa_passcode=None, + enable_diag=False, + diag_log_path="/tmp", + diag_allowlist_path=None, connection_name="connectionName", account="accountnameValue", user="usernameValue",