snowflake-cli 2.8.2__py3-none-any.whl → 3.0.1__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 (251) hide show
  1. snowflake/cli/__about__.py +1 -1
  2. snowflake/cli/{app → _app}/__main__.py +1 -1
  3. snowflake/cli/{app → _app}/cli_app.py +22 -13
  4. snowflake/cli/{app → _app}/commands_registration/builtin_plugins.py +15 -19
  5. snowflake/cli/{app → _app}/commands_registration/command_plugins_loader.py +9 -9
  6. snowflake/cli/{app → _app}/commands_registration/commands_registration_with_callbacks.py +4 -4
  7. snowflake/cli/{app → _app}/commands_registration/exception_logging.py +2 -2
  8. snowflake/cli/{app → _app}/commands_registration/typer_registration.py +2 -2
  9. snowflake/cli/{app → _app}/dev/docs/commands_docs_generator.py +30 -12
  10. snowflake/cli/{app → _app}/dev/docs/generator.py +3 -3
  11. snowflake/cli/{app → _app}/dev/docs/project_definition_docs_generator.py +4 -4
  12. snowflake/cli/{app → _app}/dev/docs/templates/usage.rst.jinja2 +14 -4
  13. snowflake/cli/{app → _app}/main_typer.py +2 -2
  14. snowflake/cli/{app → _app}/printing.py +2 -2
  15. snowflake/cli/_app/secret.py +9 -0
  16. snowflake/cli/{app → _app}/snow_connector.py +127 -61
  17. snowflake/cli/{app → _app}/telemetry.py +38 -7
  18. snowflake/cli/_app/version_check.py +74 -0
  19. snowflake/cli/{plugins → _plugins}/connection/commands.py +34 -11
  20. snowflake/cli/_plugins/connection/plugin_spec.py +30 -0
  21. snowflake/cli/{plugins → _plugins}/connection/util.py +16 -0
  22. snowflake/cli/{plugins → _plugins}/cortex/commands.py +54 -49
  23. snowflake/cli/{plugins → _plugins}/cortex/constants.py +1 -1
  24. snowflake/cli/{plugins → _plugins}/cortex/manager.py +5 -5
  25. snowflake/cli/{plugins → _plugins}/cortex/plugin_spec.py +1 -1
  26. snowflake/cli/{plugins → _plugins}/git/commands.py +11 -7
  27. snowflake/cli/{plugins → _plugins}/git/manager.py +55 -9
  28. snowflake/cli/{plugins → _plugins}/git/plugin_spec.py +1 -1
  29. snowflake/cli/_plugins/helpers/commands.py +90 -0
  30. snowflake/cli/{plugins/notebook → _plugins/helpers}/plugin_spec.py +1 -1
  31. snowflake/cli/{plugins → _plugins}/init/commands.py +2 -2
  32. snowflake/cli/{plugins → _plugins}/init/plugin_spec.py +1 -1
  33. snowflake/cli/{plugins → _plugins}/nativeapp/artifacts.py +24 -9
  34. snowflake/cli/_plugins/nativeapp/bundle_context.py +31 -0
  35. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/artifact_processor.py +4 -4
  36. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/compiler.py +37 -18
  37. snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +249 -0
  38. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/setup/setup_driver.py.source +5 -2
  39. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/extension_function_utils.py +5 -5
  40. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/models.py +1 -1
  41. snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/python_processor.py +29 -34
  42. snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +114 -0
  43. snowflake/cli/{plugins → _plugins}/nativeapp/commands.py +252 -132
  44. snowflake/cli/{plugins → _plugins}/nativeapp/common_flags.py +1 -1
  45. snowflake/cli/_plugins/nativeapp/entities/application.py +878 -0
  46. snowflake/cli/_plugins/nativeapp/entities/application_package.py +1392 -0
  47. snowflake/cli/{plugins → _plugins}/nativeapp/exceptions.py +3 -12
  48. snowflake/cli/_plugins/nativeapp/manager.py +415 -0
  49. snowflake/cli/{plugins/connection → _plugins/nativeapp}/plugin_spec.py +1 -1
  50. snowflake/cli/{plugins → _plugins}/nativeapp/policy.py +3 -0
  51. snowflake/cli/{plugins → _plugins}/nativeapp/project_model.py +36 -20
  52. snowflake/cli/_plugins/nativeapp/run_processor.py +184 -0
  53. snowflake/cli/_plugins/nativeapp/same_account_install_method.py +70 -0
  54. snowflake/cli/_plugins/nativeapp/teardown_processor.py +70 -0
  55. snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +262 -0
  56. snowflake/cli/{plugins → _plugins}/nativeapp/version/commands.py +20 -49
  57. snowflake/cli/_plugins/nativeapp/version/version_processor.py +98 -0
  58. snowflake/cli/{plugins → _plugins}/notebook/commands.py +3 -2
  59. snowflake/cli/{plugins → _plugins}/notebook/manager.py +5 -5
  60. snowflake/cli/{plugins/nativeapp → _plugins/notebook}/plugin_spec.py +1 -1
  61. snowflake/cli/{plugins → _plugins}/object/command_aliases.py +4 -4
  62. snowflake/cli/{plugins → _plugins}/object/commands.py +4 -5
  63. snowflake/cli/{plugins → _plugins}/object/manager.py +36 -15
  64. snowflake/cli/{plugins → _plugins}/object/plugin_spec.py +1 -1
  65. snowflake/cli/_plugins/snowpark/commands.py +450 -0
  66. snowflake/cli/_plugins/snowpark/common.py +268 -0
  67. snowflake/cli/{plugins → _plugins}/snowpark/models.py +0 -7
  68. snowflake/cli/{plugins → _plugins}/snowpark/package/anaconda_packages.py +2 -36
  69. snowflake/cli/{plugins → _plugins}/snowpark/package/commands.py +13 -74
  70. snowflake/cli/{plugins → _plugins}/snowpark/package/manager.py +2 -2
  71. snowflake/cli/{plugins → _plugins}/snowpark/package_utils.py +5 -5
  72. snowflake/cli/_plugins/snowpark/plugin_spec.py +30 -0
  73. snowflake/cli/_plugins/snowpark/snowpark_entity.py +29 -0
  74. snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +173 -0
  75. snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +109 -0
  76. snowflake/cli/{plugins → _plugins}/snowpark/snowpark_shared.py +0 -36
  77. snowflake/cli/{plugins → _plugins}/snowpark/zipper.py +16 -8
  78. snowflake/cli/{plugins → _plugins}/spcs/__init__.py +5 -7
  79. snowflake/cli/{plugins → _plugins}/spcs/compute_pool/commands.py +8 -8
  80. snowflake/cli/{plugins → _plugins}/spcs/compute_pool/manager.py +3 -3
  81. snowflake/cli/{plugins → _plugins}/spcs/image_registry/commands.py +3 -3
  82. snowflake/cli/{plugins → _plugins}/spcs/image_repository/commands.py +6 -6
  83. snowflake/cli/{plugins → _plugins}/spcs/image_repository/manager.py +1 -1
  84. snowflake/cli/{plugins → _plugins}/spcs/plugin_spec.py +1 -1
  85. snowflake/cli/{plugins → _plugins}/spcs/services/commands.py +44 -11
  86. snowflake/cli/{plugins → _plugins}/spcs/services/manager.py +43 -5
  87. snowflake/cli/{plugins → _plugins}/sql/commands.py +20 -17
  88. snowflake/cli/{plugins → _plugins}/sql/manager.py +1 -1
  89. snowflake/cli/{plugins → _plugins}/sql/plugin_spec.py +1 -1
  90. snowflake/cli/{plugins → _plugins}/stage/commands.py +15 -14
  91. snowflake/cli/{plugins → _plugins}/stage/diff.py +1 -47
  92. snowflake/cli/{plugins → _plugins}/stage/manager.py +12 -7
  93. snowflake/cli/{plugins → _plugins}/stage/plugin_spec.py +1 -1
  94. snowflake/cli/_plugins/stage/utils.py +54 -0
  95. snowflake/cli/{plugins → _plugins}/streamlit/commands.py +64 -48
  96. snowflake/cli/{plugins → _plugins}/streamlit/manager.py +67 -69
  97. snowflake/cli/_plugins/streamlit/plugin_spec.py +30 -0
  98. snowflake/cli/_plugins/streamlit/streamlit_entity.py +12 -0
  99. snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +66 -0
  100. snowflake/cli/_plugins/workspace/action_context.py +18 -0
  101. snowflake/cli/_plugins/workspace/commands.py +306 -0
  102. snowflake/cli/_plugins/workspace/manager.py +74 -0
  103. snowflake/cli/_plugins/workspace/plugin_spec.py +30 -0
  104. snowflake/cli/api/cli_global_context.py +152 -295
  105. snowflake/cli/api/commands/common.py +25 -0
  106. snowflake/cli/api/commands/decorators.py +19 -4
  107. snowflake/cli/api/commands/experimental_behaviour.py +2 -3
  108. snowflake/cli/api/commands/flags.py +127 -228
  109. snowflake/cli/api/commands/overrideable_parameter.py +143 -0
  110. snowflake/cli/api/commands/snow_typer.py +21 -11
  111. snowflake/cli/api/commands/utils.py +18 -0
  112. snowflake/cli/api/config.py +44 -12
  113. snowflake/cli/api/connections.py +216 -0
  114. snowflake/cli/api/console/abc.py +8 -3
  115. snowflake/cli/api/constants.py +11 -0
  116. snowflake/cli/api/entities/common.py +56 -0
  117. snowflake/cli/api/entities/utils.py +370 -0
  118. snowflake/cli/api/errno.py +1 -0
  119. snowflake/cli/api/exceptions.py +31 -5
  120. snowflake/cli/api/feature_flags.py +0 -1
  121. snowflake/cli/api/identifiers.py +28 -5
  122. snowflake/cli/api/metrics.py +92 -0
  123. snowflake/cli/api/project/definition.py +48 -6
  124. snowflake/cli/api/project/definition_conversion.py +400 -0
  125. snowflake/cli/api/project/definition_manager.py +16 -5
  126. snowflake/cli/api/project/project_verification.py +3 -3
  127. snowflake/cli/api/project/schemas/entities/common.py +91 -16
  128. snowflake/cli/api/project/schemas/entities/entities.py +37 -6
  129. snowflake/cli/api/project/schemas/project_definition.py +180 -49
  130. snowflake/cli/api/project/schemas/updatable_model.py +11 -3
  131. snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
  132. snowflake/cli/api/project/schemas/{identifier_model.py → v1/identifier_model.py} +3 -1
  133. snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
  134. snowflake/cli/api/project/schemas/{native_app → v1/native_app}/application.py +8 -9
  135. snowflake/cli/api/project/schemas/{native_app → v1/native_app}/native_app.py +4 -4
  136. snowflake/cli/api/project/schemas/{native_app → v1/native_app}/package.py +7 -1
  137. snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
  138. snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/callable.py +2 -2
  139. snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/snowpark.py +2 -2
  140. snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
  141. snowflake/cli/api/project/schemas/{streamlit → v1/streamlit}/streamlit.py +2 -1
  142. snowflake/cli/api/project/util.py +23 -6
  143. snowflake/cli/api/rendering/jinja.py +14 -8
  144. snowflake/cli/api/rendering/project_definition_templates.py +5 -1
  145. snowflake/cli/api/rendering/sql_templates.py +56 -11
  146. snowflake/cli/api/rest_api.py +11 -5
  147. snowflake/cli/api/secure_path.py +16 -18
  148. snowflake/cli/api/secure_utils.py +90 -1
  149. snowflake/cli/api/sql_execution.py +43 -23
  150. snowflake/cli/api/utils/definition_rendering.py +45 -13
  151. {snowflake_cli-2.8.2.dist-info → snowflake_cli-3.0.1.dist-info}/METADATA +18 -18
  152. snowflake_cli-3.0.1.dist-info/RECORD +242 -0
  153. snowflake_cli-3.0.1.dist-info/entry_points.txt +2 -0
  154. snowflake/cli/api/commands/project_initialisation.py +0 -65
  155. snowflake/cli/api/commands/typer_pre_execute.py +0 -26
  156. snowflake/cli/api/project/schemas/entities/application_entity.py +0 -44
  157. snowflake/cli/api/project/schemas/entities/application_package_entity.py +0 -66
  158. snowflake/cli/app/build_and_push.sh +0 -8
  159. snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -172
  160. snowflake/cli/plugins/nativeapp/init.py +0 -345
  161. snowflake/cli/plugins/nativeapp/manager.py +0 -823
  162. snowflake/cli/plugins/nativeapp/run_processor.py +0 -389
  163. snowflake/cli/plugins/nativeapp/teardown_processor.py +0 -301
  164. snowflake/cli/plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -135
  165. snowflake/cli/plugins/nativeapp/version/version_processor.py +0 -362
  166. snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
  167. snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
  168. snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
  169. snowflake/cli/plugins/snowpark/commands.py +0 -546
  170. snowflake/cli/plugins/snowpark/common.py +0 -307
  171. snowflake/cli/plugins/snowpark/manager.py +0 -109
  172. snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
  173. snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
  174. snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
  175. snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
  176. snowflake/cli/plugins/streamlit/__init__.py +0 -13
  177. snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
  178. snowflake/cli/plugins/workspace/__init__.py +0 -13
  179. snowflake/cli/plugins/workspace/commands.py +0 -35
  180. snowflake/cli/plugins/workspace/plugin_spec.py +0 -30
  181. snowflake/cli/templates/default_snowpark/.gitignore +0 -4
  182. snowflake/cli/templates/default_snowpark/app/common.py +0 -2
  183. snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
  184. snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
  185. snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
  186. snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
  187. snowflake/cli/templates/default_streamlit/.gitignore +0 -4
  188. snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
  189. snowflake/cli/templates/default_streamlit/environment.yml +0 -6
  190. snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
  191. snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
  192. snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
  193. snowflake_cli-2.8.2.dist-info/RECORD +0 -240
  194. snowflake_cli-2.8.2.dist-info/entry_points.txt +0 -2
  195. /snowflake/cli/{app → _app}/__init__.py +0 -0
  196. /snowflake/cli/{api/project/schemas/native_app → _app/api_impl}/__init__.py +0 -0
  197. /snowflake/cli/{api/project/schemas/snowpark → _app/api_impl/plugin}/__init__.py +0 -0
  198. /snowflake/cli/{app → _app}/api_impl/plugin/plugin_config_provider_impl.py +0 -0
  199. /snowflake/cli/{app → _app}/commands_registration/__init__.py +0 -0
  200. /snowflake/cli/{app → _app}/commands_registration/threadsafe.py +0 -0
  201. /snowflake/cli/{app → _app}/constants.py +0 -0
  202. /snowflake/cli/{api/project/schemas/streamlit → _app/dev}/__init__.py +0 -0
  203. /snowflake/cli/{app → _app}/dev/commands_structure.py +0 -0
  204. /snowflake/cli/{app/api_impl → _app/dev/docs}/__init__.py +0 -0
  205. /snowflake/cli/{app → _app}/dev/docs/project_definition_generate_json_schema.py +0 -0
  206. /snowflake/cli/{app → _app}/dev/docs/template_utils.py +0 -0
  207. /snowflake/cli/{app → _app}/dev/docs/templates/definition_description.rst.jinja2 +0 -0
  208. /snowflake/cli/{app → _app}/dev/docs/templates/overview.rst.jinja2 +0 -0
  209. /snowflake/cli/{app → _app}/dev/pycharm_remote_debug.py +0 -0
  210. /snowflake/cli/{app → _app}/loggers.py +0 -0
  211. /snowflake/cli/{app/api_impl/plugin → _plugins}/__init__.py +0 -0
  212. /snowflake/cli/{app/dev → _plugins/connection}/__init__.py +0 -0
  213. /snowflake/cli/{app/dev/docs → _plugins/cortex}/__init__.py +0 -0
  214. /snowflake/cli/{plugins → _plugins}/cortex/types.py +0 -0
  215. /snowflake/cli/{plugins → _plugins/git}/__init__.py +0 -0
  216. /snowflake/cli/{plugins/connection → _plugins/helpers}/__init__.py +0 -0
  217. /snowflake/cli/{plugins/cortex → _plugins/init}/__init__.py +0 -0
  218. /snowflake/cli/{plugins/git → _plugins/nativeapp}/__init__.py +0 -0
  219. /snowflake/cli/{plugins/init → _plugins/nativeapp/codegen}/__init__.py +0 -0
  220. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/sandbox.py +0 -0
  221. /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -0
  222. /snowflake/cli/{plugins → _plugins}/nativeapp/constants.py +0 -0
  223. /snowflake/cli/{templates/default_snowpark/app → _plugins/nativeapp/entities}/__init__.py +0 -0
  224. /snowflake/cli/{plugins → _plugins}/nativeapp/feature_flags.py +0 -0
  225. /snowflake/cli/{plugins → _plugins}/nativeapp/utils.py +0 -0
  226. /snowflake/cli/{plugins/nativeapp → _plugins/nativeapp/version}/__init__.py +0 -0
  227. /snowflake/cli/{plugins/nativeapp/codegen → _plugins/notebook}/__init__.py +0 -0
  228. /snowflake/cli/{plugins → _plugins}/notebook/exceptions.py +0 -0
  229. /snowflake/cli/{plugins → _plugins}/notebook/types.py +0 -0
  230. /snowflake/cli/{plugins/nativeapp/version → _plugins/object}/__init__.py +0 -0
  231. /snowflake/cli/{plugins → _plugins}/object/common.py +0 -0
  232. /snowflake/cli/{plugins/notebook → _plugins/snowpark}/__init__.py +0 -0
  233. /snowflake/cli/{plugins/object → _plugins/snowpark/package}/__init__.py +0 -0
  234. /snowflake/cli/{plugins → _plugins}/snowpark/package/utils.py +0 -0
  235. /snowflake/cli/{plugins → _plugins}/spcs/common.py +0 -0
  236. /snowflake/cli/{plugins/snowpark → _plugins/spcs/compute_pool}/__init__.py +0 -0
  237. /snowflake/cli/{plugins/snowpark/package → _plugins/spcs/image_registry}/__init__.py +0 -0
  238. /snowflake/cli/{plugins → _plugins}/spcs/image_registry/manager.py +0 -0
  239. /snowflake/cli/{plugins/spcs/compute_pool → _plugins/spcs/image_repository}/__init__.py +0 -0
  240. /snowflake/cli/{plugins/spcs/image_registry → _plugins/spcs/services}/__init__.py +0 -0
  241. /snowflake/cli/{plugins/spcs/image_repository → _plugins/sql}/__init__.py +0 -0
  242. /snowflake/cli/{plugins → _plugins}/sql/snowsql_templating.py +0 -0
  243. /snowflake/cli/{plugins/spcs/jobs → _plugins/stage}/__init__.py +0 -0
  244. /snowflake/cli/{plugins → _plugins}/stage/md5.py +0 -0
  245. /snowflake/cli/{plugins/spcs/services → _plugins/streamlit}/__init__.py +0 -0
  246. /snowflake/cli/{plugins/sql → _plugins/workspace}/__init__.py +0 -0
  247. /snowflake/cli/{plugins/stage → api/project/schemas/entities}/__init__.py +0 -0
  248. /snowflake/cli/api/project/schemas/{native_app → v1/native_app}/path_mapping.py +0 -0
  249. /snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/argument.py +0 -0
  250. {snowflake_cli-2.8.2.dist-info → snowflake_cli-3.0.1.dist-info}/WHEEL +0 -0
  251. {snowflake_cli-2.8.2.dist-info → snowflake_cli-3.0.1.dist-info}/licenses/LICENSE +0 -0
