snowflake-cli-labs 2.8.0rc1__py3-none-any.whl → 2.8.2__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 (242) hide show
  1. README.md +21 -0
  2. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/METADATA +7 -95
  3. snowflake_cli_labs-2.8.2.dist-info/RECORD +5 -0
  4. snowflake/cli/__about__.py +0 -17
  5. snowflake/cli/__init__.py +0 -13
  6. snowflake/cli/api/__init__.py +0 -48
  7. snowflake/cli/api/cli_global_context.py +0 -390
  8. snowflake/cli/api/commands/__init__.py +0 -13
  9. snowflake/cli/api/commands/alias.py +0 -23
  10. snowflake/cli/api/commands/decorators.py +0 -354
  11. snowflake/cli/api/commands/execution_metadata.py +0 -40
  12. snowflake/cli/api/commands/experimental_behaviour.py +0 -19
  13. snowflake/cli/api/commands/flags.py +0 -640
  14. snowflake/cli/api/commands/project_initialisation.py +0 -65
  15. snowflake/cli/api/commands/snow_typer.py +0 -237
  16. snowflake/cli/api/commands/typer_pre_execute.py +0 -26
  17. snowflake/cli/api/config.py +0 -348
  18. snowflake/cli/api/console/__init__.py +0 -17
  19. snowflake/cli/api/console/abc.py +0 -89
  20. snowflake/cli/api/console/console.py +0 -134
  21. snowflake/cli/api/console/enum.py +0 -17
  22. snowflake/cli/api/constants.py +0 -79
  23. snowflake/cli/api/errno.py +0 -27
  24. snowflake/cli/api/exceptions.py +0 -164
  25. snowflake/cli/api/feature_flags.py +0 -55
  26. snowflake/cli/api/identifiers.py +0 -154
  27. snowflake/cli/api/output/__init__.py +0 -13
  28. snowflake/cli/api/output/formats.py +0 -20
  29. snowflake/cli/api/output/types.py +0 -118
  30. snowflake/cli/api/plugins/__init__.py +0 -13
  31. snowflake/cli/api/plugins/command/__init__.py +0 -72
  32. snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
  33. snowflake/cli/api/plugins/plugin_config.py +0 -32
  34. snowflake/cli/api/project/__init__.py +0 -13
  35. snowflake/cli/api/project/definition.py +0 -84
  36. snowflake/cli/api/project/definition_manager.py +0 -134
  37. snowflake/cli/api/project/errors.py +0 -56
  38. snowflake/cli/api/project/project_verification.py +0 -23
  39. snowflake/cli/api/project/schemas/__init__.py +0 -13
  40. snowflake/cli/api/project/schemas/entities/application_entity.py +0 -44
  41. snowflake/cli/api/project/schemas/entities/application_package_entity.py +0 -66
  42. snowflake/cli/api/project/schemas/entities/common.py +0 -78
  43. snowflake/cli/api/project/schemas/entities/entities.py +0 -30
  44. snowflake/cli/api/project/schemas/identifier_model.py +0 -49
  45. snowflake/cli/api/project/schemas/native_app/__init__.py +0 -13
  46. snowflake/cli/api/project/schemas/native_app/application.py +0 -62
  47. snowflake/cli/api/project/schemas/native_app/native_app.py +0 -93
  48. snowflake/cli/api/project/schemas/native_app/package.py +0 -78
  49. snowflake/cli/api/project/schemas/native_app/path_mapping.py +0 -65
  50. snowflake/cli/api/project/schemas/project_definition.py +0 -199
  51. snowflake/cli/api/project/schemas/snowpark/__init__.py +0 -13
  52. snowflake/cli/api/project/schemas/snowpark/argument.py +0 -28
  53. snowflake/cli/api/project/schemas/snowpark/callable.py +0 -69
  54. snowflake/cli/api/project/schemas/snowpark/snowpark.py +0 -36
  55. snowflake/cli/api/project/schemas/streamlit/__init__.py +0 -13
  56. snowflake/cli/api/project/schemas/streamlit/streamlit.py +0 -46
  57. snowflake/cli/api/project/schemas/template.py +0 -77
  58. snowflake/cli/api/project/schemas/updatable_model.py +0 -194
  59. snowflake/cli/api/project/util.py +0 -261
  60. snowflake/cli/api/rendering/__init__.py +0 -13
  61. snowflake/cli/api/rendering/jinja.py +0 -112
  62. snowflake/cli/api/rendering/project_definition_templates.py +0 -39
  63. snowflake/cli/api/rendering/project_templates.py +0 -98
  64. snowflake/cli/api/rendering/sql_templates.py +0 -60
  65. snowflake/cli/api/rest_api.py +0 -172
  66. snowflake/cli/api/sanitizers.py +0 -43
  67. snowflake/cli/api/secure_path.py +0 -362
  68. snowflake/cli/api/secure_utils.py +0 -29
  69. snowflake/cli/api/sql_execution.py +0 -260
  70. snowflake/cli/api/utils/__init__.py +0 -13
  71. snowflake/cli/api/utils/cursor.py +0 -34
  72. snowflake/cli/api/utils/definition_rendering.py +0 -383
  73. snowflake/cli/api/utils/dict_utils.py +0 -73
  74. snowflake/cli/api/utils/error_handling.py +0 -23
  75. snowflake/cli/api/utils/graph.py +0 -97
  76. snowflake/cli/api/utils/models.py +0 -63
  77. snowflake/cli/api/utils/naming_utils.py +0 -13
  78. snowflake/cli/api/utils/path_utils.py +0 -36
  79. snowflake/cli/api/utils/templating_functions.py +0 -144
  80. snowflake/cli/api/utils/types.py +0 -35
  81. snowflake/cli/app/__init__.py +0 -22
  82. snowflake/cli/app/__main__.py +0 -31
  83. snowflake/cli/app/api_impl/__init__.py +0 -13
  84. snowflake/cli/app/api_impl/plugin/__init__.py +0 -13
  85. snowflake/cli/app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
  86. snowflake/cli/app/build_and_push.sh +0 -8
  87. snowflake/cli/app/cli_app.py +0 -243
  88. snowflake/cli/app/commands_registration/__init__.py +0 -33
  89. snowflake/cli/app/commands_registration/builtin_plugins.py +0 -54
  90. snowflake/cli/app/commands_registration/command_plugins_loader.py +0 -169
  91. snowflake/cli/app/commands_registration/commands_registration_with_callbacks.py +0 -105
  92. snowflake/cli/app/commands_registration/exception_logging.py +0 -26
  93. snowflake/cli/app/commands_registration/threadsafe.py +0 -48
  94. snowflake/cli/app/commands_registration/typer_registration.py +0 -153
  95. snowflake/cli/app/constants.py +0 -19
  96. snowflake/cli/app/dev/__init__.py +0 -13
  97. snowflake/cli/app/dev/commands_structure.py +0 -48
  98. snowflake/cli/app/dev/docs/__init__.py +0 -13
  99. snowflake/cli/app/dev/docs/commands_docs_generator.py +0 -100
  100. snowflake/cli/app/dev/docs/generator.py +0 -35
  101. snowflake/cli/app/dev/docs/project_definition_docs_generator.py +0 -58
  102. snowflake/cli/app/dev/docs/project_definition_generate_json_schema.py +0 -227
  103. snowflake/cli/app/dev/docs/template_utils.py +0 -23
  104. snowflake/cli/app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
  105. snowflake/cli/app/dev/docs/templates/overview.rst.jinja2 +0 -9
  106. snowflake/cli/app/dev/docs/templates/usage.rst.jinja2 +0 -57
  107. snowflake/cli/app/dev/pycharm_remote_debug.py +0 -46
  108. snowflake/cli/app/loggers.py +0 -199
  109. snowflake/cli/app/main_typer.py +0 -62
  110. snowflake/cli/app/printing.py +0 -181
  111. snowflake/cli/app/snow_connector.py +0 -243
  112. snowflake/cli/app/telemetry.py +0 -189
  113. snowflake/cli/plugins/__init__.py +0 -13
  114. snowflake/cli/plugins/connection/__init__.py +0 -13
  115. snowflake/cli/plugins/connection/commands.py +0 -330
  116. snowflake/cli/plugins/connection/plugin_spec.py +0 -30
  117. snowflake/cli/plugins/connection/util.py +0 -179
  118. snowflake/cli/plugins/cortex/__init__.py +0 -13
  119. snowflake/cli/plugins/cortex/commands.py +0 -327
  120. snowflake/cli/plugins/cortex/constants.py +0 -17
  121. snowflake/cli/plugins/cortex/manager.py +0 -189
  122. snowflake/cli/plugins/cortex/plugin_spec.py +0 -30
  123. snowflake/cli/plugins/cortex/types.py +0 -22
  124. snowflake/cli/plugins/git/__init__.py +0 -13
  125. snowflake/cli/plugins/git/commands.py +0 -305
  126. snowflake/cli/plugins/git/manager.py +0 -96
  127. snowflake/cli/plugins/git/plugin_spec.py +0 -30
  128. snowflake/cli/plugins/init/__init__.py +0 -13
  129. snowflake/cli/plugins/init/commands.py +0 -244
  130. snowflake/cli/plugins/init/plugin_spec.py +0 -30
  131. snowflake/cli/plugins/nativeapp/__init__.py +0 -13
  132. snowflake/cli/plugins/nativeapp/artifacts.py +0 -742
  133. snowflake/cli/plugins/nativeapp/codegen/__init__.py +0 -13
  134. snowflake/cli/plugins/nativeapp/codegen/artifact_processor.py +0 -91
  135. snowflake/cli/plugins/nativeapp/codegen/compiler.py +0 -130
  136. snowflake/cli/plugins/nativeapp/codegen/sandbox.py +0 -306
  137. snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -172
  138. snowflake/cli/plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -56
  139. snowflake/cli/plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
  140. snowflake/cli/plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
  141. snowflake/cli/plugins/nativeapp/codegen/snowpark/models.py +0 -61
  142. snowflake/cli/plugins/nativeapp/codegen/snowpark/python_processor.py +0 -528
  143. snowflake/cli/plugins/nativeapp/commands.py +0 -439
  144. snowflake/cli/plugins/nativeapp/common_flags.py +0 -44
  145. snowflake/cli/plugins/nativeapp/constants.py +0 -27
  146. snowflake/cli/plugins/nativeapp/exceptions.py +0 -122
  147. snowflake/cli/plugins/nativeapp/feature_flags.py +0 -24
  148. snowflake/cli/plugins/nativeapp/init.py +0 -345
  149. snowflake/cli/plugins/nativeapp/manager.py +0 -823
  150. snowflake/cli/plugins/nativeapp/plugin_spec.py +0 -30
  151. snowflake/cli/plugins/nativeapp/policy.py +0 -50
  152. snowflake/cli/plugins/nativeapp/project_model.py +0 -195
  153. snowflake/cli/plugins/nativeapp/run_processor.py +0 -389
  154. snowflake/cli/plugins/nativeapp/teardown_processor.py +0 -301
  155. snowflake/cli/plugins/nativeapp/utils.py +0 -98
  156. snowflake/cli/plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -135
  157. snowflake/cli/plugins/nativeapp/version/__init__.py +0 -13
  158. snowflake/cli/plugins/nativeapp/version/commands.py +0 -170
  159. snowflake/cli/plugins/nativeapp/version/version_processor.py +0 -362
  160. snowflake/cli/plugins/notebook/__init__.py +0 -13
  161. snowflake/cli/plugins/notebook/commands.py +0 -84
  162. snowflake/cli/plugins/notebook/exceptions.py +0 -20
  163. snowflake/cli/plugins/notebook/manager.py +0 -71
  164. snowflake/cli/plugins/notebook/plugin_spec.py +0 -30
  165. snowflake/cli/plugins/notebook/types.py +0 -16
  166. snowflake/cli/plugins/object/__init__.py +0 -13
  167. snowflake/cli/plugins/object/command_aliases.py +0 -94
  168. snowflake/cli/plugins/object/commands.py +0 -174
  169. snowflake/cli/plugins/object/common.py +0 -85
  170. snowflake/cli/plugins/object/manager.py +0 -96
  171. snowflake/cli/plugins/object/plugin_spec.py +0 -30
  172. snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
  173. snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
  174. snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
  175. snowflake/cli/plugins/snowpark/__init__.py +0 -13
  176. snowflake/cli/plugins/snowpark/commands.py +0 -548
  177. snowflake/cli/plugins/snowpark/common.py +0 -307
  178. snowflake/cli/plugins/snowpark/manager.py +0 -109
  179. snowflake/cli/plugins/snowpark/models.py +0 -156
  180. snowflake/cli/plugins/snowpark/package/__init__.py +0 -13
  181. snowflake/cli/plugins/snowpark/package/anaconda_packages.py +0 -233
  182. snowflake/cli/plugins/snowpark/package/commands.py +0 -256
  183. snowflake/cli/plugins/snowpark/package/manager.py +0 -43
  184. snowflake/cli/plugins/snowpark/package/utils.py +0 -26
  185. snowflake/cli/plugins/snowpark/package_utils.py +0 -354
  186. snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
  187. snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
  188. snowflake/cli/plugins/snowpark/snowpark_shared.py +0 -95
  189. snowflake/cli/plugins/snowpark/zipper.py +0 -81
  190. snowflake/cli/plugins/spcs/__init__.py +0 -35
  191. snowflake/cli/plugins/spcs/common.py +0 -99
  192. snowflake/cli/plugins/spcs/compute_pool/__init__.py +0 -13
  193. snowflake/cli/plugins/spcs/compute_pool/commands.py +0 -240
  194. snowflake/cli/plugins/spcs/compute_pool/manager.py +0 -121
  195. snowflake/cli/plugins/spcs/image_registry/__init__.py +0 -13
  196. snowflake/cli/plugins/spcs/image_registry/commands.py +0 -65
  197. snowflake/cli/plugins/spcs/image_registry/manager.py +0 -105
  198. snowflake/cli/plugins/spcs/image_repository/__init__.py +0 -13
  199. snowflake/cli/plugins/spcs/image_repository/commands.py +0 -196
  200. snowflake/cli/plugins/spcs/image_repository/manager.py +0 -84
  201. snowflake/cli/plugins/spcs/jobs/__init__.py +0 -13
  202. snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
  203. snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
  204. snowflake/cli/plugins/spcs/plugin_spec.py +0 -30
  205. snowflake/cli/plugins/spcs/services/__init__.py +0 -13
  206. snowflake/cli/plugins/spcs/services/commands.py +0 -311
  207. snowflake/cli/plugins/spcs/services/manager.py +0 -170
  208. snowflake/cli/plugins/sql/__init__.py +0 -13
  209. snowflake/cli/plugins/sql/commands.py +0 -83
  210. snowflake/cli/plugins/sql/manager.py +0 -92
  211. snowflake/cli/plugins/sql/plugin_spec.py +0 -30
  212. snowflake/cli/plugins/sql/snowsql_templating.py +0 -28
  213. snowflake/cli/plugins/stage/__init__.py +0 -13
  214. snowflake/cli/plugins/stage/commands.py +0 -261
  215. snowflake/cli/plugins/stage/diff.py +0 -326
  216. snowflake/cli/plugins/stage/manager.py +0 -544
  217. snowflake/cli/plugins/stage/md5.py +0 -160
  218. snowflake/cli/plugins/stage/plugin_spec.py +0 -30
  219. snowflake/cli/plugins/streamlit/__init__.py +0 -13
  220. snowflake/cli/plugins/streamlit/commands.py +0 -186
  221. snowflake/cli/plugins/streamlit/manager.py +0 -222
  222. snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
  223. snowflake/cli/plugins/workspace/__init__.py +0 -13
  224. snowflake/cli/plugins/workspace/commands.py +0 -35
  225. snowflake/cli/plugins/workspace/plugin_spec.py +0 -30
  226. snowflake/cli/templates/default_snowpark/.gitignore +0 -4
  227. snowflake/cli/templates/default_snowpark/app/__init__.py +0 -0
  228. snowflake/cli/templates/default_snowpark/app/common.py +0 -2
  229. snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
  230. snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
  231. snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
  232. snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
  233. snowflake/cli/templates/default_streamlit/.gitignore +0 -4
  234. snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
  235. snowflake/cli/templates/default_streamlit/environment.yml +0 -6
  236. snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
  237. snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
  238. snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
  239. snowflake_cli_labs-2.8.0rc1.dist-info/RECORD +0 -240
  240. snowflake_cli_labs-2.8.0rc1.dist-info/entry_points.txt +0 -2
  241. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/WHEEL +0 -0
  242. {snowflake_cli_labs-2.8.0rc1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,243 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from __future__ import annotations
16
-
17
- import contextlib
18
- import logging
19
- import os
20
- from typing import Dict, Optional
21
-
22
- import snowflake.connector
23
- from click.exceptions import ClickException
24
- from snowflake.cli.api.cli_global_context import cli_context
25
- from snowflake.cli.api.config import (
26
- get_connection_dict,
27
- get_default_connection_dict,
28
- get_default_connection_name,
29
- )
30
- from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB
31
- from snowflake.cli.api.exceptions import (
32
- InvalidConnectionConfiguration,
33
- SnowflakeConnectionError,
34
- )
35
- from snowflake.cli.api.secure_path import SecurePath
36
- from snowflake.cli.app.constants import (
37
- PARAM_APPLICATION_NAME,
38
- )
39
- from snowflake.cli.app.telemetry import command_info
40
- from snowflake.connector import SnowflakeConnection
41
- from snowflake.connector.errors import DatabaseError, ForbiddenError
42
-
43
- log = logging.getLogger(__name__)
44
-
45
-
46
- ENCRYPTED_PKCS8_PK_HEADER = b"-----BEGIN ENCRYPTED PRIVATE KEY-----"
47
- UNENCRYPTED_PKCS8_PK_HEADER = b"-----BEGIN PRIVATE KEY-----"
48
-
49
-
50
- def connect_to_snowflake(
51
- temporary_connection: bool = False,
52
- mfa_passcode: Optional[str] = None,
53
- enable_diag: Optional[bool] = False,
54
- diag_log_path: Optional[str] = None,
55
- diag_allowlist_path: Optional[str] = None,
56
- connection_name: Optional[str] = None,
57
- **overrides,
58
- ) -> SnowflakeConnection:
59
- if temporary_connection and connection_name:
60
- raise ClickException("Can't use connection name and temporary connection.")
61
-
62
- using_session_token = (
63
- "session_token" in overrides and overrides["session_token"] is not None
64
- )
65
- using_master_token = (
66
- "master_token" in overrides and overrides["master_token"] is not None
67
- )
68
- _raise_errors_related_to_session_token(
69
- temporary_connection, using_session_token, using_master_token
70
- )
71
-
72
- if connection_name:
73
- connection_parameters = get_connection_dict(connection_name)
74
- elif temporary_connection:
75
- connection_parameters = {} # we will apply overrides in next step
76
- else:
77
- connection_parameters = get_default_connection_dict()
78
- cli_context.connection_context.set_connection_name(
79
- get_default_connection_name()
80
- )
81
-
82
- # Apply overrides to connection details
83
- for key, value in overrides.items():
84
- # Command line override case
85
- if value:
86
- connection_parameters[key] = value
87
- continue
88
-
89
- # Generic environment variable case, apply only if value not passed via flag or connection variable
90
- generic_env_value = os.environ.get(f"SNOWFLAKE_{key}".upper())
91
- if key not in connection_parameters and generic_env_value:
92
- connection_parameters[key] = generic_env_value
93
- continue
94
-
95
- # Clean up connection params
96
- connection_parameters = {
97
- k: v for k, v in connection_parameters.items() if v is not None
98
- }
99
-
100
- connection_parameters = update_connection_details_with_private_key(
101
- connection_parameters
102
- )
103
-
104
- if mfa_passcode:
105
- connection_parameters["passcode"] = mfa_passcode
106
-
107
- if connection_parameters.get("authenticator") == "username_password_mfa":
108
- connection_parameters["client_request_mfa_token"] = True
109
-
110
- if enable_diag:
111
- connection_parameters["enable_connection_diag"] = enable_diag
112
- if diag_log_path:
113
- connection_parameters["connection_diag_log_path"] = diag_log_path
114
- if diag_allowlist_path:
115
- connection_parameters[
116
- "connection_diag_allowlist_path"
117
- ] = diag_allowlist_path
118
-
119
- # Make sure the connection is not closed if it was shared to the SnowCLI, instead of being created in the SnowCLI
120
- _avoid_closing_the_connection_if_it_was_shared(
121
- using_session_token, using_master_token, connection_parameters
122
- )
123
-
124
- _update_connection_application_name(connection_parameters)
125
-
126
- try:
127
- # Whatever output is generated when creating connection,
128
- # we don't want it in our output. This is particularly important
129
- # for cases when external browser and json format are used.
130
- # Redirecting both stdout and stderr for offline usage.
131
- with contextlib.redirect_stdout(None), contextlib.redirect_stderr(None):
132
- return snowflake.connector.connect(
133
- application=command_info(),
134
- **connection_parameters,
135
- )
136
- except ForbiddenError as err:
137
- raise SnowflakeConnectionError(err)
138
- except DatabaseError as err:
139
- raise InvalidConnectionConfiguration(err.msg)
140
-
141
-
142
- def _avoid_closing_the_connection_if_it_was_shared(
143
- using_session_token: bool, using_master_token: bool, connection_parameters: Dict
144
- ):
145
- if using_session_token and using_master_token:
146
- connection_parameters["server_session_keep_alive"] = True
147
-
148
-
149
- def _raise_errors_related_to_session_token(
150
- temporary_connection: bool, using_session_token: bool, using_master_token: bool
151
- ):
152
- if not temporary_connection and (using_session_token or using_master_token):
153
- raise ClickException(
154
- "When using a session or master token, you must use a temporary connection"
155
- )
156
- if using_session_token and not using_master_token:
157
- raise ClickException(
158
- "When using a session token, you must provide the corresponding master token"
159
- )
160
- if using_master_token and not using_session_token:
161
- raise ClickException(
162
- "When using a master token, you must provide the corresponding session token"
163
- )
164
-
165
-
166
- def update_connection_details_with_private_key(connection_parameters: Dict):
167
- if "private_key_path" in connection_parameters:
168
- if connection_parameters.get("authenticator") == "SNOWFLAKE_JWT":
169
- private_key = _load_pem_to_der(connection_parameters["private_key_path"])
170
- connection_parameters["private_key"] = private_key
171
- del connection_parameters["private_key_path"]
172
- else:
173
- raise ClickException(
174
- "Private Key authentication requires authenticator set to SNOWFLAKE_JWT"
175
- )
176
- return connection_parameters
177
-
178
-
179
- def _update_connection_application_name(connection_parameters: Dict):
180
- """Update version and name of app handling connection."""
181
- connection_application_params = {
182
- "application_name": PARAM_APPLICATION_NAME,
183
- }
184
- connection_parameters.update(connection_application_params)
185
-
186
-
187
- def _load_pem_to_der(private_key_path: str) -> bytes:
188
- """
189
- Given a private key file path (in PEM format), decode key data into DER
190
- format
191
- """
192
-
193
- with SecurePath(private_key_path).open(
194
- "rb", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB
195
- ) as f:
196
- private_key_pem = f.read()
197
-
198
- private_key_passphrase = os.getenv("PRIVATE_KEY_PASSPHRASE", None)
199
- if (
200
- private_key_pem.startswith(ENCRYPTED_PKCS8_PK_HEADER)
201
- and private_key_passphrase is None
202
- ):
203
- raise ClickException(
204
- "Encrypted private key, you must provide the"
205
- "passphrase in the environment variable PRIVATE_KEY_PASSPHRASE"
206
- )
207
-
208
- if not private_key_pem.startswith(
209
- ENCRYPTED_PKCS8_PK_HEADER
210
- ) and not private_key_pem.startswith(UNENCRYPTED_PKCS8_PK_HEADER):
211
- raise ClickException(
212
- "Private key provided is not in PKCS#8 format. Please use correct format."
213
- )
214
-
215
- if private_key_pem.startswith(UNENCRYPTED_PKCS8_PK_HEADER):
216
- private_key_passphrase = None
217
-
218
- return prepare_private_key(private_key_pem, private_key_passphrase)
219
-
220
-
221
- def prepare_private_key(private_key_pem, private_key_passphrase=None):
222
- from cryptography.hazmat.backends import default_backend
223
- from cryptography.hazmat.primitives.serialization import (
224
- Encoding,
225
- NoEncryption,
226
- PrivateFormat,
227
- load_pem_private_key,
228
- )
229
-
230
- private_key = load_pem_private_key(
231
- private_key_pem,
232
- (
233
- str.encode(private_key_passphrase)
234
- if private_key_passphrase is not None
235
- else private_key_passphrase
236
- ),
237
- default_backend(),
238
- )
239
- return private_key.private_bytes(
240
- encoding=Encoding.DER,
241
- format=PrivateFormat.PKCS8,
242
- encryption_algorithm=NoEncryption(),
243
- )
@@ -1,189 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- from __future__ import annotations
16
-
17
- import platform
18
- import sys
19
- from enum import Enum, unique
20
- from typing import Any, Dict, Union
21
-
22
- import click
23
- from snowflake.cli.__about__ import VERSION
24
- from snowflake.cli.api.cli_global_context import cli_context
25
- from snowflake.cli.api.commands.execution_metadata import ExecutionMetadata
26
- from snowflake.cli.api.config import get_feature_flags_section
27
- from snowflake.cli.api.output.formats import OutputFormat
28
- from snowflake.cli.api.utils.error_handling import ignore_exceptions
29
- from snowflake.cli.app.constants import PARAM_APPLICATION_NAME
30
- from snowflake.connector.telemetry import (
31
- TelemetryData,
32
- TelemetryField,
33
- )
34
- from snowflake.connector.time_util import get_time_millis
35
-
36
-
37
- @unique
38
- class CLITelemetryField(Enum):
39
- # Basic information
40
- SOURCE = "source"
41
- VERSION_CLI = "version_cli"
42
- VERSION_PYTHON = "version_python"
43
- VERSION_OS = "version_os"
44
- # Command execution context
45
- COMMAND = "command"
46
- COMMAND_GROUP = "command_group"
47
- COMMAND_FLAGS = "command_flags"
48
- COMMAND_EXECUTION_ID = "command_execution_id"
49
- COMMAND_RESULT_STATUS = "command_result_status"
50
- COMMAND_OUTPUT_TYPE = "command_output_type"
51
- COMMAND_EXECUTION_TIME = "command_execution_time"
52
- # Configuration
53
- CONFIG_FEATURE_FLAGS = "config_feature_flags"
54
- # Information
55
- EVENT = "event"
56
- ERROR_MSG = "error_msg"
57
- ERROR_TYPE = "error_type"
58
- IS_CLI_EXCEPTION = "is_cli_exception"
59
- # Project context
60
- PROJECT_DEFINITION_VERSION = "project_definition_version"
61
-
62
-
63
- class TelemetryEvent(Enum):
64
- CMD_EXECUTION = "executing_command"
65
- CMD_EXECUTION_ERROR = "error_executing_command"
66
- CMD_EXECUTION_RESULT = "result_executing_command"
67
-
68
-
69
- TelemetryDict = Dict[Union[CLITelemetryField, TelemetryField], Any]
70
-
71
-
72
- def _find_command_info() -> TelemetryDict:
73
- ctx = click.get_current_context()
74
- command_path = ctx.command_path.split(" ")[1:]
75
- return {
76
- CLITelemetryField.COMMAND: command_path,
77
- CLITelemetryField.COMMAND_GROUP: command_path[0],
78
- CLITelemetryField.COMMAND_FLAGS: {
79
- k: ctx.get_parameter_source(k).name # type: ignore[attr-defined]
80
- for k, v in ctx.params.items()
81
- if v # noqa
82
- },
83
- CLITelemetryField.COMMAND_OUTPUT_TYPE: ctx.params.get(
84
- "format", OutputFormat.TABLE
85
- ).value,
86
- CLITelemetryField.PROJECT_DEFINITION_VERSION: str(_get_definition_version()),
87
- }
88
-
89
-
90
- def _get_definition_version() -> str | None:
91
- from snowflake.cli.api.cli_global_context import cli_context
92
-
93
- if cli_context.project_definition:
94
- return cli_context.project_definition.definition_version
95
- return None
96
-
97
-
98
- def command_info() -> str:
99
- info = _find_command_info()
100
- command = ".".join(info[CLITelemetryField.COMMAND])
101
- return f"{PARAM_APPLICATION_NAME}.{command}".upper()
102
-
103
-
104
- def python_version() -> str:
105
- py_ver = sys.version_info
106
- return f"{py_ver.major}.{py_ver.minor}.{py_ver.micro}"
107
-
108
-
109
- class CLITelemetryClient:
110
- def __init__(self, ctx):
111
- self._ctx = ctx
112
-
113
- @staticmethod
114
- def generate_telemetry_data_dict(
115
- telemetry_payload: TelemetryDict,
116
- ) -> Dict[str, Any]:
117
- data = {
118
- CLITelemetryField.SOURCE: PARAM_APPLICATION_NAME,
119
- CLITelemetryField.VERSION_CLI: VERSION,
120
- CLITelemetryField.VERSION_OS: platform.platform(),
121
- CLITelemetryField.VERSION_PYTHON: python_version(),
122
- CLITelemetryField.CONFIG_FEATURE_FLAGS: {
123
- k: str(v) for k, v in get_feature_flags_section().items()
124
- },
125
- **_find_command_info(),
126
- **telemetry_payload,
127
- }
128
- # To map Enum to string, so we don't have to use .value every time
129
- return {getattr(k, "value", k): v for k, v in data.items()} # type: ignore[arg-type]
130
-
131
- @property
132
- def _telemetry(self):
133
- return self._ctx.connection._telemetry # noqa
134
-
135
- def send(self, payload: TelemetryDict):
136
- if self._telemetry:
137
- message = self.generate_telemetry_data_dict(payload)
138
- telemetry_data = TelemetryData.from_telemetry_data_dict(
139
- from_dict=message, timestamp=get_time_millis()
140
- )
141
- self._telemetry.try_add_log_to_batch(telemetry_data)
142
-
143
- def flush(self):
144
- self._telemetry.send_batch()
145
-
146
-
147
- _telemetry = CLITelemetryClient(ctx=cli_context)
148
-
149
-
150
- @ignore_exceptions()
151
- def log_command_usage(execution: ExecutionMetadata):
152
- _telemetry.send(
153
- {
154
- TelemetryField.KEY_TYPE: TelemetryEvent.CMD_EXECUTION.value,
155
- CLITelemetryField.COMMAND_EXECUTION_ID: execution.execution_id,
156
- }
157
- )
158
-
159
-
160
- @ignore_exceptions()
161
- def log_command_result(execution: ExecutionMetadata):
162
- _telemetry.send(
163
- {
164
- TelemetryField.KEY_TYPE: TelemetryEvent.CMD_EXECUTION_RESULT.value,
165
- CLITelemetryField.COMMAND_EXECUTION_ID: execution.execution_id,
166
- CLITelemetryField.COMMAND_RESULT_STATUS: execution.status.value,
167
- CLITelemetryField.COMMAND_EXECUTION_TIME: execution.get_duration(),
168
- }
169
- )
170
-
171
-
172
- @ignore_exceptions()
173
- def log_command_execution_error(exception: Exception, execution: ExecutionMetadata):
174
- exception_type: str = type(exception).__name__
175
- is_cli_exception: bool = issubclass(exception.__class__, click.ClickException)
176
- _telemetry.send(
177
- {
178
- TelemetryField.KEY_TYPE: TelemetryEvent.CMD_EXECUTION_ERROR.value,
179
- CLITelemetryField.COMMAND_EXECUTION_ID: execution.execution_id,
180
- CLITelemetryField.ERROR_TYPE: exception_type,
181
- CLITelemetryField.IS_CLI_EXCEPTION: is_cli_exception,
182
- CLITelemetryField.COMMAND_EXECUTION_TIME: execution.get_duration(),
183
- }
184
- )
185
-
186
-
187
- @ignore_exceptions()
188
- def flush_telemetry():
189
- _telemetry.flush()
@@ -1,13 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
@@ -1,13 +0,0 @@
1
- # Copyright (c) 2024 Snowflake Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.