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,237 +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 dataclasses
18
- import logging
19
- from functools import wraps
20
- from typing import Any, Callable, Dict, List, Optional, Tuple
21
-
22
- import typer
23
- from snowflake.cli.api.commands.decorators import (
24
- global_options,
25
- global_options_with_connection,
26
- )
27
- from snowflake.cli.api.commands.execution_metadata import (
28
- ExecutionMetadata,
29
- ExecutionStatus,
30
- )
31
- from snowflake.cli.api.commands.flags import DEFAULT_CONTEXT_SETTINGS
32
- from snowflake.cli.api.commands.typer_pre_execute import run_pre_execute_commands
33
- from snowflake.cli.api.exceptions import CommandReturnTypeError
34
- from snowflake.cli.api.output.types import CommandResult
35
- from snowflake.cli.api.sanitizers import sanitize_for_terminal
36
-
37
- log = logging.getLogger(__name__)
38
-
39
-
40
- class SnowTyper(typer.Typer):
41
- def __init__(self, /, **kwargs):
42
- self._sanitize_kwargs(kwargs)
43
- super().__init__(
44
- **kwargs,
45
- context_settings=DEFAULT_CONTEXT_SETTINGS,
46
- pretty_exceptions_show_locals=False,
47
- no_args_is_help=True,
48
- add_completion=True,
49
- )
50
-
51
- @staticmethod
52
- def _sanitize_kwargs(kwargs: Dict):
53
- # Sanitize all string options that are visible in terminal output
54
- known_keywords = [
55
- "help",
56
- "short_help",
57
- "options_metavar",
58
- "rich_help_panel",
59
- "epilog",
60
- ]
61
- for kw in known_keywords:
62
- if kw in kwargs:
63
- kwargs[kw] = sanitize_for_terminal(kwargs[kw])
64
- return kwargs
65
-
66
- @wraps(typer.Typer.command)
67
- def command(
68
- self,
69
- name: Optional[str] = None,
70
- requires_global_options: bool = True,
71
- requires_connection: bool = False,
72
- is_enabled: Callable[[], bool] | None = None,
73
- **kwargs,
74
- ):
75
- """
76
- Custom implementation of Typer.command that adds ability to execute additional
77
- logic before and after execution as well as process the result and act on possible
78
- errors.
79
- """
80
- name = sanitize_for_terminal(name)
81
- self._sanitize_kwargs(kwargs)
82
- if is_enabled is not None and not is_enabled():
83
- return lambda func: func
84
-
85
- def custom_command(command_callable):
86
- """Custom command wrapper similar to Typer.command."""
87
- # Sanitize doc string which is used to create help in terminal
88
- command_callable.__doc__ = sanitize_for_terminal(command_callable.__doc__)
89
-
90
- if requires_connection:
91
- command_callable = global_options_with_connection(command_callable)
92
- elif requires_global_options:
93
- command_callable = global_options(command_callable)
94
-
95
- @wraps(command_callable)
96
- def command_callable_decorator(*args, **kw):
97
- """Wrapper around command callable. This is what happens at "runtime"."""
98
- execution = ExecutionMetadata()
99
- self.pre_execute(execution)
100
- try:
101
- result = command_callable(*args, **kw)
102
- self.process_result(result)
103
- execution.complete(ExecutionStatus.SUCCESS)
104
- except Exception as err:
105
- execution.complete(ExecutionStatus.FAILURE)
106
- self.exception_handler(err, execution)
107
- raise
108
- finally:
109
- self.post_execute(execution)
110
-
111
- return super(SnowTyper, self).command(name=name, **kwargs)(
112
- command_callable_decorator
113
- )
114
-
115
- return custom_command
116
-
117
- @staticmethod
118
- def pre_execute(execution: ExecutionMetadata):
119
- """
120
- Callback executed before running any command callable (after context execution).
121
- Pay attention to make this method safe to use if performed operations are not necessary
122
- for executing the command in proper way.
123
- """
124
- from snowflake.cli.app.telemetry import log_command_usage
125
-
126
- log.debug("Executing command pre execution callback")
127
- run_pre_execute_commands()
128
- log_command_usage(execution)
129
-
130
- @staticmethod
131
- def process_result(result):
132
- """Command result processor"""
133
- from snowflake.cli.app.printing import print_result
134
-
135
- # Because we still have commands like "logs" that do not return anything.
136
- # We should improve it in future.
137
- if not result:
138
- return
139
- if not isinstance(result, CommandResult):
140
- raise CommandReturnTypeError(type(result))
141
- print_result(result)
142
-
143
- @staticmethod
144
- def exception_handler(exception: Exception, execution: ExecutionMetadata):
145
- """
146
- Callback executed on command execution error.
147
- """
148
- from snowflake.cli.app.telemetry import log_command_execution_error
149
-
150
- log.debug("Executing command exception callback")
151
- log_command_execution_error(exception, execution)
152
-
153
- @staticmethod
154
- def post_execute(execution: ExecutionMetadata):
155
- """
156
- Callback executed after running any command callable. Pay attention to make this method safe to
157
- use if performed operations are not necessary for executing the command in proper way.
158
- """
159
- from snowflake.cli.app.telemetry import flush_telemetry, log_command_result
160
-
161
- log.debug("Executing command post execution callback")
162
- log_command_result(execution)
163
- flush_telemetry()
164
-
165
-
166
- @dataclasses.dataclass
167
- class SnowTyperCommandData:
168
- """
169
- Class for storing data of commands to be registered in SnowTyper instances created by SnowTyperFactory.
170
- """
171
-
172
- func: Callable
173
- args: Tuple[Any, ...]
174
- kwargs: Dict[str, Any]
175
-
176
-
177
- class SnowTyperFactory:
178
- """
179
- SnowTyper factory. Usage is similar to SnowTyper, except that create_instance()
180
- creates actual SnowTyper instance.
181
- """
182
-
183
- def __init__(
184
- self,
185
- /,
186
- name: Optional[str] = None,
187
- help: Optional[str] = None, # noqa: A002
188
- short_help: Optional[str] = None,
189
- is_hidden: Optional[Callable[[], bool]] = None,
190
- deprecated: bool = False,
191
- ):
192
- self.name = name
193
- self.help = help
194
- self.short_help = short_help
195
- self.is_hidden = is_hidden
196
- self.deprecated = deprecated
197
- self.commands_to_register: List[SnowTyperCommandData] = []
198
- self.subapps_to_register: List[SnowTyperFactory] = []
199
- self.callbacks_to_register: List[Callable] = []
200
-
201
- def create_instance(self) -> SnowTyper:
202
- app = SnowTyper(
203
- name=self.name,
204
- help=self.help,
205
- short_help=self.short_help,
206
- hidden=self.is_hidden() if self.is_hidden else False,
207
- deprecated=self.deprecated,
208
- )
209
- # register commands
210
- for command in self.commands_to_register:
211
- app.command(*command.args, **command.kwargs)(command.func)
212
- # register callbacks
213
- for callback in self.callbacks_to_register:
214
- app.callback()(callback)
215
- # add subgroups
216
- for subapp in self.subapps_to_register:
217
- app.add_typer(subapp.create_instance())
218
- return app
219
-
220
- def command(self, *args, **kwargs):
221
- def decorator(command):
222
- self.commands_to_register.append(
223
- SnowTyperCommandData(command, args=args, kwargs=kwargs)
224
- )
225
- return command
226
-
227
- return decorator
228
-
229
- def add_typer(self, snow_typer: SnowTyperFactory) -> None:
230
- self.subapps_to_register.append(snow_typer)
231
-
232
- def callback(self):
233
- def decorator(callback):
234
- self.callbacks_to_register.append(callback)
235
- return callback
236
-
237
- return decorator
@@ -1,26 +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 typing import Callable
16
-
17
- from snowflake.cli.api.cli_global_context import cli_context_manager
18
-
19
-
20
- def register_pre_execute_command(command: Callable[[], None]) -> None:
21
- cli_context_manager.add_typer_pre_execute_commands(command)
22
-
23
-
24
- def run_pre_execute_commands() -> None:
25
- for command in cli_context_manager.typer_pre_execute_commands:
26
- command()
@@ -1,348 +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 logging
18
- import os
19
- import warnings
20
- from contextlib import contextmanager
21
- from dataclasses import asdict, dataclass, field
22
- from pathlib import Path
23
- from typing import Any, Dict, Optional, Union
24
-
25
- import tomlkit
26
- from click import ClickException
27
- from snowflake.cli.api.exceptions import (
28
- ConfigFileTooWidePermissionsError,
29
- MissingConfiguration,
30
- UnsupportedConfigSectionTypeError,
31
- )
32
- from snowflake.cli.api.secure_path import SecurePath
33
- from snowflake.cli.api.secure_utils import file_permissions_are_strict
34
- from snowflake.cli.api.utils.types import try_cast_to_bool
35
- from snowflake.connector.compat import IS_WINDOWS
36
- from snowflake.connector.config_manager import CONFIG_MANAGER
37
- from snowflake.connector.constants import CONFIG_FILE, CONNECTIONS_FILE
38
- from snowflake.connector.errors import ConfigSourceError, MissingConfigOptionError
39
- from tomlkit import TOMLDocument, dump
40
- from tomlkit.container import Container
41
- from tomlkit.exceptions import NonExistentKey
42
- from tomlkit.items import Table
43
-
44
- log = logging.getLogger(__name__)
45
-
46
-
47
- class Empty:
48
- pass
49
-
50
-
51
- CONNECTIONS_SECTION = "connections"
52
- CLI_SECTION = "cli"
53
- LOGS_SECTION = "logs"
54
- PLUGINS_SECTION = "plugins"
55
-
56
- LOGS_SECTION_PATH = [CLI_SECTION, LOGS_SECTION]
57
- PLUGINS_SECTION_PATH = [CLI_SECTION, PLUGINS_SECTION]
58
- FEATURE_FLAGS_SECTION_PATH = [CLI_SECTION, "features"]
59
-
60
- CONFIG_MANAGER.add_option(
61
- name=CLI_SECTION,
62
- parse_str=tomlkit.parse,
63
- default=dict(),
64
- )
65
-
66
-
67
- @dataclass
68
- class ConnectionConfig:
69
- account: Optional[str] = None
70
- user: Optional[str] = None
71
- password: Optional[str] = field(default=None, repr=False)
72
- host: Optional[str] = None
73
- region: Optional[str] = None
74
- port: Optional[int] = None
75
- database: Optional[str] = None
76
- schema: Optional[str] = None
77
- warehouse: Optional[str] = None
78
- role: Optional[str] = None
79
- authenticator: Optional[str] = None
80
- private_key_path: Optional[str] = None
81
- token_file_path: Optional[str] = None
82
-
83
- _other_settings: dict = field(default_factory=lambda: {})
84
-
85
- @classmethod
86
- def from_dict(cls, config_dict: dict) -> ConnectionConfig:
87
- known_settings = {}
88
- other_settings = {}
89
- for key, value in config_dict.items():
90
- if key in cls.__dict__:
91
- known_settings[key] = value
92
- else:
93
- other_settings[key] = value
94
- return cls(**known_settings, _other_settings=other_settings)
95
-
96
- def to_dict_of_known_non_empty_values(self) -> dict:
97
- return {
98
- k: v
99
- for k, v in asdict(self).items()
100
- if k != "_other_settings" and v is not None
101
- }
102
-
103
- def _non_empty_other_values(self) -> dict:
104
- return {k: v for k, v in self._other_settings.items() if v is not None}
105
-
106
- def to_dict_of_all_non_empty_values(self) -> dict:
107
- return {
108
- **self.to_dict_of_known_non_empty_values(),
109
- **self._non_empty_other_values(),
110
- }
111
-
112
-
113
- def config_init(config_file: Optional[Path]):
114
- """
115
- Initializes the app configuration. Config provided via cli flag takes precedence.
116
- If config file does not exist we create an empty one.
117
- """
118
- from snowflake.cli.app.loggers import create_initial_loggers
119
-
120
- if config_file:
121
- CONFIG_MANAGER.file_path = config_file
122
- else:
123
- _check_default_config_files_permissions()
124
- if not CONFIG_MANAGER.file_path.exists():
125
- _initialise_config(CONFIG_MANAGER.file_path)
126
- _read_config_file()
127
- create_initial_loggers()
128
-
129
-
130
- def add_connection(name: str, connection_config: ConnectionConfig):
131
- set_config_value(
132
- section=CONNECTIONS_SECTION,
133
- key=name,
134
- value=connection_config.to_dict_of_all_non_empty_values(),
135
- )
136
-
137
-
138
- _DEFAULT_LOGS_CONFIG = {
139
- "save_logs": True,
140
- "path": str(CONFIG_MANAGER.file_path.parent / "logs"),
141
- "level": "info",
142
- }
143
-
144
- _DEFAULT_CLI_CONFIG = {LOGS_SECTION: _DEFAULT_LOGS_CONFIG}
145
-
146
-
147
- @contextmanager
148
- def _config_file():
149
- _read_config_file()
150
- conf_file_cache = CONFIG_MANAGER.conf_file_cache
151
- yield conf_file_cache
152
- _dump_config(conf_file_cache)
153
-
154
-
155
- def _read_config_file():
156
- with warnings.catch_warnings():
157
- if IS_WINDOWS:
158
- warnings.filterwarnings(
159
- action="ignore",
160
- message="Bad owner or permissions.*",
161
- module="snowflake.connector.config_manager",
162
- )
163
- try:
164
- CONFIG_MANAGER.read_config()
165
- except ConfigSourceError as exception:
166
- raise ClickException(
167
- f"Configuration file seems to be corrupted. {str(exception.__cause__)}"
168
- )
169
-
170
-
171
- def _initialise_logs_section():
172
- with _config_file() as conf_file_cache:
173
- if conf_file_cache.get(CLI_SECTION) is None:
174
- conf_file_cache[CLI_SECTION] = _DEFAULT_CLI_CONFIG
175
- if conf_file_cache[CLI_SECTION].get(LOGS_SECTION) is None:
176
- conf_file_cache[CLI_SECTION][LOGS_SECTION] = _DEFAULT_LOGS_CONFIG
177
-
178
-
179
- def set_config_value(section: str | None, key: str, value: Any):
180
- with _config_file() as conf_file_cache:
181
- if section:
182
- if conf_file_cache.get(section) is None:
183
- conf_file_cache[section] = {}
184
- conf_file_cache[section][key] = value
185
- else:
186
- conf_file_cache[key] = value
187
-
188
-
189
- def get_logs_config() -> dict:
190
- logs_config = _DEFAULT_LOGS_CONFIG.copy()
191
- if config_section_exists(*LOGS_SECTION_PATH):
192
- logs_config.update(**get_config_section(*LOGS_SECTION_PATH))
193
- return logs_config
194
-
195
-
196
- def get_plugins_config() -> dict:
197
- if config_section_exists(*PLUGINS_SECTION_PATH):
198
- return get_config_section(*PLUGINS_SECTION_PATH)
199
- else:
200
- return {}
201
-
202
-
203
- def connection_exists(connection_name: str) -> bool:
204
- return config_section_exists(CONNECTIONS_SECTION, connection_name)
205
-
206
-
207
- def config_section_exists(*path) -> bool:
208
- try:
209
- _find_section(*path)
210
- return True
211
- except (KeyError, NonExistentKey, MissingConfigOptionError):
212
- return False
213
-
214
-
215
- def get_all_connections() -> dict[str, ConnectionConfig]:
216
- return {
217
- k: ConnectionConfig.from_dict(connection_dict)
218
- for k, connection_dict in get_config_section("connections").items()
219
- }
220
-
221
-
222
- def get_connection_dict(connection_name: str) -> dict:
223
- try:
224
- return get_config_section(CONNECTIONS_SECTION, connection_name)
225
- except KeyError:
226
- raise MissingConfiguration(f"Connection {connection_name} is not configured")
227
-
228
-
229
- def get_default_connection_name() -> str:
230
- return CONFIG_MANAGER["default_connection_name"]
231
-
232
-
233
- def get_default_connection_dict() -> dict:
234
- def_connection_name = get_default_connection_name()
235
- if not connection_exists(def_connection_name):
236
- raise MissingConfiguration(
237
- f"Couldn't find connection for default connection `{def_connection_name}`. "
238
- f"Specify connection name or configure default connection."
239
- )
240
- return get_connection_dict(def_connection_name)
241
-
242
-
243
- def get_config_section(*path) -> dict:
244
- section = _find_section(*path)
245
- if isinstance(section, Container):
246
- return {s: _merge_section_with_env(section[s], *path, s) for s in section}
247
- if isinstance(section, dict):
248
- return _merge_section_with_env(section, *path)
249
- raise UnsupportedConfigSectionTypeError(type(section))
250
-
251
-
252
- def get_config_value(*path, key: str, default: Optional[Any] = Empty) -> Any:
253
- """Looks for given key under nested path in toml file."""
254
- env_variable = get_env_value(*path, key=key)
255
- if env_variable:
256
- return env_variable
257
- try:
258
- return get_config_section(*path)[key]
259
- except (KeyError, NonExistentKey, MissingConfigOptionError):
260
- if default is not Empty:
261
- return default
262
- raise
263
-
264
-
265
- def get_config_bool_value(*path, key: str, default: Optional[Any] = Empty) -> bool:
266
- value = get_config_value(*path, key=key, default=default)
267
- try:
268
- return try_cast_to_bool(value)
269
- except ValueError:
270
- raise ClickException(
271
- f"Expected boolean value for {'.'.join((*path, key))} option."
272
- )
273
-
274
-
275
- def _initialise_config(config_file: Path) -> None:
276
- config_file = SecurePath(config_file)
277
- config_file.parent.mkdir(parents=True, exist_ok=True)
278
- config_file.touch()
279
- _initialise_logs_section()
280
- log.info("Created Snowflake configuration file at %s", CONFIG_MANAGER.file_path)
281
-
282
-
283
- def get_env_variable_name(*path, key: str) -> str:
284
- return "SNOWFLAKE_" + "_".join(p.upper() for p in path) + f"_{key.upper()}"
285
-
286
-
287
- def get_env_value(*path, key: str) -> str | None:
288
- return os.environ.get(get_env_variable_name(*path, key=key))
289
-
290
-
291
- def _find_section(*path) -> TOMLDocument:
292
- section = CONFIG_MANAGER
293
- idx = 0
294
- while idx < len(path):
295
- section = section[path[idx]]
296
- idx += 1
297
- return section
298
-
299
-
300
- def _merge_section_with_env(section: Union[Table, Any], *path) -> Dict[str, str]:
301
- if isinstance(section, Table):
302
- env_variables = _get_envs_for_path(*path)
303
- section_copy = section.copy()
304
- section_copy.update(env_variables)
305
- return section_copy.unwrap()
306
- # It's a atomic value
307
- return section
308
-
309
-
310
- def _get_envs_for_path(*path) -> dict:
311
- env_variables_prefix = "_".join(["SNOWFLAKE"] + [p.upper() for p in path]) + "_"
312
- return {
313
- k.replace(env_variables_prefix, "").lower(): os.environ[k]
314
- for k in os.environ.keys()
315
- if k.startswith(env_variables_prefix)
316
- }
317
-
318
-
319
- def _dump_config(conf_file_cache: Dict):
320
- with SecurePath(CONFIG_MANAGER.file_path).open("w+") as fh:
321
- dump(conf_file_cache, fh)
322
-
323
-
324
- def _check_default_config_files_permissions() -> None:
325
- if IS_WINDOWS:
326
- return
327
- if CONNECTIONS_FILE.exists() and not file_permissions_are_strict(CONNECTIONS_FILE):
328
- raise ConfigFileTooWidePermissionsError(CONNECTIONS_FILE)
329
- if CONFIG_FILE.exists() and not file_permissions_are_strict(CONFIG_FILE):
330
- raise ConfigFileTooWidePermissionsError(CONFIG_FILE)
331
-
332
-
333
- from typing import Literal
334
-
335
-
336
- def get_feature_flags_section() -> Dict[str, bool | Literal["UNKNOWN"]]:
337
- if not config_section_exists(*FEATURE_FLAGS_SECTION_PATH):
338
- return {}
339
-
340
- flags = get_config_section(*FEATURE_FLAGS_SECTION_PATH)
341
-
342
- def _bool_or_unknown(value):
343
- try:
344
- return try_cast_to_bool(value)
345
- except ValueError:
346
- return "UNKNOWN"
347
-
348
- return {k: _bool_or_unknown(v) for k, v in flags.items()}
@@ -1,17 +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 snowflake.cli.api.console.console import cli_console
16
-
17
- __all__ = ("cli_console",)