mirror of https://github.com/databricks/cli.git
reuse
This commit is contained in:
parent
a51c5731fe
commit
16f02c0e50
|
@ -4,10 +4,9 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle"
|
"github.com/databricks/cli/bundle"
|
||||||
"github.com/databricks/cli/bundle/libraries"
|
"github.com/databricks/cli/bundle/paths"
|
||||||
"github.com/databricks/cli/bundle/permissions"
|
"github.com/databricks/cli/bundle/permissions"
|
||||||
"github.com/databricks/cli/libs/diag"
|
"github.com/databricks/cli/libs/diag"
|
||||||
"github.com/databricks/databricks-sdk-go/apierr"
|
"github.com/databricks/databricks-sdk-go/apierr"
|
||||||
|
@ -24,37 +23,12 @@ func (f *folderPermissions) Apply(ctx context.Context, b bundle.ReadOnlyBundle)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
rootPath := b.Config().Workspace.RootPath
|
bundlePaths := paths.CollectUniquePaths(b.Config().Workspace)
|
||||||
paths := []string{}
|
|
||||||
if !libraries.IsVolumesPath(rootPath) && !libraries.IsWorkspaceSharedPath(rootPath) {
|
|
||||||
paths = append(paths, rootPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasSuffix(rootPath, "/") {
|
|
||||||
rootPath += "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range []string{
|
|
||||||
b.Config().Workspace.ArtifactPath,
|
|
||||||
b.Config().Workspace.FilePath,
|
|
||||||
b.Config().Workspace.StatePath,
|
|
||||||
b.Config().Workspace.ResourcePath,
|
|
||||||
} {
|
|
||||||
if libraries.IsWorkspaceSharedPath(p) || libraries.IsVolumesPath(p) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(p, rootPath) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
paths = append(paths, p)
|
|
||||||
}
|
|
||||||
|
|
||||||
var diags diag.Diagnostics
|
var diags diag.Diagnostics
|
||||||
g, ctx := errgroup.WithContext(ctx)
|
g, ctx := errgroup.WithContext(ctx)
|
||||||
results := make([]diag.Diagnostics, len(paths))
|
results := make([]diag.Diagnostics, len(bundlePaths))
|
||||||
for i, p := range paths {
|
for i, p := range bundlePaths {
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
results[i] = checkFolderPermission(ctx, b, p)
|
results[i] = checkFolderPermission(ctx, b, p)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -38,6 +38,7 @@ func IsWorkspaceLibrary(library *compute.Library) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsVolumesPath returns true if the specified path indicates that
|
// IsVolumesPath returns true if the specified path indicates that
|
||||||
|
// it should be interpreted as a Databricks Volumes path.
|
||||||
func IsVolumesPath(path string) bool {
|
func IsVolumesPath(path string) bool {
|
||||||
return strings.HasPrefix(path, "/Volumes/")
|
return strings.HasPrefix(path, "/Volumes/")
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package paths
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/databricks/cli/bundle/config"
|
||||||
|
"github.com/databricks/cli/bundle/libraries"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CollectUniquePaths(workspace config.Workspace) []string {
|
||||||
|
rootPath := workspace.RootPath
|
||||||
|
paths := []string{}
|
||||||
|
if !libraries.IsVolumesPath(rootPath) && !libraries.IsWorkspaceSharedPath(rootPath) {
|
||||||
|
paths = append(paths, rootPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !strings.HasSuffix(rootPath, "/") {
|
||||||
|
rootPath += "/"
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range []string{
|
||||||
|
workspace.ArtifactPath,
|
||||||
|
workspace.FilePath,
|
||||||
|
workspace.StatePath,
|
||||||
|
workspace.ResourcePath,
|
||||||
|
} {
|
||||||
|
if libraries.IsWorkspaceSharedPath(p) || libraries.IsVolumesPath(p) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(p, rootPath) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
paths = append(paths, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths
|
||||||
|
}
|
|
@ -3,10 +3,9 @@ package permissions
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle"
|
"github.com/databricks/cli/bundle"
|
||||||
"github.com/databricks/cli/bundle/libraries"
|
"github.com/databricks/cli/bundle/paths"
|
||||||
"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"
|
"golang.org/x/sync/errgroup"
|
||||||
|
@ -55,38 +54,10 @@ func giveAccessForWorkspaceRoot(ctx context.Context, b *bundle.Bundle) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
w := b.WorkspaceClient().Workspace
|
w := b.WorkspaceClient().Workspace
|
||||||
rootPath := b.Config.Workspace.RootPath
|
bundlePaths := paths.CollectUniquePaths(b.Config.Workspace)
|
||||||
paths := []string{}
|
|
||||||
if !libraries.IsVolumesPath(rootPath) {
|
|
||||||
paths = append(paths, rootPath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !strings.HasSuffix(rootPath, "/") {
|
|
||||||
rootPath += "/"
|
|
||||||
}
|
|
||||||
|
|
||||||
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) &&
|
|
||||||
!libraries.IsVolumesPath(b.Config.Workspace.FilePath) {
|
|
||||||
paths = append(paths, b.Config.Workspace.FilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
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) &&
|
|
||||||
!libraries.IsVolumesPath(b.Config.Workspace.ResourcePath) {
|
|
||||||
paths = append(paths, b.Config.Workspace.ResourcePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
g, ctx := errgroup.WithContext(ctx)
|
g, ctx := errgroup.WithContext(ctx)
|
||||||
for _, p := range paths {
|
for _, p := range bundlePaths {
|
||||||
g.Go(func() error {
|
g.Go(func() error {
|
||||||
return setPermissions(ctx, w, p, permissions)
|
return setPermissions(ctx, w, p, permissions)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue