snowflake-cli-labs 2.8.1__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.1.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 -662
  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 -167
  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 -354
  126. snowflake/cli/plugins/git/manager.py +0 -105
  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 -248
  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 -85
  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 -15
  166. snowflake/cli/plugins/object/__init__.py +0 -13
  167. snowflake/cli/plugins/object/command_aliases.py +0 -95
  168. snowflake/cli/plugins/object/commands.py +0 -181
  169. snowflake/cli/plugins/object/common.py +0 -85
  170. snowflake/cli/plugins/object/manager.py +0 -97
  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 -546
  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 -157
  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 -44
  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 -241
  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 -202
  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 -312
  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 -263
  215. snowflake/cli/plugins/stage/diff.py +0 -326
  216. snowflake/cli/plugins/stage/manager.py +0 -577
  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 -179
  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.1.dist-info/RECORD +0 -240
  240. snowflake_cli_labs-2.8.1.dist-info/entry_points.txt +0 -2
  241. {snowflake_cli_labs-2.8.1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/WHEEL +0 -0
  242. {snowflake_cli_labs-2.8.1.dist-info → snowflake_cli_labs-2.8.2.dist-info}/licenses/LICENSE +0 -0
@@ -1,354 +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 itertools
18
- import logging
19
- from os import path
20
- from pathlib import Path
21
- from typing import Dict, List, Optional
22
-
23
- import typer
24
- from click import ClickException
25
- from snowflake.cli.api.commands.flags import (
26
- ExecuteVariablesOption,
27
- OnErrorOption,
28
- PatternOption,
29
- identifier_argument,
30
- like_option,
31
- )
32
- from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
33
- from snowflake.cli.api.console.console import cli_console
34
- from snowflake.cli.api.constants import ObjectType
35
- from snowflake.cli.api.output.types import CollectionResult, CommandResult, QueryResult
36
- from snowflake.cli.api.utils.path_utils import is_stage_path
37
- from snowflake.cli.plugins.git.manager import GitManager
38
- from snowflake.cli.plugins.object.command_aliases import (
39
- add_object_command_aliases,
40
- scope_option,
41
- )
42
- from snowflake.cli.plugins.object.manager import ObjectManager
43
- from snowflake.cli.plugins.stage.manager import OnErrorType
44
- from snowflake.connector import DictCursor
45
-
46
- app = SnowTyperFactory(
47
- name="git",
48
- help="Manages git repositories in Snowflake.",
49
- )
50
- log = logging.getLogger(__name__)
51
-
52
-
53
- def _repo_path_argument_callback(path):
54
- # All repository paths must start with repository scope:
55
- # "@repo_name/tag/example_tag/*"
56
- if not is_stage_path(path) or path.count("/") < 3:
57
- raise ClickException(
58
- "REPOSITORY_PATH should be a path to git repository stage with scope provided."
59
- " Path to the repository root must end with '/'."
60
- " For example: @my_repo/branches/main/"
61
- )
62
-
63
- return path
64
-
65
-
66
- RepoNameArgument = identifier_argument(sf_object="git repository", example="my_repo")
67
- RepoPathArgument = typer.Argument(
68
- metavar="REPOSITORY_PATH",
69
- help=(
70
- "Path to git repository stage with scope provided."
71
- " Path to the repository root must end with '/'."
72
- " For example: @my_repo/branches/main/"
73
- ),
74
- callback=_repo_path_argument_callback,
75
- )
76
- add_object_command_aliases(
77
- app=app,
78
- object_type=ObjectType.GIT_REPOSITORY,
79
- name_argument=RepoNameArgument,
80
- like_option=like_option(
81
- help_example='`list --like "my%"` lists all git repositories with name that begin with “my”',
82
- ),
83
- scope_option=scope_option(help_example="`list --in database my_db`"),
84
- )
85
-
86
- from snowflake.cli.api.identifiers import FQN
87
-
88
-
89
- def _assure_repository_does_not_exist(om: ObjectManager, repository_name: FQN) -> None:
90
- if om.object_exists(
91
- object_type=ObjectType.GIT_REPOSITORY.value.cli_name, fqn=repository_name
92
- ):
93
- raise ClickException(f"Repository '{repository_name}' already exists")
94
-
95
-
96
- def _validate_origin_url(url: str) -> None:
97
- if not url.startswith("https://"):
98
- raise ClickException("Url address should start with 'https'")
99
-
100
-
101
- def _unique_new_object_name(
102
- om: ObjectManager, object_type: ObjectType, proposed_fqn: FQN
103
- ) -> str:
104
- existing_objects: List[Dict] = om.show(
105
- object_type=object_type.value.cli_name,
106
- like=f"{proposed_fqn.name}%",
107
- cursor_class=DictCursor,
108
- ).fetchall()
109
- existing_names = set(o["name"].upper() for o in existing_objects)
110
-
111
- result = proposed_fqn.name
112
- i = 1
113
- while result.upper() in existing_names:
114
- result = proposed_fqn.name + str(i)
115
- i += 1
116
- return result
117
-
118
-
119
- @app.command("setup", requires_connection=True)
120
- def setup(
121
- repository_name: FQN = RepoNameArgument,
122
- **options,
123
- ) -> CommandResult:
124
- """
125
- Sets up a git repository object.
126
-
127
- You will be prompted for:
128
-
129
- * url - address of repository to be used for git clone operation
130
-
131
- * secret - Snowflake secret containing authentication credentials. Not needed if origin repository does not require
132
- authentication for RO operations (clone, fetch)
133
-
134
- * API integration - object allowing Snowflake to interact with git repository.
135
- """
136
- manager = GitManager()
137
- om = ObjectManager()
138
- _assure_repository_does_not_exist(om, repository_name)
139
-
140
- url = typer.prompt("Origin url")
141
- _validate_origin_url(url)
142
-
143
- secret_needed = typer.confirm("Use secret for authentication?")
144
- should_create_secret = False
145
- secret_name = None
146
- if secret_needed:
147
- default_secret_name = (
148
- FQN.from_string(f"{repository_name.name}_secret")
149
- .set_schema(repository_name.schema)
150
- .set_database(repository_name.database)
151
- )
152
- default_secret_name.set_name(
153
- _unique_new_object_name(
154
- om, object_type=ObjectType.SECRET, proposed_fqn=default_secret_name
155
- ),
156
- )
157
- secret_name = FQN.from_string(
158
- typer.prompt(
159
- "Secret identifier (will be created if not exists)",
160
- default=default_secret_name.name,
161
- )
162
- )
163
- if not secret_name.database:
164
- secret_name.set_database(repository_name.database)
165
- if not secret_name.schema:
166
- secret_name.set_schema(repository_name.schema)
167
-
168
- if om.object_exists(
169
- object_type=ObjectType.SECRET.value.cli_name, fqn=secret_name
170
- ):
171
- cli_console.step(f"Using existing secret '{secret_name}'")
172
- else:
173
- should_create_secret = True
174
- cli_console.step(f"Secret '{secret_name}' will be created")
175
- secret_username = typer.prompt("username")
176
- secret_password = typer.prompt("password/token", hide_input=True)
177
-
178
- # API integration is an account-level object
179
- api_integration = FQN.from_string(f"{repository_name.name}_api_integration")
180
- api_integration.set_name(
181
- typer.prompt(
182
- "API integration identifier (will be created if not exists)",
183
- default=_unique_new_object_name(
184
- om,
185
- object_type=ObjectType.INTEGRATION,
186
- proposed_fqn=api_integration,
187
- ),
188
- )
189
- )
190
-
191
- if should_create_secret:
192
- manager.create_password_secret(
193
- name=secret_name, username=secret_username, password=secret_password
194
- )
195
- cli_console.step(f"Secret '{secret_name}' successfully created.")
196
-
197
- if not om.object_exists(
198
- object_type=ObjectType.INTEGRATION.value.cli_name, fqn=api_integration
199
- ):
200
- manager.create_api_integration(
201
- name=api_integration,
202
- api_provider="git_https_api",
203
- allowed_prefix=url,
204
- secret=secret_name,
205
- )
206
- cli_console.step(f"API integration '{api_integration}' successfully created.")
207
- else:
208
- cli_console.step(f"Using existing API integration '{api_integration}'.")
209
-
210
- return QueryResult(
211
- manager.create(
212
- repo_name=repository_name,
213
- url=url,
214
- api_integration=api_integration,
215
- secret=secret_name,
216
- )
217
- )
218
-
219
-
220
- @app.command(
221
- "list-branches",
222
- requires_connection=True,
223
- )
224
- def list_branches(
225
- repository_name: FQN = RepoNameArgument,
226
- like=like_option(
227
- help_example='`list-branches --like "%_test"` lists all branches that end with "_test"'
228
- ),
229
- **options,
230
- ) -> CommandResult:
231
- """
232
- List all branches in the repository.
233
- """
234
- return QueryResult(
235
- GitManager().show_branches(repo_name=repository_name.identifier, like=like)
236
- )
237
-
238
-
239
- @app.command(
240
- "list-tags",
241
- requires_connection=True,
242
- )
243
- def list_tags(
244
- repository_name: FQN = RepoNameArgument,
245
- like=like_option(
246
- help_example='`list-tags --like "v2.0%"` lists all tags that start with "v2.0"'
247
- ),
248
- **options,
249
- ) -> CommandResult:
250
- """
251
- List all tags in the repository.
252
- """
253
- return QueryResult(
254
- GitManager().show_tags(repo_name=repository_name.identifier, like=like)
255
- )
256
-
257
-
258
- @app.command(
259
- "list-files",
260
- requires_connection=True,
261
- )
262
- def list_files(
263
- repository_path: str = RepoPathArgument,
264
- pattern=PatternOption,
265
- **options,
266
- ) -> CommandResult:
267
- """
268
- List files from given state of git repository.
269
- """
270
- return QueryResult(
271
- GitManager().list_files(stage_name=repository_path, pattern=pattern)
272
- )
273
-
274
-
275
- @app.command(
276
- "fetch",
277
- requires_connection=True,
278
- )
279
- def fetch(
280
- repository_name: FQN = RepoNameArgument,
281
- **options,
282
- ) -> CommandResult:
283
- """
284
- Fetch changes from origin to Snowflake repository.
285
- """
286
- return QueryResult(GitManager().fetch(fqn=repository_name))
287
-
288
-
289
- @app.command(
290
- "copy",
291
- requires_connection=True,
292
- )
293
- def copy(
294
- repository_path: str = RepoPathArgument,
295
- destination_path: str = typer.Argument(
296
- help="Target path for copy operation. Should be a path to a directory on remote stage or local file system.",
297
- ),
298
- parallel: int = typer.Option(
299
- 4,
300
- help="Number of parallel threads to use when downloading files.",
301
- ),
302
- **options,
303
- ):
304
- """
305
- Copies all files from given state of repository to local directory or stage.
306
-
307
- If the source path ends with '/', the command copies contents of specified directory.
308
- Otherwise, it creates a new directory or file in the destination directory.
309
- """
310
- is_copy = is_stage_path(destination_path)
311
- if is_copy:
312
- return QueryResult(
313
- GitManager().copy_files(
314
- source_path=repository_path, destination_path=destination_path
315
- )
316
- )
317
- return get(
318
- source_path=repository_path,
319
- destination_path=destination_path,
320
- parallel=parallel,
321
- )
322
-
323
-
324
- @app.command("execute", requires_connection=True)
325
- def execute(
326
- repository_path: str = RepoPathArgument,
327
- on_error: OnErrorType = OnErrorOption,
328
- variables: Optional[List[str]] = ExecuteVariablesOption,
329
- **options,
330
- ):
331
- """
332
- Execute immediate all files from the repository path. Files can be filtered with glob like pattern,
333
- e.g. `@my_repo/branches/main/*.sql`, `@my_repo/branches/main/dev/*`. Only files with `.sql`
334
- extension will be executed.
335
- """
336
- results = GitManager().execute(
337
- stage_path=repository_path, on_error=on_error, variables=variables
338
- )
339
- return CollectionResult(results)
340
-
341
-
342
- def get(source_path: str, destination_path: str, parallel: int):
343
- target = Path(destination_path).resolve()
344
-
345
- cursors = GitManager().get_recursive(
346
- stage_path=source_path, dest_path=target, parallel=parallel
347
- )
348
- results = [list(QueryResult(c).result) for c in cursors]
349
- flattened_results = list(itertools.chain.from_iterable(results))
350
- sorted_results = sorted(
351
- flattened_results,
352
- key=lambda e: (path.dirname(e["file"]), path.basename(e["file"])),
353
- )
354
- return CollectionResult(sorted_results)
@@ -1,105 +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
- from pathlib import Path
18
- from textwrap import dedent
19
- from typing import List
20
-
21
- from snowflake.cli.api.identifiers import FQN
22
- from snowflake.cli.plugins.stage.manager import (
23
- USER_STAGE_PREFIX,
24
- StageManager,
25
- StagePathParts,
26
- UserStagePathParts,
27
- )
28
- from snowflake.connector.cursor import SnowflakeCursor
29
-
30
-
31
- class GitStagePathParts(StagePathParts):
32
- def __init__(self, stage_path: str):
33
- self.stage = GitManager.get_stage_from_path(stage_path)
34
- stage_path_parts = Path(stage_path).parts
35
- git_repo_name = stage_path_parts[0].split(".")[-1]
36
- if git_repo_name.startswith("@"):
37
- git_repo_name = git_repo_name[1:]
38
- self.stage_name = "/".join([git_repo_name, *stage_path_parts[1:3], ""])
39
- self.directory = "/".join(stage_path_parts[3:])
40
- self.is_directory = True if stage_path.endswith("/") else False
41
-
42
- @property
43
- def path(self) -> str:
44
- return f"{self.stage_name.rstrip('/')}/{self.directory}"
45
-
46
- @classmethod
47
- def get_directory(cls, stage_path: str) -> str:
48
- return "/".join(Path(stage_path).parts[3:])
49
-
50
- @property
51
- def full_path(self) -> str:
52
- return f"{self.stage.rstrip('/')}/{self.directory}"
53
-
54
- def replace_stage_prefix(self, file_path: str) -> str:
55
- stage = Path(self.stage).parts[0]
56
- file_path_without_prefix = Path(file_path).parts[1:]
57
- return f"{stage}/{'/'.join(file_path_without_prefix)}"
58
-
59
- def add_stage_prefix(self, file_path: str) -> str:
60
- stage = self.stage.rstrip("/")
61
- return f"{stage}/{file_path.lstrip('/')}"
62
-
63
- def get_directory_from_file_path(self, file_path: str) -> List[str]:
64
- stage_path_length = len(Path(self.directory).parts)
65
- return list(Path(file_path).parts[3 + stage_path_length : -1])
66
-
67
-
68
- class GitManager(StageManager):
69
- def show_branches(self, repo_name: str, like: str) -> SnowflakeCursor:
70
- return self._execute_query(f"show git branches like '{like}' in {repo_name}")
71
-
72
- def show_tags(self, repo_name: str, like: str) -> SnowflakeCursor:
73
- return self._execute_query(f"show git tags like '{like}' in {repo_name}")
74
-
75
- def fetch(self, fqn: FQN) -> SnowflakeCursor:
76
- return self._execute_query(f"alter git repository {fqn} fetch")
77
-
78
- def create(
79
- self, repo_name: FQN, api_integration: str, url: str, secret: str
80
- ) -> SnowflakeCursor:
81
- query = dedent(
82
- f"""
83
- create git repository {repo_name.sql_identifier}
84
- api_integration = {api_integration}
85
- origin = '{url}'
86
- """
87
- )
88
- if secret is not None:
89
- query += f"git_credentials = {secret}\n"
90
- return self._execute_query(query)
91
-
92
- @staticmethod
93
- def get_stage_from_path(path: str):
94
- """
95
- Returns stage name from potential path on stage. For example
96
- repo/branches/main/foo/bar -> repo/branches/main/
97
- """
98
- return f"{'/'.join(Path(path).parts[0:3])}/"
99
-
100
- @staticmethod
101
- def _stage_path_part_factory(stage_path: str) -> StagePathParts:
102
- stage_path = StageManager.get_standard_stage_prefix(stage_path)
103
- if stage_path.startswith(USER_STAGE_PREFIX):
104
- return UserStagePathParts(stage_path)
105
- return GitStagePathParts(stage_path)
@@ -1,30 +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.plugins.command import (
16
- SNOWCLI_ROOT_COMMAND_PATH,
17
- CommandSpec,
18
- CommandType,
19
- plugin_hook_impl,
20
- )
21
- from snowflake.cli.plugins.git import commands
22
-
23
-
24
- @plugin_hook_impl
25
- def command_spec():
26
- return CommandSpec(
27
- parent_command_path=SNOWCLI_ROOT_COMMAND_PATH,
28
- command_type=CommandType.COMMAND_GROUP,
29
- typer_instance=commands.app.create_instance(),
30
- )
@@ -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.