snowflake-cli 3.5.0__py3-none-any.whl → 3.7.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 (64) hide show
  1. snowflake/cli/__about__.py +13 -1
  2. snowflake/cli/_app/commands_registration/builtin_plugins.py +4 -0
  3. snowflake/cli/_app/loggers.py +2 -2
  4. snowflake/cli/_app/snow_connector.py +7 -6
  5. snowflake/cli/_app/telemetry.py +3 -15
  6. snowflake/cli/_app/version_check.py +4 -4
  7. snowflake/cli/_plugins/auth/__init__.py +11 -0
  8. snowflake/cli/_plugins/auth/keypair/__init__.py +0 -0
  9. snowflake/cli/_plugins/auth/keypair/commands.py +151 -0
  10. snowflake/cli/_plugins/auth/keypair/manager.py +331 -0
  11. snowflake/cli/_plugins/auth/keypair/plugin_spec.py +30 -0
  12. snowflake/cli/_plugins/connection/commands.py +78 -1
  13. snowflake/cli/_plugins/helpers/commands.py +25 -1
  14. snowflake/cli/_plugins/helpers/snowsl_vars_reader.py +133 -0
  15. snowflake/cli/_plugins/init/commands.py +9 -6
  16. snowflake/cli/_plugins/logs/__init__.py +0 -0
  17. snowflake/cli/_plugins/logs/commands.py +105 -0
  18. snowflake/cli/_plugins/logs/manager.py +107 -0
  19. snowflake/cli/_plugins/logs/plugin_spec.py +16 -0
  20. snowflake/cli/_plugins/logs/utils.py +60 -0
  21. snowflake/cli/_plugins/nativeapp/entities/application.py +4 -1
  22. snowflake/cli/_plugins/nativeapp/sf_sql_facade.py +33 -6
  23. snowflake/cli/_plugins/notebook/commands.py +3 -0
  24. snowflake/cli/_plugins/notebook/notebook_entity.py +16 -27
  25. snowflake/cli/_plugins/object/command_aliases.py +3 -1
  26. snowflake/cli/_plugins/object/manager.py +4 -2
  27. snowflake/cli/_plugins/project/commands.py +89 -48
  28. snowflake/cli/_plugins/project/manager.py +57 -23
  29. snowflake/cli/_plugins/project/project_entity_model.py +22 -3
  30. snowflake/cli/_plugins/snowpark/commands.py +15 -2
  31. snowflake/cli/_plugins/spcs/compute_pool/commands.py +17 -5
  32. snowflake/cli/_plugins/sql/manager.py +43 -52
  33. snowflake/cli/_plugins/sql/source_reader.py +230 -0
  34. snowflake/cli/_plugins/stage/manager.py +25 -12
  35. snowflake/cli/_plugins/streamlit/commands.py +3 -0
  36. snowflake/cli/_plugins/streamlit/manager.py +19 -15
  37. snowflake/cli/api/artifacts/upload.py +30 -34
  38. snowflake/cli/api/artifacts/utils.py +8 -6
  39. snowflake/cli/api/cli_global_context.py +7 -2
  40. snowflake/cli/api/commands/decorators.py +11 -2
  41. snowflake/cli/api/commands/flags.py +35 -4
  42. snowflake/cli/api/commands/snow_typer.py +20 -2
  43. snowflake/cli/api/config.py +5 -3
  44. snowflake/cli/api/constants.py +2 -0
  45. snowflake/cli/api/entities/utils.py +29 -16
  46. snowflake/cli/api/errno.py +1 -0
  47. snowflake/cli/api/exceptions.py +75 -27
  48. snowflake/cli/api/feature_flags.py +1 -0
  49. snowflake/cli/api/identifiers.py +2 -0
  50. snowflake/cli/api/plugins/plugin_config.py +2 -2
  51. snowflake/cli/api/project/schemas/template.py +3 -3
  52. snowflake/cli/api/rendering/project_templates.py +3 -3
  53. snowflake/cli/api/rendering/sql_templates.py +2 -2
  54. snowflake/cli/api/rest_api.py +2 -3
  55. snowflake/cli/{_app → api}/secret.py +4 -1
  56. snowflake/cli/api/secure_path.py +16 -4
  57. snowflake/cli/api/sql_execution.py +8 -4
  58. snowflake/cli/api/utils/definition_rendering.py +14 -8
  59. snowflake/cli/api/utils/templating_functions.py +4 -4
  60. {snowflake_cli-3.5.0.dist-info → snowflake_cli-3.7.0.dist-info}/METADATA +11 -11
  61. {snowflake_cli-3.5.0.dist-info → snowflake_cli-3.7.0.dist-info}/RECORD +64 -52
  62. {snowflake_cli-3.5.0.dist-info → snowflake_cli-3.7.0.dist-info}/WHEEL +0 -0
  63. {snowflake_cli-3.5.0.dist-info → snowflake_cli-3.7.0.dist-info}/entry_points.txt +0 -0
  64. {snowflake_cli-3.5.0.dist-info → snowflake_cli-3.7.0.dist-info}/licenses/LICENSE +0 -0
