snowflake-cli-labs 3.0.0rc4__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.
- README.md +21 -0
- {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/METADATA +6 -96
- snowflake_cli_labs-3.0.1.dist-info/RECORD +5 -0
- snowflake/cli/__about__.py +0 -17
- snowflake/cli/__init__.py +0 -13
- snowflake/cli/_app/__init__.py +0 -22
- snowflake/cli/_app/__main__.py +0 -31
- snowflake/cli/_app/api_impl/__init__.py +0 -13
- snowflake/cli/_app/api_impl/plugin/__init__.py +0 -13
- snowflake/cli/_app/api_impl/plugin/plugin_config_provider_impl.py +0 -66
- snowflake/cli/_app/cli_app.py +0 -252
- snowflake/cli/_app/commands_registration/__init__.py +0 -33
- snowflake/cli/_app/commands_registration/builtin_plugins.py +0 -50
- snowflake/cli/_app/commands_registration/command_plugins_loader.py +0 -169
- snowflake/cli/_app/commands_registration/commands_registration_with_callbacks.py +0 -105
- snowflake/cli/_app/commands_registration/exception_logging.py +0 -26
- snowflake/cli/_app/commands_registration/threadsafe.py +0 -48
- snowflake/cli/_app/commands_registration/typer_registration.py +0 -153
- snowflake/cli/_app/constants.py +0 -19
- snowflake/cli/_app/dev/__init__.py +0 -13
- snowflake/cli/_app/dev/commands_structure.py +0 -48
- snowflake/cli/_app/dev/docs/__init__.py +0 -13
- snowflake/cli/_app/dev/docs/commands_docs_generator.py +0 -118
- snowflake/cli/_app/dev/docs/generator.py +0 -35
- snowflake/cli/_app/dev/docs/project_definition_docs_generator.py +0 -58
- snowflake/cli/_app/dev/docs/project_definition_generate_json_schema.py +0 -227
- snowflake/cli/_app/dev/docs/template_utils.py +0 -23
- snowflake/cli/_app/dev/docs/templates/definition_description.rst.jinja2 +0 -38
- snowflake/cli/_app/dev/docs/templates/overview.rst.jinja2 +0 -9
- snowflake/cli/_app/dev/docs/templates/usage.rst.jinja2 +0 -67
- snowflake/cli/_app/dev/pycharm_remote_debug.py +0 -46
- snowflake/cli/_app/loggers.py +0 -199
- snowflake/cli/_app/main_typer.py +0 -62
- snowflake/cli/_app/printing.py +0 -181
- snowflake/cli/_app/secret.py +0 -9
- snowflake/cli/_app/snow_connector.py +0 -309
- snowflake/cli/_app/telemetry.py +0 -220
- snowflake/cli/_app/version_check.py +0 -74
- snowflake/cli/_plugins/__init__.py +0 -13
- snowflake/cli/_plugins/connection/__init__.py +0 -13
- snowflake/cli/_plugins/connection/commands.py +0 -353
- snowflake/cli/_plugins/connection/plugin_spec.py +0 -30
- snowflake/cli/_plugins/connection/util.py +0 -195
- snowflake/cli/_plugins/cortex/__init__.py +0 -13
- snowflake/cli/_plugins/cortex/commands.py +0 -332
- snowflake/cli/_plugins/cortex/constants.py +0 -17
- snowflake/cli/_plugins/cortex/manager.py +0 -189
- snowflake/cli/_plugins/cortex/plugin_spec.py +0 -30
- snowflake/cli/_plugins/cortex/types.py +0 -22
- snowflake/cli/_plugins/git/__init__.py +0 -13
- snowflake/cli/_plugins/git/commands.py +0 -358
- snowflake/cli/_plugins/git/manager.py +0 -151
- snowflake/cli/_plugins/git/plugin_spec.py +0 -30
- snowflake/cli/_plugins/helpers/__init__.py +0 -13
- snowflake/cli/_plugins/helpers/commands.py +0 -61
- snowflake/cli/_plugins/helpers/plugin_spec.py +0 -30
- snowflake/cli/_plugins/init/__init__.py +0 -13
- snowflake/cli/_plugins/init/commands.py +0 -248
- snowflake/cli/_plugins/init/plugin_spec.py +0 -30
- snowflake/cli/_plugins/nativeapp/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/artifacts.py +0 -757
- snowflake/cli/_plugins/nativeapp/bundle_context.py +0 -31
- snowflake/cli/_plugins/nativeapp/codegen/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/codegen/artifact_processor.py +0 -91
- snowflake/cli/_plugins/nativeapp/codegen/compiler.py +0 -149
- snowflake/cli/_plugins/nativeapp/codegen/sandbox.py +0 -306
- snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -249
- snowflake/cli/_plugins/nativeapp/codegen/setup/setup_driver.py.source +0 -59
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -181
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/extension_function_utils.py +0 -217
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/models.py +0 -61
- snowflake/cli/_plugins/nativeapp/codegen/snowpark/python_processor.py +0 -523
- snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +0 -114
- snowflake/cli/_plugins/nativeapp/commands.py +0 -559
- snowflake/cli/_plugins/nativeapp/common_flags.py +0 -44
- snowflake/cli/_plugins/nativeapp/constants.py +0 -27
- snowflake/cli/_plugins/nativeapp/entities/__init__.py +0 -0
- snowflake/cli/_plugins/nativeapp/entities/application.py +0 -878
- snowflake/cli/_plugins/nativeapp/entities/application_package.py +0 -1392
- snowflake/cli/_plugins/nativeapp/exceptions.py +0 -113
- snowflake/cli/_plugins/nativeapp/feature_flags.py +0 -24
- snowflake/cli/_plugins/nativeapp/manager.py +0 -415
- snowflake/cli/_plugins/nativeapp/plugin_spec.py +0 -30
- snowflake/cli/_plugins/nativeapp/policy.py +0 -53
- snowflake/cli/_plugins/nativeapp/project_model.py +0 -211
- snowflake/cli/_plugins/nativeapp/run_processor.py +0 -184
- snowflake/cli/_plugins/nativeapp/same_account_install_method.py +0 -70
- snowflake/cli/_plugins/nativeapp/teardown_processor.py +0 -70
- snowflake/cli/_plugins/nativeapp/utils.py +0 -98
- snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -262
- snowflake/cli/_plugins/nativeapp/version/__init__.py +0 -13
- snowflake/cli/_plugins/nativeapp/version/commands.py +0 -141
- snowflake/cli/_plugins/nativeapp/version/version_processor.py +0 -98
- snowflake/cli/_plugins/notebook/__init__.py +0 -13
- snowflake/cli/_plugins/notebook/commands.py +0 -86
- snowflake/cli/_plugins/notebook/exceptions.py +0 -20
- snowflake/cli/_plugins/notebook/manager.py +0 -71
- snowflake/cli/_plugins/notebook/plugin_spec.py +0 -30
- snowflake/cli/_plugins/notebook/types.py +0 -15
- snowflake/cli/_plugins/object/__init__.py +0 -13
- snowflake/cli/_plugins/object/command_aliases.py +0 -95
- snowflake/cli/_plugins/object/commands.py +0 -180
- snowflake/cli/_plugins/object/common.py +0 -85
- snowflake/cli/_plugins/object/manager.py +0 -118
- snowflake/cli/_plugins/object/plugin_spec.py +0 -30
- snowflake/cli/_plugins/snowpark/__init__.py +0 -13
- snowflake/cli/_plugins/snowpark/commands.py +0 -450
- snowflake/cli/_plugins/snowpark/common.py +0 -268
- snowflake/cli/_plugins/snowpark/models.py +0 -150
- snowflake/cli/_plugins/snowpark/package/__init__.py +0 -13
- snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +0 -199
- snowflake/cli/_plugins/snowpark/package/commands.py +0 -195
- snowflake/cli/_plugins/snowpark/package/manager.py +0 -44
- snowflake/cli/_plugins/snowpark/package/utils.py +0 -26
- snowflake/cli/_plugins/snowpark/package_utils.py +0 -354
- snowflake/cli/_plugins/snowpark/plugin_spec.py +0 -30
- snowflake/cli/_plugins/snowpark/snowpark_entity.py +0 -29
- snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +0 -173
- snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +0 -109
- snowflake/cli/_plugins/snowpark/snowpark_shared.py +0 -59
- snowflake/cli/_plugins/snowpark/zipper.py +0 -89
- snowflake/cli/_plugins/spcs/__init__.py +0 -33
- snowflake/cli/_plugins/spcs/common.py +0 -99
- snowflake/cli/_plugins/spcs/compute_pool/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/compute_pool/commands.py +0 -241
- snowflake/cli/_plugins/spcs/compute_pool/manager.py +0 -121
- snowflake/cli/_plugins/spcs/image_registry/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/image_registry/commands.py +0 -65
- snowflake/cli/_plugins/spcs/image_registry/manager.py +0 -105
- snowflake/cli/_plugins/spcs/image_repository/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/image_repository/commands.py +0 -202
- snowflake/cli/_plugins/spcs/image_repository/manager.py +0 -84
- snowflake/cli/_plugins/spcs/plugin_spec.py +0 -30
- snowflake/cli/_plugins/spcs/services/__init__.py +0 -13
- snowflake/cli/_plugins/spcs/services/commands.py +0 -345
- snowflake/cli/_plugins/spcs/services/manager.py +0 -208
- snowflake/cli/_plugins/sql/__init__.py +0 -13
- snowflake/cli/_plugins/sql/commands.py +0 -86
- snowflake/cli/_plugins/sql/manager.py +0 -92
- snowflake/cli/_plugins/sql/plugin_spec.py +0 -30
- snowflake/cli/_plugins/sql/snowsql_templating.py +0 -28
- snowflake/cli/_plugins/stage/__init__.py +0 -13
- snowflake/cli/_plugins/stage/commands.py +0 -264
- snowflake/cli/_plugins/stage/diff.py +0 -280
- snowflake/cli/_plugins/stage/manager.py +0 -582
- snowflake/cli/_plugins/stage/md5.py +0 -160
- snowflake/cli/_plugins/stage/plugin_spec.py +0 -30
- snowflake/cli/_plugins/stage/utils.py +0 -54
- snowflake/cli/_plugins/streamlit/__init__.py +0 -13
- snowflake/cli/_plugins/streamlit/commands.py +0 -195
- snowflake/cli/_plugins/streamlit/manager.py +0 -220
- snowflake/cli/_plugins/streamlit/plugin_spec.py +0 -30
- snowflake/cli/_plugins/streamlit/streamlit_entity.py +0 -12
- snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +0 -66
- snowflake/cli/_plugins/workspace/__init__.py +0 -13
- snowflake/cli/_plugins/workspace/action_context.py +0 -18
- snowflake/cli/_plugins/workspace/commands.py +0 -306
- snowflake/cli/_plugins/workspace/manager.py +0 -74
- snowflake/cli/_plugins/workspace/plugin_spec.py +0 -30
- snowflake/cli/api/__init__.py +0 -48
- snowflake/cli/api/cli_global_context.py +0 -247
- snowflake/cli/api/commands/__init__.py +0 -13
- snowflake/cli/api/commands/alias.py +0 -23
- snowflake/cli/api/commands/common.py +0 -25
- snowflake/cli/api/commands/decorators.py +0 -369
- snowflake/cli/api/commands/execution_metadata.py +0 -40
- snowflake/cli/api/commands/experimental_behaviour.py +0 -18
- snowflake/cli/api/commands/flags.py +0 -561
- snowflake/cli/api/commands/overrideable_parameter.py +0 -143
- snowflake/cli/api/commands/snow_typer.py +0 -247
- snowflake/cli/api/commands/utils.py +0 -18
- snowflake/cli/api/config.py +0 -380
- snowflake/cli/api/connections.py +0 -216
- snowflake/cli/api/console/__init__.py +0 -17
- snowflake/cli/api/console/abc.py +0 -94
- snowflake/cli/api/console/console.py +0 -134
- snowflake/cli/api/console/enum.py +0 -17
- snowflake/cli/api/constants.py +0 -90
- snowflake/cli/api/entities/common.py +0 -56
- snowflake/cli/api/entities/utils.py +0 -370
- snowflake/cli/api/errno.py +0 -28
- snowflake/cli/api/exceptions.py +0 -190
- snowflake/cli/api/feature_flags.py +0 -54
- snowflake/cli/api/identifiers.py +0 -190
- snowflake/cli/api/metrics.py +0 -92
- snowflake/cli/api/output/__init__.py +0 -13
- snowflake/cli/api/output/formats.py +0 -20
- snowflake/cli/api/output/types.py +0 -118
- snowflake/cli/api/plugins/__init__.py +0 -13
- snowflake/cli/api/plugins/command/__init__.py +0 -72
- snowflake/cli/api/plugins/command/plugin_hook_specs.py +0 -21
- snowflake/cli/api/plugins/plugin_config.py +0 -32
- snowflake/cli/api/project/__init__.py +0 -13
- snowflake/cli/api/project/definition.py +0 -126
- snowflake/cli/api/project/definition_conversion.py +0 -395
- snowflake/cli/api/project/definition_manager.py +0 -145
- snowflake/cli/api/project/errors.py +0 -56
- snowflake/cli/api/project/project_verification.py +0 -23
- snowflake/cli/api/project/schemas/__init__.py +0 -13
- snowflake/cli/api/project/schemas/entities/__init__.py +0 -13
- snowflake/cli/api/project/schemas/entities/common.py +0 -153
- snowflake/cli/api/project/schemas/entities/entities.py +0 -61
- snowflake/cli/api/project/schemas/project_definition.py +0 -330
- snowflake/cli/api/project/schemas/template.py +0 -77
- snowflake/cli/api/project/schemas/updatable_model.py +0 -202
- snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/identifier_model.py +0 -51
- snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/native_app/application.py +0 -61
- snowflake/cli/api/project/schemas/v1/native_app/native_app.py +0 -93
- snowflake/cli/api/project/schemas/v1/native_app/package.py +0 -84
- snowflake/cli/api/project/schemas/v1/native_app/path_mapping.py +0 -65
- snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/snowpark/argument.py +0 -28
- snowflake/cli/api/project/schemas/v1/snowpark/callable.py +0 -69
- snowflake/cli/api/project/schemas/v1/snowpark/snowpark.py +0 -36
- snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
- snowflake/cli/api/project/schemas/v1/streamlit/streamlit.py +0 -47
- snowflake/cli/api/project/util.py +0 -278
- snowflake/cli/api/rendering/__init__.py +0 -13
- snowflake/cli/api/rendering/jinja.py +0 -118
- snowflake/cli/api/rendering/project_definition_templates.py +0 -43
- snowflake/cli/api/rendering/project_templates.py +0 -98
- snowflake/cli/api/rendering/sql_templates.py +0 -105
- snowflake/cli/api/rest_api.py +0 -178
- snowflake/cli/api/sanitizers.py +0 -43
- snowflake/cli/api/secure_path.py +0 -360
- snowflake/cli/api/secure_utils.py +0 -118
- snowflake/cli/api/sql_execution.py +0 -280
- snowflake/cli/api/utils/__init__.py +0 -13
- snowflake/cli/api/utils/cursor.py +0 -34
- snowflake/cli/api/utils/definition_rendering.py +0 -415
- snowflake/cli/api/utils/dict_utils.py +0 -73
- snowflake/cli/api/utils/error_handling.py +0 -23
- snowflake/cli/api/utils/graph.py +0 -97
- snowflake/cli/api/utils/models.py +0 -63
- snowflake/cli/api/utils/naming_utils.py +0 -13
- snowflake/cli/api/utils/path_utils.py +0 -36
- snowflake/cli/api/utils/templating_functions.py +0 -144
- snowflake/cli/api/utils/types.py +0 -35
- snowflake_cli_labs-3.0.0rc4.dist-info/RECORD +0 -242
- snowflake_cli_labs-3.0.0rc4.dist-info/entry_points.txt +0 -2
- {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/WHEEL +0 -0
- {snowflake_cli_labs-3.0.0rc4.dist-info → snowflake_cli_labs-3.0.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,71 +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 pathlib import Path
|
|
16
|
-
from textwrap import dedent
|
|
17
|
-
|
|
18
|
-
from snowflake.cli._plugins.connection.util import make_snowsight_url
|
|
19
|
-
from snowflake.cli._plugins.notebook.exceptions import NotebookStagePathError
|
|
20
|
-
from snowflake.cli._plugins.notebook.types import NotebookStagePath
|
|
21
|
-
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
22
|
-
from snowflake.cli.api.identifiers import FQN
|
|
23
|
-
from snowflake.cli.api.sql_execution import SqlExecutionMixin
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class NotebookManager(SqlExecutionMixin):
|
|
27
|
-
def execute(self, notebook_name: FQN):
|
|
28
|
-
query = f"EXECUTE NOTEBOOK {notebook_name.sql_identifier}()"
|
|
29
|
-
return self._execute_query(query=query)
|
|
30
|
-
|
|
31
|
-
def get_url(self, notebook_name: FQN):
|
|
32
|
-
fqn = notebook_name.using_connection(self._conn)
|
|
33
|
-
return make_snowsight_url(
|
|
34
|
-
self._conn,
|
|
35
|
-
f"/#/notebooks/{fqn.url_identifier}",
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
@staticmethod
|
|
39
|
-
def parse_stage_as_path(notebook_file: str) -> Path:
|
|
40
|
-
"""Parses notebook file path to pathlib.Path."""
|
|
41
|
-
if not notebook_file.endswith(".ipynb"):
|
|
42
|
-
raise NotebookStagePathError(notebook_file)
|
|
43
|
-
stage_path = Path(notebook_file)
|
|
44
|
-
if len(stage_path.parts) < 2:
|
|
45
|
-
raise NotebookStagePathError(notebook_file)
|
|
46
|
-
|
|
47
|
-
return stage_path
|
|
48
|
-
|
|
49
|
-
def create(
|
|
50
|
-
self,
|
|
51
|
-
notebook_name: FQN,
|
|
52
|
-
notebook_file: NotebookStagePath,
|
|
53
|
-
) -> str:
|
|
54
|
-
notebook_fqn = notebook_name.using_connection(self._conn)
|
|
55
|
-
stage_path = self.parse_stage_as_path(notebook_file)
|
|
56
|
-
|
|
57
|
-
queries = dedent(
|
|
58
|
-
f"""
|
|
59
|
-
CREATE OR REPLACE NOTEBOOK {notebook_fqn.sql_identifier}
|
|
60
|
-
FROM '{stage_path.parent}'
|
|
61
|
-
QUERY_WAREHOUSE = '{get_cli_context().connection.warehouse}'
|
|
62
|
-
MAIN_FILE = '{stage_path.name}';
|
|
63
|
-
// Cannot use IDENTIFIER(...)
|
|
64
|
-
ALTER NOTEBOOK {notebook_fqn.identifier} ADD LIVE VERSION FROM LAST;
|
|
65
|
-
"""
|
|
66
|
-
)
|
|
67
|
-
self._execute_queries(queries=queries)
|
|
68
|
-
|
|
69
|
-
return make_snowsight_url(
|
|
70
|
-
self._conn, f"/#/notebooks/{notebook_fqn.url_identifier}"
|
|
71
|
-
)
|
|
@@ -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._plugins.notebook import commands
|
|
16
|
-
from snowflake.cli.api.plugins.command import (
|
|
17
|
-
SNOWCLI_ROOT_COMMAND_PATH,
|
|
18
|
-
CommandSpec,
|
|
19
|
-
CommandType,
|
|
20
|
-
plugin_hook_impl,
|
|
21
|
-
)
|
|
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,15 +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
|
-
NotebookStagePath = str
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# Copyright (c) 2024 Snowflake Inc.
|
|
2
|
-
#
|
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
# you may not use this file except in compliance with the License.
|
|
5
|
-
# You may obtain a copy of the License at
|
|
6
|
-
#
|
|
7
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
#
|
|
9
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
# See the License for the specific language governing permissions and
|
|
13
|
-
# limitations under the License.
|
|
@@ -1,95 +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 typing import List, Optional, Tuple
|
|
18
|
-
|
|
19
|
-
import typer
|
|
20
|
-
from click import ClickException
|
|
21
|
-
from snowflake.cli._plugins.object.commands import (
|
|
22
|
-
ScopeOption,
|
|
23
|
-
describe,
|
|
24
|
-
drop,
|
|
25
|
-
list_,
|
|
26
|
-
scope_option, # noqa: F401
|
|
27
|
-
)
|
|
28
|
-
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
|
|
29
|
-
from snowflake.cli.api.constants import ObjectType
|
|
30
|
-
from snowflake.cli.api.identifiers import FQN
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def add_object_command_aliases(
|
|
34
|
-
app: SnowTyperFactory,
|
|
35
|
-
object_type: ObjectType,
|
|
36
|
-
name_argument: typer.Argument,
|
|
37
|
-
like_option: Optional[typer.Option],
|
|
38
|
-
scope_option: Optional[typer.Option],
|
|
39
|
-
ommit_commands: List[str] = [],
|
|
40
|
-
):
|
|
41
|
-
if "list" not in ommit_commands:
|
|
42
|
-
if not like_option:
|
|
43
|
-
raise ClickException('[like_option] have to be defined for "list" command')
|
|
44
|
-
|
|
45
|
-
if not scope_option:
|
|
46
|
-
|
|
47
|
-
@app.command("list", requires_connection=True)
|
|
48
|
-
def list_cmd(like: str = like_option, **options): # type: ignore
|
|
49
|
-
return list_(
|
|
50
|
-
object_type=object_type.value.cli_name,
|
|
51
|
-
like=like,
|
|
52
|
-
scope=ScopeOption.default,
|
|
53
|
-
**options,
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
else:
|
|
57
|
-
|
|
58
|
-
@app.command("list", requires_connection=True)
|
|
59
|
-
def list_cmd(
|
|
60
|
-
like: str = like_option, # type: ignore
|
|
61
|
-
scope: Tuple[str, str] = scope_option, # type: ignore
|
|
62
|
-
**options,
|
|
63
|
-
):
|
|
64
|
-
return list_(
|
|
65
|
-
object_type=object_type.value.cli_name,
|
|
66
|
-
like=like,
|
|
67
|
-
scope=scope,
|
|
68
|
-
**options,
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
list_cmd.__doc__ = f"Lists all available {object_type.value.sf_plural_name}."
|
|
72
|
-
|
|
73
|
-
if "drop" not in ommit_commands:
|
|
74
|
-
|
|
75
|
-
@app.command("drop", requires_connection=True)
|
|
76
|
-
def drop_cmd(name: FQN = name_argument, **options):
|
|
77
|
-
return drop(
|
|
78
|
-
object_type=object_type.value.cli_name,
|
|
79
|
-
object_name=name,
|
|
80
|
-
**options,
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
drop_cmd.__doc__ = f"Drops {object_type.value.sf_name} with given name."
|
|
84
|
-
|
|
85
|
-
if "describe" not in ommit_commands:
|
|
86
|
-
|
|
87
|
-
@app.command("describe", requires_connection=True)
|
|
88
|
-
def describe_cmd(name: FQN = name_argument, **options):
|
|
89
|
-
return describe(
|
|
90
|
-
object_type=object_type.value.cli_name,
|
|
91
|
-
object_name=name,
|
|
92
|
-
**options,
|
|
93
|
-
)
|
|
94
|
-
|
|
95
|
-
describe_cmd.__doc__ = f"Provides description of {object_type.value.sf_name}."
|
|
@@ -1,180 +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 typing import List, Optional, Tuple
|
|
18
|
-
|
|
19
|
-
import typer
|
|
20
|
-
from click import ClickException
|
|
21
|
-
from snowflake.cli._plugins.object.manager import ObjectManager
|
|
22
|
-
from snowflake.cli.api.commands.flags import (
|
|
23
|
-
IdentifierType,
|
|
24
|
-
like_option,
|
|
25
|
-
)
|
|
26
|
-
from snowflake.cli.api.commands.snow_typer import SnowTyperFactory
|
|
27
|
-
from snowflake.cli.api.commands.utils import parse_key_value_variables
|
|
28
|
-
from snowflake.cli.api.constants import SUPPORTED_OBJECTS, VALID_SCOPES
|
|
29
|
-
from snowflake.cli.api.exceptions import IncompatibleParametersError
|
|
30
|
-
from snowflake.cli.api.identifiers import FQN
|
|
31
|
-
from snowflake.cli.api.output.types import MessageResult, QueryResult
|
|
32
|
-
from snowflake.cli.api.project.util import is_valid_identifier
|
|
33
|
-
|
|
34
|
-
app = SnowTyperFactory(
|
|
35
|
-
name="object",
|
|
36
|
-
help="Manages Snowflake objects like warehouses and stages",
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
NameArgument = typer.Argument(
|
|
41
|
-
help="Name of the object.", show_default=False, click_type=IdentifierType()
|
|
42
|
-
)
|
|
43
|
-
ObjectArgument = typer.Argument(
|
|
44
|
-
help="Type of object. For example table, database, compute-pool.",
|
|
45
|
-
case_sensitive=False,
|
|
46
|
-
show_default=False,
|
|
47
|
-
)
|
|
48
|
-
# TODO: add documentation link
|
|
49
|
-
ObjectAttributesArgument = typer.Argument(
|
|
50
|
-
None,
|
|
51
|
-
help="""Object attributes provided as a list of key=value pairs,
|
|
52
|
-
for example name=my_db comment='created with Snowflake CLI'.
|
|
53
|
-
|
|
54
|
-
Check documentation for the full list of available parameters
|
|
55
|
-
for every object.
|
|
56
|
-
""",
|
|
57
|
-
show_default=False,
|
|
58
|
-
)
|
|
59
|
-
# TODO: add documentation link
|
|
60
|
-
ObjectDefinitionJsonOption = typer.Option(
|
|
61
|
-
None,
|
|
62
|
-
"--json",
|
|
63
|
-
help="""Object definition in JSON format, for example
|
|
64
|
-
\'{"name": "my_db", "comment": "created with Snowflake CLI"}\'.
|
|
65
|
-
|
|
66
|
-
Check documentation for the full list of available parameters
|
|
67
|
-
for every object.
|
|
68
|
-
""",
|
|
69
|
-
show_default=False,
|
|
70
|
-
)
|
|
71
|
-
LikeOption = like_option(
|
|
72
|
-
help_example='`list function --like "my%"` lists all functions that begin with “my”',
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def _scope_validate(object_type: str, scope: Tuple[str, str]):
|
|
77
|
-
if scope[1] is not None and not is_valid_identifier(scope[1]):
|
|
78
|
-
raise ClickException("scope name must be a valid identifier")
|
|
79
|
-
if scope[0] is not None and scope[0].lower() not in VALID_SCOPES:
|
|
80
|
-
raise ClickException(
|
|
81
|
-
f"scope must be one of the following: {', '.join(VALID_SCOPES)}"
|
|
82
|
-
)
|
|
83
|
-
if scope[0] == "compute-pool" and object_type != "service":
|
|
84
|
-
raise ClickException("compute-pool scope is only supported for listing service")
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def scope_option(help_example: str):
|
|
88
|
-
return typer.Option(
|
|
89
|
-
(None, None),
|
|
90
|
-
"--in",
|
|
91
|
-
help=f"Specifies the scope of this command using '--in <scope> <name>', for example {help_example}.",
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
ScopeOption = scope_option(
|
|
96
|
-
help_example="`list table --in database my_db`. Some object types have specialized scopes (e.g. list service --in compute-pool my_pool)"
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
SUPPORTED_TYPES_MSG = "\n\nSupported types: " + ", ".join(SUPPORTED_OBJECTS)
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
@app.command(
|
|
103
|
-
"list",
|
|
104
|
-
help=f"Lists all available Snowflake objects of given type.{SUPPORTED_TYPES_MSG}",
|
|
105
|
-
requires_connection=True,
|
|
106
|
-
)
|
|
107
|
-
def list_(
|
|
108
|
-
object_type: str = ObjectArgument,
|
|
109
|
-
like: str = LikeOption,
|
|
110
|
-
scope: Tuple[str, str] = ScopeOption,
|
|
111
|
-
**options,
|
|
112
|
-
):
|
|
113
|
-
_scope_validate(object_type, scope)
|
|
114
|
-
return QueryResult(
|
|
115
|
-
ObjectManager().show(object_type=object_type, like=like, scope=scope)
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
@app.command(
|
|
120
|
-
help=f"Drops Snowflake object of given name and type. {SUPPORTED_TYPES_MSG}",
|
|
121
|
-
requires_connection=True,
|
|
122
|
-
)
|
|
123
|
-
def drop(object_type: str = ObjectArgument, object_name: FQN = NameArgument, **options):
|
|
124
|
-
return QueryResult(ObjectManager().drop(object_type=object_type, fqn=object_name))
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
# Image repository is the only supported object that does not have a DESCRIBE command.
|
|
128
|
-
DESCRIBE_SUPPORTED_TYPES_MSG = f"\n\nSupported types: {', '.join(obj for obj in SUPPORTED_OBJECTS if obj != 'image-repository')}"
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
@app.command(
|
|
132
|
-
help=f"Provides description of an object of given type. {DESCRIBE_SUPPORTED_TYPES_MSG}",
|
|
133
|
-
requires_connection=True,
|
|
134
|
-
)
|
|
135
|
-
def describe(
|
|
136
|
-
object_type: str = ObjectArgument, object_name: FQN = NameArgument, **options
|
|
137
|
-
):
|
|
138
|
-
return QueryResult(
|
|
139
|
-
ObjectManager().describe(object_type=object_type, fqn=object_name)
|
|
140
|
-
)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
@app.command(name="create", requires_connection=True)
|
|
144
|
-
def create(
|
|
145
|
-
object_type: str = ObjectArgument,
|
|
146
|
-
object_attributes: Optional[List[str]] = ObjectAttributesArgument,
|
|
147
|
-
object_json: str = ObjectDefinitionJsonOption,
|
|
148
|
-
**options,
|
|
149
|
-
):
|
|
150
|
-
"""
|
|
151
|
-
Create an object of a given type. Check documentation for the list of supported objects
|
|
152
|
-
and parameters.
|
|
153
|
-
"""
|
|
154
|
-
import json
|
|
155
|
-
|
|
156
|
-
if object_attributes and object_json:
|
|
157
|
-
raise IncompatibleParametersError(["object_attributes", "--json"])
|
|
158
|
-
|
|
159
|
-
if object_json:
|
|
160
|
-
object_data = json.loads(object_json)
|
|
161
|
-
elif object_attributes:
|
|
162
|
-
|
|
163
|
-
def _parse_if_json(value: str):
|
|
164
|
-
try:
|
|
165
|
-
return json.loads(value)
|
|
166
|
-
except json.JSONDecodeError:
|
|
167
|
-
return value
|
|
168
|
-
|
|
169
|
-
object_data = {
|
|
170
|
-
v.key: _parse_if_json(v.value)
|
|
171
|
-
for v in parse_key_value_variables(object_attributes)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
else:
|
|
175
|
-
raise ClickException(
|
|
176
|
-
"Provide either list of object attributes, or object definition in JSON format"
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
result = ObjectManager().create(object_type=object_type, object_data=object_data)
|
|
180
|
-
return MessageResult(result)
|
|
@@ -1,85 +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 dataclasses import dataclass
|
|
18
|
-
from typing import Optional
|
|
19
|
-
|
|
20
|
-
from click import ClickException
|
|
21
|
-
from snowflake.cli.api.commands.flags import OverrideableOption
|
|
22
|
-
from snowflake.cli.api.project.util import (
|
|
23
|
-
VALID_IDENTIFIER_REGEX,
|
|
24
|
-
is_valid_identifier,
|
|
25
|
-
to_string_literal,
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@dataclass
|
|
30
|
-
class Tag:
|
|
31
|
-
name: str
|
|
32
|
-
value: str
|
|
33
|
-
|
|
34
|
-
def __post_init__(self):
|
|
35
|
-
if not is_valid_identifier(self.name):
|
|
36
|
-
raise ValueError("name of a tag must be a valid Snowflake identifier")
|
|
37
|
-
|
|
38
|
-
def value_string_literal(self):
|
|
39
|
-
return to_string_literal(self.value)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class TagError(ClickException):
|
|
43
|
-
def __init__(self):
|
|
44
|
-
super().__init__(
|
|
45
|
-
"tag must be in the format <name>=<value> where 'name' is a valid identifier and value is a string"
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def _parse_tag(tag: str) -> Tag:
|
|
50
|
-
import re
|
|
51
|
-
|
|
52
|
-
identifier_pattern = rf"(?P<tag_name>{VALID_IDENTIFIER_REGEX})"
|
|
53
|
-
value_pattern = r"(?P<tag_value>.+)"
|
|
54
|
-
result = re.fullmatch(rf"{identifier_pattern}={value_pattern}", tag)
|
|
55
|
-
if result is not None:
|
|
56
|
-
try:
|
|
57
|
-
return Tag(result.group("tag_name"), result.group("tag_value"))
|
|
58
|
-
except ValueError:
|
|
59
|
-
raise TagError()
|
|
60
|
-
else:
|
|
61
|
-
raise TagError()
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"""
|
|
65
|
-
Provides a common interface for all commands that accept a tag option (e.g. when altering the tag of an object).
|
|
66
|
-
Parses the input string in the format "name=value" into a Tag object with 'name' and 'value' properties.
|
|
67
|
-
"""
|
|
68
|
-
TagOption = OverrideableOption(
|
|
69
|
-
None, "--tag", help=f"Tag for the object.", parser=_parse_tag, metavar="NAME=VALUE"
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
def _comment_callback(comment: Optional[str]):
|
|
74
|
-
if comment is None:
|
|
75
|
-
return comment
|
|
76
|
-
return to_string_literal(comment)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"""
|
|
80
|
-
Provides a common interface for all commands that accept a comment option (e.g. when creating a new object).
|
|
81
|
-
Parses the input string into a string literal.
|
|
82
|
-
"""
|
|
83
|
-
CommentOption = OverrideableOption(
|
|
84
|
-
None, "--comment", help="Comment for the object.", callback=_comment_callback
|
|
85
|
-
)
|
|
@@ -1,118 +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 typing import Any, Dict, Optional, Tuple, Union
|
|
18
|
-
|
|
19
|
-
from click import ClickException
|
|
20
|
-
from snowflake.cli.api.constants import (
|
|
21
|
-
OBJECT_TO_NAMES,
|
|
22
|
-
ObjectNames,
|
|
23
|
-
)
|
|
24
|
-
from snowflake.cli.api.identifiers import FQN
|
|
25
|
-
from snowflake.cli.api.rest_api import RestApi
|
|
26
|
-
from snowflake.cli.api.sql_execution import SqlExecutionMixin
|
|
27
|
-
from snowflake.connector import ProgrammingError
|
|
28
|
-
from snowflake.connector.cursor import SnowflakeCursor
|
|
29
|
-
from snowflake.connector.errors import BadRequest
|
|
30
|
-
from snowflake.connector.vendored.requests.exceptions import HTTPError
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def _get_object_names(object_type: str) -> ObjectNames:
|
|
34
|
-
object_type = object_type.lower()
|
|
35
|
-
if object_type.lower() not in OBJECT_TO_NAMES:
|
|
36
|
-
raise ClickException(f"Object of type {object_type} is not supported.")
|
|
37
|
-
return OBJECT_TO_NAMES[object_type]
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class ObjectManager(SqlExecutionMixin):
|
|
41
|
-
def show(
|
|
42
|
-
self,
|
|
43
|
-
*,
|
|
44
|
-
object_type: str,
|
|
45
|
-
like: Optional[str] = None,
|
|
46
|
-
scope: Union[Tuple[str, str], Tuple[None, None]] = (None, None),
|
|
47
|
-
**kwargs,
|
|
48
|
-
) -> SnowflakeCursor:
|
|
49
|
-
object_name = _get_object_names(object_type).sf_plural_name
|
|
50
|
-
query = f"show {object_name}"
|
|
51
|
-
if like:
|
|
52
|
-
query += f" like '{like}'"
|
|
53
|
-
if scope[0] is not None:
|
|
54
|
-
query += f" in {scope[0].replace('-', ' ')} {scope[1]}"
|
|
55
|
-
return self._execute_query(query, **kwargs)
|
|
56
|
-
|
|
57
|
-
def drop(self, *, object_type: str, fqn: FQN) -> SnowflakeCursor:
|
|
58
|
-
object_name = _get_object_names(object_type).sf_name
|
|
59
|
-
return self._execute_query(f"drop {object_name} {fqn.sql_identifier}")
|
|
60
|
-
|
|
61
|
-
def describe(self, *, object_type: str, fqn: FQN):
|
|
62
|
-
# Image repository is the only supported object that does not have a DESCRIBE command.
|
|
63
|
-
if object_type == "image-repository":
|
|
64
|
-
raise ClickException(
|
|
65
|
-
f"Describe is currently not supported for object of type image-repository"
|
|
66
|
-
)
|
|
67
|
-
object_name = _get_object_names(object_type).sf_name
|
|
68
|
-
return self._execute_query(f"describe {object_name} {fqn.sql_identifier}")
|
|
69
|
-
|
|
70
|
-
def object_exists(self, *, object_type: str, fqn: FQN):
|
|
71
|
-
try:
|
|
72
|
-
self.describe(object_type=object_type, fqn=fqn)
|
|
73
|
-
return True
|
|
74
|
-
except ProgrammingError:
|
|
75
|
-
return False
|
|
76
|
-
|
|
77
|
-
def create(self, object_type: str, object_data: Dict[str, Any]) -> str:
|
|
78
|
-
rest = RestApi(self._conn)
|
|
79
|
-
url = rest.determine_url_for_create_query(object_type=object_type)
|
|
80
|
-
try:
|
|
81
|
-
response = rest.send_rest_request(url=url, method="post", data=object_data)
|
|
82
|
-
except Exception as err:
|
|
83
|
-
_handle_create_error_codes(err)
|
|
84
|
-
return response["status"]
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
def _handle_create_error_codes(err: Exception) -> None:
|
|
88
|
-
# according to https://docs.snowflake.com/developer-guide/snowflake-rest-api/reference/
|
|
89
|
-
if isinstance(err, BadRequest):
|
|
90
|
-
raise ClickException(
|
|
91
|
-
"400 bad request: Incorrect object definition (arguments misspelled or malformatted)."
|
|
92
|
-
)
|
|
93
|
-
if isinstance(err, HTTPError):
|
|
94
|
-
match err_code := err.response.status_code:
|
|
95
|
-
case 401:
|
|
96
|
-
raise ClickException(
|
|
97
|
-
"401 unauthorized: role you are using does not have permissions to create this object."
|
|
98
|
-
)
|
|
99
|
-
# error 403 should be handled by connector
|
|
100
|
-
# error 404 is handled by determine-url logic
|
|
101
|
-
# error 405 should not happen under assumption that "all listable objects can be created"
|
|
102
|
-
case 408:
|
|
103
|
-
raise ClickException(
|
|
104
|
-
"408 timeout: the request timed out and was not completed by the server."
|
|
105
|
-
)
|
|
106
|
-
case 409:
|
|
107
|
-
raise ClickException(
|
|
108
|
-
"409 conflict: object you're trying to create already exists."
|
|
109
|
-
)
|
|
110
|
-
# error 410 is a network maintenance debugging - should not happen to the user
|
|
111
|
-
case 429:
|
|
112
|
-
raise ClickException(
|
|
113
|
-
"429 too many requests. The number of requests hit the rate limit."
|
|
114
|
-
)
|
|
115
|
-
case 500 | 503 | 504:
|
|
116
|
-
raise ClickException(f"{err_code} internal server error.")
|
|
117
|
-
case _:
|
|
118
|
-
raise err
|
|
@@ -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._plugins.object import commands
|
|
16
|
-
from snowflake.cli.api.plugins.command import (
|
|
17
|
-
SNOWCLI_ROOT_COMMAND_PATH,
|
|
18
|
-
CommandSpec,
|
|
19
|
-
CommandType,
|
|
20
|
-
plugin_hook_impl,
|
|
21
|
-
)
|
|
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.
|