@@ -48,15 +48,6 @@ class ApplicationCreatedExternallyError(ClickException):
48
48
  )
49
49
 
50
50
 
51
- class UnexpectedOwnerError(ClickException):
52
- """An operation is blocked because an object is owned by an unexpected role."""
53
-
54
- def __init__(self, item: str, expected_owner: str, actual_owner: str):
55
- super().__init__(
56
- f"Cannot operate on {item}: owned by {actual_owner} (expected {expected_owner})"
57
- )
58
-
59
-
60
51
  class MissingScriptError(ClickException):
61
52
  """A referenced script was not found."""
62
53
 
@@ -64,15 +55,15 @@ class MissingScriptError(ClickException):
64
55
  super().__init__(f'Script "{relpath}" does not exist')
65
56
 
66
57
 
67
- class InvalidScriptError(ClickException):
68
- """A referenced script had syntax error(s)."""
58
+ class InvalidTemplateInFileError(ClickException):
59
+ """A referenced templated file had syntax error(s)."""
69
60
 
70
61
  def __init__(
71
62
  self, relpath: str, err: jinja2.TemplateError, lineno: Optional[int] = None
72
63
  ):
73
64
  lineno_str = f":{lineno}" if lineno is not None else ""
74
65
  super().__init__(
75
- f'Script "{relpath}{lineno_str}" does not contain a valid template: {err.message}'
66
+ f'File "{relpath}{lineno_str}" does not contain a valid template: {err.message}'
76
67
  )
