-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SetPermissions instead of UpdatePermissions when setting folder p…
…ermissions based on top-level ones (#1822) ## Changes Changed to use SetPermissions() to configure the permissions which remove other permissions on deployment folders. ## Tests Added unit test
- Loading branch information
1 parent
1896b09
commit f018daf
Showing
5 changed files
with
181 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,11 @@ func TestApplyWorkspaceRootPermissions(t *testing.T) { | |
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Workspace: config.Workspace{ | ||
RootPath: "/Users/[email protected]", | ||
RootPath: "/Users/[email protected]", | ||
ArtifactPath: "/Users/[email protected]/artifacts", | ||
FilePath: "/Users/[email protected]/files", | ||
StatePath: "/Users/[email protected]/state", | ||
ResourcePath: "/Users/[email protected]/resources", | ||
}, | ||
Permissions: []resources.Permission{ | ||
{Level: CAN_MANAGE, UserName: "TestUser"}, | ||
|
@@ -59,7 +63,7 @@ func TestApplyWorkspaceRootPermissions(t *testing.T) { | |
workspaceApi.EXPECT().GetStatusByPath(mock.Anything, "/Users/[email protected]").Return(&workspace.ObjectInfo{ | ||
ObjectId: 1234, | ||
}, nil) | ||
workspaceApi.EXPECT().UpdatePermissions(mock.Anything, workspace.WorkspaceObjectPermissionsRequest{ | ||
workspaceApi.EXPECT().SetPermissions(mock.Anything, workspace.WorkspaceObjectPermissionsRequest{ | ||
AccessControlList: []workspace.WorkspaceObjectAccessControlRequest{ | ||
{UserName: "TestUser", PermissionLevel: "CAN_MANAGE"}, | ||
{GroupName: "TestGroup", PermissionLevel: "CAN_READ"}, | ||
|
@@ -72,3 +76,116 @@ func TestApplyWorkspaceRootPermissions(t *testing.T) { | |
diags := bundle.Apply(context.Background(), b, bundle.Seq(ValidateSharedRootPermissions(), ApplyWorkspaceRootPermissions())) | ||
require.Empty(t, diags) | ||
} | ||
|
||
func TestApplyWorkspaceRootPermissionsForAllPaths(t *testing.T) { | ||
b := &bundle.Bundle{ | ||
Config: config.Root{ | ||
Workspace: config.Workspace{ | ||
RootPath: "/Some/Root/Path", | ||
ArtifactPath: "/Users/[email protected]/artifacts", | ||
FilePath: "/Users/[email protected]/files", | ||
StatePath: "/Users/[email protected]/state", | ||
ResourcePath: "/Users/[email protected]/resources", | ||
}, | ||
Permissions: []resources.Permission{ | ||
{Level: CAN_MANAGE, UserName: "TestUser"}, | ||
{Level: CAN_VIEW, GroupName: "TestGroup"}, | ||
{Level: CAN_RUN, ServicePrincipalName: "TestServicePrincipal"}, | ||
}, | ||
Resources: config.Resources{ | ||
Jobs: map[string]*resources.Job{ | ||
"job_1": {JobSettings: &jobs.JobSettings{Name: "job_1"}}, | ||
"job_2": {JobSettings: &jobs.JobSettings{Name: "job_2"}}, | ||
}, | ||
Pipelines: map[string]*resources.Pipeline{ | ||
"pipeline_1": {PipelineSpec: &pipelines.PipelineSpec{}}, | ||
"pipeline_2": {PipelineSpec: &pipelines.PipelineSpec{}}, | ||
}, | ||
Models: map[string]*resources.MlflowModel{ | ||
"model_1": {Model: &ml.Model{}}, | ||
"model_2": {Model: &ml.Model{}}, | ||
}, | ||
Experiments: map[string]*resources.MlflowExperiment{ | ||
"experiment_1": {Experiment: &ml.Experiment{}}, | ||
"experiment_2": {Experiment: &ml.Experiment{}}, | ||
}, | ||
ModelServingEndpoints: map[string]*resources.ModelServingEndpoint{ | ||
"endpoint_1": {CreateServingEndpoint: &serving.CreateServingEndpoint{}}, | ||
"endpoint_2": {CreateServingEndpoint: &serving.CreateServingEndpoint{}}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
m := mocks.NewMockWorkspaceClient(t) | ||
b.SetWorkpaceClient(m.WorkspaceClient) | ||
workspaceApi := m.GetMockWorkspaceAPI() | ||
workspaceApi.EXPECT().GetStatusByPath(mock.Anything, "/Some/Root/Path").Return(&workspace.ObjectInfo{ | ||
ObjectId: 1, | ||
}, nil) | ||
workspaceApi.EXPECT().GetStatusByPath(mock.Anything, "/Users/[email protected]/artifacts").Return(&workspace.ObjectInfo{ | ||
ObjectId: 2, | ||
}, nil) | ||
workspaceApi.EXPECT().GetStatusByPath(mock.Anything, "/Users/[email protected]/files").Return(&workspace.ObjectInfo{ | ||
ObjectId: 3, | ||
}, nil) | ||
workspaceApi.EXPECT().GetStatusByPath(mock.Anything, "/Users/[email protected]/state").Return(&workspace.ObjectInfo{ | ||
ObjectId: 4, | ||
}, nil) | ||
workspaceApi.EXPECT().GetStatusByPath(mock.Anything, "/Users/[email protected]/resources").Return(&workspace.ObjectInfo{ | ||
ObjectId: 5, | ||
}, nil) | ||
|
||
workspaceApi.EXPECT().SetPermissions(mock.Anything, workspace.WorkspaceObjectPermissionsRequest{ | ||
AccessControlList: []workspace.WorkspaceObjectAccessControlRequest{ | ||
{UserName: "TestUser", PermissionLevel: "CAN_MANAGE"}, | ||
{GroupName: "TestGroup", PermissionLevel: "CAN_READ"}, | ||
{ServicePrincipalName: "TestServicePrincipal", PermissionLevel: "CAN_RUN"}, | ||
}, | ||
WorkspaceObjectId: "1", | ||
WorkspaceObjectType: "directories", | ||
}).Return(nil, nil) | ||
|
||
workspaceApi.EXPECT().SetPermissions(mock.Anything, workspace.WorkspaceObjectPermissionsRequest{ | ||
AccessControlList: []workspace.WorkspaceObjectAccessControlRequest{ | ||
{UserName: "TestUser", PermissionLevel: "CAN_MANAGE"}, | ||
{GroupName: "TestGroup", PermissionLevel: "CAN_READ"}, | ||
{ServicePrincipalName: "TestServicePrincipal", PermissionLevel: "CAN_RUN"}, | ||
}, | ||
WorkspaceObjectId: "2", | ||
WorkspaceObjectType: "directories", | ||
}).Return(nil, nil) | ||
|
||
workspaceApi.EXPECT().SetPermissions(mock.Anything, workspace.WorkspaceObjectPermissionsRequest{ | ||
AccessControlList: []workspace.WorkspaceObjectAccessControlRequest{ | ||
{UserName: "TestUser", PermissionLevel: "CAN_MANAGE"}, | ||
{GroupName: "TestGroup", PermissionLevel: "CAN_READ"}, | ||
{ServicePrincipalName: "TestServicePrincipal", PermissionLevel: "CAN_RUN"}, | ||
}, | ||
WorkspaceObjectId: "3", | ||
WorkspaceObjectType: "directories", | ||
}).Return(nil, nil) | ||
|
||
workspaceApi.EXPECT().SetPermissions(mock.Anything, workspace.WorkspaceObjectPermissionsRequest{ | ||
AccessControlList: []workspace.WorkspaceObjectAccessControlRequest{ | ||
{UserName: "TestUser", PermissionLevel: "CAN_MANAGE"}, | ||
{GroupName: "TestGroup", PermissionLevel: "CAN_READ"}, | ||
{ServicePrincipalName: "TestServicePrincipal", PermissionLevel: "CAN_RUN"}, | ||
}, | ||
WorkspaceObjectId: "4", | ||
WorkspaceObjectType: "directories", | ||
}).Return(nil, nil) | ||
|
||
workspaceApi.EXPECT().SetPermissions(mock.Anything, workspace.WorkspaceObjectPermissionsRequest{ | ||
AccessControlList: []workspace.WorkspaceObjectAccessControlRequest{ | ||
{UserName: "TestUser", PermissionLevel: "CAN_MANAGE"}, | ||
{GroupName: "TestGroup", PermissionLevel: "CAN_READ"}, | ||
{ServicePrincipalName: "TestServicePrincipal", PermissionLevel: "CAN_RUN"}, | ||
}, | ||
WorkspaceObjectId: "5", | ||
WorkspaceObjectType: "directories", | ||
}).Return(nil, nil) | ||
|
||
diags := bundle.Apply(context.Background(), b, ApplyWorkspaceRootPermissions()) | ||
require.NoError(t, diags.Error()) | ||
} |