snowflake-cli-labs 2.8.1__py3-none-any.whl → 3.0.0__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 +1 -1
- snowflake/cli/{app → _app}/__main__.py +1 -1
- snowflake/cli/{app → _app}/cli_app.py +22 -13
- snowflake/cli/{app → _app}/commands_registration/builtin_plugins.py +15 -19
- snowflake/cli/{app → _app}/commands_registration/command_plugins_loader.py +9 -9
- snowflake/cli/{app → _app}/commands_registration/commands_registration_with_callbacks.py +4 -4
- snowflake/cli/{app → _app}/commands_registration/exception_logging.py +2 -2
- snowflake/cli/{app → _app}/commands_registration/typer_registration.py +2 -2
- snowflake/cli/{app → _app}/dev/docs/commands_docs_generator.py +30 -12
- snowflake/cli/{app → _app}/dev/docs/generator.py +3 -3
- snowflake/cli/{app → _app}/dev/docs/project_definition_docs_generator.py +4 -4
- snowflake/cli/{app → _app}/dev/docs/templates/usage.rst.jinja2 +14 -4
- snowflake/cli/{app → _app}/main_typer.py +2 -2
- snowflake/cli/{app → _app}/printing.py +2 -2
- snowflake/cli/_app/secret.py +9 -0
- snowflake/cli/{app → _app}/snow_connector.py +127 -61
- snowflake/cli/{app → _app}/telemetry.py +38 -7
- snowflake/cli/_app/version_check.py +74 -0
- snowflake/cli/{plugins → _plugins}/connection/commands.py +34 -11
- snowflake/cli/_plugins/connection/plugin_spec.py +30 -0
- snowflake/cli/{plugins → _plugins}/connection/util.py +16 -0
- snowflake/cli/{plugins → _plugins}/cortex/commands.py +54 -49
- snowflake/cli/{plugins → _plugins}/cortex/constants.py +1 -1
- snowflake/cli/{plugins → _plugins}/cortex/manager.py +5 -5
- snowflake/cli/{plugins → _plugins}/cortex/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/git/commands.py +11 -7
- snowflake/cli/{plugins → _plugins}/git/manager.py +55 -9
- snowflake/cli/{plugins → _plugins}/git/plugin_spec.py +1 -1
- snowflake/cli/_plugins/helpers/commands.py +90 -0
- snowflake/cli/{plugins/notebook → _plugins/helpers}/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/init/commands.py +2 -2
- snowflake/cli/{plugins → _plugins}/init/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/artifacts.py +24 -9
- snowflake/cli/_plugins/nativeapp/bundle_context.py +31 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/artifact_processor.py +4 -4
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/compiler.py +37 -18
- snowflake/cli/_plugins/nativeapp/codegen/setup/native_app_setup_processor.py +249 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/setup/setup_driver.py.source +5 -2
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/extension_function_utils.py +5 -5
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/models.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/python_processor.py +29 -34
- snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +114 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/commands.py +252 -132
- snowflake/cli/{plugins → _plugins}/nativeapp/common_flags.py +1 -1
- snowflake/cli/_plugins/nativeapp/entities/application.py +878 -0
- snowflake/cli/_plugins/nativeapp/entities/application_package.py +1392 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/exceptions.py +3 -12
- snowflake/cli/_plugins/nativeapp/manager.py +415 -0
- snowflake/cli/{plugins/connection → _plugins/nativeapp}/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/nativeapp/policy.py +3 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/project_model.py +36 -20
- snowflake/cli/_plugins/nativeapp/run_processor.py +184 -0
- snowflake/cli/_plugins/nativeapp/same_account_install_method.py +70 -0
- snowflake/cli/_plugins/nativeapp/teardown_processor.py +70 -0
- snowflake/cli/_plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +262 -0
- snowflake/cli/{plugins → _plugins}/nativeapp/version/commands.py +20 -49
- snowflake/cli/_plugins/nativeapp/version/version_processor.py +98 -0
- snowflake/cli/{plugins → _plugins}/notebook/commands.py +3 -2
- snowflake/cli/{plugins → _plugins}/notebook/manager.py +5 -5
- snowflake/cli/{plugins/nativeapp → _plugins/notebook}/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/object/command_aliases.py +4 -4
- snowflake/cli/{plugins → _plugins}/object/commands.py +4 -5
- snowflake/cli/{plugins → _plugins}/object/manager.py +36 -15
- snowflake/cli/{plugins → _plugins}/object/plugin_spec.py +1 -1
- snowflake/cli/_plugins/snowpark/commands.py +450 -0
- snowflake/cli/_plugins/snowpark/common.py +268 -0
- snowflake/cli/{plugins → _plugins}/snowpark/models.py +0 -7
- snowflake/cli/{plugins → _plugins}/snowpark/package/anaconda_packages.py +2 -36
- snowflake/cli/{plugins → _plugins}/snowpark/package/commands.py +13 -74
- snowflake/cli/{plugins → _plugins}/snowpark/package/manager.py +2 -2
- snowflake/cli/{plugins → _plugins}/snowpark/package_utils.py +5 -5
- snowflake/cli/_plugins/snowpark/plugin_spec.py +30 -0
- snowflake/cli/_plugins/snowpark/snowpark_entity.py +29 -0
- snowflake/cli/_plugins/snowpark/snowpark_entity_model.py +173 -0
- snowflake/cli/_plugins/snowpark/snowpark_project_paths.py +109 -0
- snowflake/cli/{plugins → _plugins}/snowpark/snowpark_shared.py +0 -36
- snowflake/cli/{plugins → _plugins}/snowpark/zipper.py +16 -8
- snowflake/cli/{plugins → _plugins}/spcs/__init__.py +5 -7
- snowflake/cli/{plugins → _plugins}/spcs/compute_pool/commands.py +8 -8
- snowflake/cli/{plugins → _plugins}/spcs/compute_pool/manager.py +3 -3
- snowflake/cli/{plugins → _plugins}/spcs/image_registry/commands.py +3 -3
- snowflake/cli/{plugins → _plugins}/spcs/image_repository/commands.py +6 -6
- snowflake/cli/{plugins → _plugins}/spcs/image_repository/manager.py +1 -1
- snowflake/cli/{plugins → _plugins}/spcs/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/spcs/services/commands.py +44 -11
- snowflake/cli/{plugins → _plugins}/spcs/services/manager.py +43 -5
- snowflake/cli/{plugins → _plugins}/sql/commands.py +20 -17
- snowflake/cli/{plugins → _plugins}/sql/manager.py +1 -1
- snowflake/cli/{plugins → _plugins}/sql/plugin_spec.py +1 -1
- snowflake/cli/{plugins → _plugins}/stage/commands.py +15 -14
- snowflake/cli/{plugins → _plugins}/stage/diff.py +1 -47
- snowflake/cli/{plugins → _plugins}/stage/manager.py +12 -7
- snowflake/cli/{plugins → _plugins}/stage/plugin_spec.py +1 -1
- snowflake/cli/_plugins/stage/utils.py +54 -0
- snowflake/cli/{plugins → _plugins}/streamlit/commands.py +64 -48
- snowflake/cli/{plugins → _plugins}/streamlit/manager.py +67 -69
- snowflake/cli/_plugins/streamlit/plugin_spec.py +30 -0
- snowflake/cli/_plugins/streamlit/streamlit_entity.py +12 -0
- snowflake/cli/_plugins/streamlit/streamlit_entity_model.py +66 -0
- snowflake/cli/_plugins/workspace/action_context.py +18 -0
- snowflake/cli/_plugins/workspace/commands.py +306 -0
- snowflake/cli/_plugins/workspace/manager.py +74 -0
- snowflake/cli/_plugins/workspace/plugin_spec.py +30 -0
- snowflake/cli/api/cli_global_context.py +152 -295
- snowflake/cli/api/commands/common.py +25 -0
- snowflake/cli/api/commands/decorators.py +19 -4
- snowflake/cli/api/commands/experimental_behaviour.py +2 -3
- snowflake/cli/api/commands/flags.py +127 -228
- snowflake/cli/api/commands/overrideable_parameter.py +143 -0
- snowflake/cli/api/commands/snow_typer.py +21 -11
- snowflake/cli/api/commands/utils.py +18 -0
- snowflake/cli/api/config.py +44 -12
- snowflake/cli/api/connections.py +216 -0
- snowflake/cli/api/console/abc.py +8 -3
- snowflake/cli/api/constants.py +11 -0
- snowflake/cli/api/entities/common.py +56 -0
- snowflake/cli/api/entities/utils.py +370 -0
- snowflake/cli/api/errno.py +1 -0
- snowflake/cli/api/exceptions.py +31 -5
- snowflake/cli/api/feature_flags.py +0 -1
- snowflake/cli/api/identifiers.py +28 -5
- snowflake/cli/api/metrics.py +92 -0
- snowflake/cli/api/project/definition.py +48 -6
- snowflake/cli/api/project/definition_conversion.py +400 -0
- snowflake/cli/api/project/definition_manager.py +16 -5
- snowflake/cli/api/project/project_verification.py +3 -3
- snowflake/cli/api/project/schemas/entities/common.py +91 -16
- snowflake/cli/api/project/schemas/entities/entities.py +37 -6
- snowflake/cli/api/project/schemas/project_definition.py +180 -49
- snowflake/cli/api/project/schemas/updatable_model.py +11 -3
- snowflake/cli/api/project/schemas/v1/__init__.py +0 -0
- snowflake/cli/api/project/schemas/{identifier_model.py → v1/identifier_model.py} +3 -1
- snowflake/cli/api/project/schemas/v1/native_app/__init__.py +0 -0
- snowflake/cli/api/project/schemas/{native_app → v1/native_app}/application.py +8 -9
- snowflake/cli/api/project/schemas/{native_app → v1/native_app}/native_app.py +4 -4
- snowflake/cli/api/project/schemas/{native_app → v1/native_app}/package.py +7 -1
- snowflake/cli/api/project/schemas/v1/snowpark/__init__.py +0 -0
- snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/callable.py +2 -2
- snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/snowpark.py +2 -2
- snowflake/cli/api/project/schemas/v1/streamlit/__init__.py +0 -0
- snowflake/cli/api/project/schemas/{streamlit → v1/streamlit}/streamlit.py +2 -1
- snowflake/cli/api/project/util.py +23 -6
- snowflake/cli/api/rendering/jinja.py +14 -8
- snowflake/cli/api/rendering/project_definition_templates.py +5 -1
- snowflake/cli/api/rendering/sql_templates.py +56 -11
- snowflake/cli/api/rest_api.py +11 -5
- snowflake/cli/api/secure_path.py +16 -18
- snowflake/cli/api/secure_utils.py +90 -1
- snowflake/cli/api/sql_execution.py +43 -23
- snowflake/cli/api/utils/definition_rendering.py +45 -13
- {snowflake_cli_labs-2.8.1.dist-info → snowflake_cli_labs-3.0.0.dist-info}/METADATA +20 -18
- snowflake_cli_labs-3.0.0.dist-info/RECORD +242 -0
- snowflake_cli_labs-3.0.0.dist-info/entry_points.txt +2 -0
- snowflake/cli/api/commands/project_initialisation.py +0 -65
- snowflake/cli/api/commands/typer_pre_execute.py +0 -26
- snowflake/cli/api/project/schemas/entities/application_entity.py +0 -44
- snowflake/cli/api/project/schemas/entities/application_package_entity.py +0 -66
- snowflake/cli/app/build_and_push.sh +0 -8
- snowflake/cli/plugins/nativeapp/codegen/setup/native_app_setup_processor.py +0 -172
- snowflake/cli/plugins/nativeapp/init.py +0 -345
- snowflake/cli/plugins/nativeapp/manager.py +0 -823
- snowflake/cli/plugins/nativeapp/run_processor.py +0 -389
- snowflake/cli/plugins/nativeapp/teardown_processor.py +0 -301
- snowflake/cli/plugins/nativeapp/v2_conversions/v2_to_v1_decorator.py +0 -135
- snowflake/cli/plugins/nativeapp/version/version_processor.py +0 -362
- snowflake/cli/plugins/object_stage_deprecated/__init__.py +0 -15
- snowflake/cli/plugins/object_stage_deprecated/commands.py +0 -122
- snowflake/cli/plugins/object_stage_deprecated/plugin_spec.py +0 -32
- snowflake/cli/plugins/snowpark/commands.py +0 -546
- snowflake/cli/plugins/snowpark/common.py +0 -307
- snowflake/cli/plugins/snowpark/manager.py +0 -109
- snowflake/cli/plugins/snowpark/plugin_spec.py +0 -30
- snowflake/cli/plugins/snowpark/snowpark_package_paths.py +0 -65
- snowflake/cli/plugins/spcs/jobs/commands.py +0 -78
- snowflake/cli/plugins/spcs/jobs/manager.py +0 -53
- snowflake/cli/plugins/streamlit/__init__.py +0 -13
- snowflake/cli/plugins/streamlit/plugin_spec.py +0 -30
- snowflake/cli/plugins/workspace/__init__.py +0 -13
- snowflake/cli/plugins/workspace/commands.py +0 -35
- snowflake/cli/plugins/workspace/plugin_spec.py +0 -30
- snowflake/cli/templates/default_snowpark/.gitignore +0 -4
- snowflake/cli/templates/default_snowpark/app/common.py +0 -2
- snowflake/cli/templates/default_snowpark/app/functions.py +0 -15
- snowflake/cli/templates/default_snowpark/app/procedures.py +0 -22
- snowflake/cli/templates/default_snowpark/requirements.txt +0 -1
- snowflake/cli/templates/default_snowpark/snowflake.yml +0 -23
- snowflake/cli/templates/default_streamlit/.gitignore +0 -4
- snowflake/cli/templates/default_streamlit/common/hello.py +0 -2
- snowflake/cli/templates/default_streamlit/environment.yml +0 -6
- snowflake/cli/templates/default_streamlit/pages/my_page.py +0 -3
- snowflake/cli/templates/default_streamlit/snowflake.yml +0 -10
- snowflake/cli/templates/default_streamlit/streamlit_app.py +0 -4
- snowflake_cli_labs-2.8.1.dist-info/RECORD +0 -240
- snowflake_cli_labs-2.8.1.dist-info/entry_points.txt +0 -2
- /snowflake/cli/{app → _app}/__init__.py +0 -0
- /snowflake/cli/{api/project/schemas/native_app → _app/api_impl}/__init__.py +0 -0
- /snowflake/cli/{api/project/schemas/snowpark → _app/api_impl/plugin}/__init__.py +0 -0
- /snowflake/cli/{app → _app}/api_impl/plugin/plugin_config_provider_impl.py +0 -0
- /snowflake/cli/{app → _app}/commands_registration/__init__.py +0 -0
- /snowflake/cli/{app → _app}/commands_registration/threadsafe.py +0 -0
- /snowflake/cli/{app → _app}/constants.py +0 -0
- /snowflake/cli/{api/project/schemas/streamlit → _app/dev}/__init__.py +0 -0
- /snowflake/cli/{app → _app}/dev/commands_structure.py +0 -0
- /snowflake/cli/{app/api_impl → _app/dev/docs}/__init__.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/project_definition_generate_json_schema.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/template_utils.py +0 -0
- /snowflake/cli/{app → _app}/dev/docs/templates/definition_description.rst.jinja2 +0 -0
- /snowflake/cli/{app → _app}/dev/docs/templates/overview.rst.jinja2 +0 -0
- /snowflake/cli/{app → _app}/dev/pycharm_remote_debug.py +0 -0
- /snowflake/cli/{app → _app}/loggers.py +0 -0
- /snowflake/cli/{app/api_impl/plugin → _plugins}/__init__.py +0 -0
- /snowflake/cli/{app/dev → _plugins/connection}/__init__.py +0 -0
- /snowflake/cli/{app/dev/docs → _plugins/cortex}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/cortex/types.py +0 -0
- /snowflake/cli/{plugins → _plugins/git}/__init__.py +0 -0
- /snowflake/cli/{plugins/connection → _plugins/helpers}/__init__.py +0 -0
- /snowflake/cli/{plugins/cortex → _plugins/init}/__init__.py +0 -0
- /snowflake/cli/{plugins/git → _plugins/nativeapp}/__init__.py +0 -0
- /snowflake/cli/{plugins/init → _plugins/nativeapp/codegen}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/sandbox.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/codegen/snowpark/callback_source.py.jinja +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/constants.py +0 -0
- /snowflake/cli/{templates/default_snowpark/app → _plugins/nativeapp/entities}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/feature_flags.py +0 -0
- /snowflake/cli/{plugins → _plugins}/nativeapp/utils.py +0 -0
- /snowflake/cli/{plugins/nativeapp → _plugins/nativeapp/version}/__init__.py +0 -0
- /snowflake/cli/{plugins/nativeapp/codegen → _plugins/notebook}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/notebook/exceptions.py +0 -0
- /snowflake/cli/{plugins → _plugins}/notebook/types.py +0 -0
- /snowflake/cli/{plugins/nativeapp/version → _plugins/object}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/object/common.py +0 -0
- /snowflake/cli/{plugins/notebook → _plugins/snowpark}/__init__.py +0 -0
- /snowflake/cli/{plugins/object → _plugins/snowpark/package}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/snowpark/package/utils.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/common.py +0 -0
- /snowflake/cli/{plugins/snowpark → _plugins/spcs/compute_pool}/__init__.py +0 -0
- /snowflake/cli/{plugins/snowpark/package → _plugins/spcs/image_registry}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/spcs/image_registry/manager.py +0 -0
- /snowflake/cli/{plugins/spcs/compute_pool → _plugins/spcs/image_repository}/__init__.py +0 -0
- /snowflake/cli/{plugins/spcs/image_registry → _plugins/spcs/services}/__init__.py +0 -0
- /snowflake/cli/{plugins/spcs/image_repository → _plugins/sql}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/sql/snowsql_templating.py +0 -0
- /snowflake/cli/{plugins/spcs/jobs → _plugins/stage}/__init__.py +0 -0
- /snowflake/cli/{plugins → _plugins}/stage/md5.py +0 -0
- /snowflake/cli/{plugins/spcs/services → _plugins/streamlit}/__init__.py +0 -0
- /snowflake/cli/{plugins/sql → _plugins/workspace}/__init__.py +0 -0
- /snowflake/cli/{plugins/stage → api/project/schemas/entities}/__init__.py +0 -0
- /snowflake/cli/api/project/schemas/{native_app → v1/native_app}/path_mapping.py +0 -0
- /snowflake/cli/api/project/schemas/{snowpark → v1/snowpark}/argument.py +0 -0
- {snowflake_cli_labs-2.8.1.dist-info → snowflake_cli_labs-3.0.0.dist-info}/WHEEL +0 -0
- {snowflake_cli_labs-2.8.1.dist-info → snowflake_cli_labs-3.0.0.dist-info}/licenses/LICENSE +0 -0
snowflake/cli/__about__.py
CHANGED
|
@@ -25,24 +25,28 @@ import click
|
|
|
25
25
|
import typer
|
|
26
26
|
from click import Context
|
|
27
27
|
from snowflake.cli import __about__
|
|
28
|
-
from snowflake.cli.
|
|
29
|
-
from snowflake.cli.api.config import config_init
|
|
30
|
-
from snowflake.cli.api.output.formats import OutputFormat
|
|
31
|
-
from snowflake.cli.api.output.types import CollectionResult
|
|
32
|
-
from snowflake.cli.api.secure_path import SecurePath
|
|
33
|
-
from snowflake.cli.app.api_impl.plugin.plugin_config_provider_impl import (
|
|
28
|
+
from snowflake.cli._app.api_impl.plugin.plugin_config_provider_impl import (
|
|
34
29
|
PluginConfigProviderImpl,
|
|
35
30
|
)
|
|
36
|
-
from snowflake.cli.
|
|
31
|
+
from snowflake.cli._app.commands_registration.commands_registration_with_callbacks import (
|
|
37
32
|
CommandsRegistrationWithCallbacks,
|
|
38
33
|
)
|
|
39
|
-
from snowflake.cli.
|
|
40
|
-
from snowflake.cli.
|
|
41
|
-
from snowflake.cli.
|
|
34
|
+
from snowflake.cli._app.dev.commands_structure import generate_commands_structure
|
|
35
|
+
from snowflake.cli._app.dev.docs.generator import generate_docs
|
|
36
|
+
from snowflake.cli._app.dev.pycharm_remote_debug import (
|
|
42
37
|
setup_pycharm_remote_debugger_if_provided,
|
|
43
38
|
)
|
|
44
|
-
from snowflake.cli.
|
|
45
|
-
from snowflake.cli.
|
|
39
|
+
from snowflake.cli._app.main_typer import SnowCliMainTyper
|
|
40
|
+
from snowflake.cli._app.printing import MessageResult, print_result
|
|
41
|
+
from snowflake.cli._app.version_check import (
|
|
42
|
+
get_new_version_msg,
|
|
43
|
+
show_new_version_banner_callback,
|
|
44
|
+
)
|
|
45
|
+
from snowflake.cli.api import Api, api_provider
|
|
46
|
+
from snowflake.cli.api.config import config_init
|
|
47
|
+
from snowflake.cli.api.output.formats import OutputFormat
|
|
48
|
+
from snowflake.cli.api.output.types import CollectionResult
|
|
49
|
+
from snowflake.cli.api.secure_path import SecurePath
|
|
46
50
|
from snowflake.connector.config_manager import CONFIG_MANAGER
|
|
47
51
|
|
|
48
52
|
log = logging.getLogger(__name__)
|
|
@@ -145,8 +149,13 @@ def _info_callback(value: bool):
|
|
|
145
149
|
|
|
146
150
|
def app_factory() -> SnowCliMainTyper:
|
|
147
151
|
app = SnowCliMainTyper()
|
|
152
|
+
new_version_msg = get_new_version_msg()
|
|
148
153
|
|
|
149
|
-
@app.callback(
|
|
154
|
+
@app.callback(
|
|
155
|
+
invoke_without_command=True,
|
|
156
|
+
epilog=new_version_msg,
|
|
157
|
+
result_callback=show_new_version_banner_callback(new_version_msg),
|
|
158
|
+
)
|
|
150
159
|
def default(
|
|
151
160
|
ctx: typer.Context,
|
|
152
161
|
version: bool = typer.Option(
|
|
@@ -12,30 +12,27 @@
|
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
|
-
from snowflake.cli.
|
|
16
|
-
from snowflake.cli.
|
|
17
|
-
from snowflake.cli.
|
|
18
|
-
from snowflake.cli.
|
|
19
|
-
from snowflake.cli.
|
|
20
|
-
from snowflake.cli.
|
|
21
|
-
from snowflake.cli.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
from snowflake.cli.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
from snowflake.cli.
|
|
28
|
-
from snowflake.cli.
|
|
29
|
-
from snowflake.cli.plugins.sql import plugin_spec as sql_plugin_spec
|
|
30
|
-
from snowflake.cli.plugins.stage import plugin_spec as stage_plugin_spec
|
|
31
|
-
from snowflake.cli.plugins.streamlit import plugin_spec as streamlit_plugin_spec
|
|
32
|
-
from snowflake.cli.plugins.workspace import plugin_spec as workspace_plugin_spec
|
|
15
|
+
from snowflake.cli._plugins.connection import plugin_spec as connection_plugin_spec
|
|
16
|
+
from snowflake.cli._plugins.cortex import plugin_spec as cortex_plugin_spec
|
|
17
|
+
from snowflake.cli._plugins.git import plugin_spec as git_plugin_spec
|
|
18
|
+
from snowflake.cli._plugins.helpers import plugin_spec as migrate_plugin_spec
|
|
19
|
+
from snowflake.cli._plugins.init import plugin_spec as init_plugin_spec
|
|
20
|
+
from snowflake.cli._plugins.nativeapp import plugin_spec as nativeapp_plugin_spec
|
|
21
|
+
from snowflake.cli._plugins.notebook import plugin_spec as notebook_plugin_spec
|
|
22
|
+
from snowflake.cli._plugins.object import plugin_spec as object_plugin_spec
|
|
23
|
+
from snowflake.cli._plugins.snowpark import plugin_spec as snowpark_plugin_spec
|
|
24
|
+
from snowflake.cli._plugins.spcs import plugin_spec as spcs_plugin_spec
|
|
25
|
+
from snowflake.cli._plugins.sql import plugin_spec as sql_plugin_spec
|
|
26
|
+
from snowflake.cli._plugins.stage import plugin_spec as stage_plugin_spec
|
|
27
|
+
from snowflake.cli._plugins.streamlit import plugin_spec as streamlit_plugin_spec
|
|
28
|
+
from snowflake.cli._plugins.workspace import plugin_spec as workspace_plugin_spec
|
|
33
29
|
|
|
34
30
|
|
|
35
31
|
# plugin name to plugin spec
|
|
36
32
|
def get_builtin_plugin_name_to_plugin_spec():
|
|
37
33
|
plugin_specs = {
|
|
38
34
|
"connection": connection_plugin_spec,
|
|
35
|
+
"helpers": migrate_plugin_spec,
|
|
39
36
|
"spcs": spcs_plugin_spec,
|
|
40
37
|
"nativeapp": nativeapp_plugin_spec,
|
|
41
38
|
"object": object_plugin_spec,
|
|
@@ -45,7 +42,6 @@ def get_builtin_plugin_name_to_plugin_spec():
|
|
|
45
42
|
"streamlit": streamlit_plugin_spec,
|
|
46
43
|
"git": git_plugin_spec,
|
|
47
44
|
"notebook": notebook_plugin_spec,
|
|
48
|
-
"object-stage-deprecated": object_stage_deprecated_plugin_spec,
|
|
49
45
|
"cortex": cortex_plugin_spec,
|
|
50
46
|
"init": init_plugin_spec,
|
|
51
47
|
"workspace": workspace_plugin_spec,
|
|
@@ -18,21 +18,21 @@ import logging
|
|
|
18
18
|
from typing import Dict, List, Optional
|
|
19
19
|
|
|
20
20
|
import pluggy
|
|
21
|
-
from snowflake.cli.
|
|
22
|
-
SNOWCLI_COMMAND_PLUGIN_NAMESPACE,
|
|
23
|
-
CommandPath,
|
|
24
|
-
CommandSpec,
|
|
25
|
-
plugin_hook_specs,
|
|
26
|
-
)
|
|
27
|
-
from snowflake.cli.app.commands_registration import (
|
|
21
|
+
from snowflake.cli._app.commands_registration import (
|
|
28
22
|
LoadedBuiltInCommandPlugin,
|
|
29
23
|
LoadedCommandPlugin,
|
|
30
24
|
LoadedExternalCommandPlugin,
|
|
31
25
|
)
|
|
32
|
-
from snowflake.cli.
|
|
26
|
+
from snowflake.cli._app.commands_registration.builtin_plugins import (
|
|
33
27
|
get_builtin_plugin_name_to_plugin_spec,
|
|
34
28
|
)
|
|
35
|
-
from snowflake.cli.
|
|
29
|
+
from snowflake.cli._app.commands_registration.exception_logging import exception_logging
|
|
30
|
+
from snowflake.cli.api.plugins.command import (
|
|
31
|
+
SNOWCLI_COMMAND_PLUGIN_NAMESPACE,
|
|
32
|
+
CommandPath,
|
|
33
|
+
CommandSpec,
|
|
34
|
+
plugin_hook_specs,
|
|
35
|
+
)
|
|
36
36
|
|
|
37
37
|
log = logging.getLogger(__name__)
|
|
38
38
|
log_exception = exception_logging(log)
|
|
@@ -17,15 +17,15 @@ from __future__ import annotations
|
|
|
17
17
|
from dataclasses import dataclass
|
|
18
18
|
from typing import Callable, List
|
|
19
19
|
|
|
20
|
-
from snowflake.cli.
|
|
21
|
-
from snowflake.cli.app.commands_registration.command_plugins_loader import (
|
|
20
|
+
from snowflake.cli._app.commands_registration.command_plugins_loader import (
|
|
22
21
|
load_builtin_and_external_command_plugins,
|
|
23
22
|
load_only_builtin_command_plugins,
|
|
24
23
|
)
|
|
25
|
-
from snowflake.cli.
|
|
26
|
-
from snowflake.cli.
|
|
24
|
+
from snowflake.cli._app.commands_registration.threadsafe import ThreadsafeCounter
|
|
25
|
+
from snowflake.cli._app.commands_registration.typer_registration import (
|
|
27
26
|
register_commands_from_plugins,
|
|
28
27
|
)
|
|
28
|
+
from snowflake.cli.api.plugins.plugin_config import PluginConfigProvider
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
@dataclass
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
from logging import Logger
|
|
16
16
|
from typing import Callable
|
|
17
17
|
|
|
18
|
-
from snowflake.cli.api.cli_global_context import
|
|
18
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def exception_logging(logger: Logger) -> Callable[[str, Exception], None]:
|
|
22
22
|
def log_error(msg: str, exception: Exception) -> None:
|
|
23
|
-
exc_info = exception if
|
|
23
|
+
exc_info = exception if get_cli_context().enable_tracebacks else None
|
|
24
24
|
logger.error(msg=msg, exc_info=exc_info)
|
|
25
25
|
|
|
26
26
|
return log_error
|
|
@@ -18,9 +18,9 @@ import logging
|
|
|
18
18
|
from typing import List
|
|
19
19
|
|
|
20
20
|
import click
|
|
21
|
+
from snowflake.cli._app.commands_registration import LoadedCommandPlugin
|
|
22
|
+
from snowflake.cli._app.commands_registration.exception_logging import exception_logging
|
|
21
23
|
from snowflake.cli.api.plugins.command import CommandSpec, CommandType
|
|
22
|
-
from snowflake.cli.app.commands_registration import LoadedCommandPlugin
|
|
23
|
-
from snowflake.cli.app.commands_registration.exception_logging import exception_logging
|
|
24
24
|
from typer.core import TyperGroup
|
|
25
25
|
|
|
26
26
|
log = logging.getLogger(__name__)
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
from __future__ import annotations
|
|
16
16
|
|
|
17
17
|
import logging
|
|
18
|
-
from typing import List, Optional
|
|
18
|
+
from typing import Any, List, Optional
|
|
19
19
|
|
|
20
20
|
from click import Command
|
|
21
|
+
from snowflake.cli._app.dev.docs.template_utils import get_template_environment
|
|
21
22
|
from snowflake.cli.api.secure_path import SecurePath
|
|
22
|
-
from snowflake.cli.app.dev.docs.template_utils import get_template_environment
|
|
23
23
|
from typer.core import TyperArgument
|
|
24
24
|
|
|
25
25
|
log = logging.getLogger(__name__)
|
|
@@ -86,15 +86,33 @@ def _render_command_usage(
|
|
|
86
86
|
# Included files, which these are, need to use the .txt extension.
|
|
87
87
|
file_path = root / f"usage-{command_name}.txt"
|
|
88
88
|
log.info("Creating %s", file_path)
|
|
89
|
+
command_help_params = _split_docstring(command.help)
|
|
90
|
+
template_params = {
|
|
91
|
+
"name": command_name,
|
|
92
|
+
"options": options,
|
|
93
|
+
"arguments": arguments,
|
|
94
|
+
"path": path,
|
|
95
|
+
}
|
|
89
96
|
with file_path.open("w+") as fh:
|
|
90
|
-
fh.write(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
fh.write(template.render(command_help_params | template_params))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _split_docstring(command_help: Optional[str]) -> dict[str, Any]:
|
|
101
|
+
if command_help is None:
|
|
102
|
+
return {}
|
|
103
|
+
|
|
104
|
+
split_command_help = command_help.split("## ")
|
|
105
|
+
|
|
106
|
+
if len(split_command_help) == 1:
|
|
107
|
+
return {"help": split_command_help[0]}
|
|
108
|
+
|
|
109
|
+
additional_sections = []
|
|
110
|
+
for section in split_command_help[1:]:
|
|
111
|
+
lines = section.split("\n")
|
|
112
|
+
additional_sections.append(
|
|
113
|
+
{"title": lines[0], "content": "\n".join(lines[1:]).strip()}
|
|
100
114
|
)
|
|
115
|
+
return {
|
|
116
|
+
"help": split_command_help[0],
|
|
117
|
+
"additional_sections": additional_sections,
|
|
118
|
+
}
|
|
@@ -17,11 +17,11 @@ from __future__ import annotations
|
|
|
17
17
|
import logging
|
|
18
18
|
|
|
19
19
|
from click import Command
|
|
20
|
-
from snowflake.cli.
|
|
21
|
-
from snowflake.cli.
|
|
22
|
-
from snowflake.cli.app.dev.docs.project_definition_docs_generator import (
|
|
20
|
+
from snowflake.cli._app.dev.docs.commands_docs_generator import generate_command_docs
|
|
21
|
+
from snowflake.cli._app.dev.docs.project_definition_docs_generator import (
|
|
23
22
|
generate_project_definition_docs,
|
|
24
23
|
)
|
|
24
|
+
from snowflake.cli.api.secure_path import SecurePath
|
|
25
25
|
|
|
26
26
|
log = logging.getLogger(__name__)
|
|
27
27
|
|
|
@@ -18,12 +18,12 @@ import logging
|
|
|
18
18
|
from typing import Any, Dict
|
|
19
19
|
|
|
20
20
|
from pydantic.json_schema import model_json_schema
|
|
21
|
-
from snowflake.cli.
|
|
22
|
-
from snowflake.cli.api.secure_path import SecurePath
|
|
23
|
-
from snowflake.cli.app.dev.docs.project_definition_generate_json_schema import (
|
|
21
|
+
from snowflake.cli._app.dev.docs.project_definition_generate_json_schema import (
|
|
24
22
|
ProjectDefinitionGenerateJsonSchema,
|
|
25
23
|
)
|
|
26
|
-
from snowflake.cli.
|
|
24
|
+
from snowflake.cli._app.dev.docs.template_utils import get_template_environment
|
|
25
|
+
from snowflake.cli.api.project.schemas.project_definition import DefinitionV11
|
|
26
|
+
from snowflake.cli.api.secure_path import SecurePath
|
|
27
27
|
|
|
28
28
|
log = logging.getLogger(__name__)
|
|
29
29
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{{ help | replace("`", "``") }}
|
|
1
|
+
{{ help | replace("`", "``") | replace("\n", " ") }}
|
|
2
2
|
|
|
3
3
|
Syntax
|
|
4
4
|
===============================================================================
|
|
@@ -26,7 +26,7 @@ Arguments
|
|
|
26
26
|
{{ param.make_metavar().replace("[", "").replace("]", "").lower() }}
|
|
27
27
|
{%- endif -%}
|
|
28
28
|
{{ '}' }}`
|
|
29
|
-
{% if param.help %}{{ " " + param.help | replace("`", "``") }}{% if param.help[-1] != '.' %}.{% endif %}{% else %} TBD{% endif %}
|
|
29
|
+
{% if param.help %}{{ " " + param.help | replace("`", "``") | replace("\n", " ") }}{% if param.help[-1] != '.' %}.{% endif %}{% if param.default %} Default: {{ param.default }}.{% endif %}{% else %} TBD{% endif %}
|
|
30
30
|
{% endfor %}
|
|
31
31
|
{% else %}
|
|
32
32
|
|
|
@@ -48,10 +48,20 @@ Options
|
|
|
48
48
|
{%- if param.type.name != "choice" %}{{ ' {' }}{% else %} {% endif %}{{ param.make_metavar() }}{% if param.type.name != "choice" %}{{ '}' }}
|
|
49
49
|
{%- endif %}
|
|
50
50
|
{%- endif %}`
|
|
51
|
-
{% if param.help %}{{ " " + param.help | replace("`", "``") }}{% if param.help[-1] != '.' %}.{% endif %}{% else %} TBD{% endif %}
|
|
52
|
-
{% endfor
|
|
51
|
+
{% if param.help %}{{ " " + param.help | replace("`", "``") | replace("\n", " ") }}{% if param.help[-1] != '.' %}.{% endif %}{% if param.default is not none %} Default: {{ param.default }}.{% endif %}{% else %} TBD{% endif %}
|
|
52
|
+
{% endfor -%}
|
|
53
53
|
{% else %}
|
|
54
54
|
|
|
55
55
|
None
|
|
56
56
|
|
|
57
57
|
{% endif -%}
|
|
58
|
+
|
|
59
|
+
{%- if additional_sections %}
|
|
60
|
+
..
|
|
61
|
+
{%- for section in additional_sections %}
|
|
62
|
+
{{ section.title }}
|
|
63
|
+
===============================================================================
|
|
64
|
+
|
|
65
|
+
{{ section.content | indent(2) }}
|
|
66
|
+
{% endfor %}
|
|
67
|
+
{% endif %}
|
|
@@ -17,13 +17,13 @@ from __future__ import annotations
|
|
|
17
17
|
import sys
|
|
18
18
|
|
|
19
19
|
import typer
|
|
20
|
-
from snowflake.cli.api.cli_global_context import
|
|
20
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
21
21
|
from snowflake.cli.api.commands.flags import DEFAULT_CONTEXT_SETTINGS, DebugOption
|
|
22
22
|
from snowflake.cli.api.console import cli_console
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def _handle_exception(exception: Exception):
|
|
26
|
-
if
|
|
26
|
+
if get_cli_context().enable_tracebacks:
|
|
27
27
|
raise exception
|
|
28
28
|
else:
|
|
29
29
|
cli_console.warning(
|
|
@@ -26,7 +26,7 @@ from rich import box, get_console
|
|
|
26
26
|
from rich import print as rich_print
|
|
27
27
|
from rich.live import Live
|
|
28
28
|
from rich.table import Table
|
|
29
|
-
from snowflake.cli.api.cli_global_context import
|
|
29
|
+
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
30
30
|
from snowflake.cli.api.output.formats import OutputFormat
|
|
31
31
|
from snowflake.cli.api.output.types import (
|
|
32
32
|
CollectionResult,
|
|
@@ -65,7 +65,7 @@ class CustomJSONEncoder(JSONEncoder):
|
|
|
65
65
|
|
|
66
66
|
|
|
67
67
|
def _get_format_type() -> OutputFormat:
|
|
68
|
-
output_format =
|
|
68
|
+
output_format = get_cli_context().output_format
|
|
69
69
|
if output_format:
|
|
70
70
|
return output_format
|
|
71
71
|
return OutputFormat.TABLE
|
|
@@ -21,11 +21,14 @@ from typing import Dict, Optional
|
|
|
21
21
|
|
|
22
22
|
import snowflake.connector
|
|
23
23
|
from click.exceptions import ClickException
|
|
24
|
-
from snowflake.cli.
|
|
24
|
+
from snowflake.cli._app.constants import (
|
|
25
|
+
PARAM_APPLICATION_NAME,
|
|
26
|
+
)
|
|
27
|
+
from snowflake.cli._app.secret import SecretType
|
|
28
|
+
from snowflake.cli._app.telemetry import command_info
|
|
25
29
|
from snowflake.cli.api.config import (
|
|
26
30
|
get_connection_dict,
|
|
27
|
-
|
|
28
|
-
get_default_connection_name,
|
|
31
|
+
get_env_value,
|
|
29
32
|
)
|
|
30
33
|
from snowflake.cli.api.constants import DEFAULT_SIZE_LIMIT_MB
|
|
31
34
|
from snowflake.cli.api.exceptions import (
|
|
@@ -33,10 +36,6 @@ from snowflake.cli.api.exceptions import (
|
|
|
33
36
|
SnowflakeConnectionError,
|
|
34
37
|
)
|
|
35
38
|
from snowflake.cli.api.secure_path import SecurePath
|
|
36
|
-
from snowflake.cli.app.constants import (
|
|
37
|
-
PARAM_APPLICATION_NAME,
|
|
38
|
-
)
|
|
39
|
-
from snowflake.cli.app.telemetry import command_info
|
|
40
39
|
from snowflake.connector import SnowflakeConnection
|
|
41
40
|
from snowflake.connector.errors import DatabaseError, ForbiddenError
|
|
42
41
|
|
|
@@ -46,6 +45,33 @@ log = logging.getLogger(__name__)
|
|
|
46
45
|
ENCRYPTED_PKCS8_PK_HEADER = b"-----BEGIN ENCRYPTED PRIVATE KEY-----"
|
|
47
46
|
UNENCRYPTED_PKCS8_PK_HEADER = b"-----BEGIN PRIVATE KEY-----"
|
|
48
47
|
|
|
48
|
+
# connection keys that can be set using SNOWFLAKE_* env vars
|
|
49
|
+
SUPPORTED_ENV_OVERRIDES = [
|
|
50
|
+
"account",
|
|
51
|
+
"user",
|
|
52
|
+
"password",
|
|
53
|
+
"authenticator",
|
|
54
|
+
"private_key_file",
|
|
55
|
+
"private_key_path",
|
|
56
|
+
"database",
|
|
57
|
+
"schema",
|
|
58
|
+
"role",
|
|
59
|
+
"warehouse",
|
|
60
|
+
"session_token",
|
|
61
|
+
"master_token",
|
|
62
|
+
"token_file_path",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
# mapping of found key -> key to set
|
|
66
|
+
CONNECTION_KEY_ALIASES = {"private_key_path": "private_key_file"}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _resolve_alias(key_or_alias: str):
|
|
70
|
+
"""
|
|
71
|
+
Given the key of an override / env var, what key should it be set as in the connection parameters?
|
|
72
|
+
"""
|
|
73
|
+
return CONNECTION_KEY_ALIASES.get(key_or_alias, key_or_alias)
|
|
74
|
+
|
|
49
75
|
|
|
50
76
|
def connect_to_snowflake(
|
|
51
77
|
temporary_connection: bool = False,
|
|
@@ -58,6 +84,10 @@ def connect_to_snowflake(
|
|
|
58
84
|
) -> SnowflakeConnection:
|
|
59
85
|
if temporary_connection and connection_name:
|
|
60
86
|
raise ClickException("Can't use connection name and temporary connection.")
|
|
87
|
+
elif not temporary_connection and not connection_name:
|
|
88
|
+
raise ClickException(
|
|
89
|
+
"One of connection name or temporary connection is required."
|
|
90
|
+
)
|
|
61
91
|
|
|
62
92
|
using_session_token = (
|
|
63
93
|
"session_token" in overrides and overrides["session_token"] is not None
|
|
@@ -70,36 +100,33 @@ def connect_to_snowflake(
|
|
|
70
100
|
)
|
|
71
101
|
|
|
72
102
|
if connection_name:
|
|
73
|
-
connection_parameters =
|
|
103
|
+
connection_parameters = {
|
|
104
|
+
_resolve_alias(k): v
|
|
105
|
+
for k, v in get_connection_dict(connection_name).items()
|
|
106
|
+
}
|
|
74
107
|
elif temporary_connection:
|
|
75
108
|
connection_parameters = {} # we will apply overrides in next step
|
|
76
|
-
else:
|
|
77
|
-
connection_parameters = get_default_connection_dict()
|
|
78
|
-
cli_context.connection_context.set_connection_name(
|
|
79
|
-
get_default_connection_name()
|
|
80
|
-
)
|
|
81
109
|
|
|
82
110
|
# Apply overrides to connection details
|
|
111
|
+
# (1) Command line override case
|
|
83
112
|
for key, value in overrides.items():
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
connection_parameters[key] = value
|
|
87
|
-
continue
|
|
113
|
+
if value is not None:
|
|
114
|
+
connection_parameters[_resolve_alias(key)] = value
|
|
88
115
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
# (2) Generic environment variable case
|
|
117
|
+
# ... apply only if value not passed via flag or connection variable
|
|
118
|
+
for key in SUPPORTED_ENV_OVERRIDES:
|
|
119
|
+
generic_env_value = get_env_value(key=key)
|
|
120
|
+
connection_key = _resolve_alias(key)
|
|
121
|
+
if connection_key not in connection_parameters and generic_env_value:
|
|
122
|
+
connection_parameters[connection_key] = generic_env_value
|
|
94
123
|
|
|
95
124
|
# Clean up connection params
|
|
96
125
|
connection_parameters = {
|
|
97
126
|
k: v for k, v in connection_parameters.items() if v is not None
|
|
98
127
|
}
|
|
99
128
|
|
|
100
|
-
|
|
101
|
-
connection_parameters
|
|
102
|
-
)
|
|
129
|
+
update_connection_details_with_private_key(connection_parameters)
|
|
103
130
|
|
|
104
131
|
if mfa_passcode:
|
|
105
132
|
connection_parameters["passcode"] = mfa_passcode
|
|
@@ -164,18 +191,45 @@ def _raise_errors_related_to_session_token(
|
|
|
164
191
|
|
|
165
192
|
|
|
166
193
|
def update_connection_details_with_private_key(connection_parameters: Dict):
|
|
167
|
-
if "
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
raise ClickException(
|
|
174
|
-
"Private Key authentication requires authenticator set to SNOWFLAKE_JWT"
|
|
175
|
-
)
|
|
194
|
+
if "private_key_file" in connection_parameters:
|
|
195
|
+
_load_private_key(connection_parameters, "private_key_file")
|
|
196
|
+
elif "private_key_path" in connection_parameters:
|
|
197
|
+
_load_private_key(connection_parameters, "private_key_path")
|
|
198
|
+
elif "private_key_raw" in connection_parameters:
|
|
199
|
+
_load_private_key_from_parameters(connection_parameters, "private_key_raw")
|
|
176
200
|
return connection_parameters
|
|
177
201
|
|
|
178
202
|
|
|
203
|
+
def _load_private_key(connection_parameters: Dict, private_key_var_name: str) -> None:
|
|
204
|
+
if connection_parameters.get("authenticator") == "SNOWFLAKE_JWT":
|
|
205
|
+
private_key_pem = _load_pem_from_file(
|
|
206
|
+
connection_parameters[private_key_var_name]
|
|
207
|
+
)
|
|
208
|
+
private_key = _load_pem_to_der(private_key_pem)
|
|
209
|
+
connection_parameters["private_key"] = private_key.value
|
|
210
|
+
del connection_parameters[private_key_var_name]
|
|
211
|
+
else:
|
|
212
|
+
raise ClickException(
|
|
213
|
+
"Private Key authentication requires authenticator set to SNOWFLAKE_JWT"
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _load_private_key_from_parameters(
|
|
218
|
+
connection_parameters: Dict, private_key_var_name: str
|
|
219
|
+
) -> None:
|
|
220
|
+
if connection_parameters.get("authenticator") == "SNOWFLAKE_JWT":
|
|
221
|
+
private_key_pem = _load_pem_from_parameters(
|
|
222
|
+
connection_parameters[private_key_var_name]
|
|
223
|
+
)
|
|
224
|
+
private_key = _load_pem_to_der(private_key_pem)
|
|
225
|
+
connection_parameters["private_key"] = private_key.value
|
|
226
|
+
del connection_parameters[private_key_var_name]
|
|
227
|
+
else:
|
|
228
|
+
raise ClickException(
|
|
229
|
+
"Private Key authentication requires authenticator set to SNOWFLAKE_JWT"
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
|
|
179
233
|
def _update_connection_application_name(connection_parameters: Dict):
|
|
180
234
|
"""Update version and name of app handling connection."""
|
|
181
235
|
connection_application_params = {
|
|
@@ -184,41 +238,49 @@ def _update_connection_application_name(connection_parameters: Dict):
|
|
|
184
238
|
connection_parameters.update(connection_application_params)
|
|
185
239
|
|
|
186
240
|
|
|
187
|
-
def
|
|
241
|
+
def _load_pem_from_file(private_key_file: str) -> SecretType:
|
|
242
|
+
with SecurePath(private_key_file).open(
|
|
243
|
+
"rb", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB
|
|
244
|
+
) as f:
|
|
245
|
+
private_key_pem = SecretType(f.read())
|
|
246
|
+
return private_key_pem
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def _load_pem_from_parameters(private_key_raw: str) -> SecretType:
|
|
250
|
+
return SecretType(private_key_raw.encode("utf-8"))
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def _load_pem_to_der(private_key_pem: SecretType) -> SecretType:
|
|
188
254
|
"""
|
|
189
255
|
Given a private key file path (in PEM format), decode key data into DER
|
|
190
256
|
format
|
|
191
257
|
"""
|
|
192
|
-
|
|
193
|
-
with SecurePath(private_key_path).open(
|
|
194
|
-
"rb", read_file_limit_mb=DEFAULT_SIZE_LIMIT_MB
|
|
195
|
-
) as f:
|
|
196
|
-
private_key_pem = f.read()
|
|
197
|
-
|
|
198
|
-
private_key_passphrase = os.getenv("PRIVATE_KEY_PASSPHRASE", None)
|
|
258
|
+
private_key_passphrase = SecretType(os.getenv("PRIVATE_KEY_PASSPHRASE", None))
|
|
199
259
|
if (
|
|
200
|
-
private_key_pem.startswith(ENCRYPTED_PKCS8_PK_HEADER)
|
|
201
|
-
and private_key_passphrase is None
|
|
260
|
+
private_key_pem.value.startswith(ENCRYPTED_PKCS8_PK_HEADER)
|
|
261
|
+
and private_key_passphrase.value is None
|
|
202
262
|
):
|
|
203
263
|
raise ClickException(
|
|
204
264
|
"Encrypted private key, you must provide the"
|
|
205
265
|
"passphrase in the environment variable PRIVATE_KEY_PASSPHRASE"
|
|
206
266
|
)
|
|
207
267
|
|
|
208
|
-
if not private_key_pem.startswith(
|
|
268
|
+
if not private_key_pem.value.startswith(
|
|
209
269
|
ENCRYPTED_PKCS8_PK_HEADER
|
|
210
|
-
) and not private_key_pem.startswith(UNENCRYPTED_PKCS8_PK_HEADER):
|
|
270
|
+
) and not private_key_pem.value.startswith(UNENCRYPTED_PKCS8_PK_HEADER):
|
|
211
271
|
raise ClickException(
|
|
212
272
|
"Private key provided is not in PKCS#8 format. Please use correct format."
|
|
213
273
|
)
|
|
214
274
|
|
|
215
|
-
if private_key_pem.startswith(UNENCRYPTED_PKCS8_PK_HEADER):
|
|
216
|
-
private_key_passphrase = None
|
|
275
|
+
if private_key_pem.value.startswith(UNENCRYPTED_PKCS8_PK_HEADER):
|
|
276
|
+
private_key_passphrase = SecretType(None)
|
|
217
277
|
|
|
218
278
|
return prepare_private_key(private_key_pem, private_key_passphrase)
|
|
219
279
|
|
|
220
280
|
|
|
221
|
-
def prepare_private_key(
|
|
281
|
+
def prepare_private_key(
|
|
282
|
+
private_key_pem: SecretType, private_key_passphrase: SecretType = SecretType(None)
|
|
283
|
+
):
|
|
222
284
|
from cryptography.hazmat.backends import default_backend
|
|
223
285
|
from cryptography.hazmat.primitives.serialization import (
|
|
224
286
|
Encoding,
|
|
@@ -227,17 +289,21 @@ def prepare_private_key(private_key_pem, private_key_passphrase=None):
|
|
|
227
289
|
load_pem_private_key,
|
|
228
290
|
)
|
|
229
291
|
|
|
230
|
-
private_key =
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
292
|
+
private_key = SecretType(
|
|
293
|
+
load_pem_private_key(
|
|
294
|
+
private_key_pem.value,
|
|
295
|
+
(
|
|
296
|
+
str.encode(private_key_passphrase.value)
|
|
297
|
+
if private_key_passphrase.value is not None
|
|
298
|
+
else private_key_passphrase.value
|
|
299
|
+
),
|
|
300
|
+
default_backend(),
|
|
301
|
+
)
|
|
238
302
|
)
|
|
239
|
-
return
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
303
|
+
return SecretType(
|
|
304
|
+
private_key.value.private_bytes(
|
|
305
|
+
encoding=Encoding.DER,
|
|
306
|
+
format=PrivateFormat.PKCS8,
|
|
307
|
+
encryption_algorithm=NoEncryption(),
|
|
308
|
+
)
|
|
243
309
|
)
|