Skip to content

Commit

Permalink
Merge branch 'main' into frank-remove-v1-test-projects
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-fcampbell authored Oct 9, 2024
2 parents 2a93612 + f6448d2 commit 34b7945
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
20 changes: 12 additions & 8 deletions src/snowflake/cli/_plugins/nativeapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,25 +367,29 @@ def app_deploy(

@app.command("validate", requires_connection=True)
@with_project_definition()
@nativeapp_definition_v2_to_v1()
@single_app_and_package()
def app_validate(
**options,
):
"""
Validates a deployed Snowflake Native App's setup script.
"""

assert_project_type("native_app")

cli_context = get_cli_context()
manager = NativeAppManager(
project_definition=cli_context.project_definition.native_app,
ws = WorkspaceManager(
project_definition=cli_context.project_definition,
project_root=cli_context.project_root,
)
package_id = options["package_entity_id"]
package = ws.get_entity(package_id)
if cli_context.output_format == OutputFormat.JSON:
return ObjectResult(manager.get_validation_result(use_scratch_stage=True))
return ObjectResult(package.get_validation_result(use_scratch_stage=True))

manager.validate(use_scratch_stage=True)
ws.perform_action(
package_id,
EntityActions.VALIDATE,
interactive=False,
force=True,
)
return MessageResult("Snowflake Native App validation succeeded.")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ def validate_setup_script(
):
"""Validates Native App setup script SQL."""
with console.phase(f"Validating Snowflake Native App setup script."):
validation_result = cls.get_validation_result(
validation_result = cls.get_validation_result_static(
console=console,
project_root=project_root,
deploy_root=deploy_root,
Expand Down Expand Up @@ -1243,8 +1243,38 @@ def validate_setup_script(
if validation_result["status"] == "FAIL":
raise SetupScriptFailedValidation()

def get_validation_result(self, use_scratch_stage: bool = True):
model = self._entity_model
workspace_ctx = self._workspace_ctx
package_name = model.fqn.identifier
return self.get_validation_result_static(
console=workspace_ctx.console,
project_root=workspace_ctx.project_root,
deploy_root=workspace_ctx.project_root / model.deploy_root,
bundle_root=workspace_ctx.project_root / model.bundle_root,
generated_root=(
workspace_ctx.project_root / model.deploy_root / model.generated_root
),
artifacts=model.artifacts,
package_name=package_name,
package_role=(model.meta and model.meta.role) or workspace_ctx.default_role,
package_distribution=model.distribution,
prune=True,
recursive=True,
paths=[],
stage_fqn=f"{package_name}.{model.stage}",
package_warehouse=(
(model.meta and model.meta.warehouse) or workspace_ctx.default_warehouse
),
post_deploy_hooks=model.meta and model.meta.post_deploy,
package_scripts=[], # Package scripts are not supported in PDFv2
policy=AllowAlwaysPolicy(),
use_scratch_stage=use_scratch_stage,
scratch_stage_fqn=f"{package_name}.{model.scratch_stage}",
)

@classmethod
def get_validation_result(
def get_validation_result_static(
cls,
console: AbstractConsole,
project_root: Path,
Expand Down
2 changes: 1 addition & 1 deletion src/snowflake/cli/_plugins/nativeapp/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def validate(self, use_scratch_stage: bool = False):
)

def get_validation_result(self, use_scratch_stage: bool = False):
return ApplicationPackageEntity.get_validation_result(
return ApplicationPackageEntity.get_validation_result_static(
console=cc,
project_root=self.project_root,
deploy_root=self.deploy_root,
Expand Down

0 comments on commit 34b7945

Please sign in to comment.