Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional subdirectory for stage in application package #1916

Merged
merged 52 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
8617252
teardown with comments
sfc-gh-pjafari Nov 29, 2024
5a3e154
make version work
sfc-gh-pjafari Nov 29, 2024
8db7a40
update path for version create
sfc-gh-pjafari Dec 2, 2024
d9eb5f4
catch tempalte processor file read error
sfc-gh-pjafari Dec 2, 2024
71108d0
make diff an entity action
sfc-gh-pjafari Dec 2, 2024
a7e3a20
remove teardown with all apps logic
sfc-gh-pjafari Dec 2, 2024
99abebf
ws change
sfc-gh-pjafari Dec 2, 2024
ce71ebf
add schema to StagePathParts
sfc-gh-pjafari Dec 3, 2024
855b413
use DefaultStagePathParts for stage in NA
sfc-gh-pjafari Dec 3, 2024
68904aa
remmove comments
sfc-gh-pjafari Dec 3, 2024
5fc642e
clean up
sfc-gh-pjafari Dec 3, 2024
49275b9
clean up
sfc-gh-pjafari Dec 3, 2024
04d807e
update comment
sfc-gh-pjafari Dec 3, 2024
be0402b
merge main
sfc-gh-pjafari Dec 3, 2024
ff369e7
rename stage
sfc-gh-pjafari Dec 3, 2024
31e1f70
remove trailing slash when no directory
sfc-gh-pjafari Dec 3, 2024
f52c6cb
update unit tests
sfc-gh-pjafari Dec 3, 2024
e95ab86
update docstring
sfc-gh-pjafari Dec 3, 2024
b663798
add unit tests for DefaultStagePathParts
sfc-gh-pjafari Dec 4, 2024
3412b3c
Merge branch 'pj-schema-in-stagepathparts' into pj-subartifacts-subdirs
sfc-gh-pjafari Dec 4, 2024
08a4110
update stage diff command and message wording
sfc-gh-pjafari Dec 4, 2024
c7a0a88
update snapshot for test_deploy
sfc-gh-pjafari Dec 4, 2024
8153807
Merge branch 'main' into pj-subartifacts-subdirs
sfc-gh-pjafari Dec 4, 2024
504f692
add integration tests
sfc-gh-pjafari Dec 4, 2024
5cbf941
Merge branch 'main' into pj-subartifacts-subdirs
sfc-gh-pjafari Dec 4, 2024
56fc4f6
iMerge branch 'pj-subartifacts-subdirs' of https://github.com/snowfla…
sfc-gh-pjafari Dec 4, 2024
b81670c
add unit tests
sfc-gh-pjafari Dec 5, 2024
889c77e
update release notes
sfc-gh-pjafari Dec 5, 2024
44263ce
remove template processor change
sfc-gh-pjafari Dec 5, 2024
70e3d38
make stage paths work for quoted ids
sfc-gh-pjafari Dec 6, 2024
c0b0826
address comments
sfc-gh-pjafari Dec 6, 2024
4ec1071
make for quoted identifiers in diff
sfc-gh-pjafari Dec 7, 2024
00db5a8
merge main
sfc-gh-pjafari Dec 12, 2024
7f30fea
make diff work with all identifiers, update docstrings
sfc-gh-pjafari Dec 12, 2024
1921805
update tests
sfc-gh-pjafari Dec 12, 2024
3f9ed94
merge main
sfc-gh-pjafari Dec 13, 2024
d84a59c
fix tests
sfc-gh-pjafari Dec 13, 2024
d865ac8
update commands
sfc-gh-pjafari Dec 17, 2024
dfb4373
merge main
sfc-gh-pjafari Dec 17, 2024
aa80ac4
replace test data with factory
sfc-gh-pjafari Dec 17, 2024
a225d44
import fixture
sfc-gh-pjafari Dec 17, 2024
b94bad5
comments
sfc-gh-pjafari Dec 18, 2024
b01d0d9
merge main
sfc-gh-pjafari Jan 8, 2025
f341e77
merge main
sfc-gh-pjafari Jan 8, 2025
6aaed28
rerun jobs
sfc-gh-pjafari Jan 8, 2025
5969b5f
Merge branch 'main' into pj-subartifacts-subdirs
sfc-gh-pjafari Jan 8, 2025
3a685b0
fix format
sfc-gh-pjafari Jan 8, 2025
18ff9fe
Merge branch 'main' into pj-subartifacts-subdirs
sfc-gh-pjafari Jan 8, 2025
df23a6e
merge main
sfc-gh-pjafari Jan 9, 2025
3b2a3eb
make state path parts factory method public
sfc-gh-pjafari Jan 9, 2025
c328d96
merge main and update tests
sfc-gh-pjafari Jan 13, 2025
36e1ddb
merge main
sfc-gh-pjafari Jan 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
* Add ability to add and remove accounts from release channels through `snow app release-channel add-accounts` and snow app release-channel remove-accounts` commands.
* Add ability to add/remove versions to/from release channels through `snow app release-channel add-version` and `snow app release-channel remove-version` commands.
* Add support for restricting Snowflake user authentication policy to Snowflake CLI-only.
* Add an optional `stage_subdirectory` field to `application package` entity. When specified, application artifacts are uploaded to this subdirectory instead of the root of the application package's stage.

## Fixes and improvements
* Fixed inability to add patches to lowercase quoted versions
* Fixes label being set to blank instead of None when not provided.
* Added a feature flag `ENABLE_SPCS_LOG_STREAMING` to control the rollout of the log streaming feature


# v3.2.2
## Backward incompatibility

Expand Down
34 changes: 18 additions & 16 deletions src/snowflake/cli/_plugins/nativeapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
force_project_definition_v2,
)
from snowflake.cli._plugins.nativeapp.version.commands import app as versions_app
from snowflake.cli._plugins.stage.diff import (
DiffResult,
compute_stage_diff,
)
from snowflake.cli._plugins.stage.utils import print_diff_to_console
from snowflake.cli._plugins.workspace.manager import WorkspaceManager
from snowflake.cli.api.cli_global_context import get_cli_context
from snowflake.cli.api.commands.decorators import (
Expand All @@ -66,6 +61,7 @@
ObjectResult,
StreamResult,
)
from snowflake.cli.api.project.util import same_identifiers
from typing_extensions import Annotated

app = SnowTyperFactory(
Expand Down Expand Up @@ -117,20 +113,15 @@ def app_diff(
project_root=cli_context.project_root,
)
package_id = options["package_entity_id"]
package = cli_context.project_definition.entities[package_id]
bundle_map = ws.perform_action(
diff = ws.perform_action(
package_id,
EntityActions.BUNDLE,
)
stage_fqn = f"{package.fqn.name}.{package.stage}"
diff: DiffResult = compute_stage_diff(
local_root=Path(package.deploy_root), stage_fqn=stage_fqn
EntityActions.DIFF,
print_to_console=cli_context.output_format != OutputFormat.JSON,
)
if cli_context.output_format == OutputFormat.JSON:
return ObjectResult(diff.to_dict())
else:
print_diff_to_console(diff, bundle_map)
return None # don't print any output

return None
sfc-gh-pjafari marked this conversation as resolved.
Show resolved Hide resolved


@app.command("run", requires_connection=True)
Expand Down Expand Up @@ -262,11 +253,22 @@ def app_teardown(
project_definition=cli_context.project_definition,
project_root=cli_context.project_root,
)

# TODO: get all apps created from this application package from snowflake, compare, confirm and drop.
# TODO: add messaging/confirmation here for extra apps found as part of above
sfc-gh-pjafari marked this conversation as resolved.
Show resolved Hide resolved
all_packages_with_id = [
package_entity.entity_id
for package_entity in project.get_entities_by_type(
ApplicationPackageEntityModel.get_type()
).values()
if same_identifiers(package_entity.fqn.name, app_package_entity.fqn.name)
]

for app_entity in project.get_entities_by_type(
ApplicationEntityModel.get_type()
).values():
# Drop each app
if app_entity.from_.target == app_package_entity.entity_id:
if app_entity.from_.target in all_packages_with_id:
ws.perform_action(
app_entity.entity_id,
EntityActions.DROP,
Expand Down
33 changes: 15 additions & 18 deletions src/snowflake/cli/_plugins/nativeapp/entities/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
UpgradeApplicationRestrictionError,
)
from snowflake.cli._plugins.nativeapp.utils import needs_confirmation
from snowflake.cli._plugins.stage.manager import DefaultStagePathParts
from snowflake.cli._plugins.workspace.context import ActionContext
from snowflake.cli.api.cli_global_context import get_cli_context, span
from snowflake.cli.api.console.abc import AbstractConsole
Expand Down Expand Up @@ -83,7 +84,6 @@
from snowflake.cli.api.project.schemas.updatable_model import DiscriminatorField
from snowflake.cli.api.project.util import (
append_test_resource_suffix,
extract_schema,
identifier_for_url,
to_identifier,
unquote_identifier,
Expand Down Expand Up @@ -331,7 +331,6 @@ def action_deploy(
paths: List[Path],
release_channel: Optional[str] = None,
validate: bool = ValidateOption,
stage_fqn: Optional[str] = None,
interactive: bool = InteractiveOption,
version: Optional[str] = None,
patch: Optional[int] = None,
Expand All @@ -346,7 +345,8 @@ def action_deploy(
package_entity: ApplicationPackageEntity = action_ctx.get_entity(
self.package_entity_id
)
stage_fqn = stage_fqn or package_entity.stage_fqn

stage_path = package_entity.stage_path

if force:
policy = AllowAlwaysPolicy()
Expand All @@ -363,7 +363,7 @@ def action_deploy(

self.create_or_upgrade_app(
package=package_entity,
stage_fqn=stage_fqn,
stage_path=stage_path,
install_method=SameAccountInstallMethod.release_directive(),
release_channel=release_channel,
policy=policy,
Expand Down Expand Up @@ -391,7 +391,7 @@ def action_deploy(

self.create_or_upgrade_app(
package=package_entity,
stage_fqn=stage_fqn,
stage_path=stage_path,
install_method=SameAccountInstallMethod.versioned_dev(version, patch),
policy=policy,
interactive=interactive,
Expand All @@ -405,13 +405,12 @@ def action_deploy(
recursive=True,
paths=[],
validate=validate,
stage_fqn=stage_fqn,
interactive=interactive,
force=force,
)
self.create_or_upgrade_app(
package=package_entity,
stage_fqn=stage_fqn,
stage_path=stage_path,
install_method=SameAccountInstallMethod.unversioned_dev(),
policy=policy,
interactive=interactive,
Expand Down Expand Up @@ -609,7 +608,7 @@ def get_objects_owned_by_application(self) -> List[ApplicationOwnedObject]:

def _upgrade_app(
self,
stage_fqn: str,
stage_path: DefaultStagePathParts,
install_method: SameAccountInstallMethod,
event_sharing: EventSharingHandler,
policy: PolicyBase,
Expand All @@ -622,7 +621,7 @@ def _upgrade_app(
return get_snowflake_facade().upgrade_application(
name=self.name,
install_method=install_method,
stage_fqn=stage_fqn,
path_to_version_directory=stage_path.full_path,
debug_mode=self.debug,
should_authorize_event_sharing=event_sharing.should_authorize_event_sharing(),
release_channel=release_channel,
Expand All @@ -636,7 +635,7 @@ def _upgrade_app(

def _create_app(
self,
stage_fqn: str,
stage_path: DefaultStagePathParts,
install_method: SameAccountInstallMethod,
event_sharing: EventSharingHandler,
package: ApplicationPackageEntity,
Expand All @@ -653,7 +652,7 @@ def _create_app(
role_to_use=package.role,
)

stage_schema = extract_schema(stage_fqn)
stage_schema = stage_path.schema
get_snowflake_facade().grant_privileges_to_role(
privileges=["usage"],
object_type=ObjectType.SCHEMA,
Expand All @@ -665,7 +664,7 @@ def _create_app(
get_snowflake_facade().grant_privileges_to_role(
privileges=["read"],
object_type=ObjectType.STAGE,
object_identifier=stage_fqn,
object_identifier=stage_path.stage,
role_to_grant=self.role,
role_to_use=package.role,
)
Expand All @@ -674,7 +673,7 @@ def _create_app(
name=self.name,
package_name=package.name,
install_method=install_method,
stage_fqn=stage_fqn,
path_to_version_directory=stage_path.full_path,
debug_mode=self.debug,
should_authorize_event_sharing=event_sharing.should_authorize_event_sharing(),
role=self.role,
Expand All @@ -686,7 +685,7 @@ def _create_app(
def create_or_upgrade_app(
self,
package: ApplicationPackageEntity,
stage_fqn: str,
stage_path: DefaultStagePathParts,
install_method: SameAccountInstallMethod,
policy: PolicyBase,
interactive: bool,
Expand All @@ -704,13 +703,11 @@ def create_or_upgrade_app(
self.name, self.role
)

stage_fqn = stage_fqn or package.stage_fqn

# 2. If existing application is found, try to upgrade the application object.
create_or_upgrade_result = None
if show_app_row:
create_or_upgrade_result = self._upgrade_app(
stage_fqn=stage_fqn,
stage_path=stage_path,
install_method=install_method,
event_sharing=event_sharing,
policy=policy,
Expand All @@ -721,7 +718,7 @@ def create_or_upgrade_app(
# 3. If no existing application found, or we performed a drop before the upgrade, we proceed to create
if create_or_upgrade_result is None:
create_or_upgrade_result = self._create_app(
stage_fqn=stage_fqn,
stage_path=stage_path,
install_method=install_method,
event_sharing=event_sharing,
package=package,
Expand Down
Loading
Loading