snowflake-cli 3.1.0__py3-none-any.whl → 3.2.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/dev/docs/templates/usage.rst.jinja2 +1 -1
- snowflake/cli/_plugins/connection/commands.py +124 -109
- snowflake/cli/_plugins/connection/util.py +54 -9
- snowflake/cli/_plugins/cortex/manager.py +1 -1
- snowflake/cli/_plugins/git/manager.py +4 -4
- snowflake/cli/_plugins/nativeapp/artifacts.py +64 -10
- snowflake/cli/_plugins/nativeapp/codegen/templates/templates_processor.py +5 -3
- snowflake/cli/_plugins/nativeapp/commands.py +10 -3
- snowflake/cli/_plugins/nativeapp/constants.py +1 -0
- snowflake/cli/_plugins/nativeapp/entities/application.py +501 -440
- snowflake/cli/_plugins/nativeapp/entities/application_package.py +563 -885
- snowflake/cli/_plugins/nativeapp/entities/models/event_sharing_telemetry.py +58 -0
- snowflake/cli/_plugins/nativeapp/same_account_install_method.py +0 -2
- snowflake/cli/_plugins/nativeapp/sf_facade.py +30 -0
- snowflake/cli/_plugins/nativeapp/sf_facade_constants.py +25 -0
- snowflake/cli/_plugins/nativeapp/sf_facade_exceptions.py +117 -0
- snowflake/cli/_plugins/nativeapp/sf_sql_facade.py +525 -0
- snowflake/cli/_plugins/nativeapp/v2_conversions/compat.py +1 -89
- snowflake/cli/_plugins/nativeapp/version/commands.py +6 -3
- snowflake/cli/_plugins/notebook/manager.py +2 -2
- snowflake/cli/_plugins/object/commands.py +10 -1
- snowflake/cli/_plugins/object/manager.py +13 -5
- snowflake/cli/_plugins/snowpark/common.py +3 -3
- snowflake/cli/_plugins/snowpark/package/anaconda_packages.py +1 -1
- snowflake/cli/_plugins/spcs/common.py +29 -0
- snowflake/cli/_plugins/spcs/compute_pool/manager.py +7 -9
- snowflake/cli/_plugins/spcs/image_registry/manager.py +2 -2
- snowflake/cli/_plugins/spcs/image_repository/manager.py +1 -1
- snowflake/cli/_plugins/spcs/services/commands.py +64 -13
- snowflake/cli/_plugins/spcs/services/manager.py +75 -15
- snowflake/cli/_plugins/sql/commands.py +9 -1
- snowflake/cli/_plugins/sql/manager.py +9 -4
- snowflake/cli/_plugins/stage/commands.py +20 -16
- snowflake/cli/_plugins/stage/diff.py +1 -1
- snowflake/cli/_plugins/stage/manager.py +140 -11
- snowflake/cli/_plugins/streamlit/manager.py +5 -5
- snowflake/cli/_plugins/workspace/commands.py +6 -3
- snowflake/cli/api/cli_global_context.py +1 -0
- snowflake/cli/api/config.py +23 -5
- snowflake/cli/api/console/console.py +4 -19
- snowflake/cli/api/entities/utils.py +19 -32
- snowflake/cli/api/errno.py +2 -0
- snowflake/cli/api/exceptions.py +9 -0
- snowflake/cli/api/metrics.py +223 -7
- snowflake/cli/api/output/types.py +1 -1
- snowflake/cli/api/project/definition_conversion.py +179 -62
- snowflake/cli/api/rest_api.py +26 -4
- snowflake/cli/api/secure_utils.py +1 -1
- snowflake/cli/api/sql_execution.py +35 -22
- snowflake/cli/api/stage_path.py +5 -2
- {snowflake_cli-3.1.0.dist-info → snowflake_cli-3.2.0.dist-info}/METADATA +7 -8
- {snowflake_cli-3.1.0.dist-info → snowflake_cli-3.2.0.dist-info}/RECORD +56 -55
- {snowflake_cli-3.1.0.dist-info → snowflake_cli-3.2.0.dist-info}/WHEEL +1 -1
- snowflake/cli/_plugins/nativeapp/manager.py +0 -392
- snowflake/cli/_plugins/nativeapp/project_model.py +0 -211
- snowflake/cli/_plugins/nativeapp/run_processor.py +0 -184
- snowflake/cli/_plugins/nativeapp/version/version_processor.py +0 -56
- {snowflake_cli-3.1.0.dist-info → snowflake_cli-3.2.0.dist-info}/entry_points.txt +0 -0
- {snowflake_cli-3.1.0.dist-info → snowflake_cli-3.2.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,392 +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 abc import ABC, abstractmethod
|
|
18
|
-
from datetime import datetime
|
|
19
|
-
from functools import cached_property
|
|
20
|
-
from pathlib import Path
|
|
21
|
-
from typing import Generator, List, Optional
|
|
22
|
-
|
|
23
|
-
from snowflake.cli._plugins.nativeapp.artifacts import (
|
|
24
|
-
BundleMap,
|
|
25
|
-
)
|
|
26
|
-
from snowflake.cli._plugins.nativeapp.entities.application import (
|
|
27
|
-
ApplicationEntity,
|
|
28
|
-
ApplicationOwnedObject,
|
|
29
|
-
)
|
|
30
|
-
from snowflake.cli._plugins.nativeapp.entities.application_package import (
|
|
31
|
-
ApplicationPackageEntity,
|
|
32
|
-
)
|
|
33
|
-
from snowflake.cli._plugins.nativeapp.policy import AllowAlwaysPolicy, PolicyBase
|
|
34
|
-
from snowflake.cli._plugins.nativeapp.project_model import (
|
|
35
|
-
NativeAppProjectModel,
|
|
36
|
-
)
|
|
37
|
-
from snowflake.cli._plugins.stage.diff import (
|
|
38
|
-
DiffResult,
|
|
39
|
-
)
|
|
40
|
-
from snowflake.cli.api.console import cli_console as cc
|
|
41
|
-
from snowflake.cli.api.entities.utils import (
|
|
42
|
-
execute_post_deploy_hooks,
|
|
43
|
-
sync_deploy_root_with_stage,
|
|
44
|
-
)
|
|
45
|
-
from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
|
|
46
|
-
from snowflake.cli.api.project.schemas.v1.native_app.native_app import NativeApp
|
|
47
|
-
from snowflake.cli.api.project.schemas.v1.native_app.path_mapping import PathMapping
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
class NativeAppCommandProcessor(ABC):
|
|
51
|
-
@abstractmethod
|
|
52
|
-
def process(self, *args, **kwargs):
|
|
53
|
-
pass
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
class NativeAppManager:
|
|
57
|
-
"""
|
|
58
|
-
Base class with frequently used functionality already implemented and ready to be used by related subclasses.
|
|
59
|
-
"""
|
|
60
|
-
|
|
61
|
-
def __init__(self, project_definition: NativeApp, project_root: Path):
|
|
62
|
-
super().__init__()
|
|
63
|
-
self._na_project = NativeAppProjectModel(
|
|
64
|
-
project_definition=project_definition,
|
|
65
|
-
project_root=project_root,
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
@property
|
|
69
|
-
def na_project(self) -> NativeAppProjectModel:
|
|
70
|
-
return self._na_project
|
|
71
|
-
|
|
72
|
-
@property
|
|
73
|
-
def project_root(self) -> Path:
|
|
74
|
-
return self.na_project.project_root
|
|
75
|
-
|
|
76
|
-
@property
|
|
77
|
-
def definition(self) -> NativeApp:
|
|
78
|
-
return self.na_project.definition
|
|
79
|
-
|
|
80
|
-
@property
|
|
81
|
-
def artifacts(self) -> List[PathMapping]:
|
|
82
|
-
return self.na_project.artifacts
|
|
83
|
-
|
|
84
|
-
@property
|
|
85
|
-
def bundle_root(self) -> Path:
|
|
86
|
-
return self.na_project.bundle_root
|
|
87
|
-
|
|
88
|
-
@property
|
|
89
|
-
def deploy_root(self) -> Path:
|
|
90
|
-
return self.na_project.deploy_root
|
|
91
|
-
|
|
92
|
-
@property
|
|
93
|
-
def generated_root(self) -> Path:
|
|
94
|
-
return self.na_project.generated_root
|
|
95
|
-
|
|
96
|
-
@property
|
|
97
|
-
def package_scripts(self) -> List[str]:
|
|
98
|
-
return self.na_project.package_scripts
|
|
99
|
-
|
|
100
|
-
@property
|
|
101
|
-
def stage_fqn(self) -> str:
|
|
102
|
-
return self.na_project.stage_fqn
|
|
103
|
-
|
|
104
|
-
@property
|
|
105
|
-
def scratch_stage_fqn(self) -> str:
|
|
106
|
-
return self.na_project.scratch_stage_fqn
|
|
107
|
-
|
|
108
|
-
@property
|
|
109
|
-
def stage_schema(self) -> Optional[str]:
|
|
110
|
-
return self.na_project.stage_schema
|
|
111
|
-
|
|
112
|
-
@property
|
|
113
|
-
def package_warehouse(self) -> Optional[str]:
|
|
114
|
-
return self.na_project.package_warehouse
|
|
115
|
-
|
|
116
|
-
def use_package_warehouse(self):
|
|
117
|
-
return ApplicationPackageEntity.use_package_warehouse(
|
|
118
|
-
self.package_warehouse,
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
@property
|
|
122
|
-
def application_warehouse(self) -> Optional[str]:
|
|
123
|
-
return self.na_project.application_warehouse
|
|
124
|
-
|
|
125
|
-
@property
|
|
126
|
-
def project_identifier(self) -> str:
|
|
127
|
-
return self.na_project.project_identifier
|
|
128
|
-
|
|
129
|
-
@property
|
|
130
|
-
def package_name(self) -> str:
|
|
131
|
-
return self.na_project.package_name
|
|
132
|
-
|
|
133
|
-
@property
|
|
134
|
-
def package_role(self) -> str:
|
|
135
|
-
return self.na_project.package_role
|
|
136
|
-
|
|
137
|
-
@property
|
|
138
|
-
def package_distribution(self) -> str:
|
|
139
|
-
return self.na_project.package_distribution
|
|
140
|
-
|
|
141
|
-
@property
|
|
142
|
-
def app_name(self) -> str:
|
|
143
|
-
return self.na_project.app_name
|
|
144
|
-
|
|
145
|
-
@property
|
|
146
|
-
def app_role(self) -> str:
|
|
147
|
-
return self.na_project.app_role
|
|
148
|
-
|
|
149
|
-
@property
|
|
150
|
-
def app_post_deploy_hooks(self) -> Optional[List[PostDeployHook]]:
|
|
151
|
-
return self.na_project.app_post_deploy_hooks
|
|
152
|
-
|
|
153
|
-
@property
|
|
154
|
-
def package_post_deploy_hooks(self) -> Optional[List[PostDeployHook]]:
|
|
155
|
-
return self.na_project.package_post_deploy_hooks
|
|
156
|
-
|
|
157
|
-
@property
|
|
158
|
-
def debug_mode(self) -> bool:
|
|
159
|
-
return self.na_project.debug_mode
|
|
160
|
-
|
|
161
|
-
@cached_property
|
|
162
|
-
def get_app_pkg_distribution_in_snowflake(self) -> str:
|
|
163
|
-
return ApplicationPackageEntity.get_app_pkg_distribution_in_snowflake(
|
|
164
|
-
self.package_name, self.package_role
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
@cached_property
|
|
168
|
-
def account_event_table(self) -> str:
|
|
169
|
-
return ApplicationEntity.get_account_event_table()
|
|
170
|
-
|
|
171
|
-
def verify_project_distribution(
|
|
172
|
-
self, expected_distribution: Optional[str] = None
|
|
173
|
-
) -> bool:
|
|
174
|
-
return ApplicationPackageEntity.verify_project_distribution(
|
|
175
|
-
console=cc,
|
|
176
|
-
package_name=self.package_name,
|
|
177
|
-
package_role=self.package_role,
|
|
178
|
-
package_distribution=self.package_distribution,
|
|
179
|
-
expected_distribution=expected_distribution,
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
def build_bundle(self) -> BundleMap:
|
|
183
|
-
"""
|
|
184
|
-
Populates the local deploy root from artifact sources.
|
|
185
|
-
"""
|
|
186
|
-
return ApplicationPackageEntity.bundle(
|
|
187
|
-
project_root=self.project_root,
|
|
188
|
-
deploy_root=self.deploy_root,
|
|
189
|
-
bundle_root=self.bundle_root,
|
|
190
|
-
generated_root=self.generated_root,
|
|
191
|
-
package_name=self.package_name,
|
|
192
|
-
artifacts=self.artifacts,
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
def sync_deploy_root_with_stage(
|
|
196
|
-
self,
|
|
197
|
-
bundle_map: BundleMap,
|
|
198
|
-
role: str,
|
|
199
|
-
prune: bool,
|
|
200
|
-
recursive: bool,
|
|
201
|
-
stage_fqn: str,
|
|
202
|
-
local_paths_to_sync: List[Path] | None = None,
|
|
203
|
-
print_diff: bool = True,
|
|
204
|
-
) -> DiffResult:
|
|
205
|
-
return sync_deploy_root_with_stage(
|
|
206
|
-
console=cc,
|
|
207
|
-
deploy_root=self.deploy_root,
|
|
208
|
-
package_name=self.package_name,
|
|
209
|
-
stage_schema=self.stage_schema,
|
|
210
|
-
bundle_map=bundle_map,
|
|
211
|
-
role=role,
|
|
212
|
-
prune=prune,
|
|
213
|
-
recursive=recursive,
|
|
214
|
-
stage_fqn=stage_fqn,
|
|
215
|
-
local_paths_to_sync=local_paths_to_sync,
|
|
216
|
-
print_diff=print_diff,
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
def get_existing_app_info(self) -> Optional[dict]:
|
|
220
|
-
return ApplicationEntity.get_existing_app_info_static(
|
|
221
|
-
app_name=self.app_name,
|
|
222
|
-
app_role=self.app_role,
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
def get_existing_app_pkg_info(self) -> Optional[dict]:
|
|
226
|
-
return ApplicationPackageEntity.get_existing_app_pkg_info(
|
|
227
|
-
package_name=self.package_name,
|
|
228
|
-
package_role=self.package_role,
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
def get_objects_owned_by_application(self):
|
|
232
|
-
return ApplicationEntity.get_objects_owned_by_application(
|
|
233
|
-
app_name=self.app_name,
|
|
234
|
-
app_role=self.app_role,
|
|
235
|
-
)
|
|
236
|
-
|
|
237
|
-
def _application_objects_to_str(
|
|
238
|
-
self, application_objects: list[ApplicationOwnedObject]
|
|
239
|
-
) -> str:
|
|
240
|
-
return ApplicationEntity.application_objects_to_str(application_objects)
|
|
241
|
-
|
|
242
|
-
def _application_object_to_str(self, obj: ApplicationOwnedObject):
|
|
243
|
-
return ApplicationEntity.application_object_to_str(obj)
|
|
244
|
-
|
|
245
|
-
def get_snowsight_url(self) -> str:
|
|
246
|
-
"""Returns the URL that can be used to visit this app via Snowsight."""
|
|
247
|
-
return ApplicationEntity.get_snowsight_url_static(
|
|
248
|
-
self.app_name, self.application_warehouse
|
|
249
|
-
)
|
|
250
|
-
|
|
251
|
-
def create_app_package(self) -> None:
|
|
252
|
-
return ApplicationPackageEntity.create_app_package(
|
|
253
|
-
console=cc,
|
|
254
|
-
package_name=self.package_name,
|
|
255
|
-
package_role=self.package_role,
|
|
256
|
-
package_distribution=self.package_distribution,
|
|
257
|
-
)
|
|
258
|
-
|
|
259
|
-
def execute_app_post_deploy_hooks(self) -> None:
|
|
260
|
-
execute_post_deploy_hooks(
|
|
261
|
-
console=cc,
|
|
262
|
-
project_root=self.project_root,
|
|
263
|
-
post_deploy_hooks=self.app_post_deploy_hooks,
|
|
264
|
-
deployed_object_type="application",
|
|
265
|
-
database_name=self.app_name,
|
|
266
|
-
)
|
|
267
|
-
|
|
268
|
-
def deploy(
|
|
269
|
-
self,
|
|
270
|
-
bundle_map: BundleMap,
|
|
271
|
-
prune: bool,
|
|
272
|
-
recursive: bool,
|
|
273
|
-
policy: PolicyBase,
|
|
274
|
-
stage_fqn: Optional[str] = None,
|
|
275
|
-
local_paths_to_sync: List[Path] | None = None,
|
|
276
|
-
validate: bool = True,
|
|
277
|
-
print_diff: bool = True,
|
|
278
|
-
) -> DiffResult:
|
|
279
|
-
return ApplicationPackageEntity.deploy(
|
|
280
|
-
console=cc,
|
|
281
|
-
project_root=self.project_root,
|
|
282
|
-
deploy_root=self.deploy_root,
|
|
283
|
-
bundle_root=self.bundle_root,
|
|
284
|
-
generated_root=self.generated_root,
|
|
285
|
-
artifacts=self.artifacts,
|
|
286
|
-
bundle_map=bundle_map,
|
|
287
|
-
package_name=self.package_name,
|
|
288
|
-
package_role=self.package_role,
|
|
289
|
-
package_distribution=self.package_distribution,
|
|
290
|
-
prune=prune,
|
|
291
|
-
recursive=recursive,
|
|
292
|
-
paths=local_paths_to_sync,
|
|
293
|
-
print_diff=print_diff,
|
|
294
|
-
validate=validate,
|
|
295
|
-
stage_fqn=stage_fqn or self.stage_fqn,
|
|
296
|
-
package_warehouse=self.package_warehouse,
|
|
297
|
-
post_deploy_hooks=self.package_post_deploy_hooks,
|
|
298
|
-
package_scripts=self.package_scripts,
|
|
299
|
-
policy=policy,
|
|
300
|
-
)
|
|
301
|
-
|
|
302
|
-
def validate(self, use_scratch_stage: bool = False):
|
|
303
|
-
return ApplicationPackageEntity.validate_setup_script(
|
|
304
|
-
console=cc,
|
|
305
|
-
project_root=self.project_root,
|
|
306
|
-
deploy_root=self.deploy_root,
|
|
307
|
-
bundle_root=self.bundle_root,
|
|
308
|
-
generated_root=self.generated_root,
|
|
309
|
-
artifacts=self.artifacts,
|
|
310
|
-
package_name=self.package_name,
|
|
311
|
-
package_role=self.package_role,
|
|
312
|
-
package_distribution=self.package_distribution,
|
|
313
|
-
prune=True,
|
|
314
|
-
recursive=True,
|
|
315
|
-
paths=[],
|
|
316
|
-
stage_fqn=self.stage_fqn,
|
|
317
|
-
package_warehouse=self.package_warehouse,
|
|
318
|
-
policy=AllowAlwaysPolicy(),
|
|
319
|
-
use_scratch_stage=use_scratch_stage,
|
|
320
|
-
scratch_stage_fqn=self.scratch_stage_fqn,
|
|
321
|
-
)
|
|
322
|
-
|
|
323
|
-
def get_validation_result(self, use_scratch_stage: bool = False):
|
|
324
|
-
return ApplicationPackageEntity.get_validation_result_static(
|
|
325
|
-
console=cc,
|
|
326
|
-
project_root=self.project_root,
|
|
327
|
-
deploy_root=self.deploy_root,
|
|
328
|
-
bundle_root=self.bundle_root,
|
|
329
|
-
generated_root=self.generated_root,
|
|
330
|
-
artifacts=self.artifacts,
|
|
331
|
-
package_name=self.package_name,
|
|
332
|
-
package_role=self.package_role,
|
|
333
|
-
package_distribution=self.package_distribution,
|
|
334
|
-
prune=True,
|
|
335
|
-
recursive=True,
|
|
336
|
-
paths=[],
|
|
337
|
-
stage_fqn=self.stage_fqn,
|
|
338
|
-
package_warehouse=self.package_warehouse,
|
|
339
|
-
policy=AllowAlwaysPolicy(),
|
|
340
|
-
use_scratch_stage=use_scratch_stage,
|
|
341
|
-
scratch_stage_fqn=self.scratch_stage_fqn,
|
|
342
|
-
)
|
|
343
|
-
|
|
344
|
-
def get_events( # type: ignore
|
|
345
|
-
self,
|
|
346
|
-
since: str | datetime | None = None,
|
|
347
|
-
until: str | datetime | None = None,
|
|
348
|
-
record_types: list[str] | None = None,
|
|
349
|
-
scopes: list[str] | None = None,
|
|
350
|
-
consumer_org: str = "",
|
|
351
|
-
consumer_account: str = "",
|
|
352
|
-
consumer_app_hash: str = "",
|
|
353
|
-
first: int = -1,
|
|
354
|
-
last: int = -1,
|
|
355
|
-
) -> list[dict]:
|
|
356
|
-
return ApplicationEntity.get_events(
|
|
357
|
-
app_name=self.app_name,
|
|
358
|
-
package_name=self.package_name,
|
|
359
|
-
since=since,
|
|
360
|
-
until=until,
|
|
361
|
-
record_types=record_types,
|
|
362
|
-
scopes=scopes,
|
|
363
|
-
consumer_org=consumer_org,
|
|
364
|
-
consumer_account=consumer_account,
|
|
365
|
-
consumer_app_hash=consumer_app_hash,
|
|
366
|
-
first=first,
|
|
367
|
-
last=last,
|
|
368
|
-
)
|
|
369
|
-
|
|
370
|
-
def stream_events(
|
|
371
|
-
self,
|
|
372
|
-
interval_seconds: int,
|
|
373
|
-
since: str | datetime | None = None,
|
|
374
|
-
record_types: list[str] | None = None,
|
|
375
|
-
scopes: list[str] | None = None,
|
|
376
|
-
consumer_org: str = "",
|
|
377
|
-
consumer_account: str = "",
|
|
378
|
-
consumer_app_hash: str = "",
|
|
379
|
-
last: int = -1,
|
|
380
|
-
) -> Generator[dict, None, None]:
|
|
381
|
-
return ApplicationEntity.stream_events(
|
|
382
|
-
app_name=self.app_name,
|
|
383
|
-
package_name=self.package_name,
|
|
384
|
-
interval_seconds=interval_seconds,
|
|
385
|
-
since=since,
|
|
386
|
-
record_types=record_types,
|
|
387
|
-
scopes=scopes,
|
|
388
|
-
consumer_org=consumer_org,
|
|
389
|
-
consumer_account=consumer_account,
|
|
390
|
-
consumer_app_hash=consumer_app_hash,
|
|
391
|
-
last=last,
|
|
392
|
-
)
|
|
@@ -1,211 +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 functools import cached_property
|
|
18
|
-
from pathlib import Path
|
|
19
|
-
from typing import List, Optional
|
|
20
|
-
|
|
21
|
-
from snowflake.cli._plugins.nativeapp.artifacts import resolve_without_follow
|
|
22
|
-
from snowflake.cli._plugins.nativeapp.bundle_context import BundleContext
|
|
23
|
-
from snowflake.cli.api.cli_global_context import get_cli_context
|
|
24
|
-
from snowflake.cli.api.entities.common import get_sql_executor
|
|
25
|
-
from snowflake.cli.api.project.definition import (
|
|
26
|
-
default_app_package,
|
|
27
|
-
default_application,
|
|
28
|
-
default_role,
|
|
29
|
-
)
|
|
30
|
-
from snowflake.cli.api.project.schemas.entities.common import PostDeployHook
|
|
31
|
-
from snowflake.cli.api.project.schemas.v1.native_app.native_app import NativeApp
|
|
32
|
-
from snowflake.cli.api.project.schemas.v1.native_app.path_mapping import PathMapping
|
|
33
|
-
from snowflake.cli.api.project.util import (
|
|
34
|
-
append_test_resource_suffix,
|
|
35
|
-
extract_schema,
|
|
36
|
-
to_identifier,
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class NativeAppProjectModel:
|
|
41
|
-
"""
|
|
42
|
-
Exposes properties of a native app project defined in a Snowflake Project Definition file. Whenever
|
|
43
|
-
appropriate, APIs defined in this class provide suitable defaults or fallback logic to access properties
|
|
44
|
-
of the project.
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
def __init__(
|
|
48
|
-
self,
|
|
49
|
-
project_definition: NativeApp,
|
|
50
|
-
project_root: Path,
|
|
51
|
-
):
|
|
52
|
-
self._project_definition = project_definition
|
|
53
|
-
self._project_root = resolve_without_follow(project_root)
|
|
54
|
-
|
|
55
|
-
@property
|
|
56
|
-
def project_root(self) -> Path:
|
|
57
|
-
return self._project_root
|
|
58
|
-
|
|
59
|
-
@property
|
|
60
|
-
def definition(self) -> NativeApp:
|
|
61
|
-
return self._project_definition
|
|
62
|
-
|
|
63
|
-
@cached_property
|
|
64
|
-
def artifacts(self) -> List[PathMapping]:
|
|
65
|
-
return self.definition.artifacts
|
|
66
|
-
|
|
67
|
-
@cached_property
|
|
68
|
-
def bundle_root(self) -> Path:
|
|
69
|
-
return self.project_root / self.definition.bundle_root
|
|
70
|
-
|
|
71
|
-
@cached_property
|
|
72
|
-
def deploy_root(self) -> Path:
|
|
73
|
-
return self.project_root / self.definition.deploy_root
|
|
74
|
-
|
|
75
|
-
@cached_property
|
|
76
|
-
def generated_root(self) -> Path:
|
|
77
|
-
return self.deploy_root / self.definition.generated_root
|
|
78
|
-
|
|
79
|
-
@cached_property
|
|
80
|
-
def package_scripts(self) -> List[str]:
|
|
81
|
-
"""
|
|
82
|
-
Relative paths to package scripts from the project root.
|
|
83
|
-
"""
|
|
84
|
-
if self.definition.package and self.definition.package.scripts:
|
|
85
|
-
return self.definition.package.scripts
|
|
86
|
-
else:
|
|
87
|
-
return []
|
|
88
|
-
|
|
89
|
-
@cached_property
|
|
90
|
-
def stage_fqn(self) -> str:
|
|
91
|
-
return f"{self.package_name}.{self.definition.source_stage}"
|
|
92
|
-
|
|
93
|
-
@cached_property
|
|
94
|
-
def scratch_stage_fqn(self) -> str:
|
|
95
|
-
return f"{self.package_name}.{self.definition.scratch_stage}"
|
|
96
|
-
|
|
97
|
-
@cached_property
|
|
98
|
-
def stage_schema(self) -> Optional[str]:
|
|
99
|
-
return extract_schema(self.stage_fqn)
|
|
100
|
-
|
|
101
|
-
@cached_property
|
|
102
|
-
def package_warehouse(self) -> Optional[str]:
|
|
103
|
-
if self.definition.package and self.definition.package.warehouse:
|
|
104
|
-
return to_identifier(self.definition.package.warehouse)
|
|
105
|
-
else:
|
|
106
|
-
cli_context = get_cli_context()
|
|
107
|
-
if cli_context.connection.warehouse:
|
|
108
|
-
return to_identifier(cli_context.connection.warehouse)
|
|
109
|
-
return None
|
|
110
|
-
|
|
111
|
-
@cached_property
|
|
112
|
-
def application_warehouse(self) -> Optional[str]:
|
|
113
|
-
if self.definition.application and self.definition.application.warehouse:
|
|
114
|
-
return to_identifier(self.definition.application.warehouse)
|
|
115
|
-
else:
|
|
116
|
-
cli_context = get_cli_context()
|
|
117
|
-
if cli_context.connection.warehouse:
|
|
118
|
-
return to_identifier(cli_context.connection.warehouse)
|
|
119
|
-
return None
|
|
120
|
-
|
|
121
|
-
@cached_property
|
|
122
|
-
def project_identifier(self) -> str:
|
|
123
|
-
# name is expected to be a valid Snowflake identifier, but YAML parsers will
|
|
124
|
-
# sometimes strip out double quotes, so we try to get them back here.
|
|
125
|
-
return to_identifier(self.definition.name)
|
|
126
|
-
|
|
127
|
-
@property
|
|
128
|
-
def package_name(self) -> str:
|
|
129
|
-
if self.definition.package and self.definition.package.name:
|
|
130
|
-
return to_identifier(self.definition.package.name)
|
|
131
|
-
else:
|
|
132
|
-
# V1.0 PDF doesn't support templating, so if the identifier isn't
|
|
133
|
-
# explicitly specified, the default is generated here,
|
|
134
|
-
# so we have to append the test resource suffix here
|
|
135
|
-
name = default_app_package(self.project_identifier)
|
|
136
|
-
return to_identifier(append_test_resource_suffix(name))
|
|
137
|
-
|
|
138
|
-
@cached_property
|
|
139
|
-
def package_role(self) -> str:
|
|
140
|
-
if self.definition.package and self.definition.package.role:
|
|
141
|
-
return self.definition.package.role
|
|
142
|
-
else:
|
|
143
|
-
return self._default_role
|
|
144
|
-
|
|
145
|
-
@cached_property
|
|
146
|
-
def package_distribution(self) -> str:
|
|
147
|
-
if self.definition.package and self.definition.package.distribution:
|
|
148
|
-
return self.definition.package.distribution.lower()
|
|
149
|
-
else:
|
|
150
|
-
return "internal"
|
|
151
|
-
|
|
152
|
-
@property
|
|
153
|
-
def app_name(self) -> str:
|
|
154
|
-
if self.definition.application and self.definition.application.name:
|
|
155
|
-
return to_identifier(self.definition.application.name)
|
|
156
|
-
else:
|
|
157
|
-
# V1.0 PDF doesn't support templating, so if the identifier isn't
|
|
158
|
-
# explicitly specified, the default is generated here,
|
|
159
|
-
# so we have to append the test resource suffix here
|
|
160
|
-
name = default_application(self.project_identifier)
|
|
161
|
-
return to_identifier(append_test_resource_suffix(name))
|
|
162
|
-
|
|
163
|
-
@cached_property
|
|
164
|
-
def app_role(self) -> str:
|
|
165
|
-
if self.definition.application and self.definition.application.role:
|
|
166
|
-
return self.definition.application.role
|
|
167
|
-
else:
|
|
168
|
-
return self._default_role
|
|
169
|
-
|
|
170
|
-
@cached_property
|
|
171
|
-
def app_post_deploy_hooks(self) -> Optional[List[PostDeployHook]]:
|
|
172
|
-
"""
|
|
173
|
-
List of application instance post deploy hooks.
|
|
174
|
-
"""
|
|
175
|
-
if self.definition.application and self.definition.application.post_deploy:
|
|
176
|
-
return self.definition.application.post_deploy
|
|
177
|
-
else:
|
|
178
|
-
return None
|
|
179
|
-
|
|
180
|
-
@cached_property
|
|
181
|
-
def package_post_deploy_hooks(self) -> Optional[List[PostDeployHook]]:
|
|
182
|
-
"""
|
|
183
|
-
List of application package post deploy hooks.
|
|
184
|
-
"""
|
|
185
|
-
if self.definition.package and self.definition.package.post_deploy:
|
|
186
|
-
return self.definition.package.post_deploy
|
|
187
|
-
else:
|
|
188
|
-
return None
|
|
189
|
-
|
|
190
|
-
@cached_property
|
|
191
|
-
def _default_role(self) -> str:
|
|
192
|
-
role = default_role()
|
|
193
|
-
if role is None:
|
|
194
|
-
role = get_sql_executor().current_role()
|
|
195
|
-
return role
|
|
196
|
-
|
|
197
|
-
@cached_property
|
|
198
|
-
def debug_mode(self) -> Optional[bool]:
|
|
199
|
-
if self.definition.application:
|
|
200
|
-
return self.definition.application.debug
|
|
201
|
-
return None
|
|
202
|
-
|
|
203
|
-
def get_bundle_context(self) -> BundleContext:
|
|
204
|
-
return BundleContext(
|
|
205
|
-
package_name=self.package_name,
|
|
206
|
-
artifacts=self.artifacts,
|
|
207
|
-
project_root=self.project_root,
|
|
208
|
-
bundle_root=self.bundle_root,
|
|
209
|
-
deploy_root=self.deploy_root,
|
|
210
|
-
generated_root=self.generated_root,
|
|
211
|
-
)
|