This commit is contained in:
Andrew Nester 2024-10-22 16:28:32 +02:00
parent 99fbf33ef1
commit a51c5731fe
No known key found for this signature in database
GPG Key ID: 12BC628A44B7DA57
1 changed files with 27 additions and 27 deletions

View File

@ -6,8 +6,10 @@ import (
"strings" "strings"
"github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/libraries"
"github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/diag"
"github.com/databricks/databricks-sdk-go/service/workspace" "github.com/databricks/databricks-sdk-go/service/workspace"
"golang.org/x/sync/errgroup"
) )
type workspaceRootPermissions struct { type workspaceRootPermissions struct {
@ -53,46 +55,44 @@ func giveAccessForWorkspaceRoot(ctx context.Context, b *bundle.Bundle) error {
} }
w := b.WorkspaceClient().Workspace w := b.WorkspaceClient().Workspace
err := setPermissions(ctx, w, b.Config.Workspace.RootPath, permissions) rootPath := b.Config.Workspace.RootPath
if err != nil { paths := []string{}
return err if !libraries.IsVolumesPath(rootPath) {
paths = append(paths, rootPath)
} }
// Adding backslash to the root path if !strings.HasSuffix(rootPath, "/") {
rootPath := b.Config.Workspace.RootPath
if rootPath[len(rootPath)-1] != '/' {
rootPath += "/" rootPath += "/"
} }
if !strings.HasPrefix(b.Config.Workspace.ArtifactPath, rootPath) { if !strings.HasPrefix(b.Config.Workspace.ArtifactPath, rootPath) &&
err = setPermissions(ctx, w, b.Config.Workspace.ArtifactPath, permissions) !libraries.IsVolumesPath(b.Config.Workspace.ArtifactPath) {
if err != nil { paths = append(paths, b.Config.Workspace.ArtifactPath)
return err
}
} }
if !strings.HasPrefix(b.Config.Workspace.FilePath, rootPath) { if !strings.HasPrefix(b.Config.Workspace.FilePath, rootPath) &&
err = setPermissions(ctx, w, b.Config.Workspace.FilePath, permissions) !libraries.IsVolumesPath(b.Config.Workspace.FilePath) {
if err != nil { paths = append(paths, b.Config.Workspace.FilePath)
return err
}
} }
if !strings.HasPrefix(b.Config.Workspace.StatePath, rootPath) { if !strings.HasPrefix(b.Config.Workspace.StatePath, rootPath) &&
err = setPermissions(ctx, w, b.Config.Workspace.StatePath, permissions) !libraries.IsVolumesPath(b.Config.Workspace.StatePath) {
if err != nil { paths = append(paths, b.Config.Workspace.StatePath)
return err
}
} }
if !strings.HasPrefix(b.Config.Workspace.ResourcePath, rootPath) { if !strings.HasPrefix(b.Config.Workspace.ResourcePath, rootPath) &&
err = setPermissions(ctx, w, b.Config.Workspace.ResourcePath, permissions) !libraries.IsVolumesPath(b.Config.Workspace.ResourcePath) {
if err != nil { paths = append(paths, b.Config.Workspace.ResourcePath)
return err
}
} }
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 { func setPermissions(ctx context.Context, w workspace.WorkspaceInterface, path string, permissions []workspace.WorkspaceObjectAccessControlRequest) error {