Skip to content
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

Added validator for folder permissions #1824

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

andrewnester
Copy link
Contributor

Changes

This validator checks permissions defined in top-level bundle config and permissions set in workspace and raises the warning if they don't match

Tests

Warning: permission not found

Permission (level: CAN_MANAGE, user_name: [email protected]) not set for bundle workspace folder /Workspace/Users/[email protected]/.bundle/clusters/dev
Bundle permissions:
- level: CAN_MANAGE, user_name: [email protected]
- level: CAN_MANAGE, user_name: [email protected]

Workspace permissions:
- levels: [CAN_MANAGE], user_name: [email protected]
- levels: [CAN_MANAGE], group_name: admins

bundle/config/validate/folder_permissions.go Outdated Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Outdated Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Outdated Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Outdated Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Outdated Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Outdated Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Outdated Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Outdated Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Show resolved Hide resolved
bundle/config/validate/folder_permissions.go Outdated Show resolved Hide resolved
if !strings.HasPrefix(b.Config().Workspace.ResourcePath, rootPath) &&
!libraries.IsVolumesPath(b.Config().Workspace.ResourcePath) {
paths = append(paths, b.Config().Workspace.ResourcePath)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the logic expanded like this, it can be a loop on the different paths.

bundle/config/validate/folder_permissions.go Show resolved Hide resolved
bundle/permissions/check.go Outdated Show resolved Hide resolved
bundle/permissions/check.go Outdated Show resolved Hide resolved
bundle/permissions/check.go Outdated Show resolved Hide resolved
bundle/permissions/check.go Outdated Show resolved Hide resolved
bundle/permissions/check.go Show resolved Hide resolved
for i, p := range paths {
g.Go(func() error {
diags, err, _ := syncGroup.Do(p, func() (any, error) {
diags := checkFolderPermission(ctx, b, p)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These paths are different by design so there won't be reuse at this level. I figured you could initialize the sync group here and pass it to checkFolderPermissions. Then inside of getClosestExistingObject, you can use syncGroup.Do() to make sure you're only doing a single call for any given path at any level.

Those calls will be done multiple times in the current approach.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, this will apply only to cases where the different paths are not a child of the root. This should be infrequent enough that we can skip caching altogether.

"github.com/stretchr/testify/require"
)

func TestValidateFolderPermissions(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add suffix to capture the intent; I believe it is to test what happens if the root path doesn't exist yet.

require.Empty(t, diags)
}

func TestValidateFolderPermissionsDifferentCount(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer about a different count.

require.Equal(t, diag.Warning, diags[1].Severity)
}

func TestNoRootFolder(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing prefix: TestValidateFolderPermissions

bundle/permissions/check.go Outdated Show resolved Hide resolved
bundle/permissions/check.go Outdated Show resolved Hide resolved
if perm.UserName != "" {
sb.WriteString(fmt.Sprintf("- level: %s\n user_name: %s\n", perm.Level, perm.UserName))
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this use p.String() defined in permission.go?

}

return fmt.Sprintf("level: %s", p.Level)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also see comment below; if this is not used it can be removed.

andrewnester and others added 2 commits October 16, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants