From 53e1f6df6a2d809cc930568e29c9593b71d0942a Mon Sep 17 00:00:00 2001 From: Ilya Kuznetsov Date: Mon, 18 Nov 2024 16:05:21 +0100 Subject: [PATCH] fix: Skip permissions set and check for in-place --- bundle/bundle_read_only.go | 4 ++++ bundle/config/validate/folder_permissions.go | 4 ++++ bundle/config/validate/folder_permissions_test.go | 3 +++ bundle/permissions/workspace_root.go | 4 ++++ bundle/permissions/workspace_root_test.go | 2 ++ 5 files changed, 17 insertions(+) diff --git a/bundle/bundle_read_only.go b/bundle/bundle_read_only.go index ceab95c0b..466b09034 100644 --- a/bundle/bundle_read_only.go +++ b/bundle/bundle_read_only.go @@ -32,6 +32,10 @@ func (r ReadOnlyBundle) SyncRoot() vfs.Path { return r.b.SyncRoot } +func (r ReadOnlyBundle) SyncRootPath() string { + return r.b.SyncRootPath +} + func (r ReadOnlyBundle) WorkspaceClient() *databricks.WorkspaceClient { return r.b.WorkspaceClient() } diff --git a/bundle/config/validate/folder_permissions.go b/bundle/config/validate/folder_permissions.go index 505e82a1e..4cc2d9a01 100644 --- a/bundle/config/validate/folder_permissions.go +++ b/bundle/config/validate/folder_permissions.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "path" + "strings" "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/libraries" @@ -30,6 +31,9 @@ func (f *folderPermissions) Apply(ctx context.Context, b bundle.ReadOnlyBundle) g, ctx := errgroup.WithContext(ctx) results := make([]diag.Diagnostics, len(bundlePaths)) for i, p := range bundlePaths { + if strings.HasPrefix(p, b.SyncRootPath()) { + continue + } g.Go(func() error { results[i] = checkFolderPermission(ctx, b, p) return nil diff --git a/bundle/config/validate/folder_permissions_test.go b/bundle/config/validate/folder_permissions_test.go index 8e68c9fbf..2af2a349c 100644 --- a/bundle/config/validate/folder_permissions_test.go +++ b/bundle/config/validate/folder_permissions_test.go @@ -77,6 +77,7 @@ func TestFolderPermissionsInheritedWhenRootPathDoesNotExist(t *testing.T) { func TestValidateFolderPermissionsFailsOnMissingBundlePermission(t *testing.T) { b := &bundle.Bundle{ + SyncRootPath: t.TempDir(), Config: config.Root{ Workspace: config.Workspace{ RootPath: "/Workspace/Users/foo@bar.com", @@ -129,6 +130,7 @@ func TestValidateFolderPermissionsFailsOnMissingBundlePermission(t *testing.T) { func TestValidateFolderPermissionsFailsOnPermissionMismatch(t *testing.T) { b := &bundle.Bundle{ + SyncRootPath: t.TempDir(), Config: config.Root{ Workspace: config.Workspace{ RootPath: "/Workspace/Users/foo@bar.com", @@ -174,6 +176,7 @@ func TestValidateFolderPermissionsFailsOnPermissionMismatch(t *testing.T) { func TestValidateFolderPermissionsFailsOnNoRootFolder(t *testing.T) { b := &bundle.Bundle{ + SyncRootPath: t.TempDir(), Config: config.Root{ Workspace: config.Workspace{ RootPath: "/NotExisting", diff --git a/bundle/permissions/workspace_root.go b/bundle/permissions/workspace_root.go index de4f3a7fe..665be88ca 100644 --- a/bundle/permissions/workspace_root.go +++ b/bundle/permissions/workspace_root.go @@ -3,6 +3,7 @@ package permissions import ( "context" "fmt" + "strings" "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/libraries" @@ -59,6 +60,9 @@ func giveAccessForWorkspaceRoot(ctx context.Context, b *bundle.Bundle) error { g, ctx := errgroup.WithContext(ctx) for _, p := range bundlePaths { + if strings.HasPrefix(p, b.SyncRootPath) { + continue + } g.Go(func() error { return setPermissions(ctx, w, p, permissions) }) diff --git a/bundle/permissions/workspace_root_test.go b/bundle/permissions/workspace_root_test.go index c48704a63..7b9937609 100644 --- a/bundle/permissions/workspace_root_test.go +++ b/bundle/permissions/workspace_root_test.go @@ -19,6 +19,7 @@ import ( func TestApplyWorkspaceRootPermissions(t *testing.T) { b := &bundle.Bundle{ + SyncRootPath: t.TempDir(), Config: config.Root{ Workspace: config.Workspace{ RootPath: "/Users/foo@bar.com", @@ -79,6 +80,7 @@ func TestApplyWorkspaceRootPermissions(t *testing.T) { func TestApplyWorkspaceRootPermissionsForAllPaths(t *testing.T) { b := &bundle.Bundle{ + SyncRootPath: t.TempDir(), Config: config.Root{ Workspace: config.Workspace{ RootPath: "/Some/Root/Path",