snowflake-cli 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.
- snowflake/cli/__about__.py +17 -0
- snowflake/cli/__init__.py +13 -0
- snowflake/cli/api/__init__.py +48 -0
- snowflake/cli/api/cli_global_context.py +390 -0
- snowflake/cli/api/commands/__init__.py +13 -0
- snowflake/cli/api/commands/alias.py +23 -0
- snowflake/cli/api/commands/decorators.py +354 -0
- snowflake/cli/api/commands/execution_metadata.py +40 -0
- snowflake/cli/api/commands/experimental_behaviour.py +19 -0
- snowflake/cli/api/commands/flags.py +662 -0
- snowflake/cli/api/commands/project_initialisation.py +65 -0
- snowflake/cli/api/commands/snow_typer.py +237 -0
- snowflake/cli/api/commands/typer_pre_execute.py +26 -0
- snowflake/cli/api/config.py +348 -0
- snowflake/cli/api/console/__init__.py +17 -0
- snowflake/cli/api/console/abc.py +89 -0
- snowflake/cli/api/console/console.py +134 -0
- snowflake/cli/api/console/enum.py +17 -0
- snowflake/cli/api/constants.py +79 -0
- snowflake/cli/api/errno.py +27 -0
- snowflake/cli/api/exceptions.py +164 -0
- snowflake/cli/api/feature_flags.py +55 -0
- snowflake/cli/api/identifiers.py +167 -0
- snowflake/cli/api/output/__init__.py +13 -0
- snowflake/cli/api/output/formats.py +20 -0
- snowflake/cli/api/output/types.py +118 -0
- snowflake/cli/api/plugins/__init__.py +13 -0
- snowflake/cli/api/plugins/command/__init__.py +72 -0
- snowflake/cli/api/plugins/command/plugin_hook_specs.py +21 -0
- snowflake/cli/api/plugins/plugin_config.py +32 -0
- snowflake/cli/api/project/__init__.py +13 -0
- snowflake/cli/api/project/definition.py +84 -0
- snowflake/cli/api/project/definition_manager.py +134 -0
- snowflake/cli/api/project/errors.py +56 -0
- snowflake/cli/api/project/project_verification.py +23 -0
- snowflake/cli/api/project/schemas/__init__.py +13 -0
- snowflake/cli/api/project/schemas/entities/application_entity.py +44 -0
- snowflake/cli/api/project/schemas/entities/application_package_entity.py +66 -0
- snowflake/cli/api/project/schemas/entities/common.py +78 -0
- snowflake/cli/api/project/schemas/entities/entities.py +30 -0
- snowflake/cli/api/project/schemas/identifier_model.py +49 -0
- snowflake/cli/api/project/schemas/native_app/__init__.py +13 -0
- snowflake/cli/api/project/schemas/native_app/application.py +62 -0
- snowflake/cli/api/project/schemas/native_app/native_app.py +93 -0
- snowflake/cli/api/project/schemas/native_app/package.py +78 -0
- snowflake/cli/api/project/schemas/native_app/path_mapping.py +65 -0
- snowflake/cli/api/project/schemas/project_definition.py +199 -0
- snowflake/cli/api/project/schemas/snowpark/__init__.py +13 -0
- snowflake/cli/api/project/schemas/snowpark/argument.py +28 -0
- snowflake/cli/api/project/schemas/snowpark/callable.py +69 -0
- snowflake/cli/api/project/schemas/snowpark/snowpark.py +36 -0
- snowflake/cli/api/project/schemas/streamlit/__init__.py +13 -0
- snowflake/cli/api/project/schemas/streamlit/streamlit.py +46 -0
- snowflake/cli/api/project/schemas/template.py +77 -0
- snowflake/cli/api/project/schemas/updatable_model.py +194 -0
- snowflake/cli/api/project/util.py +261 -0
- snowflake/cli/api/rendering/__init__.py +13 -0
- snowflake/cli/api/rendering/jinja.py +112 -0
- snowflake/cli/api/rendering/project_definition_templates.py +39 -0
- snowflake/cli/api/rendering/project_templates.py +98 -0
- snowflake/cli/api/rendering/sql_templates.py +60 -0
- snowflake/cli/api/rest_api.py +172 -0
- snowflake/cli/api/sanitizers.py +43 -0
- snowflake/cli/api/secure_path.py +362 -0
- snowflake/cli/api/secure_utils.py +29 -0
- snowflake/cli/api/sql_execution.py +260 -0
- snowflake/cli/api/utils/__init__.py +13 -0
- snowflake/cli/api/utils/cursor.py +34 -0
- snowflake/cli/api/utils/definition_rendering.py +383 -0
- snowflake/cli/api/utils/dict_utils.py +73 -0
- snowflake/cli/api/utils/error_handling.py +23 -0
- snowflake/cli/api/utils/graph.py +97 -0
- snowflake/cli/api/utils/models.py +63 -0
- snowflake/cli/api/utils/naming_utils.py +13 -0
- snowflake/cli/api/utils/path_utils.py +36 -0
- snowflake/cli/api/utils/templating_functions.py +144 -0
- snowflake/cli/api/utils/types.py +35 -0
- snowflake/cli/app/__init__.py +22 -0
- snowflake/cli/app/__main__.py +31 -0
- snowflake/cli/app/api_impl/__init__.py +13 -0
- snowflake/cli/app/api_impl/plugin/__init__.py +13 -0
- snowflake/cli/app/api_impl/plugin/plugin_config_provider_impl.py +66 -0
- snowflake/cli/app/build_and_push.sh +8 -0
- snowflake/cli/app/cli_app.py +243 -0
- snowflake/cli/app/commands_registration/__init__.py +33 -0
- snowflake/cli/app/commands_registration/builtin_plugins.py +54 -0
- snowflake/cli/app/commands_registration/command_plugins_loader.py +169 -0
- snowflake/cli/app/commands_registration/commands_registration_with_callbacks.py +105 -0
- snowflake/cli/app/commands_registration/exception_logging.py +26 -0
- snowflake/cli/app/commands_registration/threadsafe.py +48 -0
- snowflake/cli/app/commands_registration/typer_registration.py +153 -0
- snowflake/cli/app/constants.py +19 -0
- snowflake/cli/app/dev/__init__.py +13 -0
- snowflake/cli/app/dev/commands_structure.py +48 -0
- snowflake/cli/app/dev/docs/__init__.py +13 -0
- snowflake/cli/app/dev/docs/commands_docs_generator.py +100 -0
- snowflake/cli/app/dev/docs/generator.py +35 -0
- snowflake/cli/app/dev/docs/project_definition_docs_generator.py +58 -0
- snowflake/cli/app/dev/docs/project_definition_generate_json_schema.py +227 -0
- snowflake/cli/app/dev/docs/template_utils.py +23 -0
- snowflake/cli/app/dev/docs/templates/definition_description.rst.jinja2 +38 -0
- snowflake/cli/app/dev/docs/templates/overview.rst.jinja2 +9 -0
- snowflake/cli/app/dev/docs/templates/usage.rst.jinja2 +57 -0
- snowflake/cli/app/dev/pycharm_remote_debug.py +46 -0
- snowflake/cli/app/loggers.py +199 -0
- snowflake/cli/app/main_typer.py +62 -0
- snowflake/cli/app/printing.py +181 -0
- snowflake/cli/app/snow_connector.py +243 -0
- snowflake/cli/app/telemetry.py +189 -0
- snowflake/cli/plugins/__init__.py +13 -0
- snowflake/cli/plugins/connection/__init__.py +13 -0
- snowflake/cli/plugins/connection/commands.py +330 -0
- snowflake/cli/plugins/connection/plugin_spec.py +30 -0
- snowflake/cli/plugins/connection/util.py +179 -0
- snowflake/cli/plugins/cortex/__init__.py +13 -0
- snowflake/cli/plugins/cortex/commands.py +327 -0
- snowflake/cli/plugins/cortex/constants.py +17 -0
- snowflake/cli/plugins/cortex/manager.py +189 -0
- snowflake/cli/plugins/cortex/plugin_spec.py +30 -0
- snowflake/cli/plugins/cortex/types.py +22 -0
- snowflake/cli/plugins/git/__init__.py +13 -0
- snowflake/cli/plugins/git/commands.py +354 -0
- snowflake/cli/plugins/git/manager.py +105 -0
- snowflake/cli/plugins/git/plugin_spec.py +30 -0
- snowflake/cli/plugins/init/__init__.py +13 -0
- snowflake/cli/plugins/init/commands.py +248 -0
- snowflake/cli/plugins/init/plugin_spec.py +30 -0
- snowflake/cli/plugins/nativeapp/__init__.py +13 -0
- snowflake/cli/plugins/nativeapp/artifacts.py +742 -0
- snowflake/cli/plugins/nativeapp/codegen/__init__.py +13 -0
- snowflake/cli/plugins/nativeapp/codegen/artifact_processor.py +91 -0
- snowflake/cli/plugins/nativeapp/codegen/compiler.py +130 -0
- snowflake/cli/plugins/nativeapp/codegen/sandbox.py +306 -0
- snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +172 -0
- snowflake/cli/plugins/nativeapp/codegen/setup/setup_driver.py.source +56 -0
- snowflake/cli/plugins/nativeapp/codegen/snowpark/callback_source.py.jinja +181 -0
- snowflake/cli/plugins/nativeapp/codegen/snowpark/extension_function_utils.py +217 -0
- snowflake/cli/plugins/nativeapp/codegen/snowpark/models.py +61 -0
- snowflake/cli/plugins/nativeapp/codegen/snowpark/python_processor.py +528 -0
- snowflake/cli/plugins/nativeapp/commands.py +439 -0
- snowflake/cli/plugins/nativeapp/common_flags.py +44 -0
- snowflake/cli/plugins/nativeapp/constants.py +27 -0
- snowflake/cli/plugins/nativeapp/exceptions.py +122 -0
- snowflake/cli/plugins/nativeapp/feature_flags.py +24 -0
- snowflake/cli/plugins/nativeapp/init.py +345 -0
- snowflake/cli/plugins/nativeapp/manager.py +823 -0
- snowflake/cli/plugins/nativeapp/plugin_spec.py +30 -0
- snowflake/cli/plugins/nativeapp/policy.py +50 -0
- snowflake/cli/plugins/nativeapp/project_model.py +195 -0
- snowflake/cli/plugins/nativeapp/run_processor.py +389 -0
- snowflake/cli/plugins/nativeapp/teardown_processor.py +301 -0
- snowflake/cli/plugins/nativeapp/utils.py +98 -0
- snowflake/cli/plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +135 -0
- snowflake/cli/plugins/nativeapp/version/__init__.py +13 -0
- snowflake/cli/plugins/nativeapp/version/commands.py +170 -0
- snowflake/cli/plugins/nativeapp/version/version_processor.py +362 -0
- snowflake/cli/plugins/notebook/__init__.py +13 -0
- snowflake/cli/plugins/notebook/commands.py +85 -0
- snowflake/cli/plugins/notebook/exceptions.py +20 -0
- snowflake/cli/plugins/notebook/manager.py +71 -0
- snowflake/cli/plugins/notebook/plugin_spec.py +30 -0
- snowflake/cli/plugins/notebook/types.py +15 -0
- snowflake/cli/plugins/object/__init__.py +13 -0
- snowflake/cli/plugins/object/command_aliases.py +95 -0
- snowflake/cli/plugins/object/commands.py +181 -0
- snowflake/cli/plugins/object/common.py +85 -0
- snowflake/cli/plugins/object/manager.py +97 -0
- snowflake/cli/plugins/object/plugin_spec.py +30 -0
- snowflake/cli/plugins/object_stage_deprecated/__init__.py +15 -0
- snowflake/cli/plugins/object_stage_deprecated/commands.py +122 -0
- snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +32 -0
- snowflake/cli/plugins/snowpark/__init__.py +13 -0
- snowflake/cli/plugins/snowpark/commands.py +546 -0
- snowflake/cli/plugins/snowpark/common.py +307 -0
- snowflake/cli/plugins/snowpark/manager.py +109 -0
- snowflake/cli/plugins/snowpark/models.py +157 -0
- snowflake/cli/plugins/snowpark/package/__init__.py +13 -0
- snowflake/cli/plugins/snowpark/package/anaconda_packages.py +233 -0
- snowflake/cli/plugins/snowpark/package/commands.py +256 -0
- snowflake/cli/plugins/snowpark/package/manager.py +44 -0
- snowflake/cli/plugins/snowpark/package/utils.py +26 -0
- snowflake/cli/plugins/snowpark/package_utils.py +354 -0
- snowflake/cli/plugins/snowpark/plugin_spec.py +30 -0
- snowflake/cli/plugins/snowpark/snowpark_package_paths.py +65 -0
- snowflake/cli/plugins/snowpark/snowpark_shared.py +95 -0
- snowflake/cli/plugins/snowpark/zipper.py +81 -0
- snowflake/cli/plugins/spcs/__init__.py +35 -0
- snowflake/cli/plugins/spcs/common.py +99 -0
- snowflake/cli/plugins/spcs/compute_pool/__init__.py +13 -0
- snowflake/cli/plugins/spcs/compute_pool/commands.py +241 -0
- snowflake/cli/plugins/spcs/compute_pool/manager.py +121 -0
- snowflake/cli/plugins/spcs/image_registry/__init__.py +13 -0
- snowflake/cli/plugins/spcs/image_registry/commands.py +65 -0
- snowflake/cli/plugins/spcs/image_registry/manager.py +105 -0
- snowflake/cli/plugins/spcs/image_repository/__init__.py +13 -0
- snowflake/cli/plugins/spcs/image_repository/commands.py +202 -0
- snowflake/cli/plugins/spcs/image_repository/manager.py +84 -0
- snowflake/cli/plugins/spcs/jobs/__init__.py +13 -0
- snowflake/cli/plugins/spcs/jobs/commands.py +78 -0
- snowflake/cli/plugins/spcs/jobs/manager.py +53 -0
- snowflake/cli/plugins/spcs/plugin_spec.py +30 -0
- snowflake/cli/plugins/spcs/services/__init__.py +13 -0
- snowflake/cli/plugins/spcs/services/commands.py +312 -0
- snowflake/cli/plugins/spcs/services/manager.py +170 -0
- snowflake/cli/plugins/sql/__init__.py +13 -0
- snowflake/cli/plugins/sql/commands.py +83 -0
- snowflake/cli/plugins/sql/manager.py +92 -0
- snowflake/cli/plugins/sql/plugin_spec.py +30 -0
- snowflake/cli/plugins/sql/snowsql_templating.py +28 -0
- snowflake/cli/plugins/stage/__init__.py +13 -0
- snowflake/cli/plugins/stage/commands.py +263 -0
- snowflake/cli/plugins/stage/diff.py +326 -0
- snowflake/cli/plugins/stage/manager.py +577 -0
- snowflake/cli/plugins/stage/md5.py +160 -0
- snowflake/cli/plugins/stage/plugin_spec.py +30 -0
- snowflake/cli/plugins/streamlit/__init__.py +13 -0
- snowflake/cli/plugins/streamlit/commands.py +179 -0
- snowflake/cli/plugins/streamlit/manager.py +222 -0
- snowflake/cli/plugins/streamlit/plugin_spec.py +30 -0
- snowflake/cli/plugins/workspace/__init__.py +13 -0
- snowflake/cli/plugins/workspace/commands.py +35 -0
- snowflake/cli/plugins/workspace/plugin_spec.py +30 -0
- snowflake/cli/templates/default_snowpark/.gitignore +4 -0
- snowflake/cli/templates/default_snowpark/app/__init__.py +0 -0
- snowflake/cli/templates/default_snowpark/app/common.py +2 -0
- snowflake/cli/templates/default_snowpark/app/functions.py +15 -0
- snowflake/cli/templates/default_snowpark/app/procedures.py +22 -0
- snowflake/cli/templates/default_snowpark/requirements.txt +1 -0
- snowflake/cli/templates/default_snowpark/snowflake.yml +23 -0
- snowflake/cli/templates/default_streamlit/.gitignore +4 -0
- snowflake/cli/templates/default_streamlit/common/hello.py +2 -0
- snowflake/cli/templates/default_streamlit/environment.yml +6 -0
- snowflake/cli/templates/default_streamlit/pages/my_page.py +3 -0
- snowflake/cli/templates/default_streamlit/snowflake.yml +10 -0
- snowflake/cli/templates/default_streamlit/streamlit_app.py +4 -0
- snowflake_cli-2.8.2.dist-info/METADATA +325 -0
- snowflake_cli-2.8.2.dist-info/RECORD +240 -0
- snowflake_cli-2.8.2.dist-info/WHEEL +4 -0
- snowflake_cli-2.8.2.dist-info/entry_points.txt +2 -0
- snowflake_cli-2.8.2.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,354 @@
|
|
|
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 inspect
|
|
18
|
+
from functools import wraps
|
|
19
|
+
from inspect import Signature
|
|
20
|
+
from typing import Callable, Dict, List, Optional, get_type_hints
|
|
21
|
+
|
|
22
|
+
from snowflake.cli.api.cli_global_context import cli_context
|
|
23
|
+
from snowflake.cli.api.commands.flags import (
|
|
24
|
+
AccountOption,
|
|
25
|
+
AuthenticatorOption,
|
|
26
|
+
ConnectionOption,
|
|
27
|
+
DatabaseOption,
|
|
28
|
+
DebugOption,
|
|
29
|
+
DiagAllowlistPathOption,
|
|
30
|
+
DiagLogPathOption,
|
|
31
|
+
EnableDiagOption,
|
|
32
|
+
MasterTokenOption,
|
|
33
|
+
MfaPasscodeOption,
|
|
34
|
+
OutputFormatOption,
|
|
35
|
+
PasswordOption,
|
|
36
|
+
PrivateKeyPathOption,
|
|
37
|
+
RoleOption,
|
|
38
|
+
SchemaOption,
|
|
39
|
+
SessionTokenOption,
|
|
40
|
+
SilentOption,
|
|
41
|
+
TemporaryConnectionOption,
|
|
42
|
+
TokenFilePathOption,
|
|
43
|
+
UserOption,
|
|
44
|
+
VerboseOption,
|
|
45
|
+
WarehouseOption,
|
|
46
|
+
experimental_option,
|
|
47
|
+
project_definition_option,
|
|
48
|
+
project_env_overrides_option,
|
|
49
|
+
)
|
|
50
|
+
from snowflake.cli.api.exceptions import CommandReturnTypeError
|
|
51
|
+
from snowflake.cli.api.output.formats import OutputFormat
|
|
52
|
+
from snowflake.cli.api.output.types import CommandResult
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def global_options(func: Callable):
|
|
56
|
+
"""
|
|
57
|
+
Decorator providing default flags for overriding global parameters. Values are
|
|
58
|
+
updated in global SnowCLI state.
|
|
59
|
+
|
|
60
|
+
To use this decorator your command needs to accept **options as last argument.
|
|
61
|
+
"""
|
|
62
|
+
return _global_options_decorator_factory(func, GLOBAL_OPTIONS)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def global_options_with_connection(func: Callable):
|
|
66
|
+
"""
|
|
67
|
+
Decorator providing default flags including connection flags for overriding
|
|
68
|
+
global parameters. Values are updated in global SnowCLI state.
|
|
69
|
+
|
|
70
|
+
To use this decorator your command needs to accept **options as last argument.
|
|
71
|
+
"""
|
|
72
|
+
return _global_options_decorator_factory(
|
|
73
|
+
func, [*GLOBAL_CONNECTION_OPTIONS, *GLOBAL_OPTIONS]
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def with_project_definition(is_optional: bool = False):
|
|
78
|
+
def _decorator(func: Callable):
|
|
79
|
+
|
|
80
|
+
return _options_decorator_factory(
|
|
81
|
+
func,
|
|
82
|
+
additional_options=[
|
|
83
|
+
inspect.Parameter(
|
|
84
|
+
"project_definition",
|
|
85
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
86
|
+
annotation=Optional[str],
|
|
87
|
+
default=project_definition_option(is_optional),
|
|
88
|
+
),
|
|
89
|
+
inspect.Parameter(
|
|
90
|
+
"env_overrides",
|
|
91
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
92
|
+
annotation=List[str],
|
|
93
|
+
default=project_env_overrides_option(),
|
|
94
|
+
),
|
|
95
|
+
],
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
return _decorator
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def with_experimental_behaviour(
|
|
102
|
+
experimental_behaviour_description: Optional[str] = None,
|
|
103
|
+
):
|
|
104
|
+
"""
|
|
105
|
+
Decorator providing --experimental flag, which allows to use experimental behaviour in commands implementation.
|
|
106
|
+
|
|
107
|
+
To use this decorator your command needs to accept **options as last argument.
|
|
108
|
+
"""
|
|
109
|
+
additional_options = [
|
|
110
|
+
inspect.Parameter(
|
|
111
|
+
"experimental",
|
|
112
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
113
|
+
annotation=Optional[bool],
|
|
114
|
+
default=experimental_option(experimental_behaviour_description),
|
|
115
|
+
),
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
def decorator(func: Callable):
|
|
119
|
+
return _options_decorator_factory(
|
|
120
|
+
func=func,
|
|
121
|
+
additional_options=additional_options,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
return decorator
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def _execute_before_command_using_global_options(**options):
|
|
128
|
+
from snowflake.cli.app.loggers import create_loggers
|
|
129
|
+
|
|
130
|
+
create_loggers(cli_context.verbose, cli_context.enable_tracebacks)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _global_options_decorator_factory(
|
|
134
|
+
func: Callable, additional_options: List[inspect.Parameter]
|
|
135
|
+
):
|
|
136
|
+
return _options_decorator_factory(
|
|
137
|
+
func=func,
|
|
138
|
+
additional_options=additional_options,
|
|
139
|
+
execute_before_command_using_new_options=_execute_before_command_using_global_options,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _options_decorator_factory(
|
|
144
|
+
func: Callable,
|
|
145
|
+
additional_options: List[inspect.Parameter],
|
|
146
|
+
execute_before_command_using_new_options: Optional[Callable] = None,
|
|
147
|
+
):
|
|
148
|
+
"""
|
|
149
|
+
execute_before_command_using_new_options executes before command telemetry has been emitted,
|
|
150
|
+
but after command line options have been populated.
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
@wraps(func)
|
|
154
|
+
def wrapper(**options):
|
|
155
|
+
if execute_before_command_using_new_options:
|
|
156
|
+
execute_before_command_using_new_options(**options)
|
|
157
|
+
return func(**options)
|
|
158
|
+
|
|
159
|
+
wrapper.__signature__ = _extend_signature_with_additional_options(func, additional_options) # type: ignore
|
|
160
|
+
return wrapper
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _extend_signature_with_additional_options(
|
|
164
|
+
func: Callable, additional_options: List[inspect.Parameter]
|
|
165
|
+
) -> Signature:
|
|
166
|
+
"""Extends function signature with additional options"""
|
|
167
|
+
sig = inspect.signature(func)
|
|
168
|
+
|
|
169
|
+
# Remove **options from signature
|
|
170
|
+
existing_parameters = tuple(
|
|
171
|
+
[p for p in sig.parameters.values() if not _is_options_parameter(p)]
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
type_hints = get_type_hints(func)
|
|
175
|
+
existing_parameters_with_evaluated_types = [
|
|
176
|
+
_evaluate_param_type(p, type_hints) for p in existing_parameters
|
|
177
|
+
]
|
|
178
|
+
parameters = [
|
|
179
|
+
*existing_parameters_with_evaluated_types,
|
|
180
|
+
*additional_options,
|
|
181
|
+
]
|
|
182
|
+
return sig.replace(parameters=parameters)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def _is_options_parameter(param: inspect.Parameter) -> bool:
|
|
186
|
+
return param.kind == inspect.Parameter.VAR_KEYWORD and param.name == "options"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _evaluate_param_type(
|
|
190
|
+
param: inspect.Parameter, type_hints: Dict[str, type]
|
|
191
|
+
) -> inspect.Parameter:
|
|
192
|
+
type_annotation = (
|
|
193
|
+
type_hints.get(param.annotation)
|
|
194
|
+
if isinstance(param.annotation, str)
|
|
195
|
+
else param.annotation
|
|
196
|
+
)
|
|
197
|
+
return inspect.Parameter(
|
|
198
|
+
name=param.name,
|
|
199
|
+
kind=param.kind,
|
|
200
|
+
annotation=type_annotation,
|
|
201
|
+
default=param.default,
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
GLOBAL_CONNECTION_OPTIONS = [
|
|
206
|
+
inspect.Parameter(
|
|
207
|
+
"connection",
|
|
208
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
209
|
+
annotation=Optional[str],
|
|
210
|
+
default=ConnectionOption,
|
|
211
|
+
),
|
|
212
|
+
inspect.Parameter(
|
|
213
|
+
"account",
|
|
214
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
215
|
+
annotation=Optional[str],
|
|
216
|
+
default=AccountOption,
|
|
217
|
+
),
|
|
218
|
+
inspect.Parameter(
|
|
219
|
+
"user",
|
|
220
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
221
|
+
annotation=Optional[str],
|
|
222
|
+
default=UserOption,
|
|
223
|
+
),
|
|
224
|
+
inspect.Parameter(
|
|
225
|
+
"password",
|
|
226
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
227
|
+
annotation=Optional[str],
|
|
228
|
+
default=PasswordOption,
|
|
229
|
+
),
|
|
230
|
+
inspect.Parameter(
|
|
231
|
+
"authenticator",
|
|
232
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
233
|
+
annotation=Optional[str],
|
|
234
|
+
default=AuthenticatorOption,
|
|
235
|
+
),
|
|
236
|
+
inspect.Parameter(
|
|
237
|
+
"private_key_path",
|
|
238
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
239
|
+
annotation=Optional[str],
|
|
240
|
+
default=PrivateKeyPathOption,
|
|
241
|
+
),
|
|
242
|
+
inspect.Parameter(
|
|
243
|
+
"session_token",
|
|
244
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
245
|
+
annotation=Optional[str],
|
|
246
|
+
default=SessionTokenOption,
|
|
247
|
+
),
|
|
248
|
+
inspect.Parameter(
|
|
249
|
+
"master_token",
|
|
250
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
251
|
+
annotation=Optional[str],
|
|
252
|
+
default=MasterTokenOption,
|
|
253
|
+
),
|
|
254
|
+
inspect.Parameter(
|
|
255
|
+
"token_file_path",
|
|
256
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
257
|
+
annotation=Optional[str],
|
|
258
|
+
default=TokenFilePathOption,
|
|
259
|
+
),
|
|
260
|
+
inspect.Parameter(
|
|
261
|
+
"database",
|
|
262
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
263
|
+
annotation=Optional[str],
|
|
264
|
+
default=DatabaseOption,
|
|
265
|
+
),
|
|
266
|
+
inspect.Parameter(
|
|
267
|
+
"schema",
|
|
268
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
269
|
+
annotation=Optional[str],
|
|
270
|
+
default=SchemaOption,
|
|
271
|
+
),
|
|
272
|
+
inspect.Parameter(
|
|
273
|
+
"role",
|
|
274
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
275
|
+
annotation=Optional[str],
|
|
276
|
+
default=RoleOption,
|
|
277
|
+
),
|
|
278
|
+
inspect.Parameter(
|
|
279
|
+
"warehouse",
|
|
280
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
281
|
+
annotation=Optional[str],
|
|
282
|
+
default=WarehouseOption,
|
|
283
|
+
),
|
|
284
|
+
inspect.Parameter(
|
|
285
|
+
"temporary_connection",
|
|
286
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
287
|
+
annotation=Optional[bool],
|
|
288
|
+
default=TemporaryConnectionOption,
|
|
289
|
+
),
|
|
290
|
+
inspect.Parameter(
|
|
291
|
+
"mfa_passcode",
|
|
292
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
293
|
+
annotation=Optional[str],
|
|
294
|
+
default=MfaPasscodeOption,
|
|
295
|
+
),
|
|
296
|
+
inspect.Parameter(
|
|
297
|
+
"enable_diag",
|
|
298
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
299
|
+
annotation=Optional[bool],
|
|
300
|
+
default=EnableDiagOption,
|
|
301
|
+
),
|
|
302
|
+
inspect.Parameter(
|
|
303
|
+
"diag_log_path",
|
|
304
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
305
|
+
annotation=Optional[str],
|
|
306
|
+
default=DiagLogPathOption,
|
|
307
|
+
),
|
|
308
|
+
inspect.Parameter(
|
|
309
|
+
"diag_allowlist_path",
|
|
310
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
311
|
+
annotation=Optional[str],
|
|
312
|
+
default=DiagAllowlistPathOption,
|
|
313
|
+
),
|
|
314
|
+
]
|
|
315
|
+
|
|
316
|
+
GLOBAL_OPTIONS = [
|
|
317
|
+
inspect.Parameter(
|
|
318
|
+
"format",
|
|
319
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
320
|
+
annotation=OutputFormat,
|
|
321
|
+
default=OutputFormatOption,
|
|
322
|
+
),
|
|
323
|
+
inspect.Parameter(
|
|
324
|
+
"verbose",
|
|
325
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
326
|
+
annotation=Optional[bool],
|
|
327
|
+
default=VerboseOption,
|
|
328
|
+
),
|
|
329
|
+
inspect.Parameter(
|
|
330
|
+
"debug",
|
|
331
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
332
|
+
annotation=Optional[bool],
|
|
333
|
+
default=DebugOption,
|
|
334
|
+
),
|
|
335
|
+
inspect.Parameter(
|
|
336
|
+
"silent",
|
|
337
|
+
inspect.Parameter.KEYWORD_ONLY,
|
|
338
|
+
annotation=Optional[bool],
|
|
339
|
+
default=SilentOption,
|
|
340
|
+
),
|
|
341
|
+
]
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
def with_output(func):
|
|
345
|
+
from snowflake.cli.app.printing import print_result
|
|
346
|
+
|
|
347
|
+
@wraps(func)
|
|
348
|
+
def wrapper(*args, **kwargs):
|
|
349
|
+
output_data = func(*args, **kwargs)
|
|
350
|
+
if not isinstance(output_data, CommandResult):
|
|
351
|
+
raise CommandReturnTypeError(type(output_data))
|
|
352
|
+
print_result(output_data)
|
|
353
|
+
|
|
354
|
+
return wrapper
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
import time
|
|
15
|
+
import uuid
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
|
+
from enum import Enum
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class ExecutionStatus(Enum):
|
|
21
|
+
SUCCESS = "success"
|
|
22
|
+
FAILURE = "failure"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass
|
|
26
|
+
class ExecutionMetadata:
|
|
27
|
+
start_time: float = 0.0
|
|
28
|
+
end_time: float = 0.0
|
|
29
|
+
status: ExecutionStatus = ExecutionStatus.SUCCESS
|
|
30
|
+
execution_id: str = field(default_factory=lambda: uuid.uuid4().hex)
|
|
31
|
+
|
|
32
|
+
def __post_init__(self):
|
|
33
|
+
self.start_time = time.monotonic()
|
|
34
|
+
|
|
35
|
+
def complete(self, status: ExecutionStatus):
|
|
36
|
+
self.end_time = time.monotonic()
|
|
37
|
+
self.status = status
|
|
38
|
+
|
|
39
|
+
def get_duration(self):
|
|
40
|
+
return self.end_time - self.start_time
|
|
@@ -0,0 +1,19 @@
|
|
|
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.cli_global_context import cli_context
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def experimental_behaviour_enabled() -> bool:
|
|
19
|
+
return cli_context.experimental
|