Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnester committed Oct 22, 2024
1 parent 20f33d6 commit c45c441
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
5 changes: 5 additions & 0 deletions bundle/libraries/workspace_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ func IsWorkspaceLibrary(library *compute.Library) bool {

return IsWorkspacePath(path)
}

// IsVolumesPath returns true if the specified path indicates that
func IsVolumesPath(path string) bool {
return strings.HasPrefix(path, "/Volumes/")
}
54 changes: 27 additions & 27 deletions bundle/permissions/workspace_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"strings"

"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/libraries"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/databricks-sdk-go/service/workspace"
"golang.org/x/sync/errgroup"
)

type workspaceRootPermissions struct {
Expand Down Expand Up @@ -53,46 +55,44 @@ func giveAccessForWorkspaceRoot(ctx context.Context, b *bundle.Bundle) error {
}

w := b.WorkspaceClient().Workspace
err := setPermissions(ctx, w, b.Config.Workspace.RootPath, permissions)
if err != nil {
return err
rootPath := b.Config.Workspace.RootPath
paths := []string{}
if !libraries.IsVolumesPath(rootPath) {
paths = append(paths, rootPath)
}

// Adding backslash to the root path
rootPath := b.Config.Workspace.RootPath
if rootPath[len(rootPath)-1] != '/' {
if !strings.HasSuffix(rootPath, "/") {
rootPath += "/"
}

if !strings.HasPrefix(b.Config.Workspace.ArtifactPath, rootPath) {
err = setPermissions(ctx, w, b.Config.Workspace.ArtifactPath, permissions)
if err != nil {
return err
}
if !strings.HasPrefix(b.Config.Workspace.ArtifactPath, rootPath) &&
!libraries.IsVolumesPath(b.Config.Workspace.ArtifactPath) {
paths = append(paths, b.Config.Workspace.ArtifactPath)
}

if !strings.HasPrefix(b.Config.Workspace.FilePath, rootPath) {
err = setPermissions(ctx, w, b.Config.Workspace.FilePath, permissions)
if err != nil {
return err
}
if !strings.HasPrefix(b.Config.Workspace.FilePath, rootPath) &&
!libraries.IsVolumesPath(b.Config.Workspace.FilePath) {
paths = append(paths, b.Config.Workspace.FilePath)
}

if !strings.HasPrefix(b.Config.Workspace.StatePath, rootPath) {
err = setPermissions(ctx, w, b.Config.Workspace.StatePath, permissions)
if err != nil {
return err
}
if !strings.HasPrefix(b.Config.Workspace.StatePath, rootPath) &&
!libraries.IsVolumesPath(b.Config.Workspace.StatePath) {
paths = append(paths, b.Config.Workspace.StatePath)
}

if !strings.HasPrefix(b.Config.Workspace.ResourcePath, rootPath) {
err = setPermissions(ctx, w, b.Config.Workspace.ResourcePath, permissions)
if err != nil {
return err
}
if !strings.HasPrefix(b.Config.Workspace.ResourcePath, rootPath) &&
!libraries.IsVolumesPath(b.Config.Workspace.ResourcePath) {
paths = append(paths, b.Config.Workspace.ResourcePath)
}

return err
g, ctx := errgroup.WithContext(ctx)
for _, p := range paths {
g.Go(func() error {
return setPermissions(ctx, w, p, permissions)
})
}

return g.Wait()
}

func setPermissions(ctx context.Context, w workspace.WorkspaceInterface, path string, permissions []workspace.WorkspaceObjectAccessControlRequest) error {
Expand Down

0 comments on commit c45c441

Please sign in to comment.