-
Notifications
You must be signed in to change notification settings - Fork 153
Use SetPermissions instead of UpdatePermissions when setting folder permissions based on top-level ones #1822
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package paths | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/databricks/cli/bundle/config" | ||
| "github.com/databricks/cli/bundle/libraries" | ||
| ) | ||
|
|
||
| func CollectUniqueWorkspacePathPrefixes(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 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,10 @@ import ( | |
| "fmt" | ||
|
|
||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/bundle/paths" | ||
| "github.com/databricks/cli/libs/diag" | ||
| "github.com/databricks/databricks-sdk-go/service/workspace" | ||
| "golang.org/x/sync/errgroup" | ||
| ) | ||
|
|
||
| type workspaceRootPermissions struct { | ||
|
|
@@ -52,16 +54,30 @@ func giveAccessForWorkspaceRoot(ctx context.Context, b *bundle.Bundle) error { | |
| } | ||
|
|
||
| w := b.WorkspaceClient().Workspace | ||
| obj, err := w.GetStatusByPath(ctx, b.Config.Workspace.RootPath) | ||
| bundlePaths := paths.CollectUniqueWorkspacePathPrefixes(b.Config.Workspace) | ||
|
|
||
| g, ctx := errgroup.WithContext(ctx) | ||
| for _, p := range bundlePaths { | ||
| 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 { | ||
| obj, err := w.GetStatusByPath(ctx, path) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it guaranteed that all paths exist at this point? If not, then this function should do a create-if-not-exists.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's guaranteed because it's done after files.Upload
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this also hold for the other paths?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrewnester Can you clarify this one? E.g. does the state path or the resources path exist after
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, all of them will be created prior, the current mutator order is |
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, err = w.UpdatePermissions(ctx, workspace.WorkspaceObjectPermissionsRequest{ | ||
| _, err = w.SetPermissions(ctx, workspace.WorkspaceObjectPermissionsRequest{ | ||
| WorkspaceObjectId: fmt.Sprint(obj.ObjectId), | ||
| WorkspaceObjectType: "directories", | ||
| AccessControlList: permissions, | ||
| }) | ||
|
|
||
| return err | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.