@@ -14,4 +14,16 @@
14
14
 
15
15
  from __future__ import annotations
16
16
 
17
- VERSION = "3.5.0"
17
+ from enum import Enum, unique
18
+
19
+ VERSION = "3.7.0"
20
+
21
+
22
+ @unique
23
+ class CLIInstallationSource(Enum):
24
+ BINARY = "binary"
25
+ PYPI = "pypi"
26
+
27
+
28
+ # This variable is changed in binary release script
29
+ INSTALLATION_SOURCE = CLIInstallationSource.PYPI
@@ -12,11 +12,13 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ from snowflake.cli._plugins.auth.keypair import plugin_spec as auth_plugin_spec
15
16
  from snowflake.cli._plugins.connection import plugin_spec as connection_plugin_spec
16
17
  from snowflake.cli._plugins.cortex import plugin_spec as cortex_plugin_spec
17
18
  from snowflake.cli._plugins.git import plugin_spec as git_plugin_spec
18
19
  from snowflake.cli._plugins.helpers import plugin_spec as migrate_plugin_spec
19
20
  from snowflake.cli._plugins.init import plugin_spec as init_plugin_spec
21
+ from snowflake.cli._plugins.logs import plugin_spec as logs_plugin_spec
20
22
  from snowflake.cli._plugins.nativeapp import plugin_spec as nativeapp_plugin_spec
21
23
  from snowflake.cli._plugins.notebook import plugin_spec as notebook_plugin_spec
22
24
  from snowflake.cli._plugins.object import plugin_spec as object_plugin_spec
@@ -33,6 +35,7 @@ from snowflake.cli._plugins.workspace import plugin_spec as workspace_plugin_spe
33
35
  # plugin name to plugin spec
34
36
  def get_builtin_plugin_name_to_plugin_spec():
35
37
  plugin_specs = {
38
+ "auth": auth_plugin_spec,
36
39
  "connection": connection_plugin_spec,
37
40
  "helpers": migrate_plugin_spec,
38
41
  "spcs": spcs_plugin_spec,
@@ -49,6 +52,7 @@ def get_builtin_plugin_name_to_plugin_spec():
49
52
  "init": init_plugin_spec,
50
53
  "workspace": workspace_plugin_spec,
51
54
  "plugin": plugin_plugin_spec,
55
+ "logs": logs_plugin_spec,
52
56
  }
53
57
 
54
58
  return plugin_specs
@@ -20,7 +20,7 @@ from dataclasses import asdict, dataclass, field
20
20
  from typing import Any, Dict, List
21
21
 
22
22
  import typer
23
- from snowflake.cli.api.exceptions import InvalidLogsConfiguration
23
+ from snowflake.cli.api.exceptions import InvalidLogsConfigurationError
24
24
  from snowflake.cli.api.secure_path import SecurePath
25
25
  from snowflake.connector.errors import ConfigSourceError
26
26
 
@@ -129,7 +129,7 @@ class FileLogsConfig:
129
129
  logging.CRITICAL,
130
130
  ]
131
131
  if self.level not in possible_log_levels:
132
- raise InvalidLogsConfiguration(
132
+ raise InvalidLogsConfigurationError(
133
133
  f"Invalid 'level' value set in [logs] section: {config['level']}. "
134
134
  f"'level' should be one of: {' / '.join(logging.getLevelName(lvl) for lvl in possible_log_levels)}"
135
135
  )
@@ -21,12 +21,11 @@ from typing import Dict, Optional
21
21
 
22
22
  import snowflake.connector
23
23
  from click.exceptions import ClickException
24
- from snowflake.cli.__about__ import VERSION
24
+ from snowflake.cli import __about__
25
25
  from snowflake.cli._app.constants import (
26
26
  INTERNAL_APPLICATION_NAME,
27
27
  PARAM_APPLICATION_NAME,
28
28
  )
29
- from snowflake.cli._app.secret import SecretType
30
29
  from snowflake.cli._app.telemetry import command_info
31
30
  from snowflake.cli.api.config import (
32
31
  get_connection_dict,
@@ -34,10 +33,11 @@ from snowflake.cli.api.config import (
34
33
  )
35
34
  from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB
36
35
  from snowflake.cli.api.exceptions import (
37
- InvalidConnectionConfiguration,
36
+ InvalidConnectionConfigurationError,
38
37
  SnowflakeConnectionError,
39
38
  )
40
39
  from snowflake.cli.api.feature_flags import FeatureFlag
40
+ from snowflake.cli.api.secret import SecretType
41
41
  from snowflake.cli.api.secure_path import SecurePath
42
42
  from snowflake.connector import SnowflakeConnection
43
43
  from snowflake.connector.errors import DatabaseError, ForbiddenError
@@ -56,6 +56,7 @@ SUPPORTED_ENV_OVERRIDES = [
56
56
  "authenticator",
57
57
  "private_key_file",
58
58
  "private_key_path",
59
+ "private_key_raw",
59
60
  "database",
60
61
  "schema",
61
62
  "role",
@@ -168,7 +169,7 @@ def connect_to_snowflake(
168
169
  except ForbiddenError as err:
169
170
  raise SnowflakeConnectionError(err)
170
171
  except DatabaseError as err:
171
- raise InvalidConnectionConfiguration(err.msg)
172
+ raise InvalidConnectionConfigurationError(err.msg)
172
173
 
173
174
 
174
175
  def _avoid_closing_the_connection_if_it_was_shared(
@@ -247,7 +248,7 @@ def _update_internal_application_info(connection_parameters: Dict):
247
248
  """Update internal application data if ENABLE_SEPARATE_AUTHENTICATION_POLICY_ID is enabled."""
248
249
  if FeatureFlag.ENABLE_SEPARATE_AUTHENTICATION_POLICY_ID.is_enabled():
249
250
  connection_parameters["internal_application_name"] = INTERNAL_APPLICATION_NAME
250
- connection_parameters["internal_application_version"] = VERSION
251
+ connection_parameters["internal_application_version"] = __about__.VERSION
251
252
 
252
253
 
253
254
  def _load_pem_from_file(private_key_file: str) -> SecretType:
@@ -273,7 +274,7 @@ def _load_pem_to_der(private_key_pem: SecretType) -> SecretType:
273
274
  and private_key_passphrase.value is None
274
275
  ):
275
276
  raise ClickException(
276
- "Encrypted private key, you must provide the"
277
+ "Encrypted private key, you must provide the "
277
278
  "passphrase in the environment variable PRIVATE_KEY_PASSPHRASE"
278
279
  )
279
280
 
@@ -22,7 +22,7 @@ from typing import Any, Dict, Union
22
22
 
23
23
  import click
24
24
  import typer
25
- from snowflake.cli.__about__ import VERSION
25
+ from snowflake.cli import __about__
26
26
  from snowflake.cli._app.constants import PARAM_APPLICATION_NAME
27
27
  from snowflake.cli.api.cli_global_context import (
28
28
  _CliGlobalContextAccess,
@@ -40,12 +40,6 @@ from snowflake.connector.telemetry import (
40
40
  from snowflake.connector.time_util import get_time_millis
41
41
 
42
42
 
43
- @unique
44
- class CLIInstallationSource(Enum):
45
- BINARY = "binary"
46
- PYPI = "pypi"
47
-
48
-
49
43
  @unique
50
44
  class CLITelemetryField(Enum):
51
45
  # Basic information
@@ -172,12 +166,6 @@ def _get_definition_version() -> str | None:
172
166
  return None
173
167
 
174
168
 
175
- def _get_installation_source() -> CLIInstallationSource:
176
- if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
177
- return CLIInstallationSource.BINARY
178
- return CLIInstallationSource.PYPI
179
-
180
-
181
169
  def _get_ci_environment_type() -> str:
182
170
  if "GITHUB_ACTIONS" in os.environ:
183
171
  return "GITHUB_ACTIONS"
@@ -214,8 +202,8 @@ class CLITelemetryClient:
214
202
  ) -> Dict[str, Any]:
215
203
  data = {
216
204
  CLITelemetryField.SOURCE: PARAM_APPLICATION_NAME,
217
- CLITelemetryField.INSTALLATION_SOURCE: _get_installation_source().value,
218
- CLITelemetryField.VERSION_CLI: VERSION,
205
+ CLITelemetryField.INSTALLATION_SOURCE: __about__.INSTALLATION_SOURCE.value,
206
+ CLITelemetryField.VERSION_CLI: __about__.VERSION,
219
207
  CLITelemetryField.VERSION_OS: platform.platform(),
220
208
  CLITelemetryField.VERSION_PYTHON: python_version(),
221
209
  CLITelemetryField.COMMAND_CI_ENVIRONMENT: _get_ci_environment_type(),
@@ -8,6 +8,8 @@ from snowflake.cli.api.console import cli_console
8
8
  from snowflake.cli.api.secure_path import SecurePath
9
9
  from snowflake.connector.config_manager import CONFIG_MANAGER
10
10
 
11
+ REPOSITORY_URL = "https://pypi.org/pypi/snowflake-cli/json"
12
+
11
13
 
12
14
  def get_new_version_msg() -> str | None:
13
15
  last = _VersionCache().get_last_version()
@@ -45,9 +47,7 @@ class _VersionCache:
45
47
  @staticmethod
46
48
  def _get_version_from_pypi() -> str | None:
47
49
  headers = {"Content-Type": "application/vnd.pypi.simple.v1+json"}
48
- response = requests.get(
49
- "https://pypi.org/pypi/snowflake-cli-labs/json", headers=headers, timeout=3
50
- )
50
+ response = requests.get(REPOSITORY_URL, headers=headers, timeout=3)
51
51
  response.raise_for_status()
52
52
  return response.json()["info"]["version"]
53
53
 
@@ -60,7 +60,7 @@ class _VersionCache:
60
60
 
61
61
  def _read_latest_version(self) -> Version | None:
62
62
  if self._cache_file.exists():
63
- data = json.loads(self._cache_file.read_text())
63
+ data = json.loads(self._cache_file.read_text(file_size_limit_mb=1))
64
64
  now = time.time()
65
65
  if data[_VersionCache._last_time] > now - 60 * 60:
66
66
  return Version(data[_VersionCache._version])
@@ -0,0 +1,11 @@
1
+ from snowflake.cli._plugins.auth.keypair.commands import app as keypair_app
2
+ from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
3
+ from snowflake.cli.api.feature_flags import FeatureFlag
4
+
5
+ app = SnowTyperFactory(
6
+ name="auth",
7
+ help="Manages authentication methods.",
8
+ is_hidden=lambda: FeatureFlag.ENABLE_AUTH_KEYPAIR.is_disabled(),
9
+ )
10
+
11
+ app.add_typer(keypair_app)
File without changes
@@ -0,0 +1,151 @@
1
+ from pathlib import Path
2
+
3
+ import typer
4
+ from snowflake.cli._plugins.auth.keypair.manager import AuthManager, PublicKeyProperty
5
+ from snowflake.cli.api.commands.flags import SecretTypeParser
6
+ from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
7
+ from snowflake.cli.api.output.types import (
8
+ CollectionResult,
9
+ CommandResult,
10
+ MessageResult,
11
+ SingleQueryResult,
12
+ )
13
+ from snowflake.cli.api.secret import SecretType
14
+ from snowflake.cli.api.secure_path import SecurePath
15
+
16
+ app = SnowTyperFactory(
17
+ name="keypair",
18
+ help="Manages authentication.",
19
+ )
20
+
21
+
22
+ KEY_PAIR_DEFAULT_PATH = "~/.ssh"
23
+
24
+
25
+ def _show_connection_name_prompt(ctx: typer.Context, value: str):
26
+ for param in ctx.command.params:
27
+ if param.name == "connection_name":
28
+ if value:
29
+ param.prompt = "Enter connection name"
30
+ break
31
+ return value
32
+
33
+
34
+ _new_connection_option = typer.Option(
35
+ True,
36
+ help="Create a new connection.",
37
+ prompt="Create a new connection?",
38
+ callback=_show_connection_name_prompt,
39
+ show_default=False,
40
+ hidden=True,
41
+ )
42
+
43
+
44
+ _connection_name_option = typer.Option(
45
+ None,
46
+ help="The new connection name.",
47
+ prompt=False,
48
+ show_default=False,
49
+ hidden=True,
50
+ )
51
+
52
+
53
+ _key_length_option = typer.Option(
54
+ 2048,
55
+ "--key-length",
56
+ help="The RSA key length.",
57
+ prompt="Enter key length",
58
+ )
59
+
60
+
61
+ _output_path_option = typer.Option(
62
+ KEY_PAIR_DEFAULT_PATH,
63
+ "--output-path",
64
+ help="The output path for private and public keys",
65
+ prompt="Enter output path",
66
+ )
67
+
68
+
69
+ _private_key_passphrase_option = typer.Option(
70
+ "",
71
+ "--private-key-passphrase",
72
+ help="The private key passphrase.",
73
+ click_type=SecretTypeParser(),
74
+ prompt="Enter private key passphrase",
75
+ hide_input=True,
76
+ show_default=False,
77
+ )
78
+
79
+
80
+ @app.command("setup", requires_connection=True)
81
+ def setup(
82
+ new_connection: bool = _new_connection_option,
83
+ connection_name: str = _connection_name_option,
84
+ key_length: int = _key_length_option,
85
+ output_path: Path = _output_path_option,
86
+ private_key_passphrase: SecretType = _private_key_passphrase_option,
87
+ **options,
88
+ ):
89
+ """
90
+ Generates the key pair, sets the public key for the user in Snowflake, and creates or updates the connection.
91
+ """
92
+ AuthManager().setup(
93
+ connection_name=connection_name,
94
+ key_length=key_length,
95
+ output_path=SecurePath(output_path),
96
+ private_key_passphrase=private_key_passphrase,
97
+ )
98
+ return MessageResult(f"Setup completed.")
99
+
100
+
101
+ @app.command("rotate", requires_connection=True)
102
+ def rotate(
103
+ key_length: int = _key_length_option,
104
+ output_path: Path = _output_path_option,
105
+ private_key_passphrase: SecretType = _private_key_passphrase_option,
106
+ **options,
107
+ ):
108
+ """
109
+ Rotates the key for the connection. Generates the key pair, sets the public key for the user in Snowflake, and creates or updates the connection.
110
+ """
111
+ AuthManager().rotate(
112
+ key_length=key_length,
113
+ output_path=SecurePath(output_path),
114
+ private_key_passphrase=private_key_passphrase,
115
+ )
116
+ return MessageResult(f"Rotate completed.")
117
+
118
+
119
+ @app.command("list", requires_connection=True)
120
+ def list_keys(**options) -> CommandResult:
121
+ """
122
+ Lists the public keys set for the user.
123
+ """
124
+ return CollectionResult(AuthManager().list_keys())
125
+
126
+
127
+ @app.command("remove", requires_connection=True)
128
+ def remove(
129
+ public_key_property: PublicKeyProperty = typer.Option(
130
+ ...,
131
+ "--key-id",
132
+ help=f"Local path to the template directory or a URL to Git repository with templates.",
133
+ show_default=False,
134
+ ),
135
+ **options,
136
+ ):
137
+ """
138
+ Removes the public key for the user.
139
+ """
140
+ return SingleQueryResult(
141
+ AuthManager().remove_public_key(public_key_property=public_key_property)
142
+ )
143
+
144
+
145
+ @app.command("status", requires_connection=True)
146
+ def status(**options):
147
+ """
148
+ Verifies the key pair configuration and tests the connection.
149
+ """
150
+ AuthManager().status()
151
+ return MessageResult("Status check completed.")