77
68
  self.err = err
78
69
 
@@ -0,0 +1,415 @@
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
+ from abc import ABC, abstractmethod
18
+ from datetime import datetime
19
+ from functools import cached_property
20
+ from pathlib import Path
21
+ from typing import Generator, List, Optional
22
+
23
+ from snowflake.cli._plugins.nativeapp.artifacts import (
24
+ BundleMap,
25
+ )
26
+ from snowflake.cli._plugins.nativeapp.entities.application import (
27
+ ApplicationEntity,
28
+ ApplicationOwnedObject,
29
+ )
30
+ from snowflake.cli._plugins.nativeapp.entities.application_package import (
31
+ ApplicationPackageEntity,
32
+ )
33
+ from snowflake.cli._plugins.nativeapp.policy import AllowAlwaysPolicy, PolicyBase
34
+ from snowflake.cli._plugins.nativeapp.project_model import (
35
+ NativeAppProjectModel,
36
+ )
37
+ from snowflake.cli._plugins.stage.diff import (
38
+ DiffResult,
39
+ )
40
+ from snowflake.cli.api.console import cli_console as cc
41
+ from snowflake.cli.api.entities.utils import (
42
+ execute_post_deploy_hooks,
43
+ sync_deploy_root_with_stage,
44
+ )
45
+ from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
46
+ from snowflake.cli.api.project.schemas.v1.native_app.native_app import NativeApp
47
+ from snowflake.cli.api.project.schemas.v1.native_app.path_mapping import PathMapping
48
+
49
+
50
+ class NativeAppCommandProcessor(ABC):
51
+ @abstractmethod
52
+ def process(self, *args, **kwargs):
53
+ pass
54
+
55
+
56
+ class NativeAppManager:
57
+ """
58
+ Base class with frequently used functionality already implemented and ready to be used by related subclasses.
59
+ """
60
+
61
+ def __init__(self, project_definition: NativeApp, project_root: Path):
62
+ super().__init__()
63
+ self._na_project = NativeAppProjectModel(
64
+ project_definition=project_definition,
65
+ project_root=project_root,
66
+ )
67
+
68
+ @property
69
+ def na_project(self) -> NativeAppProjectModel:
70
+ return self._na_project
71
+
72
+ @property
73
+ def project_root(self) -> Path:
74
+ return self.na_project.project_root
75
+
76
+ @property
77
+ def definition(self) -> NativeApp:
78
+ return self.na_project.definition
79
+
80
+ @property
81
+ def artifacts(self) -> List[PathMapping]:
82
+ return self.na_project.artifacts
83
+
84
+ @property
85
+ def bundle_root(self) -> Path:
86
+ return self.na_project.bundle_root
87
+
88
+ @property
89
+ def deploy_root(self) -> Path:
90
+ return self.na_project.deploy_root
91
+
92
+ @property
93
+ def generated_root(self) -> Path:
94
+ return self.na_project.generated_root
95
+
96
+ @property
97
+ def package_scripts(self) -> List[str]:
98
+ return self.na_project.package_scripts
99
+
100
+ @property
101
+ def stage_fqn(self) -> str:
102
+ return self.na_project.stage_fqn
103
+
104
+ @property
105
+ def scratch_stage_fqn(self) -> str:
106
+ return self.na_project.scratch_stage_fqn
107
+
108
+ @property
109
+ def stage_schema(self) -> Optional[str]:
110
+ return self.na_project.stage_schema
111
+
112
+ @property
113
+ def package_warehouse(self) -> Optional[str]:
114
+ return self.na_project.package_warehouse
115
+
116
+ def use_package_warehouse(self):
117
+ return ApplicationPackageEntity.use_package_warehouse(
118
+ self.package_warehouse,
119
+ )
120
+
121
+ @property
122
+ def application_warehouse(self) -> Optional[str]:
123
+ return self.na_project.application_warehouse
124
+
125
+ @property
126
+ def project_identifier(self) -> str:
127
+ return self.na_project.project_identifier
128
+
129
+ @property
130
+ def package_name(self) -> str:
131
+ return self.na_project.package_name
132
+
133
+ @property
134
+ def package_role(self) -> str:
135
+ return self.na_project.package_role
136
+
137
+ @property
138
+ def package_distribution(self) -> str:
139
+ return self.na_project.package_distribution
140
+
141
+ @property
142
+ def app_name(self) -> str:
143
+ return self.na_project.app_name
144
+
145
+ @property
146
+ def app_role(self) -> str:
147
+ return self.na_project.app_role
148
+
149
+ @property
150
+ def app_post_deploy_hooks(self) -> Optional[List[PostDeployHook]]:
151
+ return self.na_project.app_post_deploy_hooks
152
+
153
+ @property
154
+ def package_post_deploy_hooks(self) -> Optional[List[PostDeployHook]]:
155
+ return self.na_project.package_post_deploy_hooks
156
+
157
+ @property
158
+ def debug_mode(self) -> bool:
159
+ return self.na_project.debug_mode
160
+
161
+ @cached_property
162
+ def get_app_pkg_distribution_in_snowflake(self) -> str:
163
+ return ApplicationPackageEntity.get_app_pkg_distribution_in_snowflake(
164
+ self.package_name, self.package_role
165
+ )
166
+
167
+ @cached_property
168
+ def account_event_table(self) -> str:
169
+ return ApplicationEntity.get_account_event_table()
170
+
171
+ def verify_project_distribution(
172
+ self, expected_distribution: Optional[str] = None
173
+ ) -> bool:
174
+ return ApplicationPackageEntity.verify_project_distribution(
175
+ console=cc,
176
+ package_name=self.package_name,
177
+ package_role=self.package_role,
178
+ package_distribution=self.package_distribution,
179
+ expected_distribution=expected_distribution,
180
+ )
181
+
182
+ def build_bundle(self) -> BundleMap:
183
+ """
184
+ Populates the local deploy root from artifact sources.
185
+ """
186
+ return ApplicationPackageEntity.bundle(
187
+ project_root=self.project_root,
188
+ deploy_root=self.deploy_root,
189
+ bundle_root=self.bundle_root,
190
+ generated_root=self.generated_root,
191
+ package_name=self.package_name,
192
+ artifacts=self.artifacts,
193
+ )
194
+
195
+ def sync_deploy_root_with_stage(
196
+ self,
197
+ bundle_map: BundleMap,
198
+ role: str,
199
+ prune: bool,
200
+ recursive: bool,
201
+ stage_fqn: str,
202
+ local_paths_to_sync: List[Path] | None = None,
203
+ print_diff: bool = True,
204
+ ) -> DiffResult:
205
+ return sync_deploy_root_with_stage(
206
+ console=cc,
207
+ deploy_root=self.deploy_root,
208
+ package_name=self.package_name,
209
+ stage_schema=self.stage_schema,
210
+ bundle_map=bundle_map,
211
+ role=role,
212
+ prune=prune,
213
+ recursive=recursive,
214
+ stage_fqn=stage_fqn,
215
+ local_paths_to_sync=local_paths_to_sync,
216
+ print_diff=print_diff,
217
+ )
218
+
219
+ def get_existing_app_info(self) -> Optional[dict]:
220
+ return ApplicationEntity.get_existing_app_info(
221
+ app_name=self.app_name,
222
+ app_role=self.app_role,
223
+ )
224
+
225
+ def get_existing_app_pkg_info(self) -> Optional[dict]:
226
+ return ApplicationPackageEntity.get_existing_app_pkg_info(
227
+ package_name=self.package_name,
228
+ package_role=self.package_role,
229
+ )
230
+
231
+ def get_objects_owned_by_application(self):
232
+ return ApplicationEntity.get_objects_owned_by_application(
233
+ app_name=self.app_name,
234
+ app_role=self.app_role,
235
+ )
236
+
237
+ def _application_objects_to_str(
238
+ self, application_objects: list[ApplicationOwnedObject]
239
+ ) -> str:
240
+ return ApplicationEntity.application_objects_to_str(application_objects)
241
+
242
+ def _application_object_to_str(self, obj: ApplicationOwnedObject):
243
+ return ApplicationEntity.application_object_to_str(obj)
244
+
245
+ def get_snowsight_url(self) -> str:
246
+ """Returns the URL that can be used to visit this app via Snowsight."""
247
+ return ApplicationEntity.get_snowsight_url(
248
+ self.app_name, self.application_warehouse
249
+ )
250
+
251
+ def create_app_package(self) -> None:
252
+ return ApplicationPackageEntity.create_app_package(
253
+ console=cc,
254
+ package_name=self.package_name,
255
+ package_role=self.package_role,
256
+ package_distribution=self.package_distribution,
257
+ )
258
+
259
+ def _apply_package_scripts(self) -> None:
260
+ return ApplicationPackageEntity.apply_package_scripts(
261
+ console=cc,
262
+ package_scripts=self.package_scripts,
263
+ package_warehouse=self.package_warehouse,
264
+ project_root=self.project_root,
265
+ package_role=self.package_role,
266
+ package_name=self.package_name,
267
+ )
268
+
269
+ def execute_package_post_deploy_hooks(self) -> None:
270
+ execute_post_deploy_hooks(
271
+ console=cc,
272
+ project_root=self.project_root,
273
+ post_deploy_hooks=self.package_post_deploy_hooks,
274
+ deployed_object_type="application package",
275
+ database_name=self.package_name,
276
+ )
277
+
278
+ def execute_app_post_deploy_hooks(self) -> None:
279
+ execute_post_deploy_hooks(
280
+ console=cc,
281
+ project_root=self.project_root,
282
+ post_deploy_hooks=self.app_post_deploy_hooks,
283
+ deployed_object_type="application",
284
+ database_name=self.app_name,
285
+ )
286
+
287
+ def deploy(
288
+ self,
289
+ bundle_map: BundleMap,
290
+ prune: bool,
291
+ recursive: bool,
292
+ policy: PolicyBase,
293
+ stage_fqn: Optional[str] = None,
294
+ local_paths_to_sync: List[Path] | None = None,
295
+ validate: bool = True,
296
+ print_diff: bool = True,
297
+ ) -> DiffResult:
298
+ return ApplicationPackageEntity.deploy(
299
+ console=cc,
300
+ project_root=self.project_root,
301
+ deploy_root=self.deploy_root,
302
+ bundle_root=self.bundle_root,
303
+ generated_root=self.generated_root,
304
+ artifacts=self.artifacts,
305
+ bundle_map=bundle_map,
306
+ package_name=self.package_name,
307
+ package_role=self.package_role,
308
+ package_distribution=self.package_distribution,
309
+ prune=prune,
310
+ recursive=recursive,
311
+ paths=local_paths_to_sync,
312
+ print_diff=print_diff,
313
+ validate=validate,
314
+ stage_fqn=stage_fqn or self.stage_fqn,
315
+ package_warehouse=self.package_warehouse,
316
+ post_deploy_hooks=self.package_post_deploy_hooks,
317
+ package_scripts=self.package_scripts,
318
+ policy=policy,
319
+ )
320
+
321
+ def validate(self, use_scratch_stage: bool = False):
322
+ return ApplicationPackageEntity.validate_setup_script(
323
+ console=cc,
324
+ project_root=self.project_root,
325
+ deploy_root=self.deploy_root,
326
+ bundle_root=self.bundle_root,
327
+ generated_root=self.generated_root,
328
+ artifacts=self.artifacts,
329
+ package_name=self.package_name,
330
+ package_role=self.package_role,
331
+ package_distribution=self.package_distribution,
332
+ prune=True,
333
+ recursive=True,
334
+ paths=[],
335
+ stage_fqn=self.stage_fqn,
336
+ package_warehouse=self.package_warehouse,
337
+ post_deploy_hooks=self.package_post_deploy_hooks,
338
+ package_scripts=self.package_scripts,
339
+ policy=AllowAlwaysPolicy(),
340
+ use_scratch_stage=use_scratch_stage,
341
+ scratch_stage_fqn=self.scratch_stage_fqn,
342
+ )
343
+
344
+ def get_validation_result(self, use_scratch_stage: bool = False):
345
+ return ApplicationPackageEntity.get_validation_result(
346
+ console=cc,
347
+ project_root=self.project_root,
348
+ deploy_root=self.deploy_root,
349
+ bundle_root=self.bundle_root,
350
+ generated_root=self.generated_root,
351
+ artifacts=self.artifacts,
352
+ package_name=self.package_name,
353
+ package_role=self.package_role,
354
+ package_distribution=self.package_distribution,
355
+ prune=True,
356
+ recursive=True,
357
+ paths=[],
358
+ stage_fqn=self.stage_fqn,
359
+ package_warehouse=self.package_warehouse,
360
+ post_deploy_hooks=self.package_post_deploy_hooks,
361
+ package_scripts=self.package_scripts,
362
+ policy=AllowAlwaysPolicy(),
363
+ use_scratch_stage=use_scratch_stage,
364
+ scratch_stage_fqn=self.scratch_stage_fqn,
365
+ )
366
+
367
+ def get_events( # type: ignore
368
+ self,
369
+ since: str | datetime | None = None,
370
+ until: str | datetime | None = None,
371
+ record_types: list[str] | None = None,
372
+ scopes: list[str] | None = None,
373
+ consumer_org: str = "",
374
+ consumer_account: str = "",
375
+ consumer_app_hash: str = "",
376
+ first: int = -1,
377
+ last: int = -1,
378
+ ) -> list[dict]:
379
+ return ApplicationEntity.get_events(
380
+ app_name=self.app_name,
381
+ package_name=self.package_name,
382
+ since=since,
383
+ until=until,
384
+ record_types=record_types,
385
+ scopes=scopes,
386
+ consumer_org=consumer_org,
387
+ consumer_account=consumer_account,
388
+ consumer_app_hash=consumer_app_hash,
389
+ first=first,
390
+ last=last,
391
+ )
392
+
393
+ def stream_events(
394
+ self,
395
+ interval_seconds: int,
396
+ since: str | datetime | None = None,
397
+ record_types: list[str] | None = None,
398
+ scopes: list[str] | None = None,
399
+ consumer_org: str = "",
400
+ consumer_account: str = "",
401
+ consumer_app_hash: str = "",
402
+ last: int = -1,
403
+ ) -> Generator[dict, None, None]:
404
+ return ApplicationEntity.stream_events(
405
+ app_name=self.app_name,
406
+ package_name=self.package_name,
407
+ interval_seconds=interval_seconds,
408
+ since=since,
409
+ record_types=record_types,
410
+ scopes=scopes,
411
+ consumer_org=consumer_org,
412
+ consumer_account=consumer_account,
413
+ consumer_app_hash=consumer_app_hash,
414
+ last=last,
415
+ )
@@ -12,13 +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.nativeapp import commands
15
16
  from snowflake.cli.api.plugins.command import (
16
17
  SNOWCLI_ROOT_COMMAND_PATH,
17
18
  CommandSpec,
18
19
  CommandType,
19
20
  plugin_hook_impl,
20
21
  )
21
- from snowflake.cli.plugins.connection import commands
22
22
 
23
23
 
24
24
  @plugin_hook_impl
@@ -27,6 +27,9 @@ class PolicyBase(ABC):
27
27
  def should_proceed(self, user_prompt: Optional[str]) -> bool:
28
28
  pass
29
29
 
30
+ def __eq__(self, value: object) -> bool:
31
+ return self.__class__ == value.__class__
32
+
30
33
 
31
34
  class AllowAlwaysPolicy(PolicyBase):
32
35
  """Always allow a Snowflake CLI command to continue execution."""
@@ -18,27 +18,23 @@ from functools import cached_property
18
18
  from pathlib import Path
19
19
  from typing import List, Optional
20
20
 
21
- from snowflake.cli.api.cli_global_context import cli_context
21
+ from snowflake.cli._plugins.nativeapp.artifacts import resolve_without_follow
22
+ from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext
23
+ from snowflake.cli.api.cli_global_context import get_cli_context
24
+ from snowflake.cli.api.entities.common import get_sql_executor
22
25
  from snowflake.cli.api.project.definition import (
23
26
  default_app_package,
24
27
  default_application,
25
28
  default_role,
26
29
  )
27
- from snowflake.cli.api.project.schemas.native_app.application import (
28
- PostDeployHook,
30
+ from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
31
+ from snowflake.cli.api.project.schemas.v1.native_app.native_app import NativeApp
32
+ from snowflake.cli.api.project.schemas.v1.native_app.path_mapping import PathMapping
33
+ from snowflake.cli.api.project.util import (
34
+ append_test_resource_suffix,
35
+ extract_schema,
36
+ to_identifier,
29
37
  )
30
- from snowflake.cli.api.project.schemas.native_app.native_app import NativeApp
31
- from snowflake.cli.api.project.schemas.native_app.path_mapping import PathMapping
32
- from snowflake.cli.api.project.util import extract_schema, to_identifier
33
- from snowflake.cli.plugins.nativeapp.artifacts import resolve_without_follow
34
- from snowflake.connector import DictCursor
35
-
36
-
37
- def current_role() -> str:
38
- conn = cli_context.connection
39
- *_, cursor = conn.execute_string("select current_role()", cursor_class=DictCursor)
40
- role_result = cursor.fetchone()
41
- return role_result["CURRENT_ROLE()"]
42
38
 
43
39
 
44
40
  class NativeAppProjectModel:
@@ -107,6 +103,7 @@ class NativeAppProjectModel:
107
103
  if self.definition.package and self.definition.package.warehouse:
108
104
  return to_identifier(self.definition.package.warehouse)
109
105
  else:
106
+ cli_context = get_cli_context()
110
107
  if cli_context.connection.warehouse:
111
108
  return to_identifier(cli_context.connection.warehouse)
112
109
  return None
@@ -116,6 +113,7 @@ class NativeAppProjectModel:
116
113
  if self.definition.application and self.definition.application.warehouse:
117
114
  return to_identifier(self.definition.application.warehouse)
118
115
  else:
116
+ cli_context = get_cli_context()
119
117
  if cli_context.connection.warehouse:
120
118
  return to_identifier(cli_context.connection.warehouse)
121
119
  return None
@@ -126,12 +124,16 @@ class NativeAppProjectModel:
126
124
  # sometimes strip out double quotes, so we try to get them back here.
127
125
  return to_identifier(self.definition.name)
128
126
 
129
- @cached_property
127
+ @property
130
128
  def package_name(self) -> str:
131
129
  if self.definition.package and self.definition.package.name:
132
130
  return to_identifier(self.definition.package.name)
133
131
  else:
134
- return to_identifier(default_app_package(self.project_identifier))
132
+ # V1.0 PDF doesn't support templating, so if the identifier isn't
133
+ # explicitly specified, the default is generated here,
134
+ # so we have to append the test resource suffix here
135
+ name = default_app_package(self.project_identifier)
136
+ return to_identifier(append_test_resource_suffix(name))
135
137
 
136
138
  @cached_property
137
139
  def package_role(self) -> str:
@@ -147,12 +149,16 @@ class NativeAppProjectModel:
147
149
  else:
148
150
  return "internal"
149
151
 
150
- @cached_property
152
+ @property
151
153
  def app_name(self) -> str:
152
154
  if self.definition.application and self.definition.application.name:
153
155
  return to_identifier(self.definition.application.name)
154
156
  else:
155
- return to_identifier(default_application(self.project_identifier))
157
+ # V1.0 PDF doesn't support templating, so if the identifier isn't
158
+ # explicitly specified, the default is generated here,
159
+ # so we have to append the test resource suffix here
160
+ name = default_application(self.project_identifier)
161
+ return to_identifier(append_test_resource_suffix(name))
156
162
 
157
163
  @cached_property
158
164
  def app_role(self) -> str:
@@ -185,7 +191,7 @@ class NativeAppProjectModel:
185
191
  def _default_role(self) -> str:
186
192
  role = default_role()
187
193
  if role is None:
188
- role = current_role()
194
+ role = get_sql_executor().current_role()
189
195
  return role
190
196
 
191
197
  @cached_property
@@ -193,3 +199,13 @@ class NativeAppProjectModel:
193
199
  if self.definition.application:
194
200
  return self.definition.application.debug
195
201
  return None
202
+
203
+ def get_bundle_context(self) -> BundleContext:
204
+ return BundleContext(
205
+ package_name=self.package_name,
206
+ artifacts=self.artifacts,
207
+ project_root=self.project_root,
208
+ bundle_root=self.bundle_root,
209
+ deploy_root=self.deploy_root,
210
+ generated_root=self.generated_root,
211
